01: /*
02: * $Id: MulticastConnector.java 10961 2008-02-22 19:01:02Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: public static final String MULTICAST = "multicast";
24: private boolean loopback = false;
25: private int timeToLive = INT_VALUE_NOT_SET;
26:
27: public String getProtocol() {
28: return MULTICAST;
29: }
30:
31: //@java.lang.Override
32: protected void doInitialise() throws InitialisationException {
33: dispatcherSocketsPool.setFactory(new MulticastSocketFactory());
34: dispatcherSocketsPool.setTestOnBorrow(false);
35: dispatcherSocketsPool.setTestOnReturn(true);
36: //For clarity, note that the max active value does not need to be 1 since you can have multiple
37: //Multicast sockets bound to a single port
38: //dispatcherSocketsPool.setMaxActive(1);
39: }
40:
41: public boolean isLoopback() {
42: return loopback;
43: }
44:
45: public void setLoopback(boolean loopback) {
46: this .loopback = loopback;
47: }
48:
49: public int getTimeToLive() {
50: return timeToLive;
51: }
52:
53: public void setTimeToLive(int timeToLive) {
54: this .timeToLive = timeToLive;
55: }
56:
57: //@java.lang.Override
58: protected Object getReceiverKey(Service service,
59: InboundEndpoint endpoint) {
60: //you can have multiple Multicast sockets bound to a single port,
61: // so store listeners with the service name too
62: return endpoint.getEndpointURI().getAddress() + "/"
63: + service.getName();
64: }
65: }
|