1 /* 2 * $Id: FixedHostRmiClientSocketFactory.java 11234 2008-03-06 23:44:34Z tcarlson $ 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.module.management.agent; 12 13 import java.io.IOException; 14 import java.io.Serializable; 15 import java.net.Socket; 16 import java.rmi.server.RMIClientSocketFactory; 17 18 /** 19 * This implementation will enforce specific overrideHost/ip for RMI calls on multi-NIC servers. 20 * TODO MULE-1440 this should probably be moved into the RMI transport. 21 */ 22 public class FixedHostRmiClientSocketFactory implements RMIClientSocketFactory, Serializable 23 { 24 /** 25 * Host to use instead of the default one. 26 */ 27 private String overrideHost; 28 29 /** 30 * Default constructor. 31 */ 32 public FixedHostRmiClientSocketFactory () 33 { 34 } 35 36 /** 37 * Create a new instance. 38 * @param overrideHost host/ip to enforce 39 */ 40 public FixedHostRmiClientSocketFactory (final String overrideHost) 41 { 42 this.overrideHost = overrideHost; 43 } 44 45 /** 46 * Create a client socket connected to the specified overrideHost and port. 47 * 48 * @param host the host name IGNORED if an override configured 49 * @param port the port number 50 * @return a socket connected to the specified overrideHost and port. 51 * @throws java.io.IOException if an I/O error occurs during socket creation 52 */ 53 public Socket createSocket (String host, int port) throws IOException 54 { 55 /* NOTE this is StringUtils.defaultIfEmpty(overrideHost, host) 56 This socket factory is required on the client, minimize the dependency graph 57 */ 58 final String hostToUse = (overrideHost == null || overrideHost.trim().length() == 0) ? host : overrideHost; 59 60 return new Socket(hostToUse, port); 61 } 62 63 /** 64 * Getter for property 'overrideHost'. 65 * 66 * @return Value for property 'overrideHost'. 67 */ 68 public String getOverrideHost () 69 { 70 return overrideHost; 71 } 72 73 /** 74 * Setter for property 'overrideHost'. 75 * 76 * @param overrideHost Value to set for property 'overrideHost'. 77 */ 78 public void setOverrideHost (final String overrideHost) 79 { 80 this.overrideHost = overrideHost; 81 } 82 }