Coverage Report - org.mule.providers.multicast.MulticastSocketFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
MulticastSocketFactory
5%
1/22
0%
0/4
1.6
 
 1  
 /*
 2  
  * $Id: MulticastSocketFactory.java 7963 2007-08-21 08:53:15Z 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  
 package org.mule.providers.multicast;
 11  
 
 12  
 import org.mule.providers.udp.UdpSocketFactory;
 13  
 import org.mule.umo.endpoint.UMOImmutableEndpoint;
 14  
 import org.mule.umo.provider.UMOConnector;
 15  
 
 16  
 import java.io.IOException;
 17  
 import java.net.DatagramSocket;
 18  
 import java.net.InetAddress;
 19  
 import java.net.MulticastSocket;
 20  
 
 21  
 /**
 22  
  * TODO
 23  
  */
 24  22
 public class MulticastSocketFactory extends UdpSocketFactory
 25  
 {
 26  
 
 27  
     public Object makeObject(Object key) throws Exception
 28  
     {
 29  0
         UMOImmutableEndpoint ep = (UMOImmutableEndpoint)key;
 30  0
         MulticastSocket socket = (MulticastSocket)super.makeObject(key);
 31  0
         socket.setLoopbackMode(((MulticastConnector)ep.getConnector()).isLoopback());
 32  0
         int ttl  = ((MulticastConnector)ep.getConnector()).getTimeToLive();
 33  0
         if(ttl!= UMOConnector.INT_VALUE_NOT_SET)
 34  
         {
 35  0
             socket.setTimeToLive(ttl);
 36  
         }
 37  0
         return socket;
 38  
     }
 39  
 
 40  
 
 41  
     //@java.lang.Override
 42  
     public void destroyObject(Object key, Object object) throws Exception
 43  
     {
 44  0
         UMOImmutableEndpoint ep = (UMOImmutableEndpoint)key;
 45  
         InetAddress inetAddress;
 46  0
         String host = ep.getEndpointURI().getHost();
 47  0
         if("null".equalsIgnoreCase(host))
 48  
         {
 49  0
             inetAddress = InetAddress.getLocalHost();
 50  
         }
 51  
         else
 52  
         {
 53  0
             inetAddress = InetAddress.getByName(host);
 54  
         }
 55  0
         MulticastSocket socket = (MulticastSocket)object;
 56  0
         socket.leaveGroup(inetAddress);
 57  0
         super.destroyObject(key, object);
 58  0
     }
 59  
 
 60  
     protected DatagramSocket createSocket() throws IOException
 61  
     {
 62  0
         return new MulticastSocket();
 63  
     }
 64  
 
 65  
     protected DatagramSocket createSocket(int port) throws IOException
 66  
     {
 67  0
         throw new IllegalArgumentException("A group host or IP address is required");
 68  
     }
 69  
 
 70  
     protected DatagramSocket createSocket(int port, InetAddress inetAddress) throws IOException
 71  
     {
 72  0
         MulticastSocket socket = new MulticastSocket(port);
 73  0
         socket.joinGroup(inetAddress);
 74  0
         return socket;
 75  
     }
 76  
 }