View Javadoc

1   /*
2    *  Copyright 2004-2006 Stefan Reuter
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *
16   */
17  package org.asteriskjava.manager.internal;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  
22  import org.asteriskjava.manager.ResponseEvents;
23  import org.asteriskjava.manager.event.ResponseEvent;
24  import org.asteriskjava.manager.response.ManagerResponse;
25  
26  
27  /***
28   * Implementation of the ResponseEvents interface.
29   * 
30   * @author srt
31   * @version $Id: ResponseEventsImpl.java 260 2006-05-07 11:08:35Z srt $
32   * @since 0.2
33   */
34  public class ResponseEventsImpl implements ResponseEvents
35  {
36      private ManagerResponse response;
37      private final Collection<ResponseEvent> events;
38      private boolean complete;
39  
40      /***
41       * Creates a new instance.
42       */
43      public ResponseEventsImpl()
44      {
45          this.events = new ArrayList<ResponseEvent>();
46          this.complete = false;
47      }
48  
49      // implementation of the ResponseEvents interface
50  
51      public ManagerResponse getResponse()
52      {
53          return response;
54      }
55  
56      public Collection<ResponseEvent> getEvents()
57      {
58          return events;
59      }
60  
61      public boolean isComplete()
62      {
63          return complete;
64      }
65  
66      // helper methods to populate the ResponseEvents object
67  
68      /***
69       * Sets the ManagerResponse received.
70       * 
71       * @param response the ManagerResponse received.
72       */
73      public void setRepsonse(ManagerResponse response)
74      {
75          this.response = response;
76      }
77  
78      /***
79       * Adds a ResponseEvent that has been received.
80       * 
81       * @param event the ResponseEvent that has been received.
82       */
83      public void addEvent(ResponseEvent event)
84      {
85          synchronized (events)
86          {
87              events.add(event);
88          }
89      }
90  
91      /***
92       * Indicats if all events have been received.
93       * 
94       * @param complete <code>true</code> if all events have been received,
95       *            <code>false</code> otherwise.
96       */
97      public void setComplete(boolean complete)
98      {
99          this.complete = complete;
100     }
101 }