Coverage Report - org.mule.transport.tcp.TcpServerSocketFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
TcpServerSocketFactory
75%
9/12
30%
3/10
1.75
 
 1  
 /*
 2  
  * $Id: TcpServerSocketFactory.java 10489 2008-01-23 17:53:38Z dfeist $
 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.transport.tcp;
 12  
 
 13  
 import org.mule.util.StringUtils;
 14  
 
 15  
 import java.io.IOException;
 16  
 import java.net.InetAddress;
 17  
 import java.net.InetSocketAddress;
 18  
 import java.net.ServerSocket;
 19  
 import java.net.URI;
 20  
 
 21  132
 public class TcpServerSocketFactory implements SimpleServerSocketFactory
 22  
 {
 23  
 
 24  
     public ServerSocket createServerSocket(URI uri, int backlog, Boolean reuse) throws IOException
 25  
     {
 26  114
         String host = StringUtils.defaultIfEmpty(uri.getHost(), "localhost");
 27  114
         InetAddress inetAddress = InetAddress.getByName(host);
 28  
 
 29  114
         if (inetAddress.equals(InetAddress.getLocalHost())
 30  
                 || inetAddress.isLoopbackAddress()
 31  
                 || host.trim().equals("localhost"))
 32  
         {
 33  114
             return createServerSocket(uri.getPort(), backlog, reuse);
 34  
         }
 35  
         else
 36  
         {
 37  0
             return createServerSocket(inetAddress, uri.getPort(), backlog, reuse);
 38  
         }
 39  
     }
 40  
 
 41  
     public ServerSocket createServerSocket(InetAddress address, int port, int backlog, Boolean reuse) throws IOException
 42  
     {
 43  0
         return configure(new ServerSocket(), reuse, new InetSocketAddress(address, port), backlog);
 44  
     }
 45  
 
 46  
     public ServerSocket createServerSocket(int port, int backlog, Boolean reuse) throws IOException
 47  
     {
 48  114
         return configure(new ServerSocket(), reuse, new InetSocketAddress(port), backlog);
 49  
     }
 50  
 
 51  
     protected ServerSocket configure(ServerSocket socket, Boolean reuse, InetSocketAddress address, int backlog)
 52  
             throws IOException
 53  
     {
 54  114
         if (null != reuse && reuse.booleanValue() != socket.getReuseAddress())
 55  
         {
 56  0
             socket.setReuseAddress(reuse.booleanValue());
 57  
         }
 58  
         // bind *after* setting so_reuseaddress
 59  114
         socket.bind(address, backlog);
 60  114
         return socket;
 61  
     }
 62  
 
 63  
 }