View Javadoc

1   /*
2    * Copyright  2004-2005 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 net.sf.asterisk.manager.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  
22  import net.sf.asterisk.manager.ResponseEvents;
23  import net.sf.asterisk.manager.event.ResponseEvent;
24  import net.sf.asterisk.manager.response.ManagerResponse;
25  
26  /***
27   * Implementation of the ResponseEvents interface.
28   * 
29   * @author srt
30   * @version $Id: ResponseEventsImpl.java,v 1.1 2005/07/16 21:48:16 srt Exp $
31   * @since 0.2
32   */
33  public class ResponseEventsImpl implements ResponseEvents
34  {
35      private ManagerResponse response;
36      private final Collection events;
37      private boolean complete;
38  
39      /***
40       * Creates a new instance.
41       */
42      public ResponseEventsImpl()
43      {
44          this.events = new ArrayList();
45          this.complete = false;
46      }
47  
48      // implementation of the ResponseEvents interface
49  
50      public ManagerResponse getResponse()
51      {
52          return response;
53      }
54  
55      public Collection getEvents()
56      {
57          return events;
58      }
59  
60      public boolean isComplete()
61      {
62          return complete;
63      }
64  
65      // helper methods to populate the ResponseEvents object
66  
67      /***
68       * Sets the ManagerResponse received.
69       * 
70       * @param response the ManagerResponse received.
71       */
72      public void setRepsonse(ManagerResponse response)
73      {
74          this.response = response;
75      }
76  
77      /***
78       * Adds a ResponseEvent that has been received.
79       * 
80       * @param event the ResponseEvent that has been received.
81       */
82      public void addEvent(ResponseEvent event)
83      {
84          synchronized (events)
85          {
86              events.add(event);
87          }
88      }
89  
90      /***
91       * Indicats if all events have been received.
92       * 
93       * @param complete <code>true</code> if all events have been received,
94       *            <code>false</code> otherwise.
95       */
96      public void setComplete(boolean complete)
97      {
98          this.complete = complete;
99      }
100 }