JBoss Remoting SVN: r4373 - remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-14 17:03:23 -0400 (Mon, 14 Jul 2008)
New Revision: 4373
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
Log:
safe autoclose convenience method
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-12 15:08:39 UTC (rev 4372)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-14 21:03:23 UTC (rev 4373)
@@ -24,6 +24,7 @@
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.RequestCancelHandler;
import org.jboss.cx.remoting.RequestContext;
import org.jboss.cx.remoting.CloseHandler;
@@ -134,6 +135,14 @@
private static final RemoteRequestContext BLANK_REMOTE_REQUEST_CONTEXT = new BlankRemoteRequestContext();
+ public static void safeAutoClose(final RemoteClientEndpoint<?, ?> remoteClientEndpoint) {
+ try {
+ remoteClientEndpoint.autoClose();
+ } catch (Throwable t) {
+ log.error("Failed to set autoClose on %s: %s", remoteClientEndpoint, t);
+ }
+ }
+
private static final class BlankRemoteRequestContext implements RemoteRequestContext {
public void cancel(final boolean mayInterrupt) {
}
16 years, 5 months
JBoss Remoting SVN: r4372 - in remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi: remote and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-12 11:08:39 -0400 (Sat, 12 Jul 2008)
New Revision: 4372
Added:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/package-info.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/package-info.java
Log:
Some API javadoc
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/package-info.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/package-info.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/package-info.java 2008-07-12 15:08:39 UTC (rev 4372)
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+/**
+ * Service provider classes and interfaces. The classes are basic utility classes as well as abstract base classes
+ * to ease implementation.
+ */
+package org.jboss.cx.remoting.spi;
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/package-info.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/package-info.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/package-info.java 2008-07-12 15:08:39 UTC (rev 4372)
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+/**
+ * Interfaces that provide the basic building blocks of remote access.
+ */
+package org.jboss.cx.remoting.spi.remote;
16 years, 5 months
JBoss Remoting SVN: r4371 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting/spi/remote and 2 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-11 17:21:16 -0400 (Fri, 11 Jul 2008)
New Revision: 4371
Added:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Unmarshaller.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationUnmarshaller.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferInputStream.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferOutputStream.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/MarshallerFactory.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.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/RemoteServiceEndpointLocalImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarhsaller.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarshallerFactory.java
Log:
Fix bad name in RemoteServiceEndpoint; add a first blush at re-re-re-re-re-designing Marshallers (this go-around actually having the benefit of some use testing)
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java 2008-07-10 18:49:25 UTC (rev 4370)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -7,31 +7,16 @@
import org.jboss.cx.remoting.stream.ObjectSource;
/**
- * A marshaller/unmarshaller for transmitting data over a wire protocol of some sort. Each marshaller instance is
- * guaranteed to be used by only one thread. Marshallers are not pooled or reused in any way. Any pooling of marshallers
- * must be done by implementations of this class and/or {@link org.jboss.cx.remoting.spi.marshal.MarshallerFactory}.
+ * A marshaller for transmitting data over a wire protocol of some sort. Each marshaller instance is
+ * guaranteed to be used by only one thread at a time.
*
* @param <T> the type of buffer that the marshaller uses, typically {@link java.nio.ByteBuffer} or {@link java.nio.CharBuffer}
*/
-public interface Marshaller<T extends Buffer> extends Serializable {
+public interface Marshaller<T extends Buffer> {
- /**
- * Write objects to buffers. The buffers are allocated from the {@link org.jboss.xnio.BufferAllocator} that was
- * provided to the {@link org.jboss.cx.remoting.spi.marshal.MarshallerFactory}.
- *
- * @param bufferSink the sink for filled (and flipped) buffers
- * @return a sink for objects
- * @throws IOException if an error occurs while creating the marshaling sink
- */
- ObjectSink<Object> getMarshalingSink(ObjectSink<T> bufferSink) throws IOException;
+ void start(Object object) throws IOException, IllegalStateException;
- /**
- * Read objects from buffers. The buffers are freed to the {@link org.jboss.xnio.BufferAllocator} that was
- * provided to the {@link org.jboss.cx.remoting.spi.marshal.MarshallerFactory}.
- *
- * @param bufferSource the source for filled (and flipped) buffers
- * @return a source for objects
- * @throws IOException if an error occurs while creating the unmarshaling source
- */
- ObjectSource<Object> getUnmarshalingSource(ObjectSource<T> bufferSource) throws IOException;
+ boolean marshal(T buffer) throws IOException;
+
+ void clearClassPool() throws IOException;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/MarshallerFactory.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/MarshallerFactory.java 2008-07-10 18:49:25 UTC (rev 4370)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/MarshallerFactory.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -2,7 +2,6 @@
import java.io.IOException;
import java.nio.Buffer;
-import org.jboss.xnio.BufferAllocator;
/**
* A factory to produce marshallers.
@@ -14,11 +13,11 @@
/**
* Create a marshaller instance.
*
- * @param allocator the buffer allocator to use
* @param resolver the object resolver to use
- * @param classLoader the classloader to use
* @return a marshaller
* @throws IOException if an error occurs while creating the marshaller
*/
- Marshaller<T> createMarshaller(BufferAllocator<T> allocator, ObjectResolver resolver, ClassLoader classLoader) throws IOException;
+ Marshaller<T> createMarshaller(ObjectResolver resolver) throws IOException;
+
+ Unmarshaller<T> createUnmarshaller(ObjectResolver resolver, ClassLoader classLoader) throws IOException;
}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Unmarshaller.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Unmarshaller.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Unmarshaller.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -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.spi.marshal;
+
+import java.nio.Buffer;
+import java.io.IOException;
+
+/**
+ *
+ */
+public interface Unmarshaller<T extends Buffer> {
+ boolean unmarshal(T buffer) throws IOException;
+
+ Object get() throws IOException, IllegalStateException, ClassNotFoundException;
+}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java 2008-07-10 18:49:25 UTC (rev 4370)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -41,7 +41,7 @@
* @return a client endpoint
* @throws RemotingException if a client could not be opened
*/
- RemoteClientEndpoint<I, O> openClient() throws RemotingException;
+ RemoteClientEndpoint<I, O> createClientEndpoint() throws RemotingException;
/**
* Get a handle to this service endpoint. The service endpoint will not auto-close as long as there is at least
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-10 18:49:25 UTC (rev 4370)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -48,7 +48,7 @@
if (! isOpen()) {
throw new RemotingException("Client source is not open");
}
- final RemoteClientEndpoint<I,O> clientEndpoint = serviceEndpoint.openClient();
+ final RemoteClientEndpoint<I,O> clientEndpoint = serviceEndpoint.createClientEndpoint();
final Client<I, O> client = endpoint.createClient(clientEndpoint);
clientEndpoint.autoClose();
return client;
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java 2008-07-10 18:49:25 UTC (rev 4370)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -49,7 +49,7 @@
serviceContext = new ServiceContextImpl(executor);
}
- public RemoteClientEndpoint<I, O> openClient() throws RemotingException {
+ public RemoteClientEndpoint<I, O> createClientEndpoint() throws RemotingException {
if (isOpen()) {
final RemoteClientEndpointLocalImpl<I, O> clientEndpoint = new RemoteClientEndpointLocalImpl<I, O>(executor, this, requestListener);
clientEndpoint.open();
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarhsaller.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarhsaller.java 2008-07-10 18:49:25 UTC (rev 4370)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarhsaller.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -1,72 +1,71 @@
package org.jboss.cx.remoting.core.marshal;
import java.io.IOException;
-import java.io.ObjectStreamClass;
+import java.io.OutputStream;
import java.nio.ByteBuffer;
-import java.lang.reflect.Proxy;
-import java.util.Map;
-import java.util.HashMap;
+import java.util.concurrent.Executor;
import org.jboss.cx.remoting.spi.marshal.Marshaller;
import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
-import org.jboss.cx.remoting.stream.ObjectSink;
-import org.jboss.cx.remoting.stream.ObjectSource;
-import org.jboss.cx.remoting.stream.ByteBufferOutputStream;
-import org.jboss.cx.remoting.stream.ByteBufferInputStream;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.xnio.BufferAllocator;
import org.jboss.serial.io.JBossObjectOutputStream;
-import org.jboss.serial.io.JBossObjectInputStream;
/**
*
*/
public class JBossSerializationMarhsaller implements Marshaller<ByteBuffer> {
- private static final long serialVersionUID = -8197192536466706414L;
+ private final Executor executor;
- private final BufferAllocator<ByteBuffer> allocator;
- private final ObjectResolver resolver;
- private final ClassLoader classLoader;
+ private final OurObjectOutputStream objectOutputStream;
+ private final OneBufferOutputStream outputStream;
- public JBossSerializationMarhsaller(final BufferAllocator<ByteBuffer> allocator, final ObjectResolver resolver, final ClassLoader classLoader) {
- this.allocator = allocator;
- this.resolver = resolver;
- this.classLoader = classLoader;
- }
+ private final Object resultLock = new Object();
+ private boolean done = false;
- public ObjectSink<Object> getMarshalingSink(final ObjectSink<ByteBuffer> bufferSink) throws IOException {
- return new MarshalingSink(bufferSink, allocator, resolver);
+ public JBossSerializationMarhsaller(final Executor executor, final ObjectResolver resolver) throws IOException {
+ this.executor = executor;
+ outputStream = new OneBufferOutputStream(new Object());
+ objectOutputStream = new OurObjectOutputStream(outputStream, resolver);
}
- public ObjectSource<Object> getUnmarshalingSource(final ObjectSource<ByteBuffer> bufferSource) throws IOException {
- return new MarshalingSource(bufferSource, allocator, resolver, classLoader);
+ public void start(final Object object) throws IOException, IllegalStateException {
+ executor.execute(new Runnable() {
+ public void run() {
+ try {
+ synchronized (objectOutputStream) {
+ objectOutputStream.writeObject(object);
+ objectOutputStream.flush();
+ synchronized (resultLock) {
+ outputStream.flush();
+ done = true;
+ resultLock.notify();
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ });
}
- public static final class MarshalingSink implements ObjectSink<Object> {
- private final OurObjectOutputStream stream;
-
- private MarshalingSink(final ObjectSink<ByteBuffer> bufferSink, final BufferAllocator<ByteBuffer> allocator, final ObjectResolver resolver) throws IOException {
- stream = new OurObjectOutputStream(bufferSink, allocator, resolver);
+ public boolean marshal(final ByteBuffer buffer) throws IOException {
+ outputStream.setBuffer(buffer);
+ synchronized (resultLock) {
+ outputStream.await();
+ return done;
}
+ }
- public void accept(final Object instance) throws IOException {
- stream.writeObject(instance);
+ public void clearClassPool() throws IOException {
+ synchronized (objectOutputStream) {
+ objectOutputStream.reset();
}
-
- public void flush() throws IOException {
- stream.flush();
- }
-
- public void close() throws IOException {
- stream.close();
- }
}
private static final class OurObjectOutputStream extends JBossObjectOutputStream {
private final ObjectResolver resolver;
- private OurObjectOutputStream(final ObjectSink<ByteBuffer> sink, final BufferAllocator<ByteBuffer> allocator, final ObjectResolver resolver) throws IOException {
- super(new ByteBufferOutputStream(sink, allocator));
+ private OurObjectOutputStream(final OutputStream outputStream, final ObjectResolver resolver) throws IOException {
+ super(outputStream);
enableReplaceObject(true);
this.resolver = resolver;
}
@@ -75,81 +74,4 @@
return resolver.writeReplace(obj);
}
}
-
- public static final class MarshalingSource implements ObjectSource<Object> {
- private final OurObjectInputStream stream;
-
- private MarshalingSource(final ObjectSource<ByteBuffer> bufferSource, final BufferAllocator<ByteBuffer> allocator, final ObjectResolver resolver, final ClassLoader classLoader) throws IOException {
- stream = new OurObjectInputStream(bufferSource, allocator, resolver, classLoader);
- }
-
- public boolean hasNext() throws IOException {
- return true;
- }
-
- public Object next() throws IOException {
- try {
- return stream.readObject();
- } catch (ClassNotFoundException e) {
- throw new RemotingException("No class found for next object in stream", e);
- }
- }
-
- public void close() throws IOException {
- stream.close();
- }
- }
-
- private static final class OurObjectInputStream extends JBossObjectInputStream {
- private final ClassLoader classLoader;
- private final ObjectResolver resolver;
-
- private OurObjectInputStream(final ObjectSource<ByteBuffer> bufferSource, final BufferAllocator<ByteBuffer> allocator, final ObjectResolver resolver, final ClassLoader classLoader) throws IOException {
- super(new ByteBufferInputStream(bufferSource, allocator), classLoader);
- this.classLoader = classLoader;
- this.resolver = resolver;
- }
-
- protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
- final String name = desc.getName();
- if (primitiveTypes.containsKey(name)) {
- return primitiveTypes.get(name);
- } else {
- return Class.forName(name, false, classLoader);
- }
- }
-
- protected Class<?> resolveProxyClass(final String[] interfaceNames) throws IOException, ClassNotFoundException {
- final int length = interfaceNames.length;
- final Class<?>[] interfaces = new Class[length];
- for (int i = 0; i < length; i ++) {
- interfaces[i] = Class.forName(interfaceNames[i], false, classLoader);
- }
- return Proxy.getProxyClass(classLoader, interfaces);
- }
-
- protected Object resolveObject(final Object obj) throws IOException {
- return resolver.readResolve(obj);
- }
-
- private static final Map<String, Class<?>> primitiveTypes = new HashMap<String, Class<?>>();
-
- private static <T> void add(Class<T> type) {
- primitiveTypes.put(type.getName(), type);
- }
-
- static {
- add(void.class);
- add(boolean.class);
- add(byte.class);
- add(short.class);
- add(int.class);
- add(long.class);
- add(float.class);
- add(double.class);
- add(char.class);
- }
- }
-
-
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarshallerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarshallerFactory.java 2008-07-10 18:49:25 UTC (rev 4370)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarshallerFactory.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -2,17 +2,28 @@
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.util.concurrent.Executor;
import org.jboss.cx.remoting.spi.marshal.Marshaller;
import org.jboss.cx.remoting.spi.marshal.MarshallerFactory;
import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
-import org.jboss.xnio.BufferAllocator;
+import org.jboss.cx.remoting.spi.marshal.Unmarshaller;
/**
*
*/
public class JBossSerializationMarshallerFactory implements MarshallerFactory<ByteBuffer> {
- public Marshaller<ByteBuffer> createMarshaller(final BufferAllocator<ByteBuffer> allocator, final ObjectResolver resolver, final ClassLoader classLoader) throws IOException {
- return new JBossSerializationMarhsaller(allocator, resolver, classLoader);
+ private final Executor executor;
+
+ public JBossSerializationMarshallerFactory(final Executor executor) {
+ this.executor = executor;
}
+
+ public Marshaller<ByteBuffer> createMarshaller(final ObjectResolver resolver) throws IOException {
+ return new JBossSerializationMarhsaller(executor, resolver);
+ }
+
+ public Unmarshaller<ByteBuffer> createUnmarshaller(final ObjectResolver resolver, final ClassLoader classLoader) throws IOException {
+ return null;
+ }
}
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationUnmarshaller.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationUnmarshaller.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationUnmarshaller.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -0,0 +1,132 @@
+/*
+ * 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.core.marshal;
+
+import org.jboss.cx.remoting.spi.marshal.Unmarshaller;
+import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
+import org.jboss.serial.io.JBossObjectInputStream;
+import java.nio.ByteBuffer;
+import java.io.IOException;
+import java.io.ObjectStreamClass;
+import java.io.InputStream;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ *
+ */
+public final class JBossSerializationUnmarshaller implements Unmarshaller<ByteBuffer> {
+ private final Executor executor;
+ private final OurObjectInputStream objectInputStream;
+ private final ClassLoader classLoader;
+ private final ObjectResolver resolver;
+ private final AtomicBoolean running = new AtomicBoolean();
+
+
+ public JBossSerializationUnmarshaller(final Executor executor, final ObjectResolver resolver, final ClassLoader classLoader) throws IOException {
+ this.executor = executor;
+ this.resolver = resolver;
+ this.classLoader = classLoader;
+ objectInputStream = new OurObjectInputStream(new OneBufferInputStream(), resolver, classLoader);
+ }
+
+ public boolean unmarshal(final ByteBuffer buffer) throws IOException {
+ if (! running.getAndSet(true)) {
+ executor.execute(new Runnable() {
+ public void run() {
+ synchronized (objectInputStream) {
+ try {
+ final Object object = objectInputStream.readObject();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } finally {
+ running.set(false);
+ }
+ }
+ }
+ });
+ }
+ return false;
+ }
+
+ public Object get() throws IOException, ClassNotFoundException, IllegalStateException {
+ return null;
+ }
+
+ private static final class OurObjectInputStream extends JBossObjectInputStream {
+ private final ClassLoader classLoader;
+ private final ObjectResolver resolver;
+
+ private OurObjectInputStream(final InputStream inputStream, final ObjectResolver resolver, final ClassLoader classLoader) throws IOException {
+ super(inputStream, classLoader);
+ this.classLoader = classLoader;
+ this.resolver = resolver;
+ }
+
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ final String name = desc.getName();
+ if (primitiveTypes.containsKey(name)) {
+ return primitiveTypes.get(name);
+ } else {
+ return Class.forName(name, false, classLoader);
+ }
+ }
+
+ protected Class<?> resolveProxyClass(final String[] interfaceNames) throws IOException, ClassNotFoundException {
+ final int length = interfaceNames.length;
+ final Class<?>[] interfaces = new Class[length];
+ for (int i = 0; i < length; i ++) {
+ interfaces[i] = Class.forName(interfaceNames[i], false, classLoader);
+ }
+ return Proxy.getProxyClass(classLoader, interfaces);
+ }
+
+ protected Object resolveObject(final Object obj) throws IOException {
+ return resolver.readResolve(obj);
+ }
+
+ private static final Map<String, Class<?>> primitiveTypes = new HashMap<String, Class<?>>();
+
+ private static <T> void add(Class<T> type) {
+ primitiveTypes.put(type.getName(), type);
+ }
+
+ static {
+ add(void.class);
+ add(boolean.class);
+ add(byte.class);
+ add(short.class);
+ add(int.class);
+ add(long.class);
+ add(float.class);
+ add(double.class);
+ add(char.class);
+ }
+ }
+}
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferInputStream.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferInputStream.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferInputStream.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -0,0 +1,71 @@
+/*
+ * 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.core.marshal;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.nio.ByteBuffer;
+
+/**
+ *
+ */
+public final class OneBufferInputStream extends InputStream {
+
+ private final Object lock = new Object();
+ private ByteBuffer buffer;
+
+ private ByteBuffer getBuffer() throws InterruptedIOException {
+ synchronized (lock) {
+ for (;;) {
+ final ByteBuffer buffer = this.buffer;
+ if (buffer != null) {
+ if (! buffer.hasRemaining()) {
+ lock.notify();
+ this.buffer = null;
+ } else {
+ return buffer;
+ }
+ }
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new InterruptedIOException("getBuffer() operation interrupted!");
+ }
+ }
+ }
+ }
+
+ public int read() throws IOException {
+ synchronized (lock) {
+ return getBuffer().get() & 0xff;
+ }
+ }
+
+ public int read(final byte[] b, int off, int len) throws IOException {
+ synchronized (lock) {
+ return 0;
+ }
+ }
+}
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferOutputStream.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferOutputStream.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferOutputStream.java 2008-07-11 21:21:16 UTC (rev 4371)
@@ -0,0 +1,115 @@
+/*
+ * 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.core.marshal;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.nio.ByteBuffer;
+
+/**
+ *
+ */
+public final class OneBufferOutputStream extends OutputStream {
+
+ private ByteBuffer buffer;
+ private final Object lock;
+
+ public OneBufferOutputStream(final Object lock) {
+ this.lock = lock;
+ }
+
+ public void setBuffer(ByteBuffer buffer) {
+ synchronized (lock) {
+ if (this.buffer != null) {
+ throw new IllegalStateException("Buffer already set");
+ }
+ this.buffer = buffer;
+ lock.notify();
+ }
+ }
+
+ private ByteBuffer getBuffer() throws InterruptedIOException {
+ synchronized (lock) {
+ for (;;) {
+ final ByteBuffer buffer = this.buffer;
+ if (buffer != null) {
+ if (! buffer.hasRemaining()) {
+ lock.notify();
+ this.buffer = null;
+ } else {
+ return buffer;
+ }
+ }
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new InterruptedIOException("getBuffer() operation interrupted!");
+ }
+ }
+ }
+ }
+
+ public void write(final int b) throws IOException {
+ synchronized (lock) {
+ final ByteBuffer buffer = getBuffer();
+ buffer.put((byte) b);
+ }
+ }
+
+ public void write(byte[] b, int off, int len) throws IOException {
+ synchronized (lock) {
+ while (len > 0) {
+ final ByteBuffer buffer = getBuffer();
+ final int rem = Math.min(buffer.remaining(), len);
+ buffer.put(b, off, rem);
+ len -= rem; off += rem;
+ }
+ }
+ }
+
+ public void flush() throws IOException {
+ synchronized (lock) {
+ buffer = null;
+ lock.notify();
+ }
+ }
+
+ public void close() throws IOException {
+ flush();
+ }
+
+ public void await() {
+ synchronized (lock) {
+ while (buffer != null) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ buffer = null;
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ }
+}
16 years, 5 months
JBoss Remoting SVN: r4370 - in remoting3/trunk: core/src/main/java/org/jboss/cx/remoting/core and 1 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-10 14:49:25 -0400 (Thu, 10 Jul 2008)
New Revision: 4370
Added:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
Removed:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.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/RemoteClientEndpointLocalImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingSecurityManager.java
Log:
add more SPI support stuff
Copied: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java (from rev 4368, remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java)
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.spi.remote.Handle;
+import org.jboss.xnio.log.Logger;
+
+/**
+ *
+ */
+public abstract class AbstractAutoCloseable<T> extends AbstractCloseable<T> {
+
+ private final AtomicBoolean autoClose = new AtomicBoolean();
+ private final AtomicInteger refcount = new AtomicInteger(1);
+ private final Executor executor;
+
+ private static final Logger log = Logger.getLogger(AbstractAutoCloseable.class);
+
+ protected AbstractAutoCloseable(final Executor executor) {
+ super(executor);
+ this.executor = executor;
+ }
+
+ protected void safeDec() {
+ try {
+ dec();
+ } catch (Throwable t) {
+ log.trace("Failed to decrement reference count: %s", t);
+ }
+ }
+
+ protected void dec() throws RemotingException {
+ final int v = refcount.decrementAndGet();
+ if (v == 0) {
+ // we dropped the refcount to zero
+ if (refcount.compareAndSet(0, -65536)) {
+ // we are closing
+ close();
+ }
+ // someone incremented it in the meantime... lucky them
+ } else if (v < 0) {
+ // was already closed; put the count back
+ refcount.incrementAndGet();
+ }
+ // otherwise, the resource remains open
+ }
+
+ protected void inc() throws RemotingException {
+ final int v = refcount.getAndIncrement();
+ if (v < 0) {
+ // was already closed
+ refcount.decrementAndGet();
+ throw new RemotingException("Resource is closed");
+ }
+ }
+
+ public void autoClose() throws RemotingException {
+ if (! autoClose.getAndSet(true)) {
+ dec();
+ }
+ }
+
+ public Handle<T> getHandle() throws RemotingException {
+ return new HandleImpl();
+ }
+
+ private final class HandleImpl extends AbstractCloseable<Handle<T>> implements Handle<T> {
+
+ private HandleImpl() throws RemotingException {
+ super(AbstractAutoCloseable.this.executor);
+ inc();
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public T getResource() {
+ return (T) AbstractAutoCloseable.this;
+ }
+ }
+}
Copied: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java (from rev 4368, remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java)
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import org.jboss.cx.remoting.Closeable;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.spi.SpiUtils;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ *
+ */
+public abstract class AbstractCloseable<T> implements Closeable<T> {
+
+ private static final Logger log = Logger.getLogger(AbstractCloseable.class);
+
+ protected final Executor executor;
+ private final Object closeLock = new Object();
+ private final AtomicBoolean closed = new AtomicBoolean();
+ private Set<CloseHandler<? super T>> closeHandlers;
+
+ protected AbstractCloseable(final Executor executor) {
+ if (executor == null) {
+ throw new NullPointerException("executor is null");
+ }
+ this.executor = executor;
+ }
+
+ protected boolean isOpen() {
+ return ! closed.get();
+ }
+
+ public void close() throws RemotingException {
+ if (! closed.getAndSet(true)) {
+ synchronized (closeLock) {
+ if (closeHandlers != null) {
+ for (final CloseHandler<? super T> handler : closeHandlers) {
+ executor.execute(new Runnable() {
+ @SuppressWarnings({ "unchecked" })
+ public void run() {
+ SpiUtils.safeHandleClose(handler, (T) AbstractCloseable.this);
+ }
+ });
+ }
+ closeHandlers = null;
+ }
+ }
+ }
+ }
+
+ public void addCloseHandler(final CloseHandler<? super T> handler) {
+ synchronized (closeLock) {
+ if (closeHandlers == null) {
+ closeHandlers = new HashSet<CloseHandler<? super T>>();
+ }
+ closeHandlers.add(handler);
+ }
+ }
+
+ protected Executor getExecutor() {
+ return executor;
+ }
+
+ protected void finalize() throws Throwable {
+ try {
+ super.finalize();
+ } finally {
+ if (isOpen()) {
+ log.warn("Leaked a %s instance!", getClass().getName());
+ IoUtils.safeClose(this);
+ }
+ }
+ }
+}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -23,6 +23,7 @@
package org.jboss.cx.remoting.spi;
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
+import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
import org.jboss.cx.remoting.RequestCancelHandler;
import org.jboss.cx.remoting.RequestContext;
import org.jboss.cx.remoting.CloseHandler;
@@ -126,5 +127,16 @@
log.error(t, "Request completion handler failed unexpectedly");
}
}
+
+ public static RemoteRequestContext getBlankRemoteRequestContext() {
+ return BLANK_REMOTE_REQUEST_CONTEXT;
+ }
+
+ private static final RemoteRequestContext BLANK_REMOTE_REQUEST_CONTEXT = new BlankRemoteRequestContext();
+
+ private static final class BlankRemoteRequestContext implements RemoteRequestContext {
+ public void cancel(final boolean mayInterrupt) {
+ }
+ }
}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java 2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -1,103 +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.core;
-
-import java.util.concurrent.Executor;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.spi.remote.Handle;
-import org.jboss.xnio.log.Logger;
-
-/**
- *
- */
-public abstract class AbstractAutoCloseable<T> extends AbstractCloseable<T> {
-
- private final AtomicBoolean autoClose = new AtomicBoolean();
- private final AtomicInteger refcount = new AtomicInteger(1);
- private final Executor executor;
-
- private static final Logger log = Logger.getLogger(AbstractAutoCloseable.class);
-
- protected AbstractAutoCloseable(final Executor executor) {
- super(executor);
- this.executor = executor;
- }
-
- protected void safeDec() {
- try {
- dec();
- } catch (Throwable t) {
- log.trace("Failed to decrement reference count: %s", t);
- }
- }
-
- protected void dec() throws RemotingException {
- final int v = refcount.decrementAndGet();
- if (v == 0) {
- // we dropped the refcount to zero
- if (refcount.compareAndSet(0, -65536)) {
- // we are closing
- close();
- }
- // someone incremented it in the meantime... lucky them
- } else if (v < 0) {
- // was already closed; put the count back
- refcount.incrementAndGet();
- }
- // otherwise, the resource remains open
- }
-
- protected void inc() throws RemotingException {
- final int v = refcount.getAndIncrement();
- if (v < 0) {
- // was already closed
- refcount.decrementAndGet();
- throw new RemotingException("Resource is closed");
- }
- }
-
- public void autoClose() throws RemotingException {
- if (! autoClose.getAndSet(true)) {
- dec();
- }
- }
-
- public Handle<T> getHandle() throws RemotingException {
- return new HandleImpl();
- }
-
- private final class HandleImpl extends AbstractCloseable<Handle<T>> implements Handle<T> {
-
- private HandleImpl() throws RemotingException {
- super(AbstractAutoCloseable.this.executor);
- inc();
- }
-
- @SuppressWarnings({ "unchecked" })
- public T getResource() {
- return (T) AbstractAutoCloseable.this;
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -1,100 +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.core;
-
-import org.jboss.cx.remoting.Closeable;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.CloseHandler;
-import org.jboss.cx.remoting.spi.SpiUtils;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.log.Logger;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Executor;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- *
- */
-public abstract class AbstractCloseable<T> implements Closeable<T> {
-
- private static final Logger log = Logger.getLogger(AbstractCloseable.class);
-
- protected final Executor executor;
- private final Object closeLock = new Object();
- private final AtomicBoolean closed = new AtomicBoolean();
- private Set<CloseHandler<? super T>> closeHandlers;
-
- protected AbstractCloseable(final Executor executor) {
- if (executor == null) {
- throw new NullPointerException("executor is null");
- }
- this.executor = executor;
- }
-
- protected boolean isOpen() {
- return ! closed.get();
- }
-
- public void close() throws RemotingException {
- if (! closed.getAndSet(true)) {
- synchronized (closeLock) {
- if (closeHandlers != null) {
- for (final CloseHandler<? super T> handler : closeHandlers) {
- executor.execute(new Runnable() {
- @SuppressWarnings({ "unchecked" })
- public void run() {
- SpiUtils.safeHandleClose(handler, (T) AbstractCloseable.this);
- }
- });
- }
- closeHandlers = null;
- }
- }
- }
- }
-
- public void addCloseHandler(final CloseHandler<? super T> handler) {
- synchronized (closeLock) {
- if (closeHandlers == null) {
- closeHandlers = new HashSet<CloseHandler<? super T>>();
- }
- closeHandlers.add(handler);
- }
- }
-
- protected Executor getExecutor() {
- return executor;
- }
-
- protected void finalize() throws Throwable {
- try {
- super.finalize();
- } finally {
- if (isOpen()) {
- log.warn("Leaked a %s instance!", getClass().getName());
- IoUtils.safeClose(this);
- }
- }
- }
-}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java 2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -25,6 +25,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.cx.remoting.spi.AbstractCloseable;
/**
*
@@ -40,4 +41,12 @@
public ConcurrentMap<Object, Object> getAttributes() {
return attributes;
}
+
+ protected Executor getExecutor() {
+ return super.getExecutor();
+ }
+
+ protected boolean isOpen() {
+ return super.isOpen();
+ }
}
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-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -28,6 +28,7 @@
import org.jboss.cx.remoting.Endpoint;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
+import org.jboss.cx.remoting.spi.AbstractCloseable;
/**
*
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-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -158,7 +158,7 @@
boolean ok = false;
final Handle<RemoteServiceEndpoint<I,O>> handle = endpoint.getHandle();
try {
- final ClientSourceImpl<I, O> client = new ClientSourceImpl<I, O>(endpoint, executor);
+ 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);
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java 2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -26,6 +26,7 @@
import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
import org.jboss.cx.remoting.spi.SpiUtils;
+import org.jboss.cx.remoting.spi.AbstractAutoCloseable;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.RemoteExecutionException;
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java 2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -24,6 +24,7 @@
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.AbstractAutoCloseable;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
Modified: remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingSecurityManager.java
===================================================================
--- remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingSecurityManager.java 2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingSecurityManager.java 2008-07-10 18:49:25 UTC (rev 4370)
@@ -169,7 +169,7 @@
}
}
- /** @noinspection deprecation*/
+ @SuppressWarnings({"deprecation"})
public void checkMulticast(final InetAddress maddr, final byte ttl) {
try {
super.checkMulticast(maddr, ttl);
16 years, 5 months
JBoss Remoting SVN: r4369 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting/spi/remote and 4 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-10 10:56:19 -0400 (Thu, 10 Jul 2008)
New Revision: 4369
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.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/RemoteClientEndpointLocalImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
Move responsibility for creating Client and ClientSource instances to the Endpoint
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -18,5 +18,5 @@
*
* @return the new context
*/
- Client<I, O> createContext() throws RemotingException;
+ Client<I, O> createClient() throws RemotingException;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -35,8 +35,9 @@
* @param <O> the reply type
* @param requestListener the request listener
* @return the client
+ * @throws RemotingException if an error occurs
*/
- <I, O> RemoteClientEndpoint<I, O> createClient(RequestListener<I, O> requestListener) throws RemotingException;
+ <I, O> RemoteClientEndpoint<I, O> createClientEndpoint(RequestListener<I, O> requestListener) throws RemotingException;
/**
* Create a client source that can be used to acquire clients associated with a request listener on this endpoint.
@@ -49,6 +50,29 @@
* @param <O> the reply type
* @param requestListener the request listener
* @return the context source
+ * @throws RemotingException if an error occurs
*/
- <I, O> RemoteServiceEndpoint<I, O> createService(RequestListener<I, O> requestListener) throws RemotingException;
+ <I, O> RemoteServiceEndpoint<I, O> createServiceEndpoint(RequestListener<I, O> requestListener) throws RemotingException;
+
+ /**
+ * Create a client from a remote client endpoint.
+ *
+ * @param <I> the request type
+ * @param <O> the reply type
+ * @param endpoint the remote client endpoint
+ * @return the client
+ * @throws RemotingException if an error occurs
+ */
+ <I, O> Client<I, O> createClient(RemoteClientEndpoint<I, O> endpoint) throws RemotingException;
+
+ /**
+ * Create a client source from a remote service endpoint.
+ *
+ * @param <I> the request type
+ * @param <O> the reply type
+ * @param endpoint the remote service endpoint
+ * @return the client source
+ * @throws RemotingException if an error occurs
+ */
+ <I, O> ClientSource<I, O> createClientSource(RemoteServiceEndpoint<I, O> endpoint) throws RemotingException;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -65,14 +65,6 @@
Handle<RemoteClientEndpoint<I, O>> getHandle() throws RemotingException;
/**
- * Get a local client which can be used to make invocations.
- *
- * @return the client
- * @throws RemotingException if a client could not be acquired
- */
- Client<I, O> getClient() throws RemotingException;
-
- /**
* Automatically close this client endpoint when all handles and local client instances are closed.
*/
void autoClose() throws RemotingException;
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -29,7 +29,9 @@
/**
* A remote service endpoint, which can be passed to remote endpoints. Remote systems can then use the service endpoint
- * to acquire client endpoints, or they may pass it on to other systems.
+ * to acquire client endpoints, or they may pass it on to other systems. Acquiring a client endpoint using this method
+ * has the advantage that a round trip to the remote side is not necessary; the local side can spawn a client endpoint
+ * and simply notify the remote side of the change.
*/
public interface RemoteServiceEndpoint<I, O> extends Closeable<RemoteServiceEndpoint<I, O>> {
@@ -53,13 +55,6 @@
Handle<RemoteServiceEndpoint<I, O>> getHandle() throws RemotingException;
/**
- * Get a local client source which can be used to access this service.
- *
- * @return the client source
- */
- ClientSource<I, O> getClientSource() throws RemotingException;
-
- /**
* Automatically close this service endpoint when all handles and local client source instances
* are closed.
*/
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -44,7 +44,7 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public Client<I, O> createContext() throws RemotingException {
- return delegate.createContext();
+ public Client<I, O> createClient() throws RemotingException {
+ return delegate.createClient();
}
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -4,6 +4,8 @@
import org.jboss.cx.remoting.Endpoint;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.RequestListener;
+import org.jboss.cx.remoting.Client;
+import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
@@ -39,14 +41,28 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) throws RemotingException {
- return delegate.createClient(requestListener);
+ public <I, O> RemoteClientEndpoint<I, O> createClientEndpoint(final RequestListener<I, O> requestListener) throws RemotingException {
+ return delegate.createClientEndpoint(requestListener);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> RemoteServiceEndpoint<I, O> createService(final RequestListener<I, O> requestListener) throws RemotingException {
- return delegate.createService(requestListener);
+ public <I, O> RemoteServiceEndpoint<I, O> createServiceEndpoint(final RequestListener<I, O> requestListener) throws RemotingException {
+ return delegate.createServiceEndpoint(requestListener);
}
+
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
+ public <I, O> Client<I, O> createClient(final RemoteClientEndpoint<I, O> endpoint) throws RemotingException {
+ return delegate.createClient(endpoint);
+ }
+
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
+ public <I, O> ClientSource<I, O> createClientSource(final RemoteServiceEndpoint<I, O> endpoint) throws RemotingException {
+ return delegate.createClientSource(endpoint);
+ }
}
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-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -25,27 +25,30 @@
import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.Endpoint;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
-import java.util.concurrent.Executor;
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
/**
*
*/
public final class ClientSourceImpl<I, O> extends AbstractCloseable<ClientSource<I, O>> implements ClientSource<I, O> {
- private final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint;
+ private final RemoteServiceEndpoint<I, O> serviceEndpoint;
+ private final Endpoint endpoint;
- ClientSourceImpl(final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint, final Executor executor) {
- super(executor);
+ ClientSourceImpl(final RemoteServiceEndpoint<I, O> serviceEndpoint, final EndpointImpl endpoint) {
+ super(endpoint.getExecutor());
this.serviceEndpoint = serviceEndpoint;
+ this.endpoint = endpoint;
}
- public Client<I, O> createContext() throws RemotingException {
+ public Client<I, O> createClient() throws RemotingException {
if (! isOpen()) {
throw new RemotingException("Client source is not open");
}
final RemoteClientEndpoint<I,O> clientEndpoint = serviceEndpoint.openClient();
- final Client<I, O> client = clientEndpoint.getClient();
+ final Client<I, O> client = endpoint.createClient(clientEndpoint);
clientEndpoint.autoClose();
return client;
}
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-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -11,9 +11,12 @@
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.Client;
+import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.core.util.OrderedExecutorFactory;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
+import org.jboss.cx.remoting.spi.remote.Handle;
import org.jboss.cx.remoting.util.CollectionUtil;
import org.jboss.cx.remoting.util.NamingThreadFactory;
import org.jboss.cx.remoting.version.Version;
@@ -118,20 +121,58 @@
return endpointMap;
}
- public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) throws RemotingException {
+ public <I, O> RemoteClientEndpoint<I, O> createClientEndpoint(final RequestListener<I, O> requestListener) throws RemotingException {
final RemoteClientEndpointLocalImpl<I, O> clientEndpoint = new RemoteClientEndpointLocalImpl<I, O>(executor, requestListener);
clientEndpoint.addCloseHandler(remover);
clientEndpoint.open();
return clientEndpoint;
}
- public <I, O> RemoteServiceEndpoint<I, O> createService(final RequestListener<I, O> requestListener) throws RemotingException {
+ public <I, O> RemoteServiceEndpoint<I, O> createServiceEndpoint(final RequestListener<I, O> requestListener) throws RemotingException {
final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint = new RemoteServiceEndpointLocalImpl<I, O>(executor, requestListener);
serviceEndpoint.addCloseHandler(remover);
serviceEndpoint.open();
return serviceEndpoint;
}
+ public <I, O> Client<I, O> createClient(final RemoteClientEndpoint<I, O> endpoint) throws RemotingException {
+ boolean ok = false;
+ final Handle<RemoteClientEndpoint<I,O>> handle = endpoint.getHandle();
+ try {
+ final ClientImpl<I, O> client = new ClientImpl<I, O>(endpoint, executor);
+ client.addCloseHandler(new CloseHandler<Client<I, O>>() {
+ public void handleClose(final Client<I, O> closed) {
+ IoUtils.safeClose(handle);
+ }
+ });
+ ok = true;
+ return client;
+ } finally {
+ if (! ok) {
+ IoUtils.safeClose(handle);
+ }
+ }
+ }
+
+ public <I, O> ClientSource<I, O> createClientSource(final RemoteServiceEndpoint<I, O> endpoint) throws RemotingException {
+ boolean ok = false;
+ final Handle<RemoteServiceEndpoint<I,O>> handle = endpoint.getHandle();
+ try {
+ final ClientSourceImpl<I, O> client = new ClientSourceImpl<I, O>(endpoint, executor);
+ client.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
+ public void handleClose(final ClientSource<I, O> closed) {
+ IoUtils.safeClose(handle);
+ }
+ });
+ ok = true;
+ return client;
+ } finally {
+ if (! ok) {
+ IoUtils.safeClose(handle);
+ }
+ }
+ }
+
private final ResourceRemover remover = new ResourceRemover();
private final class ResourceRemover implements CloseHandler<Closeable> {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -27,7 +27,6 @@
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
import org.jboss.cx.remoting.spi.SpiUtils;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.CloseHandler;
@@ -93,25 +92,6 @@
};
}
- public Client<I, O> getClient() throws RemotingException {
- inc();
- boolean ok = false;
- try {
- final ClientImpl<I, O> client = new ClientImpl<I, O>(this, executor);
- client.addCloseHandler(new CloseHandler<Client<I, O>>() {
- public void handleClose(final Client<I, O> closed) {
- safeDec();
- }
- });
- ok = true;
- return client;
- } finally {
- if (! ok) {
- safeDec();
- }
- }
- }
-
void open() throws RemotingException {
try {
requestListener.handleClientOpen(clientContext);
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -26,7 +26,6 @@
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.CloseHandler;
import org.jboss.xnio.log.Logger;
import java.util.concurrent.Executor;
@@ -59,25 +58,6 @@
}
}
- public ClientSource<I, O> getClientSource() throws RemotingException {
- inc();
- boolean ok = false;
- try {
- final ClientSourceImpl<I, O> clientSource = new ClientSourceImpl<I, O>(this, executor);
- clientSource.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
- public void handleClose(final ClientSource<I, O> closed) {
- safeDec();
- }
- });
- ok = true;
- return clientSource;
- } finally {
- if (! ok) {
- safeDec();
- }
- }
- }
-
void open() throws RemotingException {
try {
requestListener.handleServiceOpen(serviceContext);
Modified: remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
===================================================================
--- remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -78,7 +78,7 @@
endpoint.setExecutor(executorService);
endpoint.start();
try {
- final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClient(new AbstractRequestListener<Object, Object>() {
+ final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClientEndpoint(new AbstractRequestListener<Object, Object>() {
public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
assertEquals(request, requestObj);
try {
@@ -98,7 +98,7 @@
clientEndpointClosed.set(true);
}
});
- final Client<Object,Object> client = clientEndpoint.getClient();
+ final Client<Object,Object> client = endpoint.createClient(clientEndpoint);
try {
client.addCloseHandler(new CloseHandler<Client<Object, Object>>() {
public void handleClose(final Client<Object, Object> closed) {
@@ -137,7 +137,7 @@
endpoint.setExecutor(executorService);
endpoint.start();
try {
- final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClient(new AbstractRequestListener<Object, Object>() {
+ final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClientEndpoint(new AbstractRequestListener<Object, Object>() {
public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
assertEquals(request, requestObj);
try {
@@ -157,7 +157,7 @@
clientEndpointClosed.set(true);
}
});
- final Client<Object,Object> client = clientEndpoint.getClient();
+ final Client<Object,Object> client = endpoint.createClient(clientEndpoint);
try {
client.addCloseHandler(new CloseHandler<Client<Object, Object>>() {
public void handleClose(final Client<Object, Object> closed) {
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-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-10 14:56:19 UTC (rev 4369)
@@ -31,20 +31,20 @@
}
public static <I, O> Client<I, O> createLocalClient(Endpoint endpoint, RequestListener<I, O> requestListener) throws RemotingException {
- final RemoteClientEndpoint<I, O> clientEndpoint = endpoint.createClient(requestListener);
+ final RemoteClientEndpoint<I, O> clientEndpoint = endpoint.createClientEndpoint(requestListener);
try {
- return clientEndpoint.getClient();
+ return endpoint.createClient(clientEndpoint);
} 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);
+ final RemoteServiceEndpoint<I, O> serviceEndpoint = endpoint.createServiceEndpoint(requestListener);
try {
- return clientEndpoint.getClientSource();
+ return endpoint.createClientSource(serviceEndpoint);
} finally {
- clientEndpoint.autoClose();
+ serviceEndpoint.autoClose();
}
}
16 years, 5 months
JBoss Remoting SVN: r4368 - remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-07-08 00:45:53 -0400 (Tue, 08 Jul 2008)
New Revision: 4368
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
Log:
Put resources.notifyAll() in ResourceRemover.handleClose() in a synchronized block.
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-08 00:50:00 UTC (rev 4367)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-08 04:45:53 UTC (rev 4368)
@@ -137,7 +137,10 @@
private final class ResourceRemover implements CloseHandler<Closeable> {
public void handleClose(final Closeable closed) {
resources.remove(closed);
- resources.notifyAll();
+ synchronized (resources)
+ {
+ resources.notifyAll();
+ }
}
}
}
16 years, 5 months
JBoss Remoting SVN: r4367 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting/spi/stream and 1 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-07 20:50:00 -0400 (Mon, 07 Jul 2008)
New Revision: 4367
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializerFactory.java
remoting3/trunk/build.properties
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/InputStreamStreamSerializerFactory.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/OutputStreamStreamSerailizerFactory.java
Log:
Switch to XNIO 1.0.0-CR3
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializerFactory.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializerFactory.java 2008-07-08 00:45:48 UTC (rev 4366)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializerFactory.java 2008-07-08 00:50:00 UTC (rev 4367)
@@ -1,7 +1,7 @@
package org.jboss.cx.remoting.spi.stream;
import org.jboss.xnio.IoHandler;
-import org.jboss.xnio.Client;
+import org.jboss.xnio.ChannelSource;
import org.jboss.xnio.channels.StreamChannel;
import java.io.IOException;
import java.io.Serializable;
@@ -12,5 +12,5 @@
public interface StreamSerializerFactory extends Serializable {
IoHandler<? super StreamChannel> getLocalSide(Object localSide) throws IOException;
- Object getRemoteSide(Client<StreamChannel> remoteClient) throws IOException;
+ Object getRemoteSide(ChannelSource<StreamChannel> remoteClient) throws IOException;
}
Modified: remoting3/trunk/build.properties
===================================================================
--- remoting3/trunk/build.properties 2008-07-08 00:45:48 UTC (rev 4366)
+++ remoting3/trunk/build.properties 2008-07-08 00:50:00 UTC (rev 4367)
@@ -173,7 +173,7 @@
lib.trove.local=${local.repository}/${lib.trove.path}
lib.trove.remote=${remote.repository}/${lib.trove.path}
-lib.xnio-api.version=1.0.0.CR2
+lib.xnio-api.version=1.0.0.CR3
lib.xnio-api.name=xnio-api-${lib.xnio-api.version}.jar
lib.xnio-api.license=lgpl
lib.xnio-api.dir=maven2/org/jboss/xnio/xnio-api/${lib.xnio-api.version}/
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/InputStreamStreamSerializerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/InputStreamStreamSerializerFactory.java 2008-07-08 00:45:48 UTC (rev 4366)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/InputStreamStreamSerializerFactory.java 2008-07-08 00:50:00 UTC (rev 4367)
@@ -12,7 +12,7 @@
import org.jboss.xnio.channels.CommonOptions;
import org.jboss.xnio.channels.StreamSourceChannel;
import org.jboss.xnio.IoHandler;
-import org.jboss.xnio.Client;
+import org.jboss.xnio.ChannelSource;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.BufferAllocator;
import org.jboss.xnio.IoFuture;
@@ -43,7 +43,7 @@
return new LocalHandler((InputStream) localSide, allocator);
}
- public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
+ public Object getRemoteSide(final ChannelSource<StreamChannel> remoteClient) throws IOException {
// return new RemoteInputStream(taskList, futureChannel);
return null;
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java 2008-07-08 00:45:48 UTC (rev 4366)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java 2008-07-08 00:50:00 UTC (rev 4367)
@@ -9,7 +9,7 @@
import org.jboss.xnio.channels.StreamSinkChannel;
import org.jboss.xnio.channels.CommonOptions;
import org.jboss.xnio.IoHandler;
-import org.jboss.xnio.Client;
+import org.jboss.xnio.ChannelSource;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.log.Logger;
@@ -38,7 +38,7 @@
return null;
}
- public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
+ public Object getRemoteSide(final ChannelSource<StreamChannel> remoteClient) throws IOException {
return null;
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/OutputStreamStreamSerailizerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/OutputStreamStreamSerailizerFactory.java 2008-07-08 00:45:48 UTC (rev 4366)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/OutputStreamStreamSerailizerFactory.java 2008-07-08 00:50:00 UTC (rev 4367)
@@ -10,7 +10,7 @@
import org.jboss.xnio.channels.StreamSourceChannel;
import org.jboss.xnio.channels.StreamSinkChannel;
import org.jboss.xnio.IoHandler;
-import org.jboss.xnio.Client;
+import org.jboss.xnio.ChannelSource;
import org.jboss.xnio.BufferAllocator;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.IoFuture;
@@ -36,7 +36,7 @@
});
}
- public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
+ public Object getRemoteSide(final ChannelSource<StreamChannel> remoteClient) throws IOException {
final RemoteHandler handler = new RemoteHandler(new BufferAllocator<ByteBuffer>() {
public ByteBuffer allocate() {
return ByteBuffer.allocate(512);
@@ -45,7 +45,7 @@
public void free(final ByteBuffer byteBuffer) {
}
});
- final IoFuture<StreamChannel> futureChannel = remoteClient.connect(handler);
+ final IoFuture<StreamChannel> futureChannel = remoteClient.open(handler);
return new RemoteOutputStream(handler, futureChannel);
}
16 years, 5 months
JBoss Remoting SVN: r4366 - remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-07 20:45:48 -0400 (Mon, 07 Jul 2008)
New Revision: 4366
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamDetector.java
Log:
javadoc
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamDetector.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamDetector.java 2008-07-04 02:50:34 UTC (rev 4365)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamDetector.java 2008-07-08 00:45:48 UTC (rev 4366)
@@ -1,7 +1,7 @@
package org.jboss.cx.remoting.spi.stream;
/**
- *
+ * A class that can detect whether an object is streamable.
*/
public interface StreamDetector {
/**
16 years, 5 months
JBoss Remoting SVN: r4365 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting/spi and 4 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 22:50:34 -0400 (Thu, 03 Jul 2008)
New Revision: 4365
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
Log:
Have endpoints auto-close all resources on stop; fix declaration of close handlers to allow more general handlers
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -20,5 +20,5 @@
*
* @param handler the close handler
*/
- void addCloseHandler(CloseHandler<T> handler);
+ void addCloseHandler(CloseHandler<? super T> handler);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -104,7 +104,7 @@
* @param handler the close handler
* @param closed the object that was closed
*/
- public static <T> void safeHandleClose(final CloseHandler<T> handler, final T closed) {
+ public static <T> void safeHandleClose(final CloseHandler<? super T> handler, final T closed) {
try {
handler.handleClose(closed);
} catch (Throwable t) {
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -50,5 +50,5 @@
*
* @param handler the handler
*/
- void addCloseHandler(final CloseHandler<Handle<T>> handler);
+ void addCloseHandler(final CloseHandler<? super Handle<T>> handler);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -90,5 +90,5 @@
*
* @param handler the handler to be called
*/
- void addCloseHandler(final CloseHandler<RemoteClientEndpoint<I, O>> handler);
+ void addCloseHandler(final CloseHandler<? super RemoteClientEndpoint<I, O>> handler);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -75,5 +75,5 @@
*
* @param handler the handler to be called
*/
- void addCloseHandler(final CloseHandler<RemoteServiceEndpoint<I, O>> handler);
+ void addCloseHandler(final CloseHandler<? super RemoteServiceEndpoint<I, O>> handler);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -33,7 +33,7 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void addCloseHandler(final CloseHandler<ClientSource<I, O>> closeHandler) {
+ public void addCloseHandler(final CloseHandler<? super ClientSource<I, O>> closeHandler) {
delegate.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
public void handleClose(final ClientSource<I, O> closed) {
closeHandler.handleClose(ClientSourceWrapper.this);
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -35,7 +35,7 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void addCloseHandler(final CloseHandler<Client<I, O>> closeHandler) {
+ public void addCloseHandler(final CloseHandler<? super Client<I, O>> closeHandler) {
delegate.addCloseHandler(new CloseHandler<Client<I, O>>() {
public void handleClose(final Client<I, O> closed) {
closeHandler.handleClose(ClientWrapper.this);
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -43,7 +43,7 @@
protected final Executor executor;
private final Object closeLock = new Object();
private final AtomicBoolean closed = new AtomicBoolean();
- private Set<CloseHandler<T>> closeHandlers;
+ private Set<CloseHandler<? super T>> closeHandlers;
protected AbstractCloseable(final Executor executor) {
if (executor == null) {
@@ -60,7 +60,7 @@
if (! closed.getAndSet(true)) {
synchronized (closeLock) {
if (closeHandlers != null) {
- for (final CloseHandler<T> handler : closeHandlers) {
+ for (final CloseHandler<? super T> handler : closeHandlers) {
executor.execute(new Runnable() {
@SuppressWarnings({ "unchecked" })
public void run() {
@@ -74,10 +74,10 @@
}
}
- public void addCloseHandler(final CloseHandler<T> handler) {
+ public void addCloseHandler(final CloseHandler<? super T> handler) {
synchronized (closeLock) {
if (closeHandlers == null) {
- closeHandlers = new HashSet<CloseHandler<T>>();
+ closeHandlers = new HashSet<CloseHandler<? super T>>();
}
closeHandlers.add(handler);
}
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-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -4,9 +4,13 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.Set;
+import java.io.Closeable;
import org.jboss.cx.remoting.Endpoint;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.core.util.OrderedExecutorFactory;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
@@ -14,6 +18,7 @@
import org.jboss.cx.remoting.util.NamingThreadFactory;
import org.jboss.cx.remoting.version.Version;
import org.jboss.xnio.log.Logger;
+import org.jboss.xnio.IoUtils;
/**
*
@@ -30,6 +35,7 @@
private OrderedExecutorFactory orderedExecutorFactory;
private ExecutorService executorService;
+ private final Set<Closeable> resources = CollectionUtil.synchronizedWeakHashSet();
private final ConcurrentMap<Object, Object> endpointMap = CollectionUtil.concurrentMap();
public EndpointImpl() {
@@ -43,7 +49,7 @@
return executor;
}
- public Executor getOrderedExecutor() {
+ Executor getOrderedExecutor() {
return orderedExecutorFactory.getOrderedExecutor();
}
@@ -74,12 +80,36 @@
public void stop() {
// todo security check
- if (executorService != null) {
- executorService.shutdown();
- executorService = null;
- executor = null;
+ boolean intr = false;
+ try {
+ for (Closeable resource : resources) {
+ IoUtils.safeClose(resource);
+ }
+ synchronized (resources) {
+ while (! resources.isEmpty()) {
+ try {
+ resources.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ }
+ }
+ if (executorService != null) {
+ executorService.shutdown();
+ boolean done = false;
+ do try {
+ done = executorService.awaitTermination(30L, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ intr = true;
+ } while (! done);
+ executorService = null;
+ executor = null;
+ }
+ } finally {
+ if (intr) {
+ Thread.currentThread().interrupt();
+ }
}
- // todo
}
// Endpoint implementation
@@ -90,13 +120,24 @@
public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) throws RemotingException {
final RemoteClientEndpointLocalImpl<I, O> clientEndpoint = new RemoteClientEndpointLocalImpl<I, O>(executor, requestListener);
+ clientEndpoint.addCloseHandler(remover);
clientEndpoint.open();
return clientEndpoint;
}
public <I, O> RemoteServiceEndpoint<I, O> createService(final RequestListener<I, O> requestListener) throws RemotingException {
final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint = new RemoteServiceEndpointLocalImpl<I, O>(executor, requestListener);
+ serviceEndpoint.addCloseHandler(remover);
serviceEndpoint.open();
return serviceEndpoint;
}
+
+ private final ResourceRemover remover = new ResourceRemover();
+
+ private final class ResourceRemover implements CloseHandler<Closeable> {
+ public void handleClose(final Closeable closed) {
+ resources.remove(closed);
+ resources.notifyAll();
+ }
+ }
}
Modified: remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
===================================================================
--- remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-04 02:21:32 UTC (rev 4364)
+++ remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-04 02:50:34 UTC (rev 4365)
@@ -61,6 +61,7 @@
endpoint.start();
endpoint.stop();
executorService.shutdown();
+ assertTrue(executorService.awaitTermination(1L, TimeUnit.SECONDS));
} finally {
executorService.shutdownNow();
}
@@ -117,7 +118,7 @@
safeStop(endpoint);
}
executorService.shutdown();
- executorService.awaitTermination(1L, TimeUnit.SECONDS);
+ assertTrue(executorService.awaitTermination(1L, TimeUnit.SECONDS));
assertTrue(clientEndpointClosed.get());
assertTrue(clientClosed.get());
} finally {
@@ -176,7 +177,7 @@
safeStop(endpoint);
}
executorService.shutdown();
- executorService.awaitTermination(1L, TimeUnit.SECONDS);
+ assertTrue(executorService.awaitTermination(1L, TimeUnit.SECONDS));
assertTrue(clientEndpointClosed.get());
assertTrue(clientClosed.get());
} finally {
16 years, 6 months
JBoss Remoting SVN: r4364 - remoting3/trunk.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 22:21:32 -0400 (Thu, 03 Jul 2008)
New Revision: 4364
Modified:
remoting3/trunk/build.properties
Log:
Fix license name
Modified: remoting3/trunk/build.properties
===================================================================
--- remoting3/trunk/build.properties 2008-07-04 01:57:58 UTC (rev 4363)
+++ remoting3/trunk/build.properties 2008-07-04 02:21:32 UTC (rev 4364)
@@ -135,7 +135,7 @@
lib.junit.version=3.8.1
lib.junit.name=junit.jar
-lib.junit.license=cpl
+lib.junit.license=cpl-1.0
lib.junit.dir=junit/${lib.junit.version}/lib
lib.junit.path=${lib.junit.dir}/${lib.junit.name}
lib.junit.local=${local.repository}/${lib.junit.path}
16 years, 6 months