Source code: org/activemq/transport/DiscoveryAgentSupport.java
1 /**
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.activemq.transport;
19 import java.util.Iterator;
20 import EDU.oswego.cs.dl.util.concurrent.*;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 /**
25 * A useful base class for {@link DiscoveryAgent} implementations
26 *
27 * @version $Revision: 1.1.1.1 $
28 */
29 public abstract class DiscoveryAgentSupport implements DiscoveryAgent {
30 private static final transient Log log = LogFactory.getLog(DiscoveryAgentSupport.class);
31
32 protected CopyOnWriteArrayList listeners = new CopyOnWriteArrayList();
33
34 /**
35 * Add a discovery listener
36 * @param listener
37 */
38 public void addDiscoveryListener(DiscoveryListener listener){
39 listeners.add(listener);
40 }
41
42 /**
43 * remove a discovery listener
44 * @param listener
45 */
46 public void removeDiscoveryListener(DiscoveryListener listener){
47 listeners.remove(listener);
48 }
49
50 protected void fireAddService(DiscoveryEvent event){
51 for(Iterator i = listeners.iterator(); i.hasNext();){
52 DiscoveryListener l = (DiscoveryListener)i.next();
53 if (log.isDebugEnabled()) {
54 log.debug("on Add service: " + event);
55 }
56 l.addService(event);
57 }
58 }
59
60 protected void fireRemoveService(DiscoveryEvent event){
61 for(Iterator i = listeners.iterator(); i.hasNext();){
62 DiscoveryListener l = (DiscoveryListener)i.next();
63 if (log.isDebugEnabled()) {
64 log.debug("on Remove service: " + event);
65 }
66 l.removeService(event);
67 }
68 }
69
70 }