View Javadoc

1   /*
2    * $Id: MulticastConnector.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.providers.multicast;
12  
13  import org.mule.providers.udp.UdpConnector;
14  import org.mule.umo.UMOComponent;
15  import org.mule.umo.endpoint.UMOEndpoint;
16  import org.mule.umo.lifecycle.InitialisationException;
17  
18  /**
19   * <code>MulticastConnector</code> can dispatch mule events using ip multicasting
20   */
21  public class MulticastConnector extends UdpConnector
22  {
23      private boolean loopback = false;
24      private int timeToLive = INT_VALUE_NOT_SET;
25  
26      public String getProtocol()
27      {
28          return "multicast";
29      }
30  
31  
32      //@java.lang.Override
33      protected void doInitialise() throws InitialisationException
34      {
35          dispatcherSocketsPool.setFactory(new MulticastSocketFactory());
36          dispatcherSocketsPool.setTestOnBorrow(false);
37          dispatcherSocketsPool.setTestOnReturn(true);
38          //For clarity, note that the max active value does not need to be 1 since you can have multiple
39          //Multicast sockets bound to a single port
40          //dispatcherSocketsPool.setMaxActive(1);
41      }
42  
43      public boolean isLoopback()
44      {
45          return loopback;
46      }
47  
48      public void setLoopback(boolean loopback)
49      {
50          this.loopback = loopback;
51      }
52  
53  
54      public int getTimeToLive()
55      {
56          return timeToLive;
57      }
58  
59      public void setTimeToLive(int timeToLive)
60      {
61          this.timeToLive = timeToLive;
62      }
63  
64  
65      //@java.lang.Override
66      protected Object getReceiverKey(UMOComponent component, UMOEndpoint endpoint)
67      {
68          //you can have multiple Multicast sockets bound to a single port,
69          // so store listeners with the component name too
70          return endpoint.getEndpointURI().getAddress() + "/" + component.getDescriptor().getName();
71      }
72  }