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.codehaus.activemq.transport;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import javax.jms.JMSException;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
27
28 /***
29 * An abstract base class useful for implementation inheritence
30 *
31 * @version $Revision: 1.3 $
32 */
33 public abstract class TransportServerChannelSupport implements TransportServerChannel {
34
35 private static final Log log = LogFactory.getLog(TransportServerChannelSupport.class);
36
37 private TransportChannelListener listener;
38 private List channels = new ArrayList();
39
40 public void start() throws JMSException {
41 if (listener == null) {
42 throw new JMSException("Must have a TransportChannelListener attached!");
43 }
44 }
45
46 public synchronized void stop() {
47 for (Iterator iter = channels.iterator(); iter.hasNext();) {
48 TransportChannel channel = (TransportChannel) iter.next();
49 channel.stop();
50 }
51 }
52
53 public void setTransportChannelListener(TransportChannelListener listener) {
54 this.listener = listener;
55 }
56
57 protected synchronized void addClient(TransportChannel channel) {
58 if (listener == null) {
59 log.warn("No listener attached, cannot add channel: " + channel);
60 }
61 else {
62 listener.addClient(channel);
63 channel.setTransportChannelListener(listener);
64 channels.add(channel);
65 }
66 }
67 }