Coverage Report - org.mule.module.management.agent.FixedHostRmiClientSocketFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
FixedHostRmiClientSocketFactory
0%
0/10
0%
0/4
1
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.management.agent;
 8  
 
 9  
 import java.io.IOException;
 10  
 import java.io.Serializable;
 11  
 import java.net.Socket;
 12  
 import java.rmi.server.RMIClientSocketFactory;
 13  
 
 14  
 /**
 15  
  * This implementation will enforce specific overrideHost/ip for RMI calls on multi-NIC servers.
 16  
  * TODO MULE-1440 this should probably be moved into the RMI transport.
 17  
  */
 18  
 public class FixedHostRmiClientSocketFactory implements RMIClientSocketFactory, Serializable
 19  
 {
 20  
     /**
 21  
      * Host to use instead of the default one.
 22  
      */
 23  
     private String overrideHost;
 24  
 
 25  
     /**
 26  
      * Default constructor.
 27  
      */
 28  
     public FixedHostRmiClientSocketFactory ()
 29  0
     {
 30  0
     }
 31  
 
 32  
     /**
 33  
      * Create a new instance.
 34  
      * @param overrideHost host/ip to enforce
 35  
      */
 36  
     public FixedHostRmiClientSocketFactory (final String overrideHost)
 37  0
     {
 38  0
         this.overrideHost = overrideHost;
 39  0
     }
 40  
 
 41  
     /**
 42  
      * Create a client socket connected to the specified overrideHost and port.
 43  
      *
 44  
      * @param host the host name IGNORED if an override configured
 45  
      * @param port the port number
 46  
      * @return a socket connected to the specified overrideHost and port.
 47  
      * @throws java.io.IOException if an I/O error occurs during socket creation
 48  
      */
 49  
     public Socket createSocket (String host, int port) throws IOException
 50  
     {
 51  
         /* NOTE this is StringUtils.defaultIfEmpty(overrideHost, host)
 52  
            This socket factory is required on the client, minimize the dependency graph
 53  
         */
 54  0
         final String hostToUse = (overrideHost == null || overrideHost.trim().length() == 0) ? host : overrideHost;
 55  
 
 56  0
         return new Socket(hostToUse, port);
 57  
     }
 58  
 
 59  
     /**
 60  
      * Getter for property 'overrideHost'.
 61  
      *
 62  
      * @return Value for property 'overrideHost'.
 63  
      */
 64  
     public String getOverrideHost ()
 65  
     {
 66  0
         return overrideHost;
 67  
     }
 68  
 
 69  
     /**
 70  
      * Setter for property 'overrideHost'.
 71  
      *
 72  
      * @param overrideHost Value to set for property 'overrideHost'.
 73  
      */
 74  
     public void setOverrideHost (final String overrideHost)
 75  
     {
 76  0
         this.overrideHost = overrideHost;
 77  0
     }
 78  
 }