JBoss Remoting SVN: r5595 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-11-17 15:58:18 -0500 (Tue, 17 Nov 2009)
New Revision: 5595
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java
Log:
javadoc
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java 2009-11-17 19:30:39 UTC (rev 5594)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java 2009-11-17 20:58:18 UTC (rev 5595)
@@ -104,19 +104,43 @@
*/
public static final Option<Boolean> REQUIRE_SECURE = Option.simple(RemotingOptions.class, "REQUIRE_SECURE", Boolean.class);
+ /**
+ * The size of the largest buffer that this endpoint will transmit over a connection.
+ */
public static final Option<Integer> MAX_TRANSMIT_SIZE = Option.simple(RemotingOptions.class, "MAX_TRANSMIT_SIZE", Integer.class);
+ /**
+ * The size of the largest buffer that this endpoint will accept over a connection.
+ */
public static final Option<Integer> MAX_RECEIVE_SIZE = Option.simple(RemotingOptions.class, "MAX_RECEIVE_SIZE", Integer.class);
+ /**
+ * The window size of the transmit direction for connection subchannels, in buffers.
+ */
public static final Option<Integer> TRANSMIT_WINDOW_SIZE = Option.simple(RemotingOptions.class, "TRANSMIT_WINDOW_SIZE", Integer.class);
+ /**
+ * The window size of the receive direction for connection subchannels, in buffers.
+ */
public static final Option<Integer> RECEIVE_WINDOW_SIZE = Option.simple(RemotingOptions.class, "RECEIVE_WINDOW_SIZE", Integer.class);
+ /**
+ * The maximum number of outbound subchannels to support for a connection.
+ */
public static final Option<Integer> MAX_OUTBOUND_CHANNELS = Option.simple(RemotingOptions.class, "MAX_OUTBOUND_CHANNELS", Integer.class);
+ /**
+ * The maximum number of inbound subchannels to support for a connection.
+ */
public static final Option<Integer> MAX_INBOUND_CHANNELS = Option.simple(RemotingOptions.class, "MAX_INBOUND_CHANNELS", Integer.class);
+ /**
+ * The authentication user name to use if no authentication {@code CallbackHandler} is specified.
+ */
public static final Option<String> AUTH_USER_NAME = Option.simple(RemotingOptions.class, "AUTH_USER_NAME", String.class);
+ /**
+ * The authentication realm to use if no authentication {@code CallbackHandler} is specified.
+ */
public static final Option<String> AUTH_REALM = Option.simple(RemotingOptions.class, "AUTH_REALM", String.class);
}
15 years, 1 month
JBoss Remoting SVN: r5594 - in remoting3/trunk/jboss-remoting/src/main: resources/META-INF and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-11-17 14:30:39 -0500 (Tue, 17 Nov 2009)
New Revision: 5594
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java
Removed:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
remoting3/trunk/jboss-remoting/src/main/resources/META-INF/jboss-classloading.xml
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
Log:
Changes to support interactive authentication
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-11-13 21:50:09 UTC (rev 5593)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-11-17 19:30:39 UTC (rev 5594)
@@ -10,6 +10,8 @@
import org.jboss.xnio.IoFuture;
import org.jboss.xnio.OptionMap;
+import javax.security.auth.callback.CallbackHandler;
+
/**
* A potential participant in a JBoss Remoting communications relationship.
* <p/>
@@ -102,22 +104,22 @@
/**
* Set the option map for the service. The options may include, but are not limited to:
* <ul>
- * <li>{@link Options#BUFFER_SIZE} - the recommended buffer size for marshallers to use for this service</li>
- * <li>{@link Options#CLASS_COUNT} - the recommended class count for marshallers to use for this service</li>
- * <li>{@link Options#INSTANCE_COUNT} - the recommended instance count for marshallers to use for this service</li>
- * <li>{@link Options#METRIC} - the relative desirability or "distance" of this service</li>
- * <li>{@link Options#MARSHALLING_PROTOCOLS} - the marshalling protocols which are allowed for this service,
+ * <li>{@link RemotingOptions#BUFFER_SIZE} - the recommended buffer size for marshallers to use for this service</li>
+ * <li>{@link RemotingOptions#CLASS_COUNT} - the recommended class count for marshallers to use for this service</li>
+ * <li>{@link RemotingOptions#INSTANCE_COUNT} - the recommended instance count for marshallers to use for this service</li>
+ * <li>{@link RemotingOptions#METRIC} - the relative desirability or "distance" of this service</li>
+ * <li>{@link RemotingOptions#MARSHALLING_PROTOCOLS} - the marshalling protocols which are allowed for this service,
* in order of decreasing preference; if none is given, all registered protocols will
* be made available</li>
- * <li>{@link Options#MARSHALLING_CLASS_RESOLVERS} - the class resolvers which are allowed for this service,
+ * <li>{@link RemotingOptions#MARSHALLING_CLASS_RESOLVERS} - the class resolvers which are allowed for this service,
* in order of decreasing preference; if none is given, the default class resolver is used</li>
- * <li>{@link Options#MARSHALLING_CLASS_TABLES} - the class tables which are allowed for this service, in order
+ * <li>{@link RemotingOptions#MARSHALLING_CLASS_TABLES} - the class tables which are allowed for this service, in order
* of decreasing preference</li>
- * <li>{@link Options#MARSHALLING_EXTERNALIZER_FACTORIES} - the class externalizer factories which are allowed
+ * <li>{@link RemotingOptions#MARSHALLING_EXTERNALIZER_FACTORIES} - the class externalizer factories which are allowed
* for this service, in order of decreasing preference</li>
- * <li>{@link Options#REMOTELY_VISIBLE} - {@code true} if this service should be remotely accessible,
+ * <li>{@link RemotingOptions#REMOTELY_VISIBLE} - {@code true} if this service should be remotely accessible,
* {@code false} otherwise (defaults to {@code true})</li>
- * <li>{@link Options#REQUIRE_SECURE} - {@code true} if this service may only be accessed over a secure/encrypted
+ * <li>{@link RemotingOptions#REQUIRE_SECURE} - {@code true} if this service may only be accessed over a secure/encrypted
* channel; defaults to {@code false}, however this should be set to {@code true} if sensitive data (e.g.
* passwords) may be transmitted as part of a payload</li>
* </ul>
@@ -178,6 +180,21 @@
IoFuture<? extends Connection> connect(URI destination, OptionMap connectOptions) throws IOException;
/**
+ * Open a connection with a peer. Returns a future connection which may be used to cancel the connection attempt.
+ * The given callback handler is used to retrieve local authentication information, if the protocol demands it.
+ * This method does not block; use the return value to wait for a result if you wish to block.
+ * <p/>
+ * You must have the {@link org.jboss.remoting3.EndpointPermission connect EndpointPermission} to invoke this method.
+ *
+ * @param destination the destination
+ * @param connectOptions options to configure this connection
+ * @param callbackHandler the local callback handler to use for authentication
+ * @return the future connection
+ * @throws IOException if an error occurs while starting the connect attempt
+ */
+ IoFuture<? extends Connection> connect(URI destination, OptionMap connectOptions, CallbackHandler callbackHandler) throws IOException;
+
+ /**
* Register a connection provider for a URI scheme. The provider factory is called with the context which can
* be used to accept new connections or terminate the registration.
* <p/>
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-11-13 21:50:09 UTC (rev 5593)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-11-17 19:30:39 UTC (rev 5594)
@@ -60,6 +60,8 @@
import org.jboss.xnio.TranslatingResult;
import org.jboss.xnio.WeakCloseable;
+import javax.security.auth.callback.CallbackHandler;
+
/**
*
*/
@@ -309,7 +311,7 @@
if (clientListener == null) {
throw new NullPointerException("clientListener is null");
}
- final Integer metric = optionMap.get(Options.METRIC);
+ final Integer metric = optionMap.get(RemotingOptions.METRIC);
if (metric != null && metric.intValue() < 0) {
throw new IllegalArgumentException("metric must be greater than or equal to zero");
}
@@ -487,6 +489,10 @@
}
public IoFuture<? extends Connection> connect(final URI destination, final OptionMap connectOptions) throws IOException {
+ return connect(destination, connectOptions, null);
+ }
+
+ public IoFuture<? extends Connection> connect(final URI destination, final OptionMap connectOptions, final CallbackHandler callbackHandler) throws IOException {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(CONNECT_PERM);
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-11-13 21:50:09 UTC (rev 5593)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-11-17 19:30:39 UTC (rev 5594)
@@ -1,118 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3;
-
-import org.jboss.xnio.Option;
-import org.jboss.xnio.Sequence;
-
-/**
- * Common options for service registration.
- */
-public final class Options {
-
- private Options() {
- }
-
- /**
- * Configure the maximum number of threads for a simple endpoint.
- */
- public static final Option<Integer> MAX_THREADS = Option.simple(Options.class, "MAX_THREADS", Integer.class);
-
- /**
- * Specify whether connection providers should automatically be detected and loaded.
- */
- public static final Option<Boolean> LOAD_PROVIDERS = Option.simple(Options.class, "LOAD_PROVIDERS", Boolean.class);
-
- /**
- * Request that the marshalling layer require the use of one of the listed marshalling protocols, in order of decreasing preference.
- */
- public static final Option<Sequence<String>> MARSHALLING_PROTOCOLS = Option.sequence(Options.class, "MARSHALLING_PROTOCOLS", String.class);
-
- /**
- * Request that the marshalling layer require the presense of one of the listed user-defined class tables, in order of decreasing preference.
- */
- public static final Option<Sequence<String>> MARSHALLING_CLASS_TABLES = Option.sequence(Options.class, "MARSHALLING_CLASS_TABLES", String.class);
-
- /**
- * Request that the marshalling layer require the presense of one of the listed user-defined object tables, in order of decreasing preference.
- */
- public static final Option<Sequence<String>> MARSHALLING_OBJECT_TABLES = Option.sequence(Options.class, "MARSHALLING_OBJECT_TABLES", String.class);
-
- /**
- * Request that the marshalling layer require the presense of one of the listed class resolvers, in order of decreasing preference.
- */
- public static final Option<Sequence<String>> MARSHALLING_CLASS_RESOLVERS = Option.sequence(Options.class, "MARSHALLING_CLASS_RESOLVERS", String.class);
-
- /**
- * Request that the marshalling layer require the presense of one of the listed object resolvers, in order of decreasing preference.
- */
- public static final Option<Sequence<String>> MARSHALLING_OBJECT_RESOLVERS = Option.sequence(Options.class, "MARSHALLING_OBJECT_RESOLVERS", String.class);
-
- /**
- * Request that the marshalling layer require the presense of one of the listed user-defined externalizer factories, in order of decreasing preference.
- */
- public static final Option<Sequence<String>> MARSHALLING_EXTERNALIZER_FACTORIES = Option.sequence(Options.class, "MARSHALLING_EXTERNALIZER_FACTORIES", String.class);
-
- /**
- * Specify a metric which is a hint that describes the relative desirability of this service.
- */
- public static final Option<Integer> METRIC = Option.simple(Options.class, "METRIC", Integer.class);
-
- /**
- * Specify that the registered service should or should not be visible remotely.
- */
- public static final Option<Boolean> REMOTELY_VISIBLE = Option.simple(Options.class, "REMOTELY_VISIBLE", Boolean.class);
-
- /**
- * Specify the buffer size for any configured marshaller or unmarshaller.
- */
- public static final Option<Integer> BUFFER_SIZE = Option.simple(Options.class, "BUFFER_SIZE", Integer.class);
-
- /**
- * Specify the expected class count for any configured marshaller or unmarshaller.
- */
- public static final Option<Integer> CLASS_COUNT = Option.simple(Options.class, "CLASS_COUNT", Integer.class);
-
- /**
- * Specify the expected instance count for any configured marshaller or unmarshaller.
- */
- public static final Option<Integer> INSTANCE_COUNT = Option.simple(Options.class, "INSTANCE_COUNT", Integer.class);
-
- /**
- * Specify whether the service may be accessed from connections which are unencrypted, or whether encryption is
- * required.
- */
- public static final Option<Boolean> REQUIRE_SECURE = Option.simple(Options.class, "REQUIRE_SECURE", Boolean.class);
-
- public static final Option<Integer> MAX_TRANSMIT_SIZE = Option.simple(Options.class, "MAX_TRANSMIT_SIZE", Integer.class);
-
- public static final Option<Integer> MAX_RECEIVE_SIZE = Option.simple(Options.class, "MAX_RECEIVE_SIZE", Integer.class);
-
- public static final Option<Integer> TRANSMIT_WINDOW_SIZE = Option.simple(Options.class, "TRANSMIT_WINDOW_SIZE", Integer.class);
-
- public static final Option<Integer> RECEIVE_WINDOW_SIZE = Option.simple(Options.class, "RECEIVE_WINDOW_SIZE", Integer.class);
-
- public static final Option<Integer> MAX_OUTBOUND_CHANNELS = Option.simple(Options.class, "MAX_OUTBOUND_CHANNELS", Integer.class);
-
- public static final Option<Integer> MAX_INBOUND_CHANNELS = Option.simple(Options.class, "MAX_INBOUND_CHANNELS", Integer.class);
-}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-11-13 21:50:09 UTC (rev 5593)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-11-17 19:30:39 UTC (rev 5594)
@@ -80,14 +80,14 @@
* @return the endpoint
*/
public static Endpoint createEndpoint(final String name, final int maxThreads) throws IOException {
- return createEndpoint(name, OptionMap.builder().set(Options.MAX_THREADS, maxThreads).getMap());
+ return createEndpoint(name, OptionMap.builder().set(RemotingOptions.MAX_THREADS, maxThreads).getMap());
}
/**
* Create an endpoint configured with the given option map. The following options are supported:
* <ul>
- * <li>{@link Options#MAX_THREADS} - specify the maximum number of threads for the created thread pool (default 10)</li>
- * <li>{@link Options#LOAD_PROVIDERS} - specify whether providers should be auto-loaded (default {@code true})</li>
+ * <li>{@link RemotingOptions#MAX_THREADS} - specify the maximum number of threads for the created thread pool (default 10)</li>
+ * <li>{@link RemotingOptions#LOAD_PROVIDERS} - specify whether providers should be auto-loaded (default {@code true})</li>
* </ul>
*
* @param endpointName the endpoint name
@@ -102,14 +102,14 @@
if (optionMap == null) {
throw new NullPointerException("optionMap is null");
}
- final CloseableExecutor executor = createExecutor(optionMap.get(Options.MAX_THREADS, 10));
+ final CloseableExecutor executor = createExecutor(optionMap.get(RemotingOptions.MAX_THREADS, 10));
final Endpoint endpoint = createEndpoint(executor, endpointName);
endpoint.addCloseHandler(new CloseHandler<Endpoint>() {
public void handleClose(final Endpoint closed) {
IoUtils.safeClose(executor);
}
});
- if (optionMap.get(Options.LOAD_PROVIDERS, true)) {
+ if (optionMap.get(RemotingOptions.LOAD_PROVIDERS, true)) {
for (RemotingServiceDescriptor<?> descriptor : ServiceLoader.load(RemotingServiceDescriptor.class)) {
final String name = descriptor.getName();
final Class<?> serviceType = descriptor.getType();
Copied: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java (from rev 5591, remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java)
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java 2009-11-17 19:30:39 UTC (rev 5594)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3;
+
+import org.jboss.xnio.Option;
+import org.jboss.xnio.Sequence;
+
+/**
+ * Common options for Remoting configuration.
+ */
+public final class RemotingOptions {
+
+ private RemotingOptions() {
+ }
+
+ /**
+ * Configure the maximum number of threads for a simple endpoint.
+ */
+ public static final Option<Integer> MAX_THREADS = Option.simple(RemotingOptions.class, "MAX_THREADS", Integer.class);
+
+ /**
+ * Specify whether connection providers should automatically be detected and loaded.
+ */
+ public static final Option<Boolean> LOAD_PROVIDERS = Option.simple(RemotingOptions.class, "LOAD_PROVIDERS", Boolean.class);
+
+ /**
+ * Request that the marshalling layer require the use of one of the listed marshalling protocols, in order of decreasing preference.
+ */
+ public static final Option<Sequence<String>> MARSHALLING_PROTOCOLS = Option.sequence(RemotingOptions.class, "MARSHALLING_PROTOCOLS", String.class);
+
+ /**
+ * Request that the marshalling layer require the presense of one of the listed user-defined class tables, in order of decreasing preference.
+ */
+ public static final Option<Sequence<String>> MARSHALLING_CLASS_TABLES = Option.sequence(RemotingOptions.class, "MARSHALLING_CLASS_TABLES", String.class);
+
+ /**
+ * Request that the marshalling layer require the presense of one of the listed user-defined object tables, in order of decreasing preference.
+ */
+ public static final Option<Sequence<String>> MARSHALLING_OBJECT_TABLES = Option.sequence(RemotingOptions.class, "MARSHALLING_OBJECT_TABLES", String.class);
+
+ /**
+ * Request that the marshalling layer require the presense of one of the listed class resolvers, in order of decreasing preference.
+ */
+ public static final Option<Sequence<String>> MARSHALLING_CLASS_RESOLVERS = Option.sequence(RemotingOptions.class, "MARSHALLING_CLASS_RESOLVERS", String.class);
+
+ /**
+ * Request that the marshalling layer require the presense of one of the listed object resolvers, in order of decreasing preference.
+ */
+ public static final Option<Sequence<String>> MARSHALLING_OBJECT_RESOLVERS = Option.sequence(RemotingOptions.class, "MARSHALLING_OBJECT_RESOLVERS", String.class);
+
+ /**
+ * Request that the marshalling layer require the presense of one of the listed user-defined externalizer factories, in order of decreasing preference.
+ */
+ public static final Option<Sequence<String>> MARSHALLING_EXTERNALIZER_FACTORIES = Option.sequence(RemotingOptions.class, "MARSHALLING_EXTERNALIZER_FACTORIES", String.class);
+
+ /**
+ * Specify a metric which is a hint that describes the relative desirability of this service.
+ */
+ public static final Option<Integer> METRIC = Option.simple(RemotingOptions.class, "METRIC", Integer.class);
+
+ /**
+ * Specify that the registered service should or should not be visible remotely.
+ */
+ public static final Option<Boolean> REMOTELY_VISIBLE = Option.simple(RemotingOptions.class, "REMOTELY_VISIBLE", Boolean.class);
+
+ /**
+ * Specify the buffer size for any configured marshaller or unmarshaller.
+ */
+ public static final Option<Integer> BUFFER_SIZE = Option.simple(RemotingOptions.class, "BUFFER_SIZE", Integer.class);
+
+ /**
+ * Specify the expected class count for any configured marshaller or unmarshaller.
+ */
+ public static final Option<Integer> CLASS_COUNT = Option.simple(RemotingOptions.class, "CLASS_COUNT", Integer.class);
+
+ /**
+ * Specify the expected instance count for any configured marshaller or unmarshaller.
+ */
+ public static final Option<Integer> INSTANCE_COUNT = Option.simple(RemotingOptions.class, "INSTANCE_COUNT", Integer.class);
+
+ /**
+ * Specify whether the service may be accessed from connections which are unencrypted, or whether encryption is
+ * required.
+ */
+ public static final Option<Boolean> REQUIRE_SECURE = Option.simple(RemotingOptions.class, "REQUIRE_SECURE", Boolean.class);
+
+ public static final Option<Integer> MAX_TRANSMIT_SIZE = Option.simple(RemotingOptions.class, "MAX_TRANSMIT_SIZE", Integer.class);
+
+ public static final Option<Integer> MAX_RECEIVE_SIZE = Option.simple(RemotingOptions.class, "MAX_RECEIVE_SIZE", Integer.class);
+
+ public static final Option<Integer> TRANSMIT_WINDOW_SIZE = Option.simple(RemotingOptions.class, "TRANSMIT_WINDOW_SIZE", Integer.class);
+
+ public static final Option<Integer> RECEIVE_WINDOW_SIZE = Option.simple(RemotingOptions.class, "RECEIVE_WINDOW_SIZE", Integer.class);
+
+ public static final Option<Integer> MAX_OUTBOUND_CHANNELS = Option.simple(RemotingOptions.class, "MAX_OUTBOUND_CHANNELS", Integer.class);
+
+ public static final Option<Integer> MAX_INBOUND_CHANNELS = Option.simple(RemotingOptions.class, "MAX_INBOUND_CHANNELS", Integer.class);
+
+ public static final Option<String> AUTH_USER_NAME = Option.simple(RemotingOptions.class, "AUTH_USER_NAME", String.class);
+
+ public static final Option<String> AUTH_REALM = Option.simple(RemotingOptions.class, "AUTH_REALM", String.class);
+}
Deleted: remoting3/trunk/jboss-remoting/src/main/resources/META-INF/jboss-classloading.xml
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/resources/META-INF/jboss-classloading.xml 2009-11-13 21:50:09 UTC (rev 5593)
+++ remoting3/trunk/jboss-remoting/src/main/resources/META-INF/jboss-classloading.xml 2009-11-17 19:30:39 UTC (rev 5594)
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<classloading name="jboss-remoting-api" version="3.0.0.GA" xmlns="urn:jboss:classloading:1.0">
- <capabilities>
- <package name="org.jboss.remoting3"/>
- <package name="org.jboss.remoting3.spi"/>
- <package name="org.jboss.remoting3.stream"/>
- </capabilities>
- <requirements>
- <module name="xnio-api" from-inclusive="true" from="1.2.0.GA" reExport="true"/>
- <module name="marshalling-api" from-inclusive="true" from="1.0.0.GA" reExport="true"/>
- </requirements>
-</classloading>
15 years, 1 month
JBoss Remoting SVN: r5593 - in remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3: spi and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-11-13 16:50:09 -0500 (Fri, 13 Nov 2009)
New Revision: 5593
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java
Log:
Marshallers should be registered by descriptor to provide access to version ranges
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-11-13 21:49:25 UTC (rev 5592)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-11-13 21:50:09 UTC (rev 5593)
@@ -143,7 +143,7 @@
for (String name : found.keySet()) {
final MarshallerFactory marshallerFactory = found.get(name).getMarshallerFactory();
try {
- endpoint.addProtocolService(ProtocolServiceType.MARSHALLER_FACTORY, name, marshallerFactory);
+ endpoint.addProtocolService(ProtocolServiceType.MARSHALLER_PROVIDER_DESCRIPTOR, name, marshallerFactory);
} catch (DuplicateRegistrationException e) {
log.debug("Duplicate registration for '" + name + "' of " + MarshallerFactory.class);
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java 2009-11-13 21:49:25 UTC (rev 5592)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java 2009-11-13 21:50:09 UTC (rev 5593)
@@ -22,12 +22,12 @@
package org.jboss.remoting3.spi;
-import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.ClassTable;
import org.jboss.marshalling.ObjectTable;
import org.jboss.marshalling.ClassResolver;
import org.jboss.marshalling.ObjectResolver;
import org.jboss.marshalling.ClassExternalizerFactory;
+import org.jboss.marshalling.ProviderDescriptor;
import java.io.Serializable;
public final class ProtocolServiceType<T> implements Serializable {
@@ -65,7 +65,7 @@
}
}
- public static final ProtocolServiceType<MarshallerFactory> MARSHALLER_FACTORY;
+ public static final ProtocolServiceType<ProviderDescriptor> MARSHALLER_PROVIDER_DESCRIPTOR;
public static final ProtocolServiceType<ClassTable> CLASS_TABLE;
@@ -90,7 +90,7 @@
static {
int index = 0;
SERVICE_TYPES = new ProtocolServiceType<?>[] {
- MARSHALLER_FACTORY = new ProtocolServiceType<MarshallerFactory>(MarshallerFactory.class, "MARSHALLER_FACTORY", "Marshaller factory", index++),
+ MARSHALLER_PROVIDER_DESCRIPTOR = new ProtocolServiceType<ProviderDescriptor>(ProviderDescriptor.class, "MARSHALLER_FACTORY", "Marshaller factory", index++),
CLASS_TABLE = new ProtocolServiceType<ClassTable>(ClassTable.class, "CLASS_TABLE", "Class table", index++),
OBJECT_TABLE = new ProtocolServiceType<ObjectTable>(ObjectTable.class, "OBJECT_TABLE", "Object table", index++),
CLASS_RESOLVER = new ProtocolServiceType<ClassResolver>(ClassResolver.class, "CLASS_RESOLVER", "Class resolver", index++),
15 years, 1 month
JBoss Remoting SVN: r5592 - remoting3/trunk/jboss-remoting.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-11-13 16:49:25 -0500 (Fri, 13 Nov 2009)
New Revision: 5592
Modified:
remoting3/trunk/jboss-remoting/pom.xml
Log:
Attach javadoc JAR with artifact
Modified: remoting3/trunk/jboss-remoting/pom.xml
===================================================================
--- remoting3/trunk/jboss-remoting/pom.xml 2009-11-13 03:52:48 UTC (rev 5591)
+++ remoting3/trunk/jboss-remoting/pom.xml 2009-11-13 21:49:25 UTC (rev 5592)
@@ -76,14 +76,19 @@
</execution>
</executions>
</plugin>
- </plugins>
- </build>
- <reporting>
- <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.5</version>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
<configuration>
<taglet>org.jboss.remoting3.taglet.RemotingTypeTaglet</taglet>
<tagletArtifact>
@@ -107,7 +112,7 @@
</configuration>
</plugin>
</plugins>
- </reporting>
+ </build>
<distributionManagement>
<repository>
<id>repository.jboss.org</id>
15 years, 1 month
JBoss Remoting SVN: r5591 - remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-11-12 22:52:48 -0500 (Thu, 12 Nov 2009)
New Revision: 5591
Removed:
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketRequestListenerProxy.java
Modified:
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketObjectTable.java
Log:
JBREM-1167: Remove references to RequestListener before David notices.
Modified: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketObjectTable.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketObjectTable.java 2009-11-13 03:36:46 UTC (rev 5590)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketObjectTable.java 2009-11-13 03:52:48 UTC (rev 5591)
@@ -56,7 +56,7 @@
@Override
public Writer getObjectWriter(Object object) throws IOException {
- if (object instanceof Endpoint || object instanceof Executor || object instanceof RequestListener<?, ?>) {
+ if (object instanceof Endpoint || object instanceof Executor) {
return socketObjectTableWriter;
}
return null;
@@ -72,9 +72,6 @@
if (o instanceof ExecutorToken) {
return executor;
}
- if (o instanceof SocketServiceConfiguration<?, ?>) {
- return new SocketRequestListenerProxy<I, O>(endpoint, (SocketServiceConfiguration<I, O>) o);
- }
return o;
}
@@ -89,16 +86,8 @@
log.info(this + " got Executor: " + object);
marshaller.writeObject(EXECUTOR_TOKEN);
}
- else if (object instanceof RequestListener<?, ?>) {
- log.info(this + " got RequestListener: " + object);
- SocketServiceConfiguration<?, ?> config = SocketClientListener.getRequestListenerInfo((RequestListener<?, ?>) object);
- if (config == null) {
- throw new RuntimeException(object + " is not registered with SocketClientListener");
- }
- marshaller.writeObject(config);
- }
else {
- throw new RuntimeException("expecting Endpoint or RequestListener");
+ throw new RuntimeException("expecting Endpoint or Executor");
}
}
}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketRequestListenerProxy.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketRequestListenerProxy.java 2009-11-13 03:36:46 UTC (rev 5590)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketRequestListenerProxy.java 2009-11-13 03:52:48 UTC (rev 5591)
@@ -1,121 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.TimeUnit;
-
-import org.jboss.remoting3.Client;
-import org.jboss.remoting3.Connection;
-import org.jboss.remoting3.Endpoint;
-import org.jboss.remoting3.RemoteExecutionException;
-import org.jboss.remoting3.RequestContext;
-import org.jboss.remoting3.RequestListener;
-import org.jboss.xnio.IoFuture;
-import org.jboss.xnio.OptionMap;
-import org.jboss.xnio.log.Logger;
-
-/**
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Nov 9, 2009
- * </p>
- */
-public class SocketRequestListenerProxy<I, O> implements RequestListener<I, O>, Serializable {
- private static final long serialVersionUID = -5260475991325355302L;
- private static Logger log = Logger.getLogger(SocketRequestListenerProxy.class);
-
- private Connection connection;
- private Client<I, O> client;
-
- public SocketRequestListenerProxy(Endpoint endpoint, SocketServiceConfiguration<I, O> config) throws IOException {
- URI uri;
- try {
- uri = new URI("socket://" + config.getHost() + ":" + config.getPort());
- } catch (URISyntaxException e) {
- throw new IOException(e.getCause());
- }
- connection = getFutureResult(endpoint.connect(uri, OptionMap.EMPTY), "couldn't create Connection");
- client = getFutureResult(connection.openClient(config.getServiceType(), config.getGroupName(), config.getRequestClass(), config.getResponseClass()), "couldn't create Client");
- }
-
- @Override
- public void handleClose() {
- if (connection != null) {
- try {
- connection.close();
- } catch (IOException e) {
- log.info(this + " unable to close connection " + connection);
- }
- }
- if (client != null) {
- try {
- client.close();
- } catch (IOException e) {
- log.info(this + " unable to close client " + client);
- }
- }
- }
-
- @Override
- public void handleRequest(RequestContext<O> context, I request) throws RemoteExecutionException {
- try {
- O reply = client.invoke(request);
- context.sendReply(reply);
- } catch (CancellationException e) {
- try {
- context.sendCancelled();
- } catch (IllegalStateException e1) {
- throw new RemoteExecutionException(e1);
- } catch (IOException e1) {
- throw new RemoteExecutionException(e1);
- }
- } catch (IOException e) {
- try {
- context.sendFailure(e.getMessage(), e);
- } catch (IllegalStateException e1) {
- throw new RemoteExecutionException(e1);
- } catch (IOException e1) {
- throw new RemoteExecutionException(e1);
- }
- }
- }
-
- static <T> T getFutureResult(IoFuture<T> future, String errorMessage) throws IOException {
- switch (future.await(5000, TimeUnit.MILLISECONDS)) {
- case DONE: {
- return future.get();
- }
- case FAILED: {
- throw future.getException();
- }
- default: {
- throw new IOException("unexpeced future state: " + future);
- }
- }
- }
-}
\ No newline at end of file
15 years, 1 month
JBoss Remoting SVN: r5590 - in remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples: socket and 2 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-11-12 22:36:46 -0500 (Thu, 12 Nov 2009)
New Revision: 5590
Added:
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/RequestHandlerFuture.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketConnectionProvider.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketHandleableCloseable.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketObjectTable.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketProtocol.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketRequestListenerProxy.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketServiceConfiguration.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketUsageExamples.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketClientConnectionHandler.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketClientRequestHandler.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketRequestHandlerConnector.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketClientListener.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerConnectionHandler.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerReplyHandler.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerRequestHandler.java
Log:
JBREM-1167: Adding a simple socket based protocol.
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/RequestHandlerFuture.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/RequestHandlerFuture.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/RequestHandlerFuture.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
+
+import java.io.IOException;
+
+import org.jboss.remoting3.spi.RequestHandler;
+import org.jboss.xnio.Result;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 24, 2009
+ * </p>
+ */
+public class RequestHandlerFuture implements Result<RequestHandler> {
+ private RequestHandler requestHandler;
+ private IOException exception;
+
+ @Override
+ public boolean setCancelled() {return true;}
+
+ @Override
+ public boolean setException(IOException exception) {
+ this.exception = exception;
+ return true;
+ }
+
+ @Override
+ public boolean setResult(RequestHandler result) {
+ this.requestHandler = result;
+ return true;
+ }
+
+ public RequestHandler get() {
+ return requestHandler;
+ }
+
+ public IOException getException() {
+ return exception;
+ }
+}
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketConnectionProvider.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketConnectionProvider.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketConnectionProvider.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.concurrent.Executor;
+
+import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.samples.socket.client.SocketClientConnectionHandler;
+import org.jboss.remoting3.samples.socket.server.SocketServerConnectionHandler;
+import org.jboss.remoting3.spi.AbstractHandleableCloseable;
+import org.jboss.remoting3.spi.ConnectionHandler;
+import org.jboss.remoting3.spi.ConnectionHandlerContext;
+import org.jboss.remoting3.spi.ConnectionHandlerFactory;
+import org.jboss.remoting3.spi.ConnectionProvider;
+import org.jboss.remoting3.spi.ConnectionProviderContext;
+import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.Result;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 14, 2009
+ * </p>
+ */
+public class SocketConnectionProvider<T, I, O> extends AbstractHandleableCloseable<SocketHandleableCloseable> implements ConnectionProvider<T> {
+ private Endpoint endpoint;
+ private String host;
+ private int port;
+ private SocketServerConnectionHandler<I, O> connectionHandler;
+
+
+ public SocketConnectionProvider(Endpoint endpoint, Executor executor, String host) {
+ super(executor);
+ this.endpoint = endpoint;
+ this.host = host;
+ SocketProtocol.initializeMarshalling(endpoint, executor);
+ }
+
+ public Cancellable connect(final URI uri, final OptionMap connectOptions, Result<ConnectionHandlerFactory> result) throws IllegalArgumentException {
+ result.setResult(new ConnectionHandlerFactory() {
+ public ConnectionHandler createInstance(ConnectionHandlerContext connectionContext) {
+ final ConnectionHandler connectionHandler = new SocketClientConnectionHandler(uri, connectOptions, getExecutor(), host, port);
+ registerCloseHandler(connectionHandler);
+ return connectionHandler;
+ }
+ });
+ return null;
+ }
+
+ public T getProviderInterface() {
+ return null;
+ }
+
+ public void start(final ConnectionProviderContext context, final int port) throws IOException {
+ this.port = port;
+ context.accept(new ConnectionHandlerFactory() {
+ public ConnectionHandler createInstance(ConnectionHandlerContext connectionContext) {
+ connectionHandler = new SocketServerConnectionHandler<I, O>(endpoint, getExecutor(), connectionContext, host, port);
+ registerCloseHandler(connectionHandler);
+ try {
+ connectionHandler.start();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return connectionHandler;
+ }});
+ }
+
+ public void stop() {
+ if (connectionHandler != null) {
+ connectionHandler.stop();
+ }
+ }
+
+ protected void registerCloseHandler(final ConnectionHandler connectionHandler) {
+ addCloseHandler(new CloseHandler<SocketHandleableCloseable>() {
+ public void handleClose(SocketHandleableCloseable closed) {
+ IoUtils.safeClose(connectionHandler);
+ }
+ });
+ }
+}
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketHandleableCloseable.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketHandleableCloseable.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketHandleableCloseable.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
+
+import org.jboss.remoting3.HandleableCloseable;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 31, 2009
+ * </p>
+ */
+public interface SocketHandleableCloseable extends HandleableCloseable<SocketHandleableCloseable>{
+}
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketObjectTable.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketObjectTable.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketObjectTable.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.concurrent.Executor;
+
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.remoting3.samples.socket.server.SocketClientListener;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Nov 9, 2009
+ * </p>
+ */
+public class SocketObjectTable<I, O> implements org.jboss.marshalling.ObjectTable {
+ private static final Logger log = Logger.getLogger(SocketObjectTable.class);
+ private static final EndpointToken ENDPOINT_TOKEN = new EndpointToken();
+ private static final ExecutorToken EXECUTOR_TOKEN = new ExecutorToken();
+
+ private Endpoint endpoint;
+ private Executor executor;
+ private SocketObjectTableWriter socketObjectTableWriter;
+
+ public SocketObjectTable(Endpoint endpoint, Executor executor) {
+ this.endpoint = endpoint;
+ this.executor = executor;
+ socketObjectTableWriter = new SocketObjectTableWriter();
+ }
+
+ @Override
+ public Writer getObjectWriter(Object object) throws IOException {
+ if (object instanceof Endpoint || object instanceof Executor || object instanceof RequestListener<?, ?>) {
+ return socketObjectTableWriter;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object readObject(Unmarshaller unmarshaller) throws IOException, ClassNotFoundException {
+ Object o = unmarshaller.readObject();
+ if (o instanceof EndpointToken) {
+ return endpoint;
+ }
+ if (o instanceof ExecutorToken) {
+ return executor;
+ }
+ if (o instanceof SocketServiceConfiguration<?, ?>) {
+ return new SocketRequestListenerProxy<I, O>(endpoint, (SocketServiceConfiguration<I, O>) o);
+ }
+ return o;
+ }
+
+
+ private static class SocketObjectTableWriter implements Writer {
+ public void writeObject(Marshaller marshaller, Object object) throws IOException {
+ if (object instanceof Endpoint) {
+ log.info(this + " got Endpoint: " + object);
+ marshaller.writeObject(ENDPOINT_TOKEN);
+ }
+ else if (object instanceof Executor) {
+ log.info(this + " got Executor: " + object);
+ marshaller.writeObject(EXECUTOR_TOKEN);
+ }
+ else if (object instanceof RequestListener<?, ?>) {
+ log.info(this + " got RequestListener: " + object);
+ SocketServiceConfiguration<?, ?> config = SocketClientListener.getRequestListenerInfo((RequestListener<?, ?>) object);
+ if (config == null) {
+ throw new RuntimeException(object + " is not registered with SocketClientListener");
+ }
+ marshaller.writeObject(config);
+ }
+ else {
+ throw new RuntimeException("expecting Endpoint or RequestListener");
+ }
+ }
+ }
+
+
+ private static class EndpointToken implements Serializable {
+ private static final long serialVersionUID = -7307241847641193094L;
+ }
+
+ private static class ExecutorToken implements Serializable {
+ private static final long serialVersionUID = -8687614439586428163L;
+ }
+}
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketProtocol.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketProtocol.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketProtocol.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
+
+import java.io.IOException;
+import java.util.concurrent.Executor;
+
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.MarshallingConfiguration;
+import org.jboss.marshalling.reflect.SunReflectiveCreator;
+import org.jboss.marshalling.river.RiverMarshallerFactory;
+import org.jboss.remoting3.ClientListener;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.remoting3.Endpoint.ServiceBuilder;
+import org.jboss.remoting3.samples.socket.server.SocketClientListener;
+import org.jboss.remoting3.spi.ConnectionProvider;
+import org.jboss.remoting3.spi.ConnectionProviderContext;
+import org.jboss.remoting3.spi.ConnectionProviderFactory;
+import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.IoUtils;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 14, 2009
+ * </p>
+ */
+public class SocketProtocol
+{
+ private static MarshallerFactory marshallerFactory;
+ private static MarshallingConfiguration marshallingConfiguration;
+
+
+ /**
+ * Register ConnectionProvider.
+ * This endpoint can be a socket transport client.
+ */
+ static public <T, I, O> void registerClientTransport(final Endpoint endpoint, final Executor executor, final String host) {
+ endpoint.addConnectionProvider("socket", new ConnectionProviderFactory<T>() {
+ public ConnectionProvider<T> createInstance(ConnectionProviderContext context) {
+ return new SocketConnectionProvider<T, I, O>(endpoint, executor, host);
+ }});
+ }
+
+
+ /**
+ * Register ConnectionProvider and start its listening facility.
+ * This endpoint can be both a client and server for the socket transport.
+ */
+ static public <T, I, O> Cancellable registerServerTransport(Endpoint endpoint, Executor executor, final String host, final int port) {
+ final SocketConnectionProvider<T, I, O> connectionProvider = new SocketConnectionProvider<T, I, O>(endpoint, executor, host);
+ endpoint.addConnectionProvider("socket", new ConnectionProviderFactory<T>() {
+ public ConnectionProvider<T> createInstance(ConnectionProviderContext context) {
+ try {
+ connectionProvider.start(context, port);
+ return connectionProvider;
+ } catch (IOException e) {
+ throw new RuntimeException("unable to start SocketServerConnectionProvider", e);
+ }
+ }
+ });
+
+ return new Cancellable() {
+ public Cancellable cancel() {
+ connectionProvider.stop();
+ return IoUtils.nullCancellable();
+ }
+ };
+ }
+
+
+ /**
+ * Register a service with an endpoint.
+ * This endpoint must be acting as a socket transport server.
+ */
+ @SuppressWarnings("unchecked")
+ static public <I, O> void startService(Endpoint endpoint, Executor executor, SocketServiceConfiguration<I, O> socketConfig, final RequestListener<I, O> requestListener) throws IOException {
+ String serviceType = socketConfig.getServiceType();
+ String groupName = socketConfig.getGroupName();
+ ClientListener<I, O> clientListener = new SocketClientListener<I, O>(endpoint, socketConfig, requestListener);
+ ServiceBuilder<I, O> sb = (ServiceBuilder<I, O>) endpoint.serviceBuilder();
+ sb.setRequestType(socketConfig.getRequestClass());
+ sb.setReplyType(socketConfig.getResponseClass());
+ sb.setClientListener(clientListener);
+ sb.setServiceType(serviceType);
+ sb.setGroupName(groupName);
+ sb.register();
+ }
+
+
+ static public <I, O> void initializeMarshalling(Endpoint endpoint, Executor executor) {
+ marshallerFactory = new RiverMarshallerFactory();
+ marshallingConfiguration = new MarshallingConfiguration();
+ marshallingConfiguration.setCreator(new SunReflectiveCreator());
+ marshallingConfiguration.setObjectTable(new SocketObjectTable<I, O>(endpoint, executor));
+ }
+
+
+ static public MarshallerFactory getMarshallerFactory() throws IllegalStateException {
+ if (marshallerFactory == null) {
+ throw new IllegalStateException("marshalling has not been initialized");
+ }
+ return marshallerFactory;
+ }
+
+
+ static public MarshallingConfiguration getMarshallingConfiguration() throws IllegalStateException {
+ if (marshallingConfiguration == null) {
+ throw new IllegalStateException("marshalling has not been initialized");
+ }
+ return marshallingConfiguration;
+ }
+}
+
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketRequestListenerProxy.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketRequestListenerProxy.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketRequestListenerProxy.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.remoting3.Client;
+import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.RemoteExecutionException;
+import org.jboss.remoting3.RequestContext;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Nov 9, 2009
+ * </p>
+ */
+public class SocketRequestListenerProxy<I, O> implements RequestListener<I, O>, Serializable {
+ private static final long serialVersionUID = -5260475991325355302L;
+ private static Logger log = Logger.getLogger(SocketRequestListenerProxy.class);
+
+ private Connection connection;
+ private Client<I, O> client;
+
+ public SocketRequestListenerProxy(Endpoint endpoint, SocketServiceConfiguration<I, O> config) throws IOException {
+ URI uri;
+ try {
+ uri = new URI("socket://" + config.getHost() + ":" + config.getPort());
+ } catch (URISyntaxException e) {
+ throw new IOException(e.getCause());
+ }
+ connection = getFutureResult(endpoint.connect(uri, OptionMap.EMPTY), "couldn't create Connection");
+ client = getFutureResult(connection.openClient(config.getServiceType(), config.getGroupName(), config.getRequestClass(), config.getResponseClass()), "couldn't create Client");
+ }
+
+ @Override
+ public void handleClose() {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (IOException e) {
+ log.info(this + " unable to close connection " + connection);
+ }
+ }
+ if (client != null) {
+ try {
+ client.close();
+ } catch (IOException e) {
+ log.info(this + " unable to close client " + client);
+ }
+ }
+ }
+
+ @Override
+ public void handleRequest(RequestContext<O> context, I request) throws RemoteExecutionException {
+ try {
+ O reply = client.invoke(request);
+ context.sendReply(reply);
+ } catch (CancellationException e) {
+ try {
+ context.sendCancelled();
+ } catch (IllegalStateException e1) {
+ throw new RemoteExecutionException(e1);
+ } catch (IOException e1) {
+ throw new RemoteExecutionException(e1);
+ }
+ } catch (IOException e) {
+ try {
+ context.sendFailure(e.getMessage(), e);
+ } catch (IllegalStateException e1) {
+ throw new RemoteExecutionException(e1);
+ } catch (IOException e1) {
+ throw new RemoteExecutionException(e1);
+ }
+ }
+ }
+
+ static <T> T getFutureResult(IoFuture<T> future, String errorMessage) throws IOException {
+ switch (future.await(5000, TimeUnit.MILLISECONDS)) {
+ case DONE: {
+ return future.get();
+ }
+ case FAILED: {
+ throw future.getException();
+ }
+ default: {
+ throw new IOException("unexpeced future state: " + future);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketServiceConfiguration.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketServiceConfiguration.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketServiceConfiguration.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 16, 2009
+ * </p>
+ */
+public class SocketServiceConfiguration<I, O> {
+ private String serviceType;
+ private String groupName;
+ private Class<I> requestClass;
+ private Class<O> responseClass;
+ private String host;
+ private int port;
+
+ public SocketServiceConfiguration(String serviceType, String groupName, Class<I> requestClass, Class<O> responseClass, String host, int port) {
+ this.serviceType = serviceType;
+ this.groupName = groupName;
+ this.requestClass = requestClass;
+ this.responseClass = responseClass;
+ this.host = host;
+ this.port = port;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ public Class<I> getRequestClass() {
+ return requestClass;
+ }
+
+ public void setRequestClass(Class<I> requestClass) {
+ this.requestClass = requestClass;
+ }
+
+ public Class<O> getResponseClass() {
+ return responseClass;
+ }
+
+ public void setResponseClass(Class<O> responseClass) {
+ this.responseClass = responseClass;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public String toString() {
+ return "[serviceType=" + serviceType + ", groupName=" + groupName + "requestClass=" + requestClass + ", responseClass= " + responseClass + ", host=" + host + ", port=" + port + "]";
+ }
+}
+
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketUsageExamples.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketUsageExamples.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketUsageExamples.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,602 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.jboss.remoting3.Client;
+import org.jboss.remoting3.ClientConnector;
+import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.RemoteExecutionException;
+import org.jboss.remoting3.Remoting;
+import org.jboss.remoting3.RequestContext;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 14, 2009
+ * </p>
+ */
+public class SocketUsageExamples extends TestCase {
+ private static final Logger log = Logger.getLogger(SocketUsageExamples.class);
+ private static final String DR_NICK_REQUEST = "Hi everybody!";
+ private static final String DR_NICK_RESPONSE = "Hi Dr. Nick!";
+ private static final String DR_FRANKENSTEIN_REQUEST = "Dr. Frankenstein?";
+ private static final String DR_FRANKENSTEIN_RESPONSE = "It's Frankenshteen!";
+ private static final String SERVICE_TYPE = "testservice";
+ private static final String GROUP_NAME = "testgroup";
+ private static final String HOST = "localhost";
+ private static final int PORT = 6789;
+ private static int portCounter;
+
+
+ /**
+ * Sends a message and gets a result, using Client.send().
+ *
+ * @throws Exception
+ */
+ public void testSocketTransportSend() throws Exception {
+ // Start server service.
+ log.info("entering " + getName());
+ ExecutorService serverExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint serverEndpoint = Remoting.createEndpoint(serverExecutor, "server");
+ int serverPort = PORT + portCounter++;
+ Cancellable socketServer = SocketProtocol.registerServerTransport(serverEndpoint, serverExecutor, HOST, serverPort);
+ SocketServiceConfiguration<String, String> socketServiceConfiguration = new SocketServiceConfiguration<String, String>(SERVICE_TYPE, GROUP_NAME, String.class, String.class, HOST, serverPort);
+ SocketProtocol.startService(serverEndpoint, serverExecutor, socketServiceConfiguration, new DrNickRequestListener());
+
+ // Create client and connect to server.
+ ExecutorService clientExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint clientEndpoint = Remoting.createEndpoint(serverExecutor, "client");
+ SocketProtocol.registerClientTransport(clientEndpoint, clientExecutor, HOST);
+ Connection connection = getFutureResult(clientEndpoint.connect(new URI("socket://" + HOST + ":" + serverPort), OptionMap.EMPTY), "couldn't create Connection");
+ Client<String, String> client = getFutureResult(connection.openClient(SERVICE_TYPE, GROUP_NAME, String.class, String.class), "couldn't create Client");
+
+ // Send message and get response.
+ String response = getFutureResult(client.send(DR_NICK_REQUEST), "couldn't get response");
+ assertEquals(DR_NICK_RESPONSE, response);
+
+ // Shut down.
+ client.close();
+ connection.close();
+ clientEndpoint.close();
+ socketServer.cancel();
+ serverEndpoint.close();
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * Sends a message and gets a result, using Client.invoke().
+ *
+ * @throws Exception
+ */
+ public void testSocketTransportInvoke() throws Exception {
+ // Start server service.
+ log.info("entering " + getName());
+ ExecutorService serverExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint serverEndpoint = Remoting.createEndpoint(serverExecutor, "server");
+ int serverPort = PORT + portCounter++;
+ Cancellable socketServer = SocketProtocol.registerServerTransport(serverEndpoint, serverExecutor, HOST, serverPort);
+ SocketServiceConfiguration<String, String> socketServiceConfiguration = new SocketServiceConfiguration<String, String>(SERVICE_TYPE, GROUP_NAME, String.class, String.class, HOST, serverPort);
+ SocketProtocol.startService(serverEndpoint, serverExecutor, socketServiceConfiguration, new DrNickRequestListener());
+
+ // Create client and connect to server.
+ ExecutorService clientExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint clientEndpoint = Remoting.createEndpoint(serverExecutor, "client");
+ SocketProtocol.registerClientTransport(clientEndpoint, clientExecutor, HOST);
+ Connection connection = getFutureResult(clientEndpoint.connect(new URI("socket://" + HOST + ":" + serverPort), OptionMap.EMPTY), "couldn't create Connection");
+ Client<String, String> client = getFutureResult(connection.openClient(SERVICE_TYPE, GROUP_NAME, String.class, String.class), "couldn't create Client");
+
+ // Send message and get response.
+ String response = client.invoke(DR_NICK_REQUEST);
+ assertEquals(DR_NICK_RESPONSE, response);
+
+ // Shut down.
+ client.close();
+ connection.close();
+ clientEndpoint.close();
+ socketServer.cancel();
+ serverEndpoint.close();
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * Creates two Endpoints in server mode and sends messages in both directions.
+ *
+ * @throws Exception
+ */
+ public void testSocketTwoWayTransport() throws Exception {
+ // Start west coast service.
+ log.info("entering " + getName());
+ ExecutorService westernExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint westernEndpoint = Remoting.createEndpoint(westernExecutor, "west coast server");
+ int westernPort = PORT + portCounter++;
+ Cancellable westernServer = SocketProtocol.registerServerTransport(westernEndpoint, westernExecutor, HOST, westernPort);
+ SocketServiceConfiguration<String, String> westernServiceConfiguration = new SocketServiceConfiguration<String, String>(SERVICE_TYPE, GROUP_NAME, String.class, String.class, HOST, westernPort);
+ SocketProtocol.startService(westernEndpoint, westernExecutor, westernServiceConfiguration, new DrNickRequestListener());
+
+ // Start east coast service.
+ ExecutorService easternExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint easternEndpoint = Remoting.createEndpoint(easternExecutor, "west coast server");
+ int easternPort = PORT + portCounter++;
+ Cancellable easternServer = SocketProtocol.registerServerTransport(easternEndpoint, easternExecutor, HOST, easternPort);
+ SocketServiceConfiguration<String, String> easternServiceConfiguration = new SocketServiceConfiguration<String, String>(SERVICE_TYPE, GROUP_NAME, String.class, String.class, HOST, easternPort);
+ SocketProtocol.startService(easternEndpoint, easternExecutor, easternServiceConfiguration, new DrNickRequestListener());
+
+ // Send message east to west and get response.
+ Connection eastWestConnection = getFutureResult(easternEndpoint.connect(new URI("socket://" + HOST + ":" + westernPort), OptionMap.EMPTY), "couldn't create Connection");
+ Client<String, String> eastWestClient = getFutureResult(eastWestConnection.openClient(SERVICE_TYPE, GROUP_NAME, String.class, String.class), "couldn't create Client");
+ String response = getFutureResult(eastWestClient.send(DR_NICK_REQUEST), "couldn't get response from west coast");
+ assertEquals(DR_NICK_RESPONSE, response);
+ log.info("EAST to WEST PASSES");
+ response = getFutureResult(eastWestClient.send(DR_NICK_REQUEST), "couldn't get response from west coast");
+ assertEquals(DR_NICK_RESPONSE, response);
+ log.info("EAST to WEST PASSES AGAIN");
+
+ // Send message east to west and get response.
+ Connection westEastConnection = getFutureResult(westernEndpoint.connect(new URI("socket://" + HOST + ":" + easternPort), OptionMap.EMPTY), "couldn't create Connection");
+ Client<String, String> westEastClient = getFutureResult(westEastConnection.openClient(SERVICE_TYPE, GROUP_NAME, String.class, String.class), "couldn't create Client");
+ response = getFutureResult(westEastClient.send(DR_NICK_REQUEST), "couldn't get response from east coast");
+ assertEquals(DR_NICK_RESPONSE, response);
+ log.info("WEST to EAST PASSES");
+ response = getFutureResult(westEastClient.send(DR_NICK_REQUEST), "couldn't get response from east coast");
+ assertEquals(DR_NICK_RESPONSE, response);
+ log.info("WEST to EAST PASSES AGAIN");
+
+ // Shut down.
+ eastWestClient.close();
+ eastWestConnection.close();
+ westEastClient.close();
+ westEastConnection.close();
+ easternServer.cancel();
+ westernServer.cancel();
+ westernEndpoint.close();
+ easternEndpoint.close();
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * Registers two services on a remote Endpoint and sends a message to both of them.
+ *
+ * @throws Exception
+ */
+ public void testSocketMultipleServices() throws Exception {
+ // Create server.
+ log.info("entering " + getName());
+ ExecutorService serverExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint serverEndpoint = Remoting.createEndpoint(serverExecutor, "server");
+ int serverPort = PORT + portCounter++;
+ Cancellable socketServer = SocketProtocol.registerServerTransport(serverEndpoint, serverExecutor, HOST, serverPort);
+
+ // Start first service.
+ SocketServiceConfiguration<String, String> socketServiceConfiguration = new SocketServiceConfiguration<String, String>(SERVICE_TYPE + "1", GROUP_NAME, String.class, String.class, HOST, serverPort);
+ SocketProtocol.startService(serverEndpoint, serverExecutor, socketServiceConfiguration, new DrNickRequestListener());
+
+ // Start second service.
+ socketServiceConfiguration = new SocketServiceConfiguration<String, String>(SERVICE_TYPE + "2", GROUP_NAME, String.class, String.class, HOST, serverPort);
+ SocketProtocol.startService(serverEndpoint, serverExecutor, socketServiceConfiguration, new DrFrankensteinRequestListener());
+
+ // Create client endpoint and get connection.
+ ExecutorService clientExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint clientEndpoint = Remoting.createEndpoint(serverExecutor, "client");
+ SocketProtocol.registerClientTransport(clientEndpoint, clientExecutor, HOST);
+ Connection connection = getFutureResult(clientEndpoint.connect(new URI("socket://" + HOST + ":" + serverPort), OptionMap.EMPTY), "couldn't create Connection");
+
+ // Send message to first service and get response.
+ Client<String, String> client1 = getFutureResult(connection.openClient(SERVICE_TYPE + "1", GROUP_NAME, String.class, String.class), "couldn't create Client");
+ String response = getFutureResult(client1.send(DR_NICK_REQUEST), "couldn't get response");
+ assertEquals(DR_NICK_RESPONSE, response);
+
+ // Send message to second service and get response.
+ Client<String, String> client2 = getFutureResult(connection.openClient(SERVICE_TYPE + "2", GROUP_NAME, String.class, String.class), "couldn't create Client");
+ response = getFutureResult(client2.send(DR_FRANKENSTEIN_REQUEST), "couldn't get response");
+ assertEquals(DR_FRANKENSTEIN_RESPONSE, response);
+
+ // Shut down.
+ client1.close();
+ client2.close();
+ connection.close();
+ clientEndpoint.close();
+ socketServer.cancel();
+ serverEndpoint.close();
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * Sends url for local service and gets callbacks from a remote service.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testSocketTransportCallbackWithURL() throws Exception {
+ // Start remote service.
+ log.info("entering " + getName());
+ ExecutorService remoteExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint remoteEndpoint = Remoting.createEndpoint(remoteExecutor, "remote endpoint");
+ int remotePort = PORT + portCounter++;
+ Cancellable remoteServer = SocketProtocol.registerServerTransport(remoteEndpoint, remoteExecutor, HOST, remotePort);
+ SocketServiceConfiguration<RequestWrapper, Object> remoteServiceConfiguration = new SocketServiceConfiguration<RequestWrapper, Object>(SERVICE_TYPE + "remote", GROUP_NAME, RequestWrapper.class, Object.class, HOST, remotePort);
+ SocketProtocol.startService(remoteEndpoint, remoteExecutor, remoteServiceConfiguration, new CallbackSenderRequestListenerURI(remoteEndpoint));
+
+ // Start local service.
+ ExecutorService localExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint localEndpoint = Remoting.createEndpoint(localExecutor, "local server");
+ int localPort = PORT + portCounter++;
+ Cancellable localServer = SocketProtocol.registerServerTransport(localEndpoint, localExecutor, HOST, localPort);
+ SocketServiceConfiguration<Object, Object> localServiceConfiguration = new SocketServiceConfiguration<Object, Object>(SERVICE_TYPE + "local", GROUP_NAME, Object.class, Object.class, HOST, localPort);
+ CallbackReceiverRequestListener callbackReceiver = new CallbackReceiverRequestListener();
+ SocketProtocol.startService(localEndpoint, localExecutor, localServiceConfiguration, callbackReceiver);
+
+ // Send message to remote server and get callbacks.
+ Connection connection = getFutureResult(localEndpoint.connect(new URI("socket://" + HOST + ":" + remotePort), OptionMap.EMPTY), "couldn't create Connection");
+ Client<Object, RequestWrapper> client = getFutureResult(connection.openClient(SERVICE_TYPE + "remote", GROUP_NAME, Object.class, RequestWrapper.class), "couldn't create Client");
+ RequestWrapper wrapper = new RequestWrapper();
+ wrapper.setUrl("socket://" + HOST + ":" + localPort);
+ wrapper.setServiceType(SERVICE_TYPE + "local");
+ wrapper.setGroupName(GROUP_NAME);
+ wrapper.setPayload("callback");
+ client.send(wrapper);
+ Object callback = callbackReceiver.getNext();
+ assertEquals("callback", callback);
+ callback = callbackReceiver.getNext();
+ assertEquals("callback", callback);
+ callback = callbackReceiver.getNext();
+ assertEquals("callback", callback);
+
+ // Shut down.
+ client.close();
+ connection.close();
+ localServer.cancel();
+ remoteServer.cancel();
+ remoteEndpoint.close();
+ localEndpoint.close();
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * Sends a ClientConnector and gets callbacks.
+ *
+ * @throws Exception
+ */
+ public void testSocketTransportCallbackWithClientConnector() throws Exception {
+ // Start remote service.
+ log.info("entering " + getName());
+ ExecutorService remoteExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint remoteEndpoint = Remoting.createEndpoint(remoteExecutor, "remote endpoint");
+ int remotePort = PORT + portCounter++;
+ Cancellable remoteServer = SocketProtocol.registerServerTransport(remoteEndpoint, remoteExecutor, HOST, remotePort);
+ SocketServiceConfiguration<Object, Object> remoteServiceConfiguration = new SocketServiceConfiguration<Object, Object>(SERVICE_TYPE + "remote", GROUP_NAME, Object.class, Object.class, HOST, remotePort);
+ SocketProtocol.startService(remoteEndpoint, remoteExecutor, remoteServiceConfiguration, new CallbackSenderRequestListenerClientConnector());
+
+ // Create local endpoint.
+ ExecutorService localExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Endpoint localEndpoint = Remoting.createEndpoint(localExecutor, "local server");
+ SocketProtocol.registerClientTransport(localEndpoint, localExecutor, HOST);
+
+ // Send ClientConnector to remote server and get callbacks.
+ Connection connection = getFutureResult(localEndpoint.connect(new URI("socket://" + HOST + ":" + remotePort), OptionMap.EMPTY), "couldn't create Connection");
+ Client<Object, Object> client = getFutureResult(connection.openClient(SERVICE_TYPE + "remote", GROUP_NAME, Object.class, Object.class), "couldn't create Client");
+ CallbackReceiverRequestListener callbackReceiver = new CallbackReceiverRequestListener();
+ ClientConnector<Object, Object> clientConnector = connection.createClientConnector(callbackReceiver, Object.class, Object.class);
+ assertEquals("OK", client.invoke(clientConnector));
+ assertEquals("sent callback", client.invoke("send first callback"));
+ Object callback = callbackReceiver.getNext();
+ assertEquals("callback0", callback);
+ assertEquals("sent callback", client.invoke("send second callback"));
+ callback = callbackReceiver.getNext();
+ assertEquals("callback1", callback);
+
+ // Shut down.
+ client.close();
+ connection.close();
+ remoteServer.cancel();
+ remoteEndpoint.close();
+ localEndpoint.close();
+ log.info(getName() + " PASSES");
+ }
+
+
+ static <T> T getFutureResult(IoFuture<T> future, String errorMessage) throws Exception {
+ switch (future.await(5000, TimeUnit.MILLISECONDS)) {
+ case DONE: {
+ return future.get();
+ }
+ case FAILED: {
+ log.error(errorMessage);
+ throw future.getException();
+ }
+ default: {
+ throw new Exception("unexpeced future state: " + future);
+ }
+ }
+ }
+
+
+ public static class DrNickRequestListener implements RequestListener<String, String> {
+ public void handleClose() {
+ }
+
+ public void handleRequest(RequestContext<String> context, String request) throws RemoteExecutionException {
+ try {
+ log.info(this + ": got request: " + request);
+ if (SocketUsageExamples.DR_NICK_REQUEST.equalsIgnoreCase(request))
+ context.sendReply(SocketUsageExamples.DR_NICK_RESPONSE);
+ else
+ context.sendReply(request);
+ log.info(this + ": sent response");
+ } catch (IllegalStateException e) {
+ throw new RemoteExecutionException("Dr. Nick has left the state", e);
+ }
+ catch (IOException e){
+ throw new RemoteExecutionException("Dr. Nick has left the building", e);
+ }
+ }
+ }
+
+
+ public static class DrFrankensteinRequestListener implements RequestListener<String, String> {
+ public void handleClose() {
+ }
+
+ public void handleRequest(RequestContext<String> context, String request) throws RemoteExecutionException {
+ try {
+ log.info(this + ": got request: " + request);
+ if (SocketUsageExamples.DR_FRANKENSTEIN_REQUEST.equalsIgnoreCase(request))
+ context.sendReply(SocketUsageExamples.DR_FRANKENSTEIN_RESPONSE);
+ else
+ context.sendReply(request);
+ log.info(this + ": sent response");
+ } catch (IllegalStateException e) {
+ throw new RemoteExecutionException("Dr. Nick has left the state", e);
+ }
+ catch (IOException e){
+ throw new RemoteExecutionException("Dr. Nick has left the building", e);
+ }
+ }
+ }
+
+
+ public static class RequestWrapper implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private String url;
+ private String serviceType;
+ private String groupName;
+ private Object payload;
+ public String getUrl() {
+ return url;
+ }
+ public void setUrl(String url) {
+ this.url = url;
+ }
+ public String getServiceType() {
+ return serviceType;
+ }
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+ public String getGroupName() {
+ return groupName;
+ }
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+ public Object getPayload() {
+ return payload;
+ }
+ public void setPayload(Object payload) {
+ this.payload = payload;
+ }
+ }
+
+
+ static class CallbackSenderRequestListenerURI<I, O> implements RequestListener<RequestWrapper, RequestWrapper> {
+ private Endpoint endpoint;
+
+ public CallbackSenderRequestListenerURI(Endpoint endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public void handleClose() {
+ }
+
+ public void handleRequest(RequestContext<RequestWrapper> context, RequestWrapper request) throws RemoteExecutionException {
+ log.info(this + ": got request: " + request);
+ Connection connection = null;
+ Client<Object, Object> client = null;
+ try {
+ connection = getFutureResult(endpoint.connect(new URI(request.getUrl()), OptionMap.EMPTY), "couldn't create Connection");
+ client = getFutureResult(connection.openClient(request.getServiceType(), request.getGroupName(), Object.class, Object.class), "couldn't create Client");
+ log.info(this + " got client: " + client);
+ client.send(request.payload);
+ log.info(this + ": sent callback");
+ client.send(request.payload);
+ log.info(this + ": sent callback");
+ client.send(request.payload);
+ log.info(this + ": sent callback");
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ try {
+ client.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ connection.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ static class CallbackSenderRequestListenerClientConnector implements RequestListener<Object, Object> {
+ private ClientConnector<Object, Object> clientConnector;
+ private Client<Object, Object> client;
+ private int counter;
+
+ public void handleClose() {
+ if (client != null) {
+ try {
+ client.close();
+ client = null;
+ } catch (IOException e) {
+ log.warn(this + " unable to close Client " + client);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void handleRequest(RequestContext<Object> context, Object request) throws RemoteExecutionException {
+ log.info(this + ": got request: " + request);
+
+ if (request instanceof ClientConnector<?, ?>) {
+ clientConnector = (ClientConnector<Object, Object>) request;
+ try {
+ client = clientConnector.getFutureClient().get();
+ } catch (Exception e) {
+ log.error("unable to create Client", e);
+ fail(context, "unable to create Client", e);
+ return;
+ }
+ answer(context, "OK");
+ return;
+ }
+
+ if (clientConnector == null) {
+ fail(context, "ClientConnector has not been received", null);
+ return;
+ }
+
+ try {
+ client.send("callback" + counter++);
+ answer(context, "sent callback");
+ } catch (IOException e) {
+ fail(context, "unable to send response", e);
+ }
+ }
+
+ void answer(RequestContext<Object> context, Object response) {
+ try {
+ context.sendReply(response);
+ return;
+ } catch (Exception e) {
+ try {
+ context.sendFailure("unable to respond", e);
+ return;
+ } catch (Exception e1) {
+ log.error(this + " unable to return exception", e1);
+ return;
+ }
+ }
+ }
+
+ void fail(RequestContext<Object> context, String response, Throwable t) {
+ log.error(response, t);
+ try {
+ context.sendFailure(response, t);
+ return;
+ } catch (Exception e) {
+ try {
+ context.sendFailure("unable to respond", e);
+ return;
+ } catch (Exception e1) {
+ log.error(this + " unable to return exception", e1);
+ return;
+ }
+ }
+ }
+ }
+
+
+ public static class CallbackReceiverRequestListener implements RequestListener<Object, Object> {
+ private static Logger log = Logger.getLogger(CallbackReceiverRequestListener.class);
+ private ArrayList<Object> callbacks = new ArrayList<Object>();
+
+ public void handleClose() {
+ }
+
+ public void handleRequest(RequestContext<Object> context, Object callback) throws RemoteExecutionException {
+ log.info(this + ": got callback: " + callback);
+ callbacks.add(callback);
+ synchronized (callbacks) {
+ callbacks.notify();
+ }
+ try {
+ context.sendReply("got callback");
+ } catch (Exception e) {
+ try {
+ context.sendFailure("unable to send reply", e);
+ } catch (Exception e1) {
+ log.warn("unable to send failure message", e1);
+ }
+ }
+ }
+
+ public Object getNext() {
+ if (callbacks.size() == 0) {
+ synchronized (callbacks) {
+ while (true) {
+ try {
+ log.info(this + " waiting for a callback to return");
+ callbacks.wait();
+ break;
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ return callbacks.remove(0);
+ }
+ }
+}
+
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketClientConnectionHandler.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketClientConnectionHandler.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketClientConnectionHandler.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,136 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket.client;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.URI;
+import java.util.concurrent.Executor;
+
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.Marshalling;
+import org.jboss.marshalling.MarshallingConfiguration;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.samples.socket.SocketHandleableCloseable;
+import org.jboss.remoting3.samples.socket.SocketProtocol;
+import org.jboss.remoting3.spi.AbstractHandleableCloseable;
+import org.jboss.remoting3.spi.ConnectionHandler;
+import org.jboss.remoting3.spi.RequestHandler;
+import org.jboss.remoting3.spi.RequestHandlerConnector;
+import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.Result;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 14, 2009
+ * </p>
+ */
+public class SocketClientConnectionHandler extends AbstractHandleableCloseable<SocketHandleableCloseable> implements ConnectionHandler, SocketHandleableCloseable {
+ private static final Logger log = Logger.getLogger("org.jboss.remoting.samples.socket.client.SocketClientConnectionHandler");
+
+ private String remoteHost;
+ private int remotePort;
+ private String localHost;
+
+ public SocketClientConnectionHandler(URI uri, OptionMap connectOptions, Executor executor, String localHost, int localPort) {
+ super(executor);
+ this.remoteHost = uri.getHost();
+ this.remotePort = uri.getPort();
+ this.localHost = localHost;
+ }
+
+ public RequestHandlerConnector createConnector(RequestHandler localHandler) {
+ try {
+ SocketRequestHandlerConnector<?, ?> connector = new SocketRequestHandlerConnector<Object, Object>(getExecutor(), localHandler, localHost);
+ registerCloseHandler(connector);
+ return connector;
+ } catch (IOException e) {
+ log.error(this + " unable to create SocketRequestHandlerConnector", e);
+ return null;
+ }
+ }
+
+ public Cancellable open(String serviceName, String groupName, Result<RequestHandler> result) {
+ try
+ {
+ final Socket socket = new Socket(remoteHost, remotePort);
+ log.info("client created socket");
+ MarshallerFactory factory = SocketProtocol.getMarshallerFactory();
+ MarshallingConfiguration configuration = SocketProtocol.getMarshallingConfiguration();
+ final Marshaller marshaller = factory.createMarshaller(configuration);
+ final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration);
+ marshaller.start(Marshalling.createByteOutput(socket.getOutputStream()));
+ marshaller.writeUTF(serviceName);
+ marshaller.writeUTF(groupName);
+ marshaller.flush();
+ unmarshaller.start(Marshalling.createByteInput(socket.getInputStream()));
+ result.setResult(new SocketClientRequestHandler(getExecutor(), marshaller, unmarshaller));
+ registerCloseHandler(socket, marshaller, unmarshaller);
+ } catch (IOException e) {
+ result.setException(e);
+ }
+ return IoUtils.nullCancellable();
+ }
+
+ protected void registerCloseHandler(final Socket socket, final Marshaller marshaller, final Unmarshaller unmarshaller) {
+ addCloseHandler(new CloseHandler<Object>() {
+ public void handleClose(Object closed) {
+ try {
+ marshaller.close();
+ } catch (IOException e) {
+ log.warn(this + " unable to close marshaller: " + marshaller);
+ } finally {
+ try {
+ unmarshaller.close();
+ } catch (IOException e) {
+ log.warn(this + " unable to close unmarshaller: " + unmarshaller);
+ } finally {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ log.warn(this + " unable to close socket: " + socket);
+ }
+ }
+ }
+ }
+ });
+ }
+
+ protected void registerCloseHandler(final SocketRequestHandlerConnector<?, ?> requestHandlerConnector) {
+ addCloseHandler(new CloseHandler<Object>() {
+ public void handleClose(Object closed) {
+ try {
+ requestHandlerConnector.close();
+ } catch (IOException e) {
+ log.warn(this + " unable to close SocketRequestHandlerConnector: " + requestHandlerConnector);
+ }
+ }
+ });
+ }
+}
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketClientRequestHandler.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketClientRequestHandler.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketClientRequestHandler.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket.client;
+
+import java.io.IOException;
+import java.util.concurrent.Executor;
+
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.remoting3.spi.AbstractHandleableCloseable;
+import org.jboss.remoting3.spi.RemoteRequestContext;
+import org.jboss.remoting3.spi.ReplyHandler;
+import org.jboss.remoting3.spi.RequestHandler;
+import org.jboss.remoting3.spi.SpiUtils;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 14, 2009
+ * </p>
+ */
+public class SocketClientRequestHandler extends AbstractHandleableCloseable<RequestHandler> implements RequestHandler {
+ private static final Logger log = Logger.getLogger("org.jboss.remoting.samples.socket.SocketRequestHandler");
+
+ private Marshaller marshaller;
+ private Unmarshaller unmarshaller;
+
+ public SocketClientRequestHandler(Executor executor, Marshaller marshaller, Unmarshaller unmarshaller) {
+ super(executor);
+ this.marshaller = marshaller;
+ this.unmarshaller = unmarshaller;
+ }
+
+ public RemoteRequestContext receiveRequest(Object request, final ReplyHandler replyHandler) {
+ try {
+ marshaller.writeObject(request);
+ marshaller.flush();
+ log.info(this + ": sent request: " + request);
+ }
+ catch (IOException e) {
+ SpiUtils.safeHandleException(replyHandler, e);
+ }
+
+ getExecutor().execute(new Runnable() {
+ public void run() {
+ try {
+ log.info(SocketClientRequestHandler.this + ": waiting for reply");
+ Object reply = unmarshaller.readObject();
+ log.info(this + ": reply: " + reply);
+ SpiUtils.safeHandleReply(replyHandler, reply);
+ } catch (ClassNotFoundException e) {
+ SpiUtils.safeHandleException(replyHandler, new IOException("Cannot find class: " + e.getMessage(), e));
+ } catch (IOException e) {
+ SpiUtils.safeHandleException(replyHandler, e);
+ }
+ }
+ });
+
+ return new RemoteRequestContext() {
+ public RemoteRequestContext cancel() {
+ log.debug("Closing " + SocketClientRequestHandler.this);
+ IoUtils.safeClose(SocketClientRequestHandler.this);
+ return this;
+ }
+ };
+ }
+}
+
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketRequestHandlerConnector.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketRequestHandlerConnector.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/client/SocketRequestHandlerConnector.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket.client;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.Executor;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.Marshalling;
+import org.jboss.marshalling.MarshallingConfiguration;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.samples.socket.SocketHandleableCloseable;
+import org.jboss.remoting3.samples.socket.SocketProtocol;
+import org.jboss.remoting3.samples.socket.server.SocketServerRequestHandler;
+import org.jboss.remoting3.spi.AbstractHandleableCloseable;
+import org.jboss.remoting3.spi.RequestHandler;
+import org.jboss.remoting3.spi.RequestHandlerConnector;
+import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.Result;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Nov 10, 2009
+ * </p>
+ */
+public class SocketRequestHandlerConnector<I, O> extends AbstractHandleableCloseable<SocketHandleableCloseable> implements RequestHandlerConnector, SocketHandleableCloseable, Serializable {
+ private static final long serialVersionUID = 37933691697892626L;
+ private static final Logger log = Logger.getLogger(SocketRequestHandlerConnector.class);
+
+ private String callbackHost;
+ private transient RequestHandlerServer requestHandlerServer;
+ private int callbackPort;
+ private SocketClientRequestHandler socketClientRequestHandler;
+
+ public SocketRequestHandlerConnector() {
+ // ???
+ super(new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()));
+ }
+
+ public SocketRequestHandlerConnector(Executor executor, RequestHandler localRequestHandler, String callbackHost) throws IOException {
+ super(executor);
+ this.callbackHost = callbackHost;
+ requestHandlerServer = new RequestHandlerServer(localRequestHandler, callbackHost);
+ callbackPort = requestHandlerServer.getLocalPort();
+ requestHandlerServer.start();
+ }
+
+ public Cancellable createRequestHandler(Result<RequestHandler> result) throws SecurityException {
+ if (socketClientRequestHandler != null) {
+ throw new SecurityException(this + ": a SocketClientRequestHandler has already been created");
+ }
+
+ try
+ {
+ Socket socket = new Socket(callbackHost, callbackPort);
+ log.info("server created callback Socket");
+ MarshallerFactory factory = SocketProtocol.getMarshallerFactory();
+ MarshallingConfiguration configuration = SocketProtocol.getMarshallingConfiguration();
+ final Marshaller marshaller = factory.createMarshaller(configuration);
+ final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration);
+ marshaller.start(Marshalling.createByteOutput(socket.getOutputStream()));
+ marshaller.flush();
+ unmarshaller.start(Marshalling.createByteInput(socket.getInputStream()));
+ socketClientRequestHandler = new SocketClientRequestHandler(getExecutor(), marshaller, unmarshaller);
+ result.setResult(socketClientRequestHandler);
+ registerCloseHandler(socketClientRequestHandler);
+ registerCloseHandler(marshaller);
+ registerCloseHandler(unmarshaller);
+ registerCloseHandler(socket);
+ } catch (IOException e) {
+ result.setException(e);
+ }
+
+ return IoUtils.nullCancellable();
+ }
+
+ void registerCloseHandler(final Object o) {
+ try {
+ final Method close = o.getClass().getMethod("close");
+ addCloseHandler(new CloseHandler<Object>() {
+ public void handleClose(Object closed) {
+ try {
+ close.invoke(o);
+ } catch (Exception e) {
+ log.warn(this + " unable to close " + o, e);
+ }
+ }
+ });
+ } catch (Exception e) {
+ throw new RuntimeException(this + " got object without close method: " + o);
+ }
+ }
+
+ static class RequestHandlerServer extends Thread {
+ private RequestHandler localRequestHandler;
+ private ServerSocket serverSocket;
+ private Socket socket;
+ private SocketServerRequestHandler socketServerRequestHandler;
+
+ RequestHandlerServer(RequestHandler localRequestHandler, String localHost) throws IOException {
+ this.localRequestHandler = localRequestHandler;
+ serverSocket = new ServerSocket();
+ serverSocket.bind(new InetSocketAddress(localHost, 0));
+ }
+
+ public void run() {
+ try
+ {
+ socket = serverSocket.accept();
+ log.info("client created callback Socket");
+ socketServerRequestHandler = new SocketServerRequestHandler(localRequestHandler, socket);
+ socketServerRequestHandler.start();
+ } catch (IOException e) {
+ log.error(this + " unable to accept a new Socket", e);
+ } finally {
+ try {
+ serverSocket.close();
+ } catch (IOException e) {
+ log.warn(this + " unable to close ServerSocket " + serverSocket, e);
+ }
+ serverSocket = null;
+ }
+ }
+
+ int getLocalPort() {
+ return serverSocket.getLocalPort();
+ }
+
+ void close() {
+ try {
+ if (serverSocket != null) {
+ serverSocket.close();
+ }
+ } catch (IOException e) {
+ log.warn(this + " unable to close ServerSocket " + serverSocket, e);
+ } finally {
+ try {
+ if (socket != null) {
+ socket.close();
+ }
+ } catch (IOException e) {
+ log.warn(this + " unable to close Socket " + socket, e);
+ } finally {
+ try {
+ if (socketServerRequestHandler != null) {
+ socketServerRequestHandler.close();
+ }
+ } catch (IOException e) {
+ log.warn(this + " unable to close SocketServerRequestHandler " + socketServerRequestHandler, e);
+ }
+ }
+ }
+ }
+ }
+}
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketClientListener.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketClientListener.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketClientListener.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket.server;
+
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.remoting3.ClientContext;
+import org.jboss.remoting3.ClientListener;
+import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.remoting3.samples.socket.SocketServiceConfiguration;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 16, 2009
+ * </p>
+ */
+public class SocketClientListener<I, O> implements ClientListener<I, O> {
+ private static ConcurrentHashMap<RequestListener<?, ?>, SocketServiceConfiguration<?, ?>> requestListeners = new ConcurrentHashMap<RequestListener<?, ?>, SocketServiceConfiguration<?, ?>>();
+ private RequestListener<I, O> requestListener;
+
+ public static SocketServiceConfiguration<?, ?> getRequestListenerInfo(RequestListener<?, ?> requestListener) {
+ return requestListeners.get(requestListener);
+ }
+
+ public SocketClientListener(Endpoint endpoint, SocketServiceConfiguration<I, O> socketConfig, final RequestListener<I, O> requestListener) throws IOException {
+ if (requestListeners.containsKey(requestListener)) {
+ throw new IOException(requestListener + " is already registered");
+ }
+ if (requestListeners.values().contains(socketConfig)) {
+ throw new IOException("RequestListener with characterized by " + socketConfig + " is already registered");
+ }
+ requestListeners.put(requestListener, socketConfig);
+ endpoint.addCloseHandler(new CloseHandler<Object>() {
+ public void handleClose(Object closed) {
+ requestListeners.remove(requestListener);
+ }
+ });
+ this.requestListener = requestListener;
+ }
+
+ public RequestListener<I, O> handleClientOpen(ClientContext clientContext) {
+ return requestListener;
+ }
+}
+
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerConnectionHandler.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerConnectionHandler.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerConnectionHandler.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket.server;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.Executor;
+
+import org.jboss.marshalling.MarshallingConfiguration;
+import org.jboss.marshalling.reflect.SunReflectiveCreator;
+import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.samples.socket.SocketHandleableCloseable;
+import org.jboss.remoting3.spi.AbstractHandleableCloseable;
+import org.jboss.remoting3.spi.ConnectionHandler;
+import org.jboss.remoting3.spi.ConnectionHandlerContext;
+import org.jboss.remoting3.spi.RequestHandler;
+import org.jboss.remoting3.spi.RequestHandlerConnector;
+import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.Result;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 16, 2009
+ * </p>
+ */
+public class SocketServerConnectionHandler<I, O> extends AbstractHandleableCloseable<SocketHandleableCloseable> implements ConnectionHandler, SocketHandleableCloseable {
+ private static final Logger log = Logger.getLogger("org.jboss.remoting.samples.socket.server.SocketServerAcceptor");
+
+ private Endpoint endpoint;
+ private ConnectionHandlerContext connectionHandlerContext;
+ private String host;
+ private int port;
+ private MarshallingConfiguration marshallingConfig;
+ private boolean running;
+
+ public SocketServerConnectionHandler(Endpoint endpoint, Executor executor, ConnectionHandlerContext connectionHandlerContext, String host, int port) {
+ super(executor);
+ this.endpoint = endpoint;
+ this.host = host;
+ this.port = port;
+ this.connectionHandlerContext = connectionHandlerContext;
+ marshallingConfig = new MarshallingConfiguration();
+ marshallingConfig.setCreator(new SunReflectiveCreator());
+ }
+
+ public void start() throws IOException {
+ running = true;
+ final ServerSocket ss = new ServerSocket(port, 200, InetAddress.getByName(host));
+ new Thread() {
+ public void run() {
+ while (running) {
+ try {
+ Socket socket = ss.accept();
+ log.info("server created socket");
+ SocketServerRequestHandler requestHandler = new SocketServerRequestHandler(endpoint, socket, connectionHandlerContext);
+ registerServerSocketCloseHandler(requestHandler);
+ requestHandler.start();
+ }
+ catch (IOException e) {
+ log.error("Error handling new connection", e);
+ }
+ }
+ try {
+ ss.close();
+ } catch (IOException e) {
+ log.warn("Error closing ServerSocket: " + ss);
+ }
+ }
+ }.start();
+ }
+
+
+ public void stop() {
+ running = false;
+ try {
+ close();
+ } catch (IOException e) {
+ log.warn(this + " unable to close");
+ }
+ }
+
+ @Override
+ public RequestHandlerConnector createConnector(RequestHandler localHandler) {
+ return null;
+ }
+
+ @Override
+ public Cancellable open(String serviceName, String groupName, Result<RequestHandler> result) {
+ return null;
+ }
+
+ protected void registerServerSocketCloseHandler(final SocketServerRequestHandler requestHandler) {
+ addCloseHandler(new CloseHandler<Object>() {
+ public void handleClose(Object closed) {
+ try {
+ requestHandler.close();
+ } catch (IOException e) {
+ log.warn("unable to close SocketServerRequestHandler: " + requestHandler);
+ }
+ }
+ });
+ }
+}
+
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerReplyHandler.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerReplyHandler.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerReplyHandler.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket.server;
+
+import java.io.IOException;
+
+import org.jboss.marshalling.Marshaller;
+import org.jboss.remoting3.spi.ReplyHandler;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 16, 2009
+ * </p>
+ */
+public class SocketServerReplyHandler implements ReplyHandler
+{
+ private static final Logger log = Logger.getLogger(SocketServerReplyHandler.class);
+ private Marshaller marshaller;
+
+ public SocketServerReplyHandler(Marshaller marshaller) {
+ this.marshaller = marshaller;
+ }
+
+ public void handleCancellation() throws IOException {
+ }
+
+ public void handleException(IOException exception) throws IOException {
+ marshaller.writeObject(exception);
+ marshaller.flush();
+ }
+
+ public void handleReply(Object reply) throws IOException {
+ log.info(this + " handling reply: " + reply);
+ marshaller.writeObject(reply);
+ marshaller.flush();
+ log.info(this + " handled reply: " + reply);
+ }
+}
+
Added: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerRequestHandler.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerRequestHandler.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerRequestHandler.java 2009-11-13 03:36:46 UTC (rev 5590)
@@ -0,0 +1,178 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.remoting3.samples.socket.server;
+
+import java.io.IOException;
+import java.net.Socket;
+
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.Marshalling;
+import org.jboss.marshalling.MarshallingConfiguration;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.ServiceNotFoundException;
+import org.jboss.remoting3.ServiceURI;
+import org.jboss.remoting3.samples.socket.RequestHandlerFuture;
+import org.jboss.remoting3.samples.socket.SocketProtocol;
+import org.jboss.remoting3.spi.ConnectionHandlerContext;
+import org.jboss.remoting3.spi.RemoteRequestContext;
+import org.jboss.remoting3.spi.ReplyHandler;
+import org.jboss.remoting3.spi.RequestHandler;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Oct 14, 2009
+ * </p>
+ */
+public class SocketServerRequestHandler extends Thread implements RequestHandler {
+ private static final Logger log = Logger.getLogger(SocketServerRequestHandler.class);
+ private Socket socket;
+ private Marshaller marshaller;
+ private Unmarshaller unmarshaller;
+ private RequestHandler requestHandler;
+ private ReplyHandler replyHandler;
+ private boolean running;
+
+ /**
+ * Calling this constructor creates a
+ *
+ */
+ public <I, O> SocketServerRequestHandler(final Endpoint endpoint, Socket socket, ConnectionHandlerContext connectionHandlerContext) {
+ try {
+ this.socket = socket;
+ MarshallerFactory factory = SocketProtocol.getMarshallerFactory();
+ MarshallingConfiguration configuration = SocketProtocol.getMarshallingConfiguration();
+ marshaller = factory.createMarshaller(configuration);
+ marshaller.start(Marshalling.createByteOutput(socket.getOutputStream()));
+ marshaller.flush();
+ unmarshaller = factory.createUnmarshaller(configuration);
+ unmarshaller.start(Marshalling.createByteInput(socket.getInputStream()));
+ final String serviceType = unmarshaller.readUTF();
+ final String groupName = unmarshaller.readUTF();
+ final RequestHandlerFuture requestHandlerFuture = new RequestHandlerFuture();
+
+ ConnectionHandlerContext.ServiceResult serviceResult = new ConnectionHandlerContext.ServiceResult() {
+ public void opened(final RequestHandler requestHandler, final OptionMap optionMap) {
+ requestHandlerFuture.setResult(requestHandler);
+ }
+ public void notFound() {
+ requestHandlerFuture.setException(new ServiceNotFoundException(ServiceURI.create(serviceType, groupName, endpoint.getName()), "No such service located"));
+ }
+ };
+
+ connectionHandlerContext.openService(serviceType, groupName, OptionMap.EMPTY, serviceResult);
+ requestHandler = requestHandlerFuture.get();
+ if (requestHandler == null) {
+ throw requestHandlerFuture.getException();
+ }
+ replyHandler = new SocketServerReplyHandler(marshaller);
+ } catch (Exception e) {
+ throw new RuntimeException("unable to process socket: " + socket, e);
+ }
+ }
+
+
+ public <I, O> SocketServerRequestHandler(RequestHandler localRequestHandler, Socket socket) {
+ try {
+ this.requestHandler = localRequestHandler;
+ this.socket = socket;
+ MarshallerFactory factory = SocketProtocol.getMarshallerFactory();
+ MarshallingConfiguration configuration = SocketProtocol.getMarshallingConfiguration();
+ marshaller = factory.createMarshaller(configuration);
+ marshaller.start(Marshalling.createByteOutput(socket.getOutputStream()));
+ marshaller.flush();
+ unmarshaller = factory.createUnmarshaller(configuration);
+ unmarshaller.start(Marshalling.createByteInput(socket.getInputStream()));
+ replyHandler = new SocketServerReplyHandler(marshaller);
+ } catch (Exception e) {
+ throw new RuntimeException("unable to process socket: " + socket, e);
+ }
+ }
+
+
+ @Override
+ public void run() {
+ running = true;
+ while (running) {
+ Object request;
+ try {
+ log.info(SocketServerRequestHandler.this + " waiting for next request");
+ request = unmarshaller.readObject();
+ log.info(SocketServerRequestHandler.this + " got request: " + request);
+ requestHandler.receiveRequest(request, replyHandler);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ finishClose();
+ }
+
+
+ @Override
+ public void close() throws IOException {
+ running = false;
+ }
+
+
+ @Override
+ public RemoteRequestContext receiveRequest(Object request, ReplyHandler replyHandler) {
+ return null;
+ }
+
+
+ @Override
+ public org.jboss.remoting3.HandleableCloseable.Key addCloseHandler( CloseHandler<? super RequestHandler> handler) {
+ return null;
+ }
+
+ public String toString() {
+ return "SocketServerRequestHandler[" + super.toString() + "]";
+ }
+
+ protected void finishClose() {
+ try {
+ marshaller.close();
+ } catch (IOException e) {
+ log.error(this + " unable to close Marshaller " + marshaller, e);
+ } finally {
+ try {
+ unmarshaller.close();
+ } catch (IOException e) {
+ log.error(this + " unable to close Unmarshaller " + unmarshaller, e);
+ } finally {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ log.error(this + " unable to close Socket " + socket, e);
+ }
+ }
+ }
+ }
+}
15 years, 1 month
JBoss Remoting SVN: r5589 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-11-12 18:57:01 -0500 (Thu, 12 Nov 2009)
New Revision: 5589
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java
Log:
Allow specification of default classloader for a service, defaulting to the classloader of the client listener
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-11-12 00:52:52 UTC (rev 5588)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-11-12 23:57:01 UTC (rev 5589)
@@ -233,6 +233,7 @@
private Class<I> requestType;
private Class<O> replyType;
private ClientListener<? super I, ? extends O> clientListener;
+ private ClassLoader classLoader;
private OptionMap optionMap = OptionMap.EMPTY;
public ServiceBuilder<I, O> setGroupName(final String groupName) {
@@ -275,6 +276,11 @@
return this;
}
+ public ServiceBuilder<I, O> setClassLoader(final ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ return this;
+ }
+
public ServiceBuilder<I, O> setOptionMap(final OptionMap optionMap) {
if (optionMap == null) {
throw new NullPointerException("optionMap is null");
@@ -353,6 +359,10 @@
serviceInfo.setOptionMap(optionMap);
serviceInfo.setRegistrationHandle(handle);
serviceInfo.setRequestHandlerConnector(requestHandlerConnector);
+ serviceInfo.setRequestClass(requestType);
+ serviceInfo.setReplyClass(replyType);
+ final ClassLoader classLoader = this.classLoader;
+ serviceInfo.setServiceClassLoader(classLoader == null ? clientListener.getClass().getClassLoader() : classLoader);
executor.execute(new Runnable() {
public void run() {
final Iterator<Map.Entry<Registration,ServiceRegistrationListener>> iter = serviceListenerRegistrations;
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java 2009-11-12 00:52:52 UTC (rev 5588)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java 2009-11-12 23:57:01 UTC (rev 5589)
@@ -49,6 +49,9 @@
final class ServiceInfo implements Cloneable {
private String serviceType;
private String groupName;
+ private ClassLoader serviceClassLoader;
+ private Class<?> requestClass;
+ private Class<?> replyClass;
private RequestHandlerConnector requestHandlerConnector;
private Registration registrationHandle;
private OptionMap optionMap;
@@ -96,6 +99,60 @@
}
/**
+ * Get the service's default classloader.
+ *
+ * @return the classloader
+ */
+ public ClassLoader getServiceClassLoader() {
+ return serviceClassLoader;
+ }
+
+ /**
+ * Set the service's default classloader.
+ *
+ * @param serviceClassLoader the classloader
+ */
+ public void setServiceClassLoader(final ClassLoader serviceClassLoader) {
+ this.serviceClassLoader = serviceClassLoader;
+ }
+
+ /**
+ * Get the request class.
+ *
+ * @return the request class
+ */
+ public Class<?> getRequestClass() {
+ return requestClass;
+ }
+
+ /**
+ * Set the request class.
+ *
+ * @param requestClass the request class
+ */
+ public void setRequestClass(final Class<?> requestClass) {
+ this.requestClass = requestClass;
+ }
+
+ /**
+ * Get the reply class.
+ *
+ * @return the reply class
+ */
+ public Class<?> getReplyClass() {
+ return replyClass;
+ }
+
+ /**
+ * Set the reply class.
+ *
+ * @param replyClass the reply class
+ */
+ public void setReplyClass(final Class<?> replyClass) {
+ this.replyClass = replyClass;
+ }
+
+ /**
* Get the option map.
*
* @return the option map
15 years, 1 month
JBoss Remoting SVN: r5588 - in remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3: spi and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-11-11 19:52:52 -0500 (Wed, 11 Nov 2009)
New Revision: 5588
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java
Log:
Allow lookups of protocol service providers by name
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-11-11 04:01:22 UTC (rev 5587)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-11-12 00:52:52 UTC (rev 5588)
@@ -685,6 +685,10 @@
public <T> Iterable<Map.Entry<String, T>> getProtocolServiceProviders(final ProtocolServiceType<T> serviceType) {
return getMapFor(serviceType).entrySet();
}
+
+ public <T> T getProtocolServiceProvider(final ProtocolServiceType<T> serviceType, final String name) {
+ return getMapFor(serviceType).get(name);
+ }
}
private final class LocalConnectionProvider implements ConnectionProvider<Void> {
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java 2009-11-11 04:01:22 UTC (rev 5587)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java 2009-11-12 00:52:52 UTC (rev 5588)
@@ -48,4 +48,15 @@
* @return the currently-registered providers
*/
<T> Iterable<Map.Entry<String, T>> getProtocolServiceProviders(ProtocolServiceType<T> serviceType);
+
+ /**
+ * Get one registered protocol service provider of the given type and name. Returns the provider,
+ * or {@code null} if none was registered for that name.
+ *
+ * @param serviceType the service type
+ * @param name the provider name
+ * @param <T> the type of the provider interface
+ * @return the provider, or {@code null} if none was matched
+ */
+ <T> T getProtocolServiceProvider(ProtocolServiceType<T> serviceType, String name);
}
15 years, 1 month
JBoss Remoting SVN: r5587 - remoting3/trunk/jboss-remoting.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-11-10 23:01:22 -0500 (Tue, 10 Nov 2009)
New Revision: 5587
Modified:
remoting3/trunk/jboss-remoting/pom.xml
Log:
Depend on XNIO 2.0.0.CR4
Modified: remoting3/trunk/jboss-remoting/pom.xml
===================================================================
--- remoting3/trunk/jboss-remoting/pom.xml 2009-11-05 01:15:03 UTC (rev 5586)
+++ remoting3/trunk/jboss-remoting/pom.xml 2009-11-11 04:01:22 UTC (rev 5587)
@@ -37,7 +37,7 @@
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-api</artifactId>
- <version>2.0.0.CR4-SNAPSHOT</version>
+ <version>2.0.0.CR4</version>
<scope>compile</scope>
</dependency>
<dependency>
15 years, 1 month