1 10 11 package org.mule.providers.multicast; 12 13 import org.mule.providers.AbstractConnector; 14 import org.mule.providers.udp.UdpMessageReceiver; 15 import org.mule.umo.UMOComponent; 16 import org.mule.umo.endpoint.UMOEndpoint; 17 import org.mule.umo.lifecycle.InitialisationException; 18 19 import javax.resource.spi.work.Work ; 20 21 import java.io.IOException ; 22 import java.net.DatagramPacket ; 23 import java.net.DatagramSocket ; 24 import java.net.InetAddress ; 25 import java.net.MulticastSocket ; 26 import java.net.URI ; 27 28 34 public class MulticastMessageReceiver extends UdpMessageReceiver 35 { 36 public MulticastMessageReceiver(AbstractConnector connector, UMOComponent component, UMOEndpoint endpoint) 37 throws InitialisationException 38 { 39 super(connector, component, endpoint); 40 } 41 42 protected DatagramSocket createSocket(URI uri, InetAddress inetAddress) throws IOException 43 { 44 MulticastSocket socket = new MulticastSocket (uri.getPort()); 47 socket.joinGroup(inetAddress); 48 return socket; 49 } 50 51 protected Work createWork(DatagramPacket packet) throws IOException 52 { 53 return new MulticastWorker(packet); 54 } 55 56 public class MulticastWorker extends UdpWorker 57 { 58 public MulticastWorker(DatagramPacket packet) 59 { 60 super(socket, packet); 61 } 62 63 public void dispose() 64 { 65 } 68 } 69 70 protected void doDispose() 71 { 72 if (socket != null && !socket.isClosed()) 73 { 74 try 75 { 76 ((MulticastSocket )socket).leaveGroup(inetAddress); 77 } 78 catch (IOException e) 79 { 80 logger.error("failed to leave group: " + e.getMessage(), e); 81 } 82 } 83 super.doDispose(); 84 } 85 } 86 | Popular Tags |