JBoss Remoting SVN: r4413 - remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-20 17:10:21 -0400 (Sun, 20 Jul 2008)
New Revision: 4413
Modified:
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java
Log:
Add logging to object resolver test
Modified: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java 2008-07-19 05:39:55 UTC (rev 4412)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java 2008-07-20 21:10:21 UTC (rev 4413)
@@ -26,11 +26,16 @@
import java.io.IOException;
import java.util.Collections;
import java.util.Arrays;
+import org.jboss.cx.remoting.test.support.LoggingHelper;
/**
*
*/
public final class ObjectResolverTestCase extends TestCase {
+ static {
+ LoggingHelper.init();
+ }
+
public static final class ThingOne {
}
16 years, 5 months
JBoss Remoting SVN: r4412 - remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-19 01:39:55 -0400 (Sat, 19 Jul 2008)
New Revision: 4412
Modified:
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java
Log:
Fix service registry handle leak (minor correction)
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java 2008-07-19 05:38:50 UTC (rev 4411)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java 2008-07-19 05:39:55 UTC (rev 4412)
@@ -256,11 +256,11 @@
final int serviceId = buffer.getInt();
final int clientId = buffer.getInt();
final Handle<RemoteServiceEndpoint> handle = registry.lookup(serviceId);
+ if (handle == null) {
+ log.warn("Received client open message for unknown service %d", Integer.valueOf(serviceId));
+ break;
+ }
try {
- if (handle == null) {
- log.warn("Received client open message for unknown service %d", Integer.valueOf(serviceId));
- break;
- }
final RemoteServiceEndpoint serviceEndpoint = handle.getResource();
final Handle<RemoteClientEndpoint> clientHandle = serviceEndpoint.createClientEndpoint();
// todo check for duplicate
16 years, 5 months
JBoss Remoting SVN: r4411 - in remoting3/trunk/protocol/basic/src: test/java/org/jboss/cx/remoting/protocol/basic and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-19 01:38:50 -0400 (Sat, 19 Jul 2008)
New Revision: 4411
Modified:
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java
remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java
Log:
Fix service registry handle leak
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java 2008-07-19 05:26:35 UTC (rev 4410)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java 2008-07-19 05:38:50 UTC (rev 4411)
@@ -256,16 +256,20 @@
final int serviceId = buffer.getInt();
final int clientId = buffer.getInt();
final Handle<RemoteServiceEndpoint> handle = registry.lookup(serviceId);
- if (handle == null) {
- log.warn("Received client open message for unknown service %d", Integer.valueOf(serviceId));
- break;
+ try {
+ if (handle == null) {
+ log.warn("Received client open message for unknown service %d", Integer.valueOf(serviceId));
+ break;
+ }
+ final RemoteServiceEndpoint serviceEndpoint = handle.getResource();
+ final Handle<RemoteClientEndpoint> clientHandle = serviceEndpoint.createClientEndpoint();
+ // todo check for duplicate
+ // todo validate the client ID
+ log.trace("Opening client %d from service %d", Integer.valueOf(clientId), Integer.valueOf(serviceId));
+ forwardedClients.put(Integer.valueOf(clientId), clientHandle);
+ } finally {
+ IoUtils.safeClose(handle);
}
- final RemoteServiceEndpoint serviceEndpoint = handle.getResource();
- final Handle<RemoteClientEndpoint> clientHandle = serviceEndpoint.createClientEndpoint();
- // todo check for duplicate
- // todo validate the client ID
- log.trace("Opening client %d from service %d", Integer.valueOf(clientId), Integer.valueOf(serviceId));
- forwardedClients.put(Integer.valueOf(clientId), clientHandle);
break;
}
case SERVICE_CLOSE: {
Modified: remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java
===================================================================
--- remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java 2008-07-19 05:26:35 UTC (rev 4410)
+++ remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java 2008-07-19 05:38:50 UTC (rev 4411)
@@ -91,7 +91,7 @@
try {
context.sendReply(REPLY);
} catch (RemotingException e) {
- e.printStackTrace();
+ problems.add(e);
}
}
});
16 years, 5 months
JBoss Remoting SVN: r4410 - remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-19 01:26:35 -0400 (Sat, 19 Jul 2008)
New Revision: 4410
Modified:
remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java
Log:
Clean up imports
Modified: remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java
===================================================================
--- remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java 2008-07-19 05:25:46 UTC (rev 4409)
+++ remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java 2008-07-19 05:26:35 UTC (rev 4410)
@@ -34,9 +34,6 @@
import junit.framework.TestCase;
import org.jboss.cx.remoting.core.EndpointImpl;
import org.jboss.cx.remoting.test.support.LoggingHelper;
-import org.jboss.cx.remoting.RequestListener;
-import org.jboss.cx.remoting.ClientContext;
-import org.jboss.cx.remoting.ServiceContext;
import org.jboss.cx.remoting.RequestContext;
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.ClientSource;
16 years, 5 months
JBoss Remoting SVN: r4409 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting/spi/remote and 3 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-19 01:25:46 -0400 (Sat, 19 Jul 2008)
New Revision: 4409
Added:
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/AbstractConnection.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/Connection.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ConnectionListener.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ServiceRegistryImpl.java
Removed:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpointListener.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicProtocol.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ServiceRegistry.java
remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java
Log:
Replace root client concept with a service-by-id registry, not unlike TCP ports really
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -56,7 +56,6 @@
throw new NullPointerException("executor is null");
}
this.executor = executor;
- log.trace("Opened %s", this);
}
/**
Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpointListener.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpointListener.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpointListener.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.cx.remoting.spi.remote;
-
-/**
- * A listener that watches for creation of remote client endpoints.
- */
-public interface RemoteClientEndpointListener {
-
- /**
- * Receive notification of the creation of a new endpoint.
- *
- * @param <I> the request type
- * @param <O> the reply type
- * @param endpoint the endpoint that was created
- */
- <I, O> void notifyCreated(RemoteClientEndpoint endpoint);
-}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -31,6 +31,7 @@
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
+import org.jboss.cx.remoting.spi.remote.Handle;
import java.util.concurrent.Executor;
/**
@@ -38,13 +39,17 @@
*/
public final class ClientImpl<I, O> extends AbstractContextImpl<Client<I, O>> implements Client<I, O> {
- private final RemoteClientEndpoint remoteClientEndpoint;
+ private final Handle<RemoteClientEndpoint> handle;
- ClientImpl(final RemoteClientEndpoint remoteClientEndpoint, final Executor executor) {
+ ClientImpl(final Handle<RemoteClientEndpoint> handle, final Executor executor) {
super(executor);
- this.remoteClientEndpoint = remoteClientEndpoint;
+ this.handle = handle;
}
+ protected void closeAction() throws RemotingException {
+ handle.close();
+ }
+
public O invoke(final I request) throws RemotingException, RemoteExecutionException {
if (! isOpen()) {
throw new RemotingException("Client is not open");
@@ -52,7 +57,7 @@
final QueueExecutor executor = new QueueExecutor();
final FutureReplyImpl<O> futureReply = new FutureReplyImpl<O>(executor);
final ReplyHandler replyHandler = futureReply.getReplyHandler();
- final RemoteRequestContext requestContext = remoteClientEndpoint.receiveRequest(request, replyHandler);
+ final RemoteRequestContext requestContext = handle.getResource().receiveRequest(request, replyHandler);
futureReply.setRemoteRequestContext(requestContext);
futureReply.addCompletionHandler(new RequestCompletionHandler<O>() {
public void notifyComplete(final FutureReply<O> reply) {
@@ -69,7 +74,7 @@
}
final FutureReplyImpl<O> futureReply = new FutureReplyImpl<O>(executor);
final ReplyHandler replyHandler = futureReply.getReplyHandler();
- final RemoteRequestContext requestContext = remoteClientEndpoint.receiveRequest(request, replyHandler);
+ final RemoteRequestContext requestContext = handle.getResource().receiveRequest(request, replyHandler);
futureReply.setRemoteRequestContext(requestContext);
return futureReply;
}
@@ -78,7 +83,7 @@
if (! isOpen()) {
throw new RemotingException("Client is not open");
}
- remoteClientEndpoint.receiveRequest(request);
+ handle.getResource().receiveRequest(request);
}
public String toString() {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -37,25 +37,28 @@
*/
public final class ClientSourceImpl<I, O> extends AbstractCloseable<ClientSource<I, O>> implements ClientSource<I, O> {
- private final RemoteServiceEndpoint serviceEndpoint;
+ private final Handle<RemoteServiceEndpoint> handle;
private final Endpoint endpoint;
- ClientSourceImpl(final RemoteServiceEndpoint serviceEndpoint, final EndpointImpl endpoint) {
+ ClientSourceImpl(final Handle<RemoteServiceEndpoint> handle, final EndpointImpl endpoint) {
super(endpoint.getExecutor());
- this.serviceEndpoint = serviceEndpoint;
+ this.handle = handle;
this.endpoint = endpoint;
}
+ protected void closeAction() throws RemotingException {
+ handle.close();
+ }
+
public Client<I, O> createClient() throws RemotingException {
if (! isOpen()) {
throw new RemotingException("Client source is not open");
}
- final Handle<RemoteClientEndpoint> handle = serviceEndpoint.createClientEndpoint();
+ final Handle<RemoteClientEndpoint> clientHandle = handle.getResource().createClientEndpoint();
try {
- final Client<I, O> client = endpoint.createClient(handle.getResource());
- return client;
+ return endpoint.createClient(clientHandle.getResource());
} finally {
- IoUtils.safeClose(handle);
+ IoUtils.safeClose(clientHandle);
}
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -139,7 +139,7 @@
boolean ok = false;
final Handle<RemoteClientEndpoint> handle = endpoint.getHandle();
try {
- final ClientImpl<I, O> client = new ClientImpl<I, O>(endpoint, executor);
+ final ClientImpl<I, O> client = new ClientImpl<I, O>(handle, executor);
client.addCloseHandler(new CloseHandler<Client<I, O>>() {
public void handleClose(final Client<I, O> closed) {
IoUtils.safeClose(handle);
@@ -154,16 +154,11 @@
}
}
- public <I, O> ClientSource<I, O> createClientSource(final RemoteServiceEndpoint endpoint) throws RemotingException {
+ public <I, O> ClientSource<I, O> createClientSource(final RemoteServiceEndpoint remoteServiceEndpoint) throws RemotingException {
boolean ok = false;
- final Handle<RemoteServiceEndpoint> handle = endpoint.getHandle();
+ final Handle<RemoteServiceEndpoint> handle = remoteServiceEndpoint.getHandle();
try {
- final ClientSourceImpl<I, O> client = new ClientSourceImpl<I, O>(endpoint, this);
- client.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
- public void handleClose(final ClientSource<I, O> closed) {
- IoUtils.safeClose(handle);
- }
- });
+ final ClientSourceImpl<I, O> client = new ClientSourceImpl<I, O>(handle, this);
ok = true;
return client;
} finally {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -195,6 +195,9 @@
}
while (state == State.WAITING || state == State.NEW) {
try {
+ if (now >= deadline) {
+ return null;
+ }
lock.wait(deadline - now);
} catch (InterruptedException e) {
intr = true;
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/AbstractConnection.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/AbstractConnection.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/AbstractConnection.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.cx.remoting.protocol.basic;
+
+import org.jboss.cx.remoting.spi.AbstractCloseable;
+import java.util.concurrent.Executor;
+
+/**
+ *
+ */
+public abstract class AbstractConnection extends AbstractCloseable<Connection> implements Connection {
+ /**
+ * Basic constructor.
+ *
+ * @param executor the executor used to execute the close notification handlers
+ */
+ protected AbstractConnection(final Executor executor) {
+ super(executor);
+ }
+
+ public String toString() {
+ return "connection <" + Integer.toString(hashCode()) + ">";
+ }
+}
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -33,7 +33,6 @@
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
import org.jboss.cx.remoting.spi.remote.Handle;
-import org.jboss.cx.remoting.spi.remote.RemoteClientEndpointListener;
import org.jboss.cx.remoting.spi.marshal.Unmarshaller;
import org.jboss.cx.remoting.spi.marshal.Marshaller;
import org.jboss.cx.remoting.spi.marshal.MarshallerFactory;
@@ -75,11 +74,11 @@
private final ConcurrentMap<Integer, RemoteClientEndpoint> remoteClients = concurrentMap();
// running on remote node
private final ConcurrentMap<Integer, ReplyHandler> outstandingRequests = concurrentMap();
- // forwarded to remote side
+ // forwarded to remote side (handled on this side)
private final ConcurrentMap<Integer, Handle<RemoteClientEndpoint>> forwardedClients = concurrentMap();
- // forwarded to remote side
- private final ConcurrentMap<Integer, Handle<RemoteServiceEndpoint>> forwardedServices = concurrentMap();
+ private final ServiceRegistry registry;
+
private final boolean server;
private final BufferAllocator<ByteBuffer> allocator;
@@ -90,16 +89,13 @@
private final ObjectResolver resolver;
private final ClassLoader classLoader;
- public BasicHandler(final boolean server, final BufferAllocator<ByteBuffer> allocator, final RemoteClientEndpoint root, final Executor executor, final RemoteClientEndpointListener remoteListener, final MarshallerFactory<ByteBuffer> marshallerFactory) throws RemotingException {
+ public BasicHandler(final boolean server, final BufferAllocator<ByteBuffer> allocator, final Executor executor, final MarshallerFactory<ByteBuffer> marshallerFactory, final ServiceRegistry registry) {
this.server = server;
this.allocator = allocator;
this.executor = executor;
- forwardedClients.put(Integer.valueOf(0), ((RemoteClientEndpoint)root).getHandle());
- final RemoteClientEndpointImpl endpoint = new RemoteClientEndpointImpl(0, marshallerFactory, allocator);
+ this.registry = registry;
+ final RemoteClientEndpointImpl endpoint = new RemoteClientEndpointImpl(0, allocator);
remoteClients.put(Integer.valueOf(0), endpoint);
- if (remoteListener != null) {
- remoteListener.notifyCreated(endpoint);
- }
this.marshallerFactory = marshallerFactory;
// todo
resolver = IdentityResolver.getInstance();
@@ -118,10 +114,6 @@
* Sequence number of remote clients opened locally from services from the remote side.
*/
private final AtomicInteger remoteClientIdSeq = new AtomicInteger(1);
- /**
- * Sequence number of services forwarded to the remote side.
- */
- private final AtomicInteger localServiceIdSeq = new AtomicInteger();
public void handleOpened(final AllocatedMessageChannel channel) {
if (isnew.getAndSet(false)) {
@@ -263,23 +255,21 @@
case CLIENT_OPEN: {
final int serviceId = buffer.getInt();
final int clientId = buffer.getInt();
- final Handle<RemoteServiceEndpoint> handle = getForwardedService(serviceId);
+ final Handle<RemoteServiceEndpoint> handle = registry.lookup(serviceId);
if (handle == null) {
- // todo log invalid request
+ log.warn("Received client open message for unknown service %d", Integer.valueOf(serviceId));
break;
}
final RemoteServiceEndpoint serviceEndpoint = handle.getResource();
-
+ final Handle<RemoteClientEndpoint> clientHandle = serviceEndpoint.createClientEndpoint();
+ // todo check for duplicate
+ // todo validate the client ID
+ log.trace("Opening client %d from service %d", Integer.valueOf(clientId), Integer.valueOf(serviceId));
+ forwardedClients.put(Integer.valueOf(clientId), clientHandle);
break;
}
case SERVICE_CLOSE: {
- final int serviceId = buffer.getInt();
- final Handle<RemoteServiceEndpoint> handle = takeForwardedService(serviceId);
- if (handle == null) {
- log.warn("Got client close message for unknown service %d", Integer.valueOf(serviceId));
- break;
- }
- IoUtils.safeClose(handle);
+ registry.unbind(buffer.getInt());
break;
}
default: {
@@ -326,6 +316,10 @@
return remoteClients.get(Integer.valueOf(i));
}
+ RemoteServiceEndpoint getRemoteService(final int id) {
+ return new RemoteServiceEndpointImpl(allocator, id);
+ }
+
private final class ReplyHandlerImpl implements ReplyHandler {
private final AllocatedMessageChannel channel;
@@ -421,7 +415,7 @@
int id;
do {
id = remoteClientIdSeq.getAndIncrement() << 1 | (server ? 1 : 0);
- } while (remoteClients.putIfAbsent(Integer.valueOf(id), new RemoteClientEndpointImpl(id, null, allocator)) != null);
+ } while (remoteClients.putIfAbsent(Integer.valueOf(id), new RemoteClientEndpointImpl(id, allocator)) != null);
return id;
}
@@ -446,14 +440,6 @@
return outstandingRequests.remove(Integer.valueOf(id));
}
- public Handle<RemoteServiceEndpoint> getForwardedService(final int id) {
- return forwardedServices.get(Integer.valueOf(id));
- }
-
- public Handle<RemoteServiceEndpoint> takeForwardedService(final int id) {
- return forwardedServices.remove(Integer.valueOf(id));
- }
-
// Writer members
private final BlockingQueue<WriteHandler> outputQueue = CollectionUtil.blockingQueue(64);
@@ -471,19 +457,14 @@
private final class RemoteClientEndpointImpl extends AbstractAutoCloseable<RemoteClientEndpoint> implements RemoteClientEndpoint {
private final int identifier;
- private final MarshallerFactory<ByteBuffer> marshallerFactory;
private final BufferAllocator<ByteBuffer> allocator;
- public RemoteClientEndpointImpl(final int identifier, final MarshallerFactory<ByteBuffer> marshallerFactory, final BufferAllocator<ByteBuffer> allocator) {
+ public RemoteClientEndpointImpl(final int identifier, final BufferAllocator<ByteBuffer> allocator) {
super(executor);
- if (marshallerFactory == null) {
- throw new NullPointerException("marshallerFactory is null");
- }
if (allocator == null) {
throw new NullPointerException("allocator is null");
}
this.identifier = identifier;
- this.marshallerFactory = marshallerFactory;
this.allocator = allocator;
addCloseHandler(new CloseHandler<RemoteClientEndpoint>() {
public void handleClose(final RemoteClientEndpoint closed) {
@@ -501,7 +482,7 @@
}
public void receiveRequest(final Object request) {
- log.trace("Received one-way request of type %s", request == null ? "null" : request.getClass());
+ log.trace("Sending outbound one-way request of type %s", request == null ? "null" : request.getClass());
try {
final Marshaller<ByteBuffer> marshaller = marshallerFactory.createMarshaller(null);
final List<ByteBuffer> bufferList = new ArrayList<ByteBuffer>();
@@ -529,7 +510,7 @@
}
public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler handler) {
- log.trace("Received request of type %s", request == null ? "null" : request.getClass());
+ log.trace("Sending outbound request of type %s", request == null ? "null" : request.getClass());
try {
final Marshaller<ByteBuffer> marshaller = marshallerFactory.createMarshaller(null);
final List<ByteBuffer> bufferList = new ArrayList<ByteBuffer>();
@@ -596,13 +577,11 @@
public final class RemoteServiceEndpointImpl extends AbstractAutoCloseable<RemoteServiceEndpoint> implements RemoteServiceEndpoint {
- private final MarshallerFactory<ByteBuffer> marshallerFactory;
private final BufferAllocator<ByteBuffer> allocator;
private final int identifier;
- protected RemoteServiceEndpointImpl(final MarshallerFactory<ByteBuffer> marshallerFactory, final BufferAllocator<ByteBuffer> allocator, final int identifier) {
+ protected RemoteServiceEndpointImpl(final BufferAllocator<ByteBuffer> allocator, final int identifier) {
super(executor);
- this.marshallerFactory = marshallerFactory;
this.allocator = allocator;
this.identifier = identifier;
addCloseHandler(new CloseHandler<RemoteServiceEndpoint>() {
@@ -621,10 +600,11 @@
}
public Handle<RemoteClientEndpoint> createClientEndpoint() throws RemotingException {
- final int id = openClientFromService();
+ final int clientId = openClientFromService();
final ByteBuffer buffer = allocator.allocate();
+ buffer.put((byte) MessageType.CLIENT_OPEN);
buffer.putInt(identifier);
- buffer.putInt(openClientFromService());
+ buffer.putInt(clientId);
buffer.flip();
// todo - probably should bail out if we're interrupted?
boolean intr = false;
@@ -632,7 +612,7 @@
try {
registerWriter(channel, new SimpleWriteHandler(allocator, buffer));
try {
- return new RemoteClientEndpointImpl(id, marshallerFactory, allocator).getHandle();
+ return new RemoteClientEndpointImpl(clientId, allocator).getHandle();
} finally {
if (intr) {
Thread.currentThread().interrupt();
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicProtocol.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicProtocol.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicProtocol.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -22,10 +22,9 @@
package org.jboss.cx.remoting.protocol.basic;
-import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
-import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
-import org.jboss.cx.remoting.spi.remote.RemoteClientEndpointListener;
import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
+import org.jboss.cx.remoting.spi.remote.Handle;
import org.jboss.cx.remoting.core.marshal.JavaSerializationMarshallerFactory;
import org.jboss.xnio.IoHandlerFactory;
import org.jboss.xnio.ChannelSource;
@@ -53,20 +52,13 @@
* Create a request server for the basic protocol.
*
* @param executor the executor to use for invocations
- * @param localRootSource the service to draw client endpoints from for root clients on inbound connections
* @param allocator the buffer allocator to use
- * @param remoteListener a listener which receives notification of the remote root client of the incoming connection
* @return a handler factory for passing to an XNIO server
*/
- public static IoHandlerFactory<AllocatedMessageChannel> createServer(final Executor executor, final RemoteServiceEndpoint localRootSource, final BufferAllocator<ByteBuffer> allocator, final RemoteClientEndpointListener remoteListener) {
+ public static IoHandlerFactory<AllocatedMessageChannel> createServer(final Executor executor, final BufferAllocator<ByteBuffer> allocator, final ServiceRegistry serviceRegistry) {
return new IoHandlerFactory<AllocatedMessageChannel>() {
public IoHandler<? super AllocatedMessageChannel> createHandler() {
- try {
- final RemoteClientEndpoint remoteClientEndpoint = localRootSource.createClientEndpoint().getResource();
- return new BasicHandler(true, allocator, remoteClientEndpoint, executor, remoteListener, new JavaSerializationMarshallerFactory(executor));
- } catch (RemotingException e) {
- throw new IllegalStateException("The local root endpoint is unusable", e);
- }
+ return new BasicHandler(true, allocator, executor, new JavaSerializationMarshallerFactory(executor), serviceRegistry);
}
};
}
@@ -75,19 +67,22 @@
* Create a request client for the basic protocol.
*
* @param executor the executor to use for invocations
- * @param localRoot the client endpoint to use as the local root client
* @param channelSource the XNIO channel source to use to establish the connection
* @param allocator the buffer allocator to use
- * @return the future client endpoint of the remote side's root client
+ * @param serviceRegistry the service registry
+ * @return a handle which may be used to close the connection
* @throws IOException if an error occurs
*/
- public static IoFuture<RemoteClientEndpoint> connect(final Executor executor, final RemoteClientEndpoint localRoot, final ChannelSource<AllocatedMessageChannel> channelSource, final BufferAllocator<ByteBuffer> allocator) throws IOException {
- final BasicHandler basicHandler = new BasicHandler(false, allocator, localRoot, executor, null, new JavaSerializationMarshallerFactory(executor));
+ public static IoFuture<Connection> connect(final Executor executor, final ChannelSource<AllocatedMessageChannel> channelSource, final BufferAllocator<ByteBuffer> allocator, final ServiceRegistry serviceRegistry) throws IOException {
+ final BasicHandler basicHandler = new BasicHandler(false, allocator, executor, new JavaSerializationMarshallerFactory(executor), serviceRegistry);
final IoFuture<AllocatedMessageChannel> futureChannel = channelSource.open(basicHandler);
- return new AbstractConvertingIoFuture<RemoteClientEndpoint, AllocatedMessageChannel>(futureChannel) {
- protected RemoteClientEndpoint convert(final AllocatedMessageChannel channel) throws RemotingException {
- final RemoteClientEndpoint remoteClientEndpoint = basicHandler.getRemoteClient(0);
- return remoteClientEndpoint;
+ return new AbstractConvertingIoFuture<Connection, AllocatedMessageChannel>(futureChannel) {
+ protected Connection convert(final AllocatedMessageChannel channel) throws RemotingException {
+ return new AbstractConnection(executor) {
+ public Handle<RemoteServiceEndpoint> getServiceForId(final int id) throws RemotingException {
+ return basicHandler.getRemoteService(id).getHandle();
+ }
+ };
}
};
}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/Connection.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/Connection.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/Connection.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.cx.remoting.protocol.basic;
+
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
+import org.jboss.cx.remoting.spi.remote.Handle;
+import org.jboss.cx.remoting.Closeable;
+import org.jboss.cx.remoting.RemotingException;
+
+/**
+ *
+ */
+public interface Connection extends Closeable<Connection> {
+ Handle<RemoteServiceEndpoint> getServiceForId(int id) throws RemotingException;
+}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ConnectionListener.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ConnectionListener.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ConnectionListener.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.cx.remoting.protocol.basic;
+
+/**
+ *
+ */
+public interface ConnectionListener {
+ void handleOpened(Connection connection);
+}
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ServiceRegistry.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ServiceRegistry.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ServiceRegistry.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -36,5 +36,7 @@
void unbind(int id) throws RemotingException;
+ void clear();
+
Handle<RemoteServiceEndpoint> lookup(int id) throws RemotingException;
}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ServiceRegistryImpl.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ServiceRegistryImpl.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/ServiceRegistryImpl.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.cx.remoting.protocol.basic;
+
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
+import org.jboss.cx.remoting.spi.remote.Handle;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.xnio.IoUtils;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.Iterator;
+
+/**
+ *
+ */
+public final class ServiceRegistryImpl implements ServiceRegistry {
+
+ private static final int START = 32768;
+
+ private final ConcurrentMap<Integer, Handle<RemoteServiceEndpoint>> map = CollectionUtil.concurrentMap();
+ private final AtomicInteger dynamicSequence = new AtomicInteger(START);
+ private final ServiceRegistry parent;
+
+ public ServiceRegistryImpl(final ServiceRegistry parent) {
+ this.parent = parent;
+ }
+
+ public ServiceRegistryImpl() {
+ parent = null;
+ }
+
+ public int bind(final RemoteServiceEndpoint remoteServiceEndpoint) throws RemotingException {
+ final Handle<RemoteServiceEndpoint> handle = remoteServiceEndpoint.getHandle();
+ boolean ok = false;
+ try {
+ for (;;) {
+ final int seqVal = dynamicSequence.getAndIncrement();
+ if (seqVal < 0) {
+ dynamicSequence.compareAndSet(seqVal, START);
+ continue;
+ }
+ if (map.putIfAbsent(Integer.valueOf(seqVal), handle) != null) {
+ ok = true;
+ return seqVal;
+ }
+ }
+ } finally {
+ if (! ok) {
+ IoUtils.safeClose(handle);
+ }
+ }
+ }
+
+ public void bind(final RemoteServiceEndpoint remoteServiceEndpoint, final int id) throws RemotingException {
+ final Handle<RemoteServiceEndpoint> handle = remoteServiceEndpoint.getHandle();
+ boolean ok = false;
+ try {
+ if (map.putIfAbsent(Integer.valueOf(id), handle) != null) {
+ throw new RemotingException("Service already bound to that ID");
+ }
+ ok = true;
+ } finally {
+ if (! ok) {
+ IoUtils.safeClose(handle);
+ }
+ }
+ }
+
+ public void unbind(final int id) throws RemotingException {
+ map.remove(Integer.valueOf(id));
+ }
+
+ public void clear() {
+ Iterator<Handle<RemoteServiceEndpoint>> it = map.values().iterator();
+ while (it.hasNext()) {
+ IoUtils.safeClose(it.next());
+ it.remove();
+ }
+ }
+
+ public Handle<RemoteServiceEndpoint> lookup(final int id) throws RemotingException {
+ final Handle<RemoteServiceEndpoint> handle = map.get(Integer.valueOf(id));
+ return handle != null || parent == null ? handle.getResource().getHandle() : parent.lookup(id);
+ }
+
+ protected void finalize() throws Throwable {
+ clear();
+ super.finalize();
+ }
+}
Modified: remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java
===================================================================
--- remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java 2008-07-19 05:12:10 UTC (rev 4408)
+++ remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java 2008-07-19 05:25:46 UTC (rev 4409)
@@ -22,40 +22,42 @@
package org.jboss.cx.remoting.protocol.basic;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.net.InetSocketAddress;
+import java.io.Closeable;
import junit.framework.TestCase;
-import org.jboss.xnio.Xnio;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.BufferAllocator;
-import org.jboss.xnio.ConfigurableFactory;
-import org.jboss.xnio.ChannelSource;
-import org.jboss.xnio.TcpClient;
-import org.jboss.xnio.IoFuture;
-import org.jboss.xnio.channels.Channels;
-import org.jboss.xnio.channels.AllocatedMessageChannel;
import org.jboss.cx.remoting.core.EndpointImpl;
-import org.jboss.cx.remoting.RequestContext;
-import org.jboss.cx.remoting.RemoteExecutionException;
+import org.jboss.cx.remoting.test.support.LoggingHelper;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.ClientContext;
import org.jboss.cx.remoting.ServiceContext;
+import org.jboss.cx.remoting.RequestContext;
+import org.jboss.cx.remoting.RemoteExecutionException;
+import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.test.support.LoggingHelper;
+import org.jboss.cx.remoting.FutureReply;
+import org.jboss.cx.remoting.AbstractRequestListener;
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
-import org.jboss.cx.remoting.spi.remote.RemoteClientEndpointListener;
import org.jboss.cx.remoting.spi.remote.Handle;
-import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.Collections;
-import java.util.List;
-import java.util.LinkedList;
-import java.nio.ByteBuffer;
-import java.net.InetSocketAddress;
-import java.io.Closeable;
+import org.jboss.xnio.BufferAllocator;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.Xnio;
+import org.jboss.xnio.IoHandlerFactory;
+import org.jboss.xnio.ConfigurableFactory;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.TcpConnector;
+import org.jboss.xnio.TcpClient;
+import org.jboss.xnio.ChannelSource;
+import org.jboss.xnio.channels.AllocatedMessageChannel;
+import org.jboss.xnio.channels.Channels;
+import org.jboss.xnio.channels.StreamChannel;
/**
*
@@ -66,13 +68,9 @@
}
public void testConnection() throws Throwable {
+ final String REQUEST = "request";
+ final String REPLY = "reply";
final List<Throwable> problems = Collections.synchronizedList(new LinkedList<Throwable>());
- final AtomicBoolean clientOpened = new AtomicBoolean(false);
- final AtomicBoolean client2Opened = new AtomicBoolean(false);
- final AtomicBoolean serviceOpened = new AtomicBoolean(false);
- final AtomicBoolean clientClosed = new AtomicBoolean(false);
- final AtomicBoolean serviceClosed = new AtomicBoolean(false);
- final CountDownLatch cleanupLatch = new CountDownLatch(2);
final ExecutorService executorService = Executors.newCachedThreadPool();
try {
final BufferAllocator<ByteBuffer> allocator = new BufferAllocator<ByteBuffer>() {
@@ -88,6 +86,69 @@
final EndpointImpl endpoint = new EndpointImpl();
endpoint.setExecutor(executorService);
endpoint.start();
+ try {
+ final ServiceRegistry serviceRegistry = new ServiceRegistryImpl();
+ try {
+ final Handle<RemoteServiceEndpoint> serviceEndpointHandle = endpoint.createServiceEndpoint(new AbstractRequestListener<Object, Object>() {
+ public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
+ try {
+ context.sendReply(REPLY);
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ try {
+ serviceRegistry.bind(serviceEndpointHandle.getResource(), 13);
+ final IoHandlerFactory<AllocatedMessageChannel> handlerFactory = BasicProtocol.createServer(executorService, allocator, serviceRegistry);
+ final IoHandlerFactory<StreamChannel> newHandlerFactory = Channels.convertStreamToAllocatedMessage(handlerFactory, 32768, 32768);
+ final ConfigurableFactory<Closeable> tcpServerFactory = xnio.createTcpServer(newHandlerFactory, new InetSocketAddress(12345));
+ final Closeable tcpServerCloseable = tcpServerFactory.create();
+ try {
+ final ConfigurableFactory<TcpConnector> connectorFactory = xnio.createTcpConnector();
+ final TcpConnector connector = connectorFactory.create();
+ try {
+ final TcpClient tcpClient = connector.createChannelSource(new InetSocketAddress("localhost", 12345));
+ final ChannelSource<AllocatedMessageChannel> channelSource = Channels.convertStreamToAllocatedMessage(tcpClient, 32768, 32768);
+ final IoFuture<Connection> futureCloseable = BasicProtocol.connect(executorService, channelSource, allocator, serviceRegistry);
+ final Connection connection = futureCloseable.get();
+ try {
+ final Handle<RemoteServiceEndpoint> handleThirteen = connection.getServiceForId(13);
+ try {
+ final RemoteServiceEndpoint serviceThirteen = handleThirteen.getResource();
+ final ClientSource<Object,Object> clientSource = endpoint.createClientSource(serviceThirteen);
+ try {
+ final Client<Object,Object> client = clientSource.createClient();
+ try {
+ final FutureReply<Object> future = client.send(REQUEST);
+ assertEquals(REPLY, future.get(500L, TimeUnit.MILLISECONDS));
+ } finally {
+ IoUtils.safeClose(client);
+ }
+ } finally {
+ IoUtils.safeClose(clientSource);
+ }
+ } finally {
+ IoUtils.safeClose(handleThirteen);
+ }
+ } finally {
+ IoUtils.safeClose(connection);
+ }
+ } finally {
+ // todo close connector
+ }
+ } finally {
+ IoUtils.safeClose(tcpServerCloseable);
+ }
+ } finally {
+ IoUtils.safeClose(serviceEndpointHandle);
+ }
+ } finally {
+ serviceRegistry.clear();
+ }
+ } finally {
+ endpoint.stop();
+ }
} finally {
IoUtils.safeClose(xnio);
}
16 years, 5 months
JBoss Remoting SVN: r4408 - remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-19 01:12:10 -0400 (Sat, 19 Jul 2008)
New Revision: 4408
Modified:
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java
Log:
Add thread ID to log
Modified: remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java
===================================================================
--- remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java 2008-07-19 03:57:10 UTC (rev 4407)
+++ remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java 2008-07-19 05:12:10 UTC (rev 4408)
@@ -54,6 +54,7 @@
int ms = (int) (offs % 1000L);
long s = offs / 1000L;
builder.append(String.format("%s%04d.%03d ", sign, Long.valueOf(s), Long.valueOf(ms)));
+ builder.append(String.format("tid:%d ", Integer.valueOf(record.getThreadID())));
builder.append(record.getLevel().toString());
builder.append(" [").append(record.getLoggerName()).append("] ");
builder.append(String.format(record.getMessage(), record.getParameters()));
16 years, 5 months
JBoss Remoting SVN: r4407 - in remoting2/branches/2.2/src/tests/org/jboss/test/remoting: transport/bisocket/socketfactory and 8 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-07-18 23:57:10 -0400 (Fri, 18 Jul 2008)
New Revision: 4407
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/socketfactory/SSLSocketFactoryClassNameTestRoot.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/socketfactory/SocketFactoryClassNameTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/socketfactory/
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/socketfactory/SocketFactoryClassNameTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/rmi/socketfactory/SocketFactoryClassNameTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/rmi/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java
Log:
JBREM-1014: New and updated unit tests.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/socketfactory/SSLSocketFactoryClassNameTestRoot.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/socketfactory/SSLSocketFactoryClassNameTestRoot.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/socketfactory/SSLSocketFactoryClassNameTestRoot.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,100 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.socketfactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot.TestSocketFactory;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public abstract class SSLSocketFactoryClassNameTestRoot extends SocketFactoryClassNameTestRoot
+{
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ String trustStoreFilePath = this.getClass().getResource("../.truststore").getFile();
+ System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
+ String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile();
+ System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
+ System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
+ System.setProperty("org.jboss.security.ignoreHttpsHost", "true");
+ }
+
+ protected Class getSocketFactoryClass()
+ {
+ return TestSSLSocketFactory.class;
+ }
+
+ public static class TestSSLSocketFactory extends SocketFactory
+ {
+ SocketFactory sf = SSLSocketFactory.getDefault();
+
+ public TestSSLSocketFactory()
+ {
+ }
+
+ public Socket createSocket() throws IOException, UnknownHostException
+ {
+ return sf.createSocket();
+ }
+
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ return sf.createSocket(arg0, arg1);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ return sf.createSocket(arg0, arg1);
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException,
+ UnknownHostException
+ {
+ return sf.createSocket(arg0, arg1, arg2, arg3);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ return sf.createSocket(arg0, arg1, arg2, arg3);
+ }
+ }
+}
+
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,227 @@
+package org.jboss.test.remoting.socketfactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.net.SocketFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.AbstractInvoker;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public abstract class SocketFactoryClassNameTestRoot extends TestCase
+{
+ private static Logger log = Logger.getLogger(SocketFactoryClassNameTestRoot.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testSocketFactoryClassNameInLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "/?" + Remoting.SOCKET_FACTORY_CLASS_NAME + "=" + getSocketFactoryClass().getName();
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected to " + clientLocatorURI);
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify client invoker is using configured SocketFactory.
+ AbstractInvoker invoker = (AbstractInvoker) client.getInvoker();
+ SocketFactory socketFactory = invoker.getSocketFactory();
+ log.info("SocketFactory: " + socketFactory);
+ assertTrue(getSocketFactoryClass().isInstance(socketFactory));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testSocketFactoryClassNameInConfigMap() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.SOCKET_FACTORY_CLASS_NAME, getSocketFactoryClass().getName());
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify client invoker is using configured SocketFactory.
+ AbstractInvoker invoker = (AbstractInvoker) client.getInvoker();
+ SocketFactory socketFactory = invoker.getSocketFactory();
+ log.info("SocketFactory: " + socketFactory);
+ assertTrue(getSocketFactoryClass().isInstance(socketFactory));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected abstract String getTransport();
+
+
+ protected Class getSocketFactoryClass()
+ {
+ return TestSocketFactory.class;
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ public static class TestSocketFactory extends SocketFactory
+ {
+ SocketFactory sf = SocketFactory.getDefault();
+
+ public TestSocketFactory()
+ {
+ }
+
+ public Socket createSocket() throws IOException, UnknownHostException
+ {
+ return sf.createSocket();
+ }
+
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ return sf.createSocket(arg0, arg1);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ return sf.createSocket(arg0, arg1);
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException,
+ UnknownHostException
+ {
+ return sf.createSocket(arg0, arg1, arg2, arg3);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ return sf.createSocket(arg0, arg1, arg2, arg3);
+ }
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/socketfactory/SocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,22 @@
+package org.jboss.test.remoting.transport.bisocket.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,44 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.bisocket.ssl.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "sslbisocket";
+ }
+}
+
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/socketfactory/SocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,22 @@
+package org.jboss.test.remoting.transport.http.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "http";
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,44 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.http.ssl.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "https";
+ }
+}
+
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/rmi/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/rmi/socketfactory/SocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/rmi/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,22 @@
+package org.jboss.test.remoting.transport.rmi.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "rmi";
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/rmi/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/rmi/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/rmi/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,44 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.rmi.ssl.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "sslrmi";
+ }
+}
+
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-19 03:54:45 UTC (rev 4406)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -1,34 +1,8 @@
package org.jboss.test.remoting.transport.socket.socketfactory;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.Map;
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
-import javax.management.MBeanServer;
-import javax.net.SocketFactory;
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.AbstractInvoker;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.Remoting;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
/**
*
* Unit test for JBREM-1014.
@@ -39,152 +13,10 @@
* Copyright Jul 18, 2008
* </p>
*/
-public class SocketFactoryClassNameTestCase extends TestCase
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
{
- private static Logger log = Logger.getLogger(SocketFactoryClassNameTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testSocketFactoryClassName() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.SOCKET_FACTORY_CLASS_NAME, TestSocketFactory.class.getName());
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Verify client invoker is using configured SocketFactory.
- AbstractInvoker invoker = (AbstractInvoker) client.getInvoker();
- SocketFactory socketFactory = invoker.getSocketFactory();
- log.info("SocketFactory: " + socketFactory);
- assertTrue(socketFactory instanceof TestSocketFactory);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
protected String getTransport()
{
return "socket";
}
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
- public static class TestSocketFactory extends SocketFactory
- {
- private SocketFactory sf = SocketFactory.getDefault();
-
- public TestSocketFactory()
- {
- }
-
- public Socket createSocket() throws IOException, UnknownHostException
- {
- return sf.createSocket();
- }
-
- public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
- {
- return sf.createSocket(arg0, arg1);
- }
-
- public Socket createSocket(InetAddress arg0, int arg1) throws IOException
- {
- return sf.createSocket(arg0, arg1);
- }
-
- public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException,
- UnknownHostException
- {
- return sf.createSocket(arg0, arg1, arg2, arg3);
- }
-
- public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
- {
- return sf.createSocket(arg0, arg1, arg2, arg3);
- }
- }
}
\ No newline at end of file
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2008-07-19 03:57:10 UTC (rev 4407)
@@ -0,0 +1,44 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.ssl.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+}
+
16 years, 5 months
JBoss Remoting SVN: r4406 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-07-18 23:54:45 -0400 (Fri, 18 Jul 2008)
New Revision: 4406
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/RemoteClientInvoker.java
Log:
JBREM-1014: Tries to get "socketFactoryClassName" from locator parameters when creating SocketFactory.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/RemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/RemoteClientInvoker.java 2008-07-19 01:08:00 UTC (rev 4405)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/RemoteClientInvoker.java 2008-07-19 03:54:45 UTC (rev 4406)
@@ -43,6 +43,15 @@
public RemoteClientInvoker(InvokerLocator locator, Map configuration)
{
super(locator, configuration);
+ Map parameters = locator.getParameters();
+ if (parameters != null)
+ {
+ String socketFactoryClassName = (String) locator.parameters.get(Remoting.SOCKET_FACTORY_CLASS_NAME);
+ if (socketFactoryClassName != null)
+ {
+ configuration.put(Remoting.SOCKET_FACTORY_CLASS_NAME, socketFactoryClassName);
+ }
+ }
socketFactory = createSocketFactory(configuration);
}
}
16 years, 5 months
JBoss Remoting SVN: r4405 - remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-18 21:08:00 -0400 (Fri, 18 Jul 2008)
New Revision: 4405
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
Log:
Fix spurious wakeups
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-19 00:56:37 UTC (rev 4404)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-19 01:08:00 UTC (rev 4405)
@@ -177,10 +177,12 @@
private final class ResourceRemover implements CloseHandler<Closeable> {
public void handleClose(final Closeable closed) {
- resources.remove(closed);
synchronized (resources)
{
- resources.notifyAll();
+ resources.remove(closed);
+ if (resources.isEmpty()) {
+ resources.notifyAll();
+ }
}
}
}
16 years, 5 months
JBoss Remoting SVN: r4404 - remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-18 20:56:37 -0400 (Fri, 18 Jul 2008)
New Revision: 4404
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
Log:
Yet more logging improvements
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-19 00:53:56 UTC (rev 4403)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-19 00:56:37 UTC (rev 4404)
@@ -186,6 +186,6 @@
}
public String toString() {
- return "endpoint instance <" + Integer.toString(hashCode()) + ">";
+ return "endpoint \"" + name + "\" <" + Integer.toString(hashCode()) + ">";
}
}
16 years, 5 months