View Javadoc

1   /*
2    * $Id: MulticastConnector.java 10961 2008-02-22 19:01:02Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.multicast;
12  
13  import org.mule.api.endpoint.InboundEndpoint;
14  import org.mule.api.lifecycle.InitialisationException;
15  import org.mule.api.service.Service;
16  import org.mule.transport.udp.UdpConnector;
17  
18  /**
19   * <code>MulticastConnector</code> can dispatch mule events using ip multicasting
20   */
21  public class MulticastConnector extends UdpConnector
22  {
23  
24      public static final String MULTICAST = "multicast";
25      private boolean loopback = false;
26      private int timeToLive = INT_VALUE_NOT_SET;
27  
28      public String getProtocol()
29      {
30          return MULTICAST;
31      }
32  
33  
34      //@java.lang.Override
35      protected void doInitialise() throws InitialisationException
36      {
37          dispatcherSocketsPool.setFactory(new MulticastSocketFactory());
38          dispatcherSocketsPool.setTestOnBorrow(false);
39          dispatcherSocketsPool.setTestOnReturn(true);
40          //For clarity, note that the max active value does not need to be 1 since you can have multiple
41          //Multicast sockets bound to a single port
42          //dispatcherSocketsPool.setMaxActive(1);
43      }
44  
45      public boolean isLoopback()
46      {
47          return loopback;
48      }
49  
50      public void setLoopback(boolean loopback)
51      {
52          this.loopback = loopback;
53      }
54  
55  
56      public int getTimeToLive()
57      {
58          return timeToLive;
59      }
60  
61      public void setTimeToLive(int timeToLive)
62      {
63          this.timeToLive = timeToLive;
64      }
65  
66  
67      //@java.lang.Override
68      protected Object getReceiverKey(Service service, InboundEndpoint endpoint)
69      {
70          //you can have multiple Multicast sockets bound to a single port,
71          // so store listeners with the service name too
72          return endpoint.getEndpointURI().getAddress() + "/" + service.getName();
73      }
74  }