Author: david.lloyd(a)jboss.com
Date: 2009-01-08 20:57:46 -0500 (Thu, 08 Jan 2009)
New Revision: 4790
Added:
remoting3/trunk/api/src/main/java/org/jboss/remoting/Remoting.java
Removed:
remoting3/trunk/standalone/
Modified:
remoting3/trunk/build.xml
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/MultiplexClientExample.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/MultiplexServerExample.java
Log:
Get rid of the standalone module and JAR file - instead, standalone apps include the API,
core, and protocol JARs
Copied: remoting3/trunk/api/src/main/java/org/jboss/remoting/Remoting.java (from rev 4789,
remoting3/trunk/standalone/src/main/java/org/jboss/remoting/Remoting.java)
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/Remoting.java
(rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/Remoting.java 2009-01-09 01:57:46
UTC (rev 4790)
@@ -0,0 +1,187 @@
+package org.jboss.remoting;
+
+import java.io.IOException;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.Executors;
+import org.jboss.remoting.spi.RequestHandler;
+import org.jboss.remoting.spi.RequestHandlerSource;
+import org.jboss.remoting.spi.Handle;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.CloseableExecutor;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * The standalone interface into Remoting. This class contains static methods that are
useful to standalone programs
+ * for managing endpoints and services in a simple fashion.
+ *
+ * @apiviz.landmark
+ */
+public final class Remoting {
+
+ private static final Logger log = Logger.getLogger("org.jboss.remoting");
+
+ /**
+ * Create an endpoint. The endpoint will create its own thread pool with a maximum
of 10 threads.
+ *
+ * @param name the name of the endpoint
+ * @return the endpoint
+ */
+ public static Endpoint createEndpoint(final String name) throws IOException {
+ return createEndpoint(name, 10);
+ }
+
+ /**
+ * Create an endpoint. The endpoint will create its own thread pool with a maximum
of {@code maxThreads} threads.
+ *
+ * You must have the {@link org.jboss.remoting.EndpointPermission createEndpoint
EndpointPermission} to invoke this method.
+ *
+ * @param name the name of the endpoint
+ * @param maxThreads the maximum thread count
+ * @return the endpoint
+ */
+ public static Endpoint createEndpoint(final String name, final int maxThreads) throws
IOException {
+ final CloseableExecutor executor = createExecutor(maxThreads);
+ final Endpoint endpoint = createEndpoint(executor, name);
+ endpoint.addCloseHandler(new CloseHandler<Endpoint>() {
+ public void handleClose(final Endpoint closed) {
+ IoUtils.safeClose(executor);
+ }
+ });
+ return endpoint;
+ }
+
+ private static final ThreadFactory OUR_THREAD_FACTORY = new ThreadFactory() {
+ private final ThreadFactory defaultThreadFactory =
Executors.defaultThreadFactory();
+
+ public Thread newThread(final Runnable r) {
+ final Thread thread = defaultThreadFactory.newThread(r);
+ thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
+ public void uncaughtException(final Thread t, final Throwable e) {
+ log.error(e, "Uncaught exception in thread %s", t);
+ }
+ });
+ return thread;
+ }
+ };
+
+ /**
+ * Create a simple thread pool that is compatible with Remoting. The thread pool
will have a maximum of {@code maxThreads}
+ * threads.
+ *
+ * @param maxThreads the maximum thread count
+ * @return a closeable executor
+ */
+ public static CloseableExecutor createExecutor(final int maxThreads) {
+ return IoUtils.closeableExecutor(new ThreadPoolExecutor(1, maxThreads, 30L,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50), OUR_THREAD_FACTORY, new
ThreadPoolExecutor.CallerRunsPolicy()), 30L, TimeUnit.SECONDS);
+ }
+
+ /**
+ * Create an endpoint using the given {@code Executor} to execute tasks.
+ *
+ * @param executor the executor to use
+ * @param name the name of the endpoint
+ * @return the endpoint
+ */
+ public static Endpoint createEndpoint(final Executor executor, final String name)
throws IOException {
+ try {
+ return (Endpoint)
Class.forName("org.jboss.remoting.core.EndpointImpl").getConstructor(Executor.class,
String.class).newInstance(executor, name);
+ } catch (Exception e) {
+ throw new EndpointException("Unable to create endpoint", e);
+ }
+ }
+
+ /**
+ * Create a local client from a request listener. The client will retain the sole
reference to the request listener,
+ * so when the client is closed, the listener will also be closed (unless the client
is sent to a remote endpoint).
+ *
+ * @param endpoint the endpoint to bind the request listener to
+ * @param requestListener the request listener
+ * @param requestClass the request class
+ * @param replyClass the reply class
+ * @param <I> the request type
+ * @param <O> the reply type
+ * @return a new client
+ * @throws IOException if an error occurs
+ */
+ public static <I, O> Client<I, O> createLocalClient(final Endpoint
endpoint, final RequestListener<I, O> requestListener, final Class<I>
requestClass, final Class<O> replyClass) throws IOException {
+ final Handle<RequestHandler> handle =
endpoint.createRequestHandler(requestListener, requestClass, replyClass);
+ try {
+ return endpoint.createClient(handle.getResource(), requestClass,
replyClass);
+ } finally {
+ IoUtils.safeClose(handle);
+ }
+ }
+
+ /**
+ * Create a local client source from a local service configuration. The client
source will be registered on the endpoint.
+ *
+ * @param endpoint the endpoint to bind the service to
+ * @param config the service configuration
+ * @param <I> the request type
+ * @param <O> the reply type
+ * @return a new client source
+ * @throws IOException if an error occurs
+ */
+ public static <I, O> ClientSource<I, O> createLocalClientSource(final
Endpoint endpoint, final LocalServiceConfiguration<I, O> config) throws IOException
{
+ final Handle<RequestHandlerSource> handle =
endpoint.registerService(config);
+ try {
+ return endpoint.createClientSource(handle.getResource(),
config.getRequestClass(), config.getReplyClass());
+ } finally {
+ IoUtils.safeClose(handle);
+ }
+ }
+
+ /**
+ * An exception indicating that there was a problem creating an endpoint.
+ *
+ * @apiviz.exclude
+ */
+ public static final class EndpointException extends RemotingException {
+ private static final long serialVersionUID = -9157350594373125152L;
+
+ /**
+ * Constructs a <tt>EndpointException</tt> with no detail message.
The cause is not initialized, and may
+ * subsequently be initialized by a call to {@link #initCause(Throwable)
initCause}.
+ */
+ public EndpointException() {
+ }
+
+ /**
+ * Constructs a <tt>EndpointException</tt> with the specified detail
message. The cause is not initialized, and
+ * may subsequently be initialized by a call to {@link #initCause(Throwable)
initCause}.
+ *
+ * @param msg the detail message
+ */
+ public EndpointException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs a <tt>EndpointException</tt> with the specified cause.
The detail message is set to:
+ * <pre>
+ * (cause == null ? null : cause.toString())</pre>
+ * (which typically contains the class and detail message of
<tt>cause</tt>).
+ *
+ * @param cause the cause (which is saved for later retrieval by the {@link
#getCause()} method)
+ */
+ public EndpointException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructs a <tt>EndpointException</tt> with the specified detail
message and cause.
+ *
+ * @param msg the detail message
+ * @param cause the cause (which is saved for later retrieval by the {@link
#getCause()} method)
+ */
+ public EndpointException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+ }
+
+ private Remoting() { /* empty */ }
+}
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2009-01-08 22:36:45 UTC (rev 4789)
+++ remoting3/trunk/build.xml 2009-01-09 01:57:46 UTC (rev 4790)
@@ -598,7 +598,6 @@
<path refid="api.classpath"/>
<path refid="core.classpath"/>
<path refid="protocol.basic.classpath"/>
- <path refid="standalone.classpath"/>
<path refid="testing-support.classpath"/>
<path refid="lib.junit.classpath"/>
<path refid="lib.river.classpath"/>
@@ -627,7 +626,6 @@
<path refid="api.classpath"/>
<path refid="core.classpath"/>
<path refid="protocol.basic.classpath"/>
- <path refid="standalone.classpath"/>
<path refid="testing-support.classpath"/>
<pathelement
location="protocol/basic/target/test/classes"/>
<path refid="lib.junit.classpath"/>
@@ -643,7 +641,7 @@
</junit>
</target>
- <target name="protocol.basic.test"
depends="lib.river,lib.xnio-nio,api,core,protocol.basic,standalone,testing-support,protocol.basic.test.compile">
+ <target name="protocol.basic.test"
depends="lib.river,lib.xnio-nio,api,core,protocol.basic,testing-support,protocol.basic.test.compile">
<antcall inheritall="true" inheritrefs="true"
target="protocol.basic.test.pseudotarget">
<param name="extension" value=".txt"/>
<param name="message" value="Running with no security
manager"/>
@@ -691,7 +689,6 @@
<classpath>
<path refid="api.classpath"/>
<path refid="protocol.multiplex.classpath"/>
- <path refid="standalone.classpath"/>
<path refid="lib.river.classpath"/>
</classpath>
</javac>
@@ -702,52 +699,12 @@
<delete dir="samples/target"/>
</target>
- <target name="samples" description="Build the samples module"
depends="lib.marshalling-api,lib.river,api,protocol.multiplex,standalone,samples.compile">
+ <target name="samples" description="Build the samples module"
depends="lib.marshalling-api,lib.river,api,protocol.multiplex,samples.compile">
<path id="samples.classpath">
<pathelement location="samples/target/main/classes"/>
</path>
</target>
- <!-- standalone module -->
-
- <target name="standalone.compile.depcheck">
- <mkdir dir="standalone/target/main"/>
- <uptodate property="standalone.compile.uptodate"
targetfile="standalone/target/main/.lastcompile">
- <srcfiles dir="standalone/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="standalone.compile"
depends="standalone.compile.depcheck"
unless="standalone.compile.uptodate">
- <mkdir dir="standalone/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="standalone/src/main/java"
- destdir="standalone/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="api.classpath"/>
- <path refid="core.classpath"/>
- </classpath>
- </javac>
- <touch file="standalone/target/main/.lastcompile"
verbose="false"/>
- </target>
-
- <target name="standalone.clean">
- <delete dir="standalone/target"/>
- </target>
-
- <target name="standalone" description="Build the standalone
module" depends="lib.xnio-api,api,core,standalone.compile">
- <path id="standalone.classpath">
- <pathelement location="standalone/target/main/classes"/>
- </path>
- </target>
-
<!-- testing-support module -->
<target name="testing-support.compile.depcheck">
@@ -961,81 +918,16 @@
</jar>
</target>
- <target name="standalone-jar" description="Build the standalone
JAR" depends="api,core,standalone,transporter,version">
- <delete file="jboss-remoting-standalone.jar"/>
- <jar jarfile="jboss-remoting-standalone.jar">
- <manifest>
- <attribute name="Created-By" value="${java.vm.version}
(${java.vm.vendor})"/>
- <attribute name="Specification-Title" value="JBoss
Remoting"/>
- <attribute name="Specification-Version"
value="${version}"/>
- <attribute name="Specification-Vendor" value="JBoss
(
http://www.jboss.org/)"/>
- <attribute name="Implementation-Title" value="JBoss
Remoting - Standalone Version"/>
- <attribute name="Implementation-URL"
value="http://labs.jboss.org/jbossremoting/"/>
- <attribute name="Implementation-Version"
value="${version}"/>
- <attribute name="Implementation-Vendor" value="JBoss, a
division of Red Hat, Inc."/>
- <attribute name="Implementation-Vendor-Id"
value="http://www.jboss.org"/>
- </manifest>
- <zipfileset dir="api/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- <zipfileset dir="core/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- <zipfileset dir="standalone/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- <zipfileset dir="transporter/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- <zipfileset dir="version/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- </jar>
- </target>
-
- <target name="standalone-source-jar" description="Build the
standalone source JAR"
depends="api,core,standalone,transporter,version">
- <delete file="jboss-remoting-standalone-source.jar"/>
- <jar jarfile="jboss-remoting-standalone-source.jar">
- <manifest>
- <attribute name="Created-By" value="${java.vm.version}
(${java.vm.vendor})"/>
- <attribute name="Specification-Title" value="JBoss
Remoting Source"/>
- <attribute name="Specification-Version"
value="${version}"/>
- <attribute name="Specification-Vendor" value="JBoss
(
http://www.jboss.org/)"/>
- <attribute name="Implementation-Title" value="JBoss
Remoting Source - Standalone Version"/>
- <attribute name="Implementation-URL"
value="http://labs.jboss.org/jbossremoting/"/>
- <attribute name="Implementation-Version"
value="${version}"/>
- <attribute name="Implementation-Vendor" value="JBoss, a
division of Red Hat, Inc."/>
- <attribute name="Implementation-Vendor-Id"
value="http://www.jboss.org"/>
- </manifest>
- <zipfileset dir="api/src/main/java">
- <include name="**/*.java"/>
- </zipfileset>
- <zipfileset dir="core/src/main/java">
- <include name="**/*.java"/>
- </zipfileset>
- <zipfileset dir="standalone/src/main/java">
- <include name="**/*.java"/>
- </zipfileset>
- <zipfileset dir="transporter/src/main/java">
- <include name="**/*.java"/>
- </zipfileset>
- <zipfileset dir="version/src/main/java">
- <include name="**/*.java"/>
- </zipfileset>
- </jar>
- </target>
-
<!-- ============================================== -->
<!-- JAVADOCS -->
<!-- ============================================== -->
- <target name="api-javadoc" description="Build the API JavaDoc"
depends="api,core,standalone,transporter,lib.apiviz,lib.marshalling-api,lib.xnio-api">
+ <target name="api-javadoc" description="Build the API JavaDoc"
depends="api,core,transporter,lib.apiviz,lib.marshalling-api,lib.xnio-api">
<delete dir="api/target/main/docs"/>
<mkdir dir="api/target/main/docs"/>
<javadoc destdir="api/target/main/docs" author="false"
version="false" use="false" windowtitle="JBoss Remoting
API">
<doclet name="${lib.apiviz.doclet}"
pathref="lib.apiviz.classpath"/>
<packageset dir="api/src/main/java"/>
- <packageset dir="standalone/src/main/java"/>
<packageset dir="transporter/src/main/java"/>
<doctitle><![CDATA[<h1>JBoss Remoting, version
${version}</h1>]]></doctitle>
<header><![CDATA[JBoss Remoting ${version}]]></header>
@@ -1047,7 +939,6 @@
<classpath>
<path refid="core.classpath"/>
<path refid="api.classpath"/>
- <path refid="standalone.classpath"/>
<path refid="transporter.classpath"/>
</classpath>
</javadoc>
@@ -1069,7 +960,7 @@
<!-- Distribution target -->
<!-- ============================================== -->
- <target name="dist" description="Build distribution zip file"
depends="api-jar,api-source-jar,api-javadoc-zip,core-jar,core-source-jar,standalone-jar,standalone-source-jar">
+ <target name="dist" description="Build distribution zip file"
depends="api-jar,api-source-jar,api-javadoc-zip,core-jar,core-source-jar">
<delete file="jboss-remoting.zip"/>
<zip zipfile="jboss-remoting.zip">
<zipfileset dir="${basedir}">
@@ -1078,8 +969,6 @@
<include name="jboss-remoting-api-source.jar"/>
<include name="jboss-remoting-core.jar"/>
<include name="jboss-remoting-core-source.jar"/>
- <include name="jboss-remoting-standalone.jar"/>
- <include name="jboss-remoting-standalone-source.jar"/>
<include name="jboss-remoting-javadoc.zip"/>
</zipfileset>
</zip>
@@ -1090,13 +979,13 @@
<!-- core -->
- <target name="all-core" description="Build all core targets"
depends="api,compat,core,mc-deployers,protocol.basic,protocol.multiplex,samples,standalone,testing-support,transporter"/>
+ <target name="all-core" description="Build all core targets"
depends="api,compat,core,mc-deployers,protocol.basic,protocol.multiplex,samples,testing-support,transporter"/>
- <target name="clean-core" description="Clean all core targets"
depends="api.clean,compat.clean,core.clean,mc-deployers.clean,protocol.basic.clean,protocol.multiplex.clean,samples.clean,standalone.clean,testing-support.clean,transporter.clean"/>
+ <target name="clean-core" description="Clean all core targets"
depends="api.clean,compat.clean,core.clean,mc-deployers.clean,protocol.basic.clean,protocol.multiplex.clean,samples.clean,testing-support.clean,transporter.clean"/>
<!-- JARs: These should be the third-to-last targets in the file -->
- <target name="all-jars" description="Build all the JARs"
depends="api-jar,core-jar,standalone-jar"/>
+ <target name="all-jars" description="Build all the JARs"
depends="api-jar,core-jar"/>
<!-- fetch: These should be the second-to-last targets in the file -->
Modified:
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/MultiplexClientExample.java
===================================================================
---
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/MultiplexClientExample.java 2009-01-08
22:36:45 UTC (rev 4789)
+++
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/MultiplexClientExample.java 2009-01-09
01:57:46 UTC (rev 4790)
@@ -67,61 +67,63 @@
}
public static void main(String[] args) {
- final Endpoint endpoint =
Remoting.createEndpoint("example-client-endpoint");
try {
- // now create the client
- final NamedServiceRegistry serviceRegistry = new NamedServiceRegistry();
- final MultiplexConfiguration config = new MultiplexConfiguration();
- config.setNamedServiceRegistry(serviceRegistry);
- config.setAllocator(Buffers.createHeapByteBufferAllocator(1024));
- config.setMarshallerFactory(new RiverMarshallerFactory());
- config.setExecutor(IoUtils.directExecutor());
- config.setLinkMetric(100);
- config.setMarshallingConfiguration(new MarshallingConfiguration());
- final Xnio xnio = Xnio.create();
+ final Endpoint endpoint =
Remoting.createEndpoint("example-client-endpoint");
try {
- final ConfigurableFactory<CloseableTcpConnector>
tcpConnectorFactory = xnio.createTcpConnector();
- final CloseableTcpConnector closeableTcpConnector =
tcpConnectorFactory.create();
+ // now create the client
+ final NamedServiceRegistry serviceRegistry = new NamedServiceRegistry();
+ final MultiplexConfiguration config = new MultiplexConfiguration();
+ config.setNamedServiceRegistry(serviceRegistry);
+ config.setAllocator(Buffers.createHeapByteBufferAllocator(1024));
+ config.setMarshallerFactory(new RiverMarshallerFactory());
+ config.setExecutor(IoUtils.directExecutor());
+ config.setLinkMetric(100);
+ config.setMarshallingConfiguration(new MarshallingConfiguration());
+ final Xnio xnio = Xnio.create();
try {
- final ChannelSource<AllocatedMessageChannel> channelSource =
Channels.convertStreamToAllocatedMessage(closeableTcpConnector.createChannelSource(new
InetSocketAddress("localhost", 10000)), 1024, 1024);
- final IoFuture<MultiplexConnection> futureConnection =
MultiplexProtocol.connect(endpoint, config, channelSource);
- final MultiplexConnection connection = futureConnection.get();
+ final ConfigurableFactory<CloseableTcpConnector>
tcpConnectorFactory = xnio.createTcpConnector();
+ final CloseableTcpConnector closeableTcpConnector =
tcpConnectorFactory.create();
try {
- final Handle<RequestHandlerSource> handle =
connection.openRemoteService(QualifiedName.parse("/jboss/example/string-rot-13"));
+ final ChannelSource<AllocatedMessageChannel> channelSource
= Channels.convertStreamToAllocatedMessage(closeableTcpConnector.createChannelSource(new
InetSocketAddress("localhost", 10000)), 1024, 1024);
+ final IoFuture<MultiplexConnection> futureConnection =
MultiplexProtocol.connect(endpoint, config, channelSource);
+ final MultiplexConnection connection = futureConnection.get();
try {
- final ClientSource<String, String> clientSource =
endpoint.createClientSource(handle.getResource(), String.class, String.class);
+ final Handle<RequestHandlerSource> handle =
connection.openRemoteService(QualifiedName.parse("/jboss/example/string-rot-13"));
try {
- final Client<String, String> client =
clientSource.createClient();
+ final ClientSource<String, String> clientSource =
endpoint.createClientSource(handle.getResource(), String.class, String.class);
try {
- System.out.println("Enter text, send EOF to
terminate");
- final BufferedReader inputReader = new
BufferedReader(new InputStreamReader(System.in));
- String line;
- while ((line = inputReader.readLine()) != null) {
- System.out.println("Response: " +
client.invoke(line));
+ final Client<String, String> client =
clientSource.createClient();
+ try {
+ System.out.println("Enter text, send EOF to
terminate");
+ final BufferedReader inputReader = new
BufferedReader(new InputStreamReader(System.in));
+ String line;
+ while ((line = inputReader.readLine()) != null)
{
+ System.out.println("Response: " +
client.invoke(line));
+ }
+ System.out.println("Done!");
+ } finally {
+ IoUtils.safeClose(client);
}
- System.out.println("Done!");
} finally {
- IoUtils.safeClose(client);
+ IoUtils.safeClose(clientSource);
}
} finally {
- IoUtils.safeClose(clientSource);
+ IoUtils.safeClose(handle);
}
} finally {
- IoUtils.safeClose(handle);
+ IoUtils.safeClose(connection);
}
} finally {
- IoUtils.safeClose(connection);
+ IoUtils.safeClose(closeableTcpConnector);
}
} finally {
- IoUtils.safeClose(closeableTcpConnector);
+ IoUtils.safeClose(xnio);
}
} finally {
- IoUtils.safeClose(xnio);
+ IoUtils.safeClose(endpoint);
}
} catch (IOException e) {
e.printStackTrace();
- } finally {
- IoUtils.safeClose(endpoint);
}
}
}
Modified:
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/MultiplexServerExample.java
===================================================================
---
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/MultiplexServerExample.java 2009-01-08
22:36:45 UTC (rev 4789)
+++
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/MultiplexServerExample.java 2009-01-09
01:57:46 UTC (rev 4790)
@@ -110,11 +110,11 @@
} finally {
IoUtils.safeClose(handle);
}
- } catch (IOException e) {
- e.printStackTrace();
} finally {
IoUtils.safeClose(endpoint);
}
+ } catch (IOException e) {
+ e.printStackTrace();
} finally {
IoUtils.safeClose(executor);
}