View Javadoc

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.multicast;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.codehaus.activemq.message.WireFormat;
23  import org.codehaus.activemq.transport.udp.UdpTransportChannel;
24  
25  import javax.jms.JMSException;
26  import java.io.IOException;
27  import java.net.DatagramSocket;
28  import java.net.MulticastSocket;
29  import java.net.URI;
30  
31  /***
32   * A multicast implementation of a TransportChannel
33   * 
34   * @version $Revision: 1.11 $
35   */
36  public class MulticastTransportChannel extends UdpTransportChannel {
37  
38      private static final Log log = LogFactory.getLog(MulticastTransportChannel.class);
39  
40      private boolean loopbackMode = false; // no loopback by default as we don't
41      // need to see our own messages
42  
43  
44      /***
45       * Connect to a remote Node - e.g. a Broker
46       *
47       * @param remoteLocation
48       * @throws JMSException
49       */
50      public MulticastTransportChannel(WireFormat wireFormat, URI remoteLocation) throws JMSException {
51          super(wireFormat, remoteLocation);
52      }
53  
54      /***
55       * @param socket
56       * @throws JMSException
57       */
58      public MulticastTransportChannel(WireFormat wireFormat, MulticastSocket socket) throws JMSException {
59          super(wireFormat, socket);
60      }
61  
62      public boolean isMulticast() {
63          return true;
64      }
65  
66      /***
67       * pretty print for object
68       * 
69       * @return String representation of this object
70       */
71      public String toString() {
72          return "MulticastTransportChannel: " + socket;
73      }
74  
75      protected void connect() throws IOException {
76          MulticastSocket msocket = (MulticastSocket) socket;
77          
78          //log.info("Creating multicast socket on port: " + port + " on
79          msocket.setLoopbackMode(loopbackMode);
80  
81          msocket.joinGroup(inetAddress);
82      }
83  
84      protected DatagramSocket createSocket(int port) throws IOException {
85          return new MulticastSocket(port);
86      }
87  
88  }