Author: david.lloyd(a)jboss.com
Date: 2008-07-03 13:08:28 -0400 (Thu, 03 Jul 2008)
New Revision: 4349
Modified:
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
Convenience method to cleanly/safely create a client
Modified:
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
===================================================================
---
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-07-03
14:19:31 UTC (rev 4348)
+++
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-07-03
17:08:28 UTC (rev 4349)
@@ -19,7 +19,7 @@
final StringRot13RequestListener listener = new StringRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
- final Client<String,String> client =
endpoint.createClient(listener).getClient();
+ final Client<String,String> client =
Remoting.createLocalClient(endpoint, listener);
try {
final String original = "The Secret Message\n";
final String result = client.invoke(original);
Modified:
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
===================================================================
---
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-07-03
14:19:31 UTC (rev 4348)
+++
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-07-03
17:08:28 UTC (rev 4349)
@@ -25,7 +25,7 @@
final StreamingRot13RequestListener listener = new
StreamingRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
- final Client<Reader,Reader> client =
endpoint.createClient(listener).getClient();
+ final Client<Reader,Reader> client =
Remoting.createLocalClient(endpoint, listener);
try {
final String original = "The Secret Message\n";
final StringReader originalReader = new StringReader(original);
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
---
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03
14:19:31 UTC (rev 4348)
+++
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03
17:08:28 UTC (rev 4349)
@@ -3,6 +3,8 @@
import java.io.IOException;
import java.util.concurrent.ConcurrentMap;
import org.jboss.cx.remoting.core.EndpointImpl;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
/**
*
@@ -40,6 +42,24 @@
}
}
+ public static <I, O> Client<I, O> createLocalClient(Endpoint endpoint,
RequestListener<I, O> requestListener) throws RemotingException {
+ final RemoteClientEndpoint<I, O> clientEndpoint =
endpoint.createClient(requestListener);
+ try {
+ return clientEndpoint.getClient();
+ } finally {
+ clientEndpoint.autoClose();
+ }
+ }
+
+ public static <I, O> ClientSource<I, O> createLocalClientSource(Endpoint
endpoint, RequestListener<I, O> requestListener) throws RemotingException {
+ final RemoteServiceEndpoint<I, O> clientEndpoint =
endpoint.createService(requestListener);
+ try {
+ return clientEndpoint.getClientSource();
+ } finally {
+ clientEndpoint.autoClose();
+ }
+ }
+
// privates
private Remoting() { /* empty */ }
Show replies by date