[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/socketfactory ...
Ron Sigal
ron_sigal at yahoo.com
Tue Jan 16 03:12:21 EST 2007
User: rsigal
Date: 07/01/16 03:12:21
Added: src/main/org/jboss/remoting/socketfactory
SocketCreationListener.java
ServerSocketFactoryWrapper.java
CreationListenerServerSocketFactory.java
CreationListenerServerSocket.java
CreationListenerSocketFactory.java
SocketFactoryWrapper.java
Log:
JBREM-298: Added classes to support socket creation listener facility.
Revision Changes Path
1.2 +37 -0 JBossRemoting/src/main/org/jboss/remoting/socketfactory/SocketCreationListener.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SocketCreationListener.java
===================================================================
RCS file: SocketCreationListener.java
diff -N SocketCreationListener.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SocketCreationListener.java 16 Jan 2007 08:12:21 -0000 1.2
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.remoting.socketfactory;
+
+import java.io.IOException;
+import java.net.Socket;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Jan 10, 2007
+ * </p>
+ */
+public interface SocketCreationListener
+{
+ void socketCreated(Socket socket) throws IOException;
+}
1.2 +38 -0 JBossRemoting/src/main/org/jboss/remoting/socketfactory/ServerSocketFactoryWrapper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ServerSocketFactoryWrapper.java
===================================================================
RCS file: ServerSocketFactoryWrapper.java
diff -N ServerSocketFactoryWrapper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ServerSocketFactoryWrapper.java 16 Jan 2007 08:12:21 -0000 1.2
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.remoting.socketfactory;
+
+import javax.net.ServerSocketFactory;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Jan 13, 2007
+ * </p>
+ */
+public interface ServerSocketFactoryWrapper
+{
+ ServerSocketFactory getServerSocketFactory();
+
+ void setServerSocketFactory(ServerSocketFactory factory);
+}
1.2 +99 -0 JBossRemoting/src/main/org/jboss/remoting/socketfactory/CreationListenerServerSocketFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CreationListenerServerSocketFactory.java
===================================================================
RCS file: CreationListenerServerSocketFactory.java
diff -N CreationListenerServerSocketFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CreationListenerServerSocketFactory.java 16 Jan 2007 08:12:21 -0000 1.2
@@ -0,0 +1,99 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.remoting.socketfactory;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+
+import javax.net.ServerSocketFactory;
+
+/**
+ * A CreationListenerServerSocketFactory wraps a ServerSocketFactory, and whenever
+ * the ServerSocketFactory creates a ServerSocket, the ServerSocket is wrapped in a
+ * CreationListenerServerSocket.
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Jan 10, 2007
+ * </p>
+ */
+public class CreationListenerServerSocketFactory
+ extends ServerSocketFactory
+ implements ServerSocketFactoryWrapper, Serializable
+{
+ private static final long serialVersionUID = -7939318527267014514L;
+
+ private ServerSocketFactory factory;
+ private SocketCreationListener listener;
+
+
+ public CreationListenerServerSocketFactory(ServerSocketFactory factory,
+ SocketCreationListener listener)
+ {
+ this.factory = factory;
+ this.listener = listener;
+ }
+
+
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket serverSocket = factory.createServerSocket();
+ return new CreationListenerServerSocket(serverSocket, listener);
+ }
+
+
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket serverSocket = factory.createServerSocket(port);
+ return new CreationListenerServerSocket(serverSocket, listener);
+ }
+
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket serverSocket = factory.createServerSocket(port, backlog);
+ return new CreationListenerServerSocket(serverSocket, listener);
+ }
+
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress)
+ throws IOException
+ {
+ ServerSocket serverSocket = factory.createServerSocket(port, backlog, ifAddress);
+ return new CreationListenerServerSocket(serverSocket, listener);
+ }
+
+
+ public ServerSocketFactory getServerSocketFactory()
+ {
+ return factory;
+ }
+
+
+ public void setServerSocketFactory(ServerSocketFactory factory)
+ {
+ this.factory = factory;
+ }
+}
1.2 +177 -0 JBossRemoting/src/main/org/jboss/remoting/socketfactory/CreationListenerServerSocket.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CreationListenerServerSocket.java
===================================================================
RCS file: CreationListenerServerSocket.java
diff -N CreationListenerServerSocket.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CreationListenerServerSocket.java 16 Jan 2007 08:12:21 -0000 1.2
@@ -0,0 +1,177 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.remoting.socketfactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.nio.channels.ServerSocketChannel;
+
+/**
+ * A CreationListenerServerSocket wraps a ServerSocket to which it delegates
+ * calls to accept(), and when the wrapped ServerSocket creates a Socket in
+ * accept(), a SocketCreationListener is notified before the Socket is returned.
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Jan 10, 2007
+ * </p>
+ */
+public class CreationListenerServerSocket extends ServerSocket
+{
+ private ServerSocket serverSocket;
+ private SocketCreationListener listener;
+
+
+ public CreationListenerServerSocket(ServerSocket serverSocket, SocketCreationListener listener)
+ throws IOException
+ {
+ this.serverSocket = serverSocket;
+ this.listener = listener;
+ }
+
+
+ public void bind(SocketAddress endpoint) throws IOException
+ {
+ serverSocket.bind(endpoint);
+ }
+
+
+ public void bind(SocketAddress endpoint, int backlog) throws IOException
+ {
+ serverSocket.bind(endpoint, backlog);
+ }
+
+
+ public Socket accept() throws IOException
+ {
+ Socket socket = serverSocket.accept();
+ listener.socketCreated(socket);
+ return socket;
+ }
+
+
+ public void close() throws IOException
+ {
+ serverSocket.close();
+ }
+
+
+ public boolean equals(Object obj)
+ {
+ return serverSocket.equals(obj);
+ }
+
+
+ public ServerSocketChannel getChannel()
+ {
+ return serverSocket.getChannel();
+ }
+
+
+ public InetAddress getInetAddress()
+ {
+ return serverSocket.getInetAddress();
+ }
+
+
+ public int getLocalPort()
+ {
+ return serverSocket.getLocalPort();
+ }
+
+
+ public SocketAddress getLocalSocketAddress()
+ {
+ return serverSocket.getLocalSocketAddress();
+ }
+
+
+ public int getReceiveBufferSize() throws SocketException
+ {
+ return serverSocket.getReceiveBufferSize();
+ }
+
+
+ public boolean getReuseAddress() throws SocketException
+ {
+ return serverSocket.getReuseAddress();
+ }
+
+
+ public int getSoTimeout() throws IOException
+ {
+ return serverSocket.getSoTimeout();
+ }
+
+
+ public int hashCode()
+ {
+ return serverSocket.hashCode();
+ }
+
+
+ public boolean isBound()
+ {
+ return serverSocket.isBound();
+ }
+
+
+ public boolean isClosed()
+ {
+ return serverSocket.isClosed();
+ }
+
+
+ public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)
+ {
+ serverSocket.setPerformancePreferences(connectionTime, latency, bandwidth);
+ }
+
+
+ public void setReceiveBufferSize(int size) throws SocketException
+ {
+ serverSocket.setReceiveBufferSize(size);
+ }
+
+
+ public void setReuseAddress(boolean on) throws SocketException
+ {
+ serverSocket.setReuseAddress(on);
+ }
+
+
+ public void setSoTimeout(int timeout) throws SocketException
+ {
+ serverSocket.setSoTimeout(timeout);
+ }
+
+
+ public String toString()
+ {
+ return serverSocket.toString();
+ }
+}
1.2 +162 -0 JBossRemoting/src/main/org/jboss/remoting/socketfactory/CreationListenerSocketFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CreationListenerSocketFactory.java
===================================================================
RCS file: CreationListenerSocketFactory.java
diff -N CreationListenerSocketFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CreationListenerSocketFactory.java 16 Jan 2007 08:12:21 -0000 1.2
@@ -0,0 +1,162 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.remoting.socketfactory;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+
+/**
+ * A CreationListenerSocketFactory wraps a SocketFactory and notifies a listener
+ * of the creation of a Socket before returning the socket.
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Jan 10, 2007
+ * </p>
+ */
+public class CreationListenerSocketFactory
+ extends SSLSocketFactory
+ implements SocketFactoryWrapper, Serializable
+{
+ private static final long serialVersionUID = 1210774093889434553L;
+
+ private SocketFactory factory;
+ private SocketCreationListener listener;
+
+
+ public CreationListenerSocketFactory(SocketCreationListener listener)
+ {
+ this(SocketFactory.getDefault(), listener);
+ }
+
+
+ public CreationListenerSocketFactory(SocketFactory factory, SocketCreationListener listener)
+ {
+ this.factory = factory;
+ this.listener = listener;
+ }
+
+
+ public Socket createSocket() throws IOException
+ {
+ checkFactory();
+ Socket socket = factory.createSocket();
+ listener.socketCreated(socket);
+ return socket;
+ }
+
+
+ public Socket createSocket(String host, int port)
+ throws IOException, UnknownHostException
+ {
+ checkFactory();
+ Socket socket = factory.createSocket(host, port);
+ listener.socketCreated(socket);
+ return socket;
+ }
+
+
+ public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
+ throws IOException, UnknownHostException
+ {
+ checkFactory();
+ Socket socket = factory.createSocket(host, port, clientHost, clientPort);
+ listener.socketCreated(socket);
+ return socket;
+ }
+
+
+ public Socket createSocket(InetAddress host, int port) throws IOException
+ {
+ checkFactory();
+ Socket socket = factory.createSocket(host, port);
+ listener.socketCreated(socket);
+ return socket;
+ }
+
+
+ public Socket createSocket(InetAddress address, int port, InetAddress clientAddress, int clientPort)
+ throws IOException
+ {
+ checkFactory();
+ Socket socket = factory.createSocket(address, port, clientAddress, clientPort);
+ listener.socketCreated(socket);
+ return socket;
+ }
+
+
+ public String[] getDefaultCipherSuites()
+ {
+ if (factory instanceof SSLSocketFactory)
+ return ((SSLSocketFactory) factory).getDefaultCipherSuites();
+ else
+ return null;
+ }
+
+
+ public String[] getSupportedCipherSuites()
+ {
+ if (factory instanceof SSLSocketFactory)
+ return ((SSLSocketFactory) factory).getSupportedCipherSuites();
+ else
+ return null;
+ }
+
+
+ public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException
+ {
+ if (factory instanceof SSLSocketFactory)
+ {
+ Socket socket = ((SSLSocketFactory) factory).createSocket(s, host, port, autoClose);
+ listener.socketCreated(socket);
+ return socket;
+ }
+ else
+ return null;
+ }
+
+
+ public SocketFactory getSocketFactory()
+ {
+ return factory;
+ }
+
+
+ public void setSocketFactory(SocketFactory factory)
+ {
+ this.factory = factory;
+ }
+
+
+ protected void checkFactory()
+ {
+ if (factory == null)
+ factory = SocketFactory.getDefault();
+ }
+}
1.2 +38 -0 JBossRemoting/src/main/org/jboss/remoting/socketfactory/SocketFactoryWrapper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SocketFactoryWrapper.java
===================================================================
RCS file: SocketFactoryWrapper.java
diff -N SocketFactoryWrapper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SocketFactoryWrapper.java 16 Jan 2007 08:12:21 -0000 1.2
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.remoting.socketfactory;
+
+import javax.net.SocketFactory;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Jan 13, 2007
+ * </p>
+ */
+public interface SocketFactoryWrapper
+{
+ SocketFactory getSocketFactory();
+
+ void setSocketFactory(SocketFactory factory);
+}
More information about the jboss-cvs-commits
mailing list