KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > multicast > MulticastMessageDispatcher


1 /*
2  * $Id: MulticastMessageDispatcher.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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.UdpMessageDispatcher;
14 import org.mule.umo.endpoint.UMOImmutableEndpoint;
15
16 import java.io.IOException JavaDoc;
17 import java.net.DatagramSocket JavaDoc;
18 import java.net.InetAddress JavaDoc;
19 import java.net.MulticastSocket JavaDoc;
20
21 /**
22  * <code>MulticastMessageDispatcher</code> dispatches events to a multicast address
23  *
24  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
25  * @version $Revision: 3798 $
26  */

27
28 public class MulticastMessageDispatcher extends UdpMessageDispatcher
29 {
30     public MulticastMessageDispatcher(UMOImmutableEndpoint endpoint)
31     {
32         super(endpoint);
33     }
34
35     protected DatagramSocket JavaDoc createSocket(int port, InetAddress JavaDoc inetAddress) throws IOException JavaDoc
36     {
37         MulticastSocket JavaDoc socket = new MulticastSocket JavaDoc(port);
38         socket.setLoopbackMode(((MulticastConnector)connector).isLoopback());
39         // socket.setBroadcast(connector.getBroadcast());
40
socket.setReceiveBufferSize(connector.getBufferSize());
41         socket.setSendBufferSize(connector.getBufferSize());
42         socket.joinGroup(inetAddress);
43         return socket;
44     }
45
46     protected void doDisconnect() throws Exception JavaDoc
47     {
48         try
49         {
50             if (socket != null)
51             {
52                 ((MulticastSocket JavaDoc)socket).leaveGroup(inetAddress);
53             }
54         }
55         catch (IOException JavaDoc e)
56         {
57             logger.error("Failed to leave group: " + inetAddress);
58         }
59         super.doDisconnect();
60     }
61 }
62
Popular Tags