[jboss-cvs] JBossAS SVN: r57125 - branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Sep 25 00:50:07 EDT 2006
Author: scott.stark at jboss.org
Date: 2006-09-25 00:50:06 -0400 (Mon, 25 Sep 2006)
New Revision: 57125
Added:
branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/DefaultClientSocketFactory.java
Modified:
branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/DefaultSocketFactory.java
branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/TimeoutClientSocketFactory.java
Log:
JBAS3689, Add DefaultClientSocketFactory and toString overrides
Added: branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/DefaultClientSocketFactory.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/DefaultClientSocketFactory.java 2006-09-25 04:01:03 UTC (rev 57124)
+++ branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/DefaultClientSocketFactory.java 2006-09-25 04:50:06 UTC (rev 57125)
@@ -0,0 +1,96 @@
+/*
+* JBoss, the OpenSource J2EE webOS
+*
+* Distributable under LGPL license.
+* See terms of license at gnu.org.
+*/
+package org.jboss.net.sockets;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.rmi.server.RMIClientSocketFactory;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+/**
+ * A RMIClientSocketFactory that adds a bind address override of the server
+ * host to control what the address the client uses.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 30203 $
+ */
+public class DefaultClientSocketFactory
+ implements RMIClientSocketFactory, Serializable
+{
+ private static final long serialVersionUID = -920483051658660269L;
+ /** An override of the server address */
+ private InetAddress bindAddress;
+
+ public DefaultClientSocketFactory()
+ {
+ }
+
+ public String getBindAddress()
+ {
+ String address = null;
+ if( bindAddress != null )
+ address = bindAddress.getHostAddress();
+ return address;
+ }
+ public void setBindAddress(String host) throws UnknownHostException
+ {
+ bindAddress = InetAddress.getByName(host);
+ }
+
+ /**
+ * Create a server socket on the specified port (port 0 indicates
+ * an anonymous port).
+ * @param port the port number
+ * @return the server socket on the specified port
+ * @exception java.io.IOException if an I/O error occurs during server socket
+ * creation
+ * @since 1.2
+ */
+ public Socket createSocket(String host, int port) throws IOException
+ {
+ InetAddress addr = null;
+ if( bindAddress != null )
+ addr = bindAddress;
+ else
+ addr = InetAddress.getByName(host);
+ Socket s = new Socket(addr, port);
+ return s;
+ }
+
+ public boolean equals(Object obj)
+ {
+ boolean equals = obj instanceof DefaultClientSocketFactory;
+ if( equals && bindAddress != null )
+ {
+ DefaultClientSocketFactory dcsf = (DefaultClientSocketFactory) obj;
+ InetAddress dcsfa = dcsf.bindAddress;
+ if( dcsfa != null )
+ equals = bindAddress.equals(dcsfa);
+ else
+ equals = false;
+ }
+ return equals;
+ }
+ public int hashCode()
+ {
+ int hashCode = getClass().getName().hashCode();
+ if( bindAddress != null )
+ hashCode += bindAddress.toString().hashCode();
+ return hashCode;
+ }
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer(super.toString());
+ tmp.append('[');
+ tmp.append("bindAddress=");
+ tmp.append(bindAddress);
+ tmp.append(']');
+ return tmp.toString();
+ }
+}
Modified: branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/DefaultSocketFactory.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/DefaultSocketFactory.java 2006-09-25 04:01:03 UTC (rev 57124)
+++ branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/DefaultSocketFactory.java 2006-09-25 04:50:06 UTC (rev 57125)
@@ -127,4 +127,13 @@
hashCode += bindAddress.toString().hashCode();
return hashCode;
}
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer(super.toString());
+ tmp.append('[');
+ tmp.append("bindAddress=");
+ tmp.append(bindAddress);
+ tmp.append(']');
+ return tmp.toString();
+ }
}
Modified: branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/TimeoutClientSocketFactory.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/TimeoutClientSocketFactory.java 2006-09-25 04:01:03 UTC (rev 57124)
+++ branches/JBoss_4_0_3_SP1_JBAS-3689/common/src/main/org/jboss/net/sockets/TimeoutClientSocketFactory.java 2006-09-25 04:50:06 UTC (rev 57125)
@@ -10,11 +10,10 @@
import java.io.Serializable;
import java.rmi.server.RMIClientSocketFactory;
import java.net.Socket;
-import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore;
/**
* A RMIClientSocketFactory that installs a InterruptableInputStream to be
- * responsive to thead interruption events.
+ * responsive to thread interruption events.
*
* @author Scott.Stark at jboss.org
* @version $Revision$
@@ -23,11 +22,32 @@
implements RMIClientSocketFactory, Serializable
{
private static final long serialVersionUID = -920483051658660269L;
+ /** An override of the server address */
+ private String bindAddress;
+ /** The socket setSoTimeout */
+ private long timeout = 1000;
public TimeoutClientSocketFactory()
{
}
+ public String getBindAddress()
+ {
+ return bindAddress;
+ }
+ public void setBindAddress(String addr)
+ {
+ this.bindAddress = addr;
+ }
+ public long getTimeout()
+ {
+ return timeout;
+ }
+ public void setTimeout(long timeout)
+ {
+ this.timeout = timeout;
+ }
+
/**
* Create a server socket on the specified port (port 0 indicates
* an anonymous port).
@@ -39,12 +59,14 @@
*/
public Socket createSocket(String host, int port) throws IOException
{
+ if( bindAddress != null )
+ host = bindAddress;
Socket s = new Socket(host, port);
s.setSoTimeout(1000);
TimeoutSocket ts = new TimeoutSocket(s);
return ts;
}
-
+
public boolean equals(Object obj)
{
return obj instanceof TimeoutClientSocketFactory;
More information about the jboss-cvs-commits
mailing list