JBoss Remoting SVN: r4343 - 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 00:48:51 -0400 (Thu, 03 Jul 2008)
New Revision: 4343
Added:
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
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.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/RemoteClientEndpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.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/ClientWrapper.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/ClientContextImpl.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/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceContextImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/QueueExecutor.java
Log:
Working endpoint implementation again
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java 2008-07-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -61,12 +61,4 @@
* @return the attribute map
*/
ConcurrentMap<Object, Object> getAttributes();
-
- /**
- * Get the classloader associated with this client. This is the classloader that will be used to resolve any
- * remote classes.
- *
- * @return the classloader
- */
- ClassLoader getClassLoader();
}
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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -38,7 +38,7 @@
* @param requestListener the request listener
* @return the client
*/
- <I, O> RemoteClientEndpoint<I, O> createClient(RequestListener<I, O> requestListener);
+ <I, O> RemoteClientEndpoint<I, O> createClient(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.
@@ -52,7 +52,7 @@
* @param requestListener the request listener
* @return the context source
*/
- <I, O> RemoteServiceEndpoint<I, O> createService(RequestListener<I, O> requestListener);
+ <I, O> RemoteServiceEndpoint<I, O> createService(RequestListener<I, O> requestListener) throws RemotingException;
/**
* Add a listener that is notified when a session is created.
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java 2008-07-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -31,7 +31,7 @@
/**
* Asynchronously send a request to cancel this request. Does not block the current method. Use the
- * {@link #addCompletionNotifier(RequestCompletionHandler)} method to add a notifier to be called upon completion.
+ * {@link #addCompletionHandler(RequestCompletionHandler)} method to add a notifier to be called upon completion.
*
* @param mayInterruptIfRunning
*/
@@ -117,5 +117,5 @@
*
* @return this future reply
*/
- FutureReply<T> addCompletionNotifier(RequestCompletionHandler<T> handler);
+ FutureReply<T> addCompletionHandler(RequestCompletionHandler<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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -25,6 +25,9 @@
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
import org.jboss.cx.remoting.RequestCancelHandler;
import org.jboss.cx.remoting.RequestContext;
+import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.RequestCompletionHandler;
+import org.jboss.cx.remoting.FutureReply;
import org.jboss.xnio.log.Logger;
/**
@@ -42,7 +45,7 @@
* @param msg the message
* @param cause the cause
*/
- public static void safeHandleException(ReplyHandler<?> replyHandler, String msg, Throwable cause) {
+ public static void safeHandleException(final ReplyHandler<?> replyHandler, final String msg, final Throwable cause) {
try {
replyHandler.handleException(msg, cause);
} catch (Throwable t) {
@@ -57,7 +60,7 @@
* @param replyHandler the reply handler
* @param reply the reply
*/
- public static <O> void safeHandleReply(ReplyHandler<O> replyHandler, O reply) {
+ public static <O> void safeHandleReply(final ReplyHandler<O> replyHandler, final O reply) {
try {
replyHandler.handleReply(reply);
} catch (Throwable t) {
@@ -70,7 +73,7 @@
*
* @param replyHandler the reply handler
*/
- public static void safeHandleCancellation(ReplyHandler<?> replyHandler) {
+ public static void safeHandleCancellation(final ReplyHandler<?> replyHandler) {
try {
replyHandler.handleCancellation();
} catch (Throwable t) {
@@ -81,11 +84,12 @@
/**
* Safely notify a request listener's cancel handler of cancellation.
*
+ * @param <O> the reply
* @param handler the request cancel handler
* @param requestContext the request context
* @param mayInterrupt {@code true} if the request listener threads may be interrupted
*/
- public static <O> void safeNotifyCancellation(RequestCancelHandler<O> handler, RequestContext<O> requestContext, boolean mayInterrupt) {
+ public static <O> void safeNotifyCancellation(final RequestCancelHandler<O> handler, final RequestContext<O> requestContext, boolean mayInterrupt) {
try {
handler.notifyCancel(requestContext, mayInterrupt);
} catch (Throwable t) {
@@ -93,6 +97,34 @@
}
}
+ /**
+ * Safely handle a close notification.
+ *
+ * @param <T> the type of the closable resource
+ * @param handler the close handler
+ * @param closed the object that was closed
+ */
+ public static <T> void safeHandleClose(final CloseHandler<T> handler, final T closed) {
+ try {
+ handler.handleClose(closed);
+ } catch (Throwable t) {
+ log.error(t, "Close handler failed unexpectedly");
+ }
+ }
+ /**
+ * Safely handle a future request completion.
+ *
+ * @param <O> the reply type
+ * @param handler
+ * @param futureReply
+ */
+ public static <O> void safeHandleRequestCompletion(final RequestCompletionHandler<O> handler, final FutureReply<O> futureReply) {
+ try {
+ handler.notifyComplete(futureReply);
+ } catch (Throwable t) {
+ log.error(t, "Request completion handler failed unexpectedly");
+ }
+ }
}
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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -34,6 +34,14 @@
public interface RemoteClientEndpoint<I, O> extends Closeable<RemoteClientEndpoint<I, O>> {
/**
+ * Receive a one-way request from a remote system. This method is intended to be called by protocol handlers. No
+ * reply will be sent back to the client.
+ *
+ * @param request the request
+ */
+ void receiveRequest(I request);
+
+ /**
* Receive a request from a remote system. This method is intended to be called by protocol handlers. If the
* request cannot be accepted for some reason, the
* {@link ReplyHandler#handleException(String, Throwable)}
@@ -67,7 +75,7 @@
/**
* Automatically close this client endpoint when all handles and local client instances are closed.
*/
- void autoClose();
+ void autoClose() throws RemotingException;
/**
* Close this client endpoint. The outcome of any outstanding requests is not defined, though implementations
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java 2008-07-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -30,6 +30,8 @@
/**
* Signal that the request should be cancelled, if possible.
+ *
+ * @param mayInterrupt {@code true} if the task can be interrupted (advisory)
*/
- void cancel();
+ void cancel(final boolean mayInterrupt);
}
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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -63,7 +63,7 @@
* Automatically close this service endpoint when all handles and local client source instances
* are closed.
*/
- void autoClose();
+ void autoClose() throws RemotingException;
/**
* Close this service endpoint immediately.
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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -70,11 +70,4 @@
public ConcurrentMap<Object, Object> getAttributes() {
return delegate.getAttributes();
}
-
- /**
- * {@inheritDoc} This implementation calls the same method on the delegate object.
- */
- public ClassLoader getClassLoader() {
- return delegate.getClassLoader();
- }
}
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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -45,14 +45,14 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) {
+ public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) throws RemotingException {
return delegate.createClient(requestListener);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> RemoteServiceEndpoint<I,O> createService(final RequestListener<I, O> requestListener) {
+ public <I, O> RemoteServiceEndpoint<I, O> createService(final RequestListener<I, O> requestListener) throws RemotingException {
return delegate.createService(requestListener);
}
Added: 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 (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -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.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 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;
+ }
+ }
+}
Added: 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 (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -0,0 +1,82 @@
+/*
+ * 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 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> {
+
+ protected final Executor executor;
+ private final Object closeLock = new Object();
+ private final AtomicBoolean closed = new AtomicBoolean();
+ private Set<CloseHandler<T>> closeHandlers;
+
+ protected AbstractCloseable(final Executor executor) {
+ 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<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<T> handler) {
+ synchronized (closeLock) {
+ if (closeHandlers == null) {
+ closeHandlers = new HashSet<CloseHandler<T>>();
+ }
+ closeHandlers.add(handler);
+ }
+ }
+
+ protected Executor getExecutor() {
+ return executor;
+ }
+}
Added: 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 (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -0,0 +1,43 @@
+/*
+ * 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.ConcurrentMap;
+import java.util.concurrent.Executor;
+import org.jboss.cx.remoting.util.CollectionUtil;
+
+/**
+ *
+ */
+public abstract class AbstractContextImpl<T> extends AbstractCloseable<T> {
+
+ private final ConcurrentMap<Object, Object> attributes = CollectionUtil.concurrentMap();
+
+ protected AbstractContextImpl(final Executor executor) {
+ super(executor);
+ }
+
+ public ConcurrentMap<Object, Object> getAttributes() {
+ return attributes;
+ }
+}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientContextImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientContextImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -26,31 +26,32 @@
import org.jboss.cx.remoting.ServiceContext;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.spi.SpiUtils;
+import org.jboss.cx.remoting.util.CollectionUtil;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.Set;
+import java.util.HashSet;
/**
*
*/
-public final class ClientContextImpl implements ClientContext {
+public final class ClientContextImpl extends AbstractContextImpl<ClientContext> implements ClientContext {
- private Executor executor;
+ private final ServiceContextImpl serviceContext;
- public ConcurrentMap<Object, Object> getAttributes() {
- return null;
+ ClientContextImpl(final Executor executor) {
+ super(executor);
+ serviceContext = null;
}
- public ServiceContext getServiceContext() {
- return null;
+ ClientContextImpl(final ServiceContextImpl serviceContext) {
+ super(serviceContext.getExecutor());
+ this.serviceContext = serviceContext;
}
- public void close() throws RemotingException {
+ public ServiceContext getServiceContext() {
+ return serviceContext;
}
-
- public void addCloseHandler(final CloseHandler<ClientContext> clientContextCloseHandler) {
- }
-
- public Executor getExecutor() {
- return executor;
- }
}
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -0,0 +1,83 @@
+/*
+ * 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.Client;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.RemoteExecutionException;
+import org.jboss.cx.remoting.FutureReply;
+import org.jboss.cx.remoting.RequestCompletionHandler;
+import org.jboss.cx.remoting.core.util.QueueExecutor;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.remote.ReplyHandler;
+import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
+import java.util.concurrent.Executor;
+
+/**
+ *
+ */
+public final class ClientImpl<I, O> extends AbstractContextImpl<Client<I, O>> implements Client<I, O> {
+
+ private final RemoteClientEndpoint<I, O> remoteClientEndpoint;
+
+ ClientImpl(final RemoteClientEndpoint<I, O> remoteClientEndpoint, final Executor executor) {
+ super(executor);
+ this.remoteClientEndpoint = remoteClientEndpoint;
+ }
+
+ public O invoke(final I request) throws RemotingException, RemoteExecutionException {
+ if (! isOpen()) {
+ throw new RemotingException("Client is not open");
+ }
+ final QueueExecutor executor = new QueueExecutor();
+ final FutureReplyImpl<O> futureReply = new FutureReplyImpl<O>(executor);
+ final ReplyHandler<O> replyHandler = futureReply.getReplyHandler();
+ final RemoteRequestContext requestContext = remoteClientEndpoint.receiveRequest(request, replyHandler);
+ futureReply.setRemoteRequestContext(requestContext);
+ futureReply.addCompletionHandler(new RequestCompletionHandler<O>() {
+ public void notifyComplete(final FutureReply<O> reply) {
+ executor.shutdown();
+ }
+ });
+ executor.runQueue();
+ return futureReply.get();
+ }
+
+ public FutureReply<O> send(final I request) throws RemotingException {
+ if (! isOpen()) {
+ throw new RemotingException("Client is not open");
+ }
+ final FutureReplyImpl<O> futureReply = new FutureReplyImpl<O>(executor);
+ final ReplyHandler<O> replyHandler = futureReply.getReplyHandler();
+ final RemoteRequestContext requestContext = remoteClientEndpoint.receiveRequest(request, replyHandler);
+ futureReply.setRemoteRequestContext(requestContext);
+ return futureReply;
+ }
+
+ public void sendOneWay(final I request) throws RemotingException {
+ if (! isOpen()) {
+ throw new RemotingException("Client is not open");
+ }
+ remoteClientEndpoint.receiveRequest(request);
+ }
+}
Added: 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 (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -0,0 +1,52 @@
+/*
+ * 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.ClientSource;
+import org.jboss.cx.remoting.Client;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import java.util.concurrent.Executor;
+
+/**
+ *
+ */
+public final class ClientSourceImpl<I, O> extends AbstractCloseable<ClientSource<I, O>> implements ClientSource<I, O> {
+
+ private final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint;
+
+ ClientSourceImpl(final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint, final Executor executor) {
+ super(executor);
+ this.serviceEndpoint = serviceEndpoint;
+ }
+
+ public Client<I, O> createContext() 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();
+ 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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -9,6 +9,7 @@
import org.jboss.cx.remoting.Endpoint;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.SessionListener;
+import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.core.util.OrderedExecutorFactory;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
@@ -112,12 +113,16 @@
return endpointMap;
}
- public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) {
- return new RemoteClientEndpointLocalImpl<I, O>(this, requestListener);
+ 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.open();
+ return clientEndpoint;
}
- public <I, O> RemoteServiceEndpoint<I, O> createService(final RequestListener<I, O> requestListener) {
- return new RemoteServiceEndpointLocalImpl<I, O>(this, requestListener);
+ 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.open();
+ return serviceEndpoint;
}
public void addSessionListener(final SessionListener sessionListener) {
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -0,0 +1,360 @@
+/*
+ * 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.FutureReply;
+import org.jboss.cx.remoting.RemoteExecutionException;
+import org.jboss.cx.remoting.RequestCompletionHandler;
+import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.cx.remoting.spi.remote.ReplyHandler;
+import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
+import org.jboss.cx.remoting.spi.SpiUtils;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.Executor;
+import java.util.List;
+
+/**
+ *
+ */
+public final class FutureReplyImpl<O> implements FutureReply<O> {
+
+ private final Executor executor;
+ private final ReplyHandler<O> replyHandler = new Handler();
+ private final Object lock = new Object();
+ // @protectedby lock
+ private State state = State.WAITING;
+ // @protectedby lock
+ private RemoteRequestContext remoteRequestContext;
+ // @protectedby lock
+ private O result;
+ // @protectedby lock
+ private Throwable cause;
+ // @protectedby lock
+ private String msg;
+ // @protectedby lock
+ private List<RequestCompletionHandler<O>> completionHandlers;
+
+ public FutureReplyImpl(final Executor executor) {
+ this.executor = executor;
+ }
+
+ private enum State {
+ NEW,
+ WAITING,
+ DONE,
+ CANCELLED,
+ FAILED,
+ }
+
+ void setRemoteRequestContext(final RemoteRequestContext remoteRequestContext) {
+ synchronized (lock) {
+ if (state != State.NEW) {
+ throw new IllegalStateException("Wrong state");
+ }
+ state = State.WAITING;
+ this.remoteRequestContext = remoteRequestContext;
+ }
+ }
+
+ public boolean cancel(final boolean mayInterruptIfRunning) {
+ final RemoteRequestContext context;
+ synchronized (lock) {
+ while (state == State.NEW) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ return false;
+ }
+ }
+ context = remoteRequestContext;
+ }
+ context.cancel(mayInterruptIfRunning);
+ synchronized (lock) {
+ while (state == State.WAITING) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ return false;
+ }
+ }
+ return state == State.CANCELLED;
+ }
+ }
+
+ public FutureReply<O> sendCancel(final boolean mayInterruptIfRunning) {
+ final RemoteRequestContext context;
+ synchronized (lock) {
+ while (state == State.NEW) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ return this;
+ }
+ }
+ context = remoteRequestContext;
+ }
+ context.cancel(mayInterruptIfRunning);
+ return this;
+ }
+
+ public boolean isCancelled() {
+ synchronized (lock) {
+ return state == State.CANCELLED;
+ }
+ }
+
+ public boolean isDone() {
+ synchronized (lock) {
+ return state == State.DONE;
+ }
+ }
+
+ public O get() throws CancellationException, RemoteExecutionException {
+ boolean intr = false;
+ try {
+ synchronized (lock) {
+ while (state == State.WAITING || state == State.NEW) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ }
+ switch (state) {
+ case CANCELLED:
+ throw new CancellationException("Request was cancelled");
+ case DONE:
+ return result;
+ case FAILED:
+ throw new RemoteExecutionException(msg, cause);
+ default:
+ throw new IllegalStateException("Wrong state");
+ }
+ }
+ } finally {
+ if (intr) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+
+ public O getInterruptibly() throws InterruptedException, CancellationException, RemoteExecutionException {
+ synchronized (lock) {
+ while (state == State.WAITING || state == State.NEW) {
+ lock.wait();
+ }
+ switch (state) {
+ case CANCELLED:
+ throw new CancellationException("Request was cancelled");
+ case DONE:
+ return result;
+ case FAILED:
+ throw new RemoteExecutionException(msg, cause);
+ default:
+ throw new IllegalStateException("Wrong state");
+ }
+ }
+ }
+
+ public O get(final long timeout, final TimeUnit unit) throws CancellationException, RemoteExecutionException {
+ if (unit == null) {
+ throw new NullPointerException("unit is null");
+ }
+ if (timeout < 0L) {
+ throw new IllegalArgumentException("timeout is negative");
+ }
+ boolean intr = false;
+ try {
+ synchronized (lock) {
+ long now = System.currentTimeMillis();
+ final long deadline = now + unit.toMillis(timeout);
+ if (deadline < 0L) {
+ return get();
+ }
+ while (state == State.WAITING || state == State.NEW) {
+ try {
+ lock.wait(deadline - now);
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ now = System.currentTimeMillis();
+ }
+ switch (state) {
+ case CANCELLED:
+ throw new CancellationException("Request was cancelled");
+ case DONE:
+ return result;
+ case FAILED:
+ throw new RemoteExecutionException(msg, cause);
+ default:
+ throw new IllegalStateException("Wrong state");
+ }
+ }
+ } finally {
+ if (intr) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+
+ public O getInterruptibly(final long timeout, final TimeUnit unit) throws InterruptedException, CancellationException, RemoteExecutionException {
+ if (unit == null) {
+ throw new NullPointerException("unit is null");
+ }
+ if (timeout < 0L) {
+ throw new IllegalArgumentException("timeout is negative");
+ }
+ synchronized (lock) {
+ while (state == State.WAITING || state == State.NEW) {
+ unit.timedWait(lock, timeout);
+ }
+ switch (state) {
+ case CANCELLED:
+ throw new CancellationException("Request was cancelled");
+ case DONE:
+ return result;
+ case FAILED:
+ throw new RemoteExecutionException(msg, cause);
+ case WAITING:
+ case NEW:
+ return null;
+ default:
+ throw new IllegalStateException("Wrong state");
+ }
+ }
+ }
+
+ public FutureReply<O> addCompletionHandler(final RequestCompletionHandler<O> handler) {
+ synchronized (lock) {
+ switch (state) {
+ case NEW:
+ case WAITING:
+ if (completionHandlers == null) {
+ completionHandlers = CollectionUtil.arrayList();
+ }
+ completionHandlers.add(handler);
+ break;
+ default:
+ SpiUtils.safeHandleRequestCompletion(handler, this);
+ break;
+ }
+ }
+ return this;
+ }
+
+ ReplyHandler<O> getReplyHandler() {
+ return replyHandler;
+ }
+
+ private void runCompletionHandlers() {
+ synchronized (lock) {
+ final List<RequestCompletionHandler<O>> handlers = completionHandlers;
+ if (handlers != null) {
+ completionHandlers = null;
+ executor.execute(new Runnable() {
+ public void run() {
+ for (RequestCompletionHandler<O> handler : handlers) {
+ SpiUtils.safeHandleRequestCompletion(handler, FutureReplyImpl.this);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ private final class Handler implements ReplyHandler<O> {
+
+ public void handleReply(final O reply) {
+ synchronized (lock) {
+ while (state == State.NEW) {
+ boolean intr = false;
+ try {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ } finally {
+ if (intr) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ if (state == State.WAITING) {
+ state = State.DONE;
+ result = reply;
+ runCompletionHandlers();
+ }
+ }
+ }
+
+ public void handleException(final String exMsg, final Throwable exCause) {
+ synchronized (lock) {
+ while (state == State.NEW) {
+ boolean intr = false;
+ try {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ } finally {
+ if (intr) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ if (state == State.WAITING) {
+ state = State.FAILED;
+ msg = exMsg;
+ cause = exCause;
+ runCompletionHandlers();
+ }
+ }
+ }
+
+ public void handleCancellation() {
+ synchronized (lock) {
+ while (state == State.NEW) {
+ boolean intr = false;
+ try {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ } finally {
+ if (intr) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ if (state == State.WAITING) {
+ state = State.CANCELLED;
+ runCompletionHandlers();
+ }
+ }
+ }
+ }
+}
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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -25,40 +25,54 @@
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
-import org.jboss.cx.remoting.spi.remote.Handle;
import org.jboss.cx.remoting.spi.SpiUtils;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.RemoteExecutionException;
+import org.jboss.cx.remoting.CloseHandler;
import org.jboss.xnio.log.Logger;
import java.util.concurrent.Executor;
/**
*
*/
-public final class RemoteClientEndpointLocalImpl<I, O> implements RemoteClientEndpoint<I, O> {
+public final class RemoteClientEndpointLocalImpl<I, O> extends AbstractAutoCloseable<RemoteClientEndpoint<I, O>> implements RemoteClientEndpoint<I, O> {
- private final EndpointImpl endpointImpl;
private final RequestListener<I, O> requestListener;
private final Executor executor;
- private final ClientContextImpl clientContext = new ClientContextImpl();
+ private final ClientContextImpl clientContext;
private static final Logger log = Logger.getLogger(RemoteClientEndpointLocalImpl.class);
- public RemoteClientEndpointLocalImpl(final EndpointImpl endpointImpl, final RequestListener<I, O> requestListener) {
- this.endpointImpl = endpointImpl;
+ private RemoteClientEndpointLocalImpl(final Executor executor, final RequestListener<I, O> requestListener, final ClientContextImpl clientContext) {
+ super(executor);
+ this.executor = executor;
this.requestListener = requestListener;
- executor = endpointImpl.getExecutor();
+ this.clientContext = clientContext;
}
- public RemoteClientEndpointLocalImpl(final EndpointImpl endpointImpl, final RemoteServiceEndpointLocalImpl<I, O> service, final RequestListener<I, O> requestListener) {
- this.endpointImpl = endpointImpl;
- this.requestListener = requestListener;
- executor = endpointImpl.getExecutor();
+ RemoteClientEndpointLocalImpl(final Executor executor, final RemoteServiceEndpointLocalImpl<I, O> service, final RequestListener<I, O> requestListener) {
+ this(executor, requestListener, new ClientContextImpl(service.getServiceContext()));
}
+ RemoteClientEndpointLocalImpl(final Executor executor, final RequestListener<I, O> requestListener) {
+ this(executor, requestListener, new ClientContextImpl(executor));
+ }
+
+ public void receiveRequest(final I request) {
+ final RequestContextImpl<O> context = new RequestContextImpl<O>(clientContext);
+ executor.execute(new Runnable() {
+ public void run() {
+ try {
+ requestListener.handleRequest(context, request);
+ } catch (Throwable t) {
+ log.error(t, "Unexpected exception in request listener");
+ }
+ }
+ });
+ }
+
public RemoteRequestContext receiveRequest(final I request, final ReplyHandler<O> replyHandler) {
final RequestContextImpl<O> context = new RequestContextImpl<O>(replyHandler, clientContext);
executor.execute(new Runnable() {
@@ -73,26 +87,45 @@
}
});
return new RemoteRequestContext() {
- public void cancel() {
- context.cancel();
+ public void cancel(final boolean mayInterrupt) {
+ context.cancel(mayInterrupt);
}
};
}
- public Handle<RemoteClientEndpoint<I, O>> getHandle() throws RemotingException {
- return null;
- }
-
public Client<I, O> getClient() throws RemotingException {
- return null;
+ 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();
+ }
+ }
}
- public void autoClose() {
+ void open() throws RemotingException {
+ try {
+ requestListener.handleClientOpen(clientContext);
+ addCloseHandler(new CloseHandler<RemoteClientEndpoint<I, O>>() {
+ public void handleClose(final RemoteClientEndpoint<I, O> closed) {
+ try {
+ requestListener.handleClientClose(clientContext);
+ } catch (Throwable t) {
+ log.error(t, "Unexpected exception in request listener client close handler method");
+ }
+ }
+ });
+ } catch (Throwable t) {
+ throw new RemotingException("Failed to open client context", t);
+ }
}
-
- public void close() throws RemotingException {
- }
-
- public void addCloseHandler(final CloseHandler<RemoteClientEndpoint<I, O>> handler) {
- }
}
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-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -24,43 +24,78 @@
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
-import org.jboss.cx.remoting.spi.remote.Handle;
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;
/**
*
*/
-public final class RemoteServiceEndpointLocalImpl<I, O> implements RemoteServiceEndpoint<I, O> {
+public final class RemoteServiceEndpointLocalImpl<I, O> extends AbstractAutoCloseable<RemoteServiceEndpoint<I, O>> implements RemoteServiceEndpoint<I, O> {
- private final EndpointImpl endpointImpl;
private final RequestListener<I, O> requestListener;
+ private final ServiceContextImpl serviceContext;
+ private final Executor executor;
- public RemoteServiceEndpointLocalImpl(final EndpointImpl endpointImpl, final RequestListener<I, O> requestListener) {
- this.endpointImpl = endpointImpl;
+ private static final Logger log = Logger.getLogger(RemoteServiceEndpointLocalImpl.class);
+
+ RemoteServiceEndpointLocalImpl(final Executor executor, final RequestListener<I, O> requestListener) {
+ super(executor);
this.requestListener = requestListener;
+ this.executor = executor;
+ serviceContext = new ServiceContextImpl(executor);
}
public RemoteClientEndpoint<I, O> openClient() throws RemotingException {
- return new RemoteClientEndpointLocalImpl<I, O>(endpointImpl, this, requestListener);
+ if (isOpen()) {
+ final RemoteClientEndpointLocalImpl<I, O> clientEndpoint = new RemoteClientEndpointLocalImpl<I, O>(executor, this, requestListener);
+ clientEndpoint.open();
+ return clientEndpoint;
+ } else {
+ throw new RemotingException("RemotingServiceEndpoint is closed");
+ }
}
- public Handle<RemoteServiceEndpoint<I, O>> getHandle() throws RemotingException {
- return null;
- }
-
public ClientSource<I, O> getClientSource() throws RemotingException {
- return null;
+ 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();
+ }
+ }
}
- public void autoClose() {
+ void open() throws RemotingException {
+ try {
+ requestListener.handleServiceOpen(serviceContext);
+ addCloseHandler(new CloseHandler<RemoteServiceEndpoint<I, O>>() {
+ public void handleClose(final RemoteServiceEndpoint<I, O> closed) {
+ try {
+ requestListener.handleServiceClose(serviceContext);
+ } catch (Throwable t) {
+ log.error(t, "Unexpected exception in request listener client close handler method");
+ }
+ }
+ });
+ } catch (Throwable t) {
+ throw new RemotingException("Failed to open client context", t);
+ }
}
- public void close() throws RemotingException {
+ ServiceContextImpl getServiceContext() {
+ return serviceContext;
}
-
- public void addCloseHandler(final CloseHandler<RemoteServiceEndpoint<I, O>> handler) {
- }
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -54,6 +54,12 @@
executor = new TaggingExecutor(clientContext.getExecutor());
}
+ RequestContextImpl(final ClientContextImpl clientContext) {
+ this.clientContext = clientContext;
+ executor = new TaggingExecutor(clientContext.getExecutor());
+ replyHandler = null;
+ }
+
public ClientContext getContext() {
return clientContext;
}
@@ -64,7 +70,9 @@
public void sendReply(final O reply) throws RemotingException, IllegalStateException {
if (! closed.getAndSet(true)) {
- replyHandler.handleReply(reply);
+ if (replyHandler != null) {
+ replyHandler.handleReply(reply);
+ }
} else {
throw new IllegalStateException("Reply already sent");
}
@@ -72,7 +80,9 @@
public void sendFailure(final String msg, final Throwable cause) throws RemotingException, IllegalStateException {
if (! closed.getAndSet(true)) {
- replyHandler.handleException(msg, cause);
+ if (replyHandler != null) {
+ replyHandler.handleException(msg, cause);
+ }
} else {
throw new IllegalStateException("Reply already sent");
}
@@ -80,7 +90,9 @@
public void sendCancelled() throws RemotingException, IllegalStateException {
if (! closed.getAndSet(true)) {
- replyHandler.handleCancellation();
+ if (replyHandler != null) {
+ replyHandler.handleCancellation();
+ }
} else {
throw new IllegalStateException("Reply already sent");
}
@@ -103,17 +115,23 @@
executor.execute(command);
}
- protected void cancel() {
+ protected void cancel(final boolean mayInterrupt) {
if (! cancelled.getAndSet(true)) {
synchronized (cancelLock) {
if (cancelHandlers != null) {
- for (RequestCancelHandler<O> handler : cancelHandlers) {
- SpiUtils.safeNotifyCancellation(handler, this, false);
+ for (final RequestCancelHandler<O> handler : cancelHandlers) {
+ executor.execute(new Runnable() {
+ public void run() {
+ SpiUtils.safeNotifyCancellation(handler, RequestContextImpl.this, mayInterrupt);
+ }
+ });
}
cancelHandlers = null;
}
}
- executor.interruptAll();
+ if (mayInterrupt) {
+ executor.interruptAll();
+ }
}
}
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceContextImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceContextImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -25,20 +25,15 @@
import org.jboss.cx.remoting.ServiceContext;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.ClientContext;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.Executor;
/**
*
*/
-public final class ServiceContextImpl implements ServiceContext {
-
- public ConcurrentMap<Object, Object> getAttributes() {
- return null;
+public final class ServiceContextImpl extends AbstractContextImpl<ServiceContext> implements ServiceContext {
+ protected ServiceContextImpl(final Executor executor) {
+ super(executor);
}
-
- public void close() throws RemotingException {
- }
-
- public void addCloseHandler(final CloseHandler<ServiceContext> serviceContextCloseHandler) {
- }
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/QueueExecutor.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/QueueExecutor.java 2008-07-03 00:44:19 UTC (rev 4342)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/QueueExecutor.java 2008-07-03 04:48:51 UTC (rev 4343)
@@ -32,6 +32,7 @@
state = State.RUNNING;
queue.notify();
// fall thru
+ case STOPPING:
case RUNNING:
queue.add(command);
break;
@@ -51,7 +52,7 @@
try {
queue.wait();
} catch (InterruptedException e) {
- e.printStackTrace();
+ intr = true;
}
}
if (state == State.DOWN) {
16 years, 4 months
JBoss Remoting SVN: r4342 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting and 11 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-02 20:44:19 -0400 (Wed, 02 Jul 2008)
New Revision: 4342
Added:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientContextImpl.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/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceContextImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/TaggingExecutor.java
Removed:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealClient.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealClientSource.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientInitiator.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientMarker.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientResponder.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceMarker.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundClient.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundClient.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreStream.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientInitiator.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientResponder.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestInitiator.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestResponder.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceInitiator.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceResponder.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/StreamMarker.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationObjectMessageInput.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationObjectMessageOutput.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/IteratorStreamSerializerFactory.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSinkStreamSerializerFactory.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestListener.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/ReplyHandler.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java
remoting3/trunk/build.xml
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
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/StreamResolver.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/service/ClassLoaderResourceListener.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/service/ServiceLocatorListener.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/DefaultStreamDetector.java
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/util/DecodingBuilder.java
remoting3/trunk/mc-deployers/src/main/java/org/jboss/cx/remoting/beans/SessionBean.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StreamingRot13RequestListener.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StringRot13RequestListener.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
Get r3 building again (amazingly)
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-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -21,24 +21,6 @@
ConcurrentMap<Object, Object> getAttributes();
/**
- * Open an outbound session to another endpoint. The protocol used is determined by the URI scheme. The URI user-info part
- * must be {@code null} unless the specific protocol has an additional authentication scheme (e.g. HTTP BASIC). The
- * authority is used to locate the server (the exact interpretation is dependent upon the protocol). The path may be
- * relative to a protocol-specific deployment path.
- *
- * You must have the TODO permission to invoke this method.
- *
- * @param remoteUri the URI of the server to connect to
- * @param attributeMap the attribute map to use to configure this session
- * @param rootListener the root request listener for this end of the session
- * @return a new session
- *
- * @throws RemotingException if there is a problem creating the session, or if the request or reply type does not
- * match the remote service
- */
- Session openSession(URI remoteUri, AttributeMap attributeMap, RequestListener<?, ?> rootListener) throws RemotingException;
-
- /**
* Get the name of this endpoint.
*
* @return the endpoint name, or {@code null} if there is no name
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestListener.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestListener.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestListener.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -23,8 +23,7 @@
/**
* Handle a request. If this method throws {@code RemoteExecutionException}, then that exception is passed
- * back to the caller and the request is marked as complete. If this method throws {@code InterruptedException},
- * the request is cancelled, and the interrupted status is propagated to the executor.. Otherwise, the request
+ * back to the caller and the request is marked as complete. Otherwise, the request
* listener must send back either a reply (using the {@code sendReply()} method on the {@code RequestContext}) or
* an exception (using the {@code sendException()} method on the {@code RequestContext}). Failure to do so may
* cause the client to hang indefinitely.
@@ -33,9 +32,8 @@
* @param request the received request
*
* @throws RemoteExecutionException if the execution failed in some way
- * @throws InterruptedException if the thread is interrupted
*/
- void handleRequest(RequestContext<O> context, I request) throws RemoteExecutionException, InterruptedException;
+ void handleRequest(RequestContext<O> context, I request) throws RemoteExecutionException;
/**
* Handle the close of a service.
Added: 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 (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -0,0 +1,98 @@
+/*
+ * 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.spi.remote.ReplyHandler;
+import org.jboss.cx.remoting.RequestCancelHandler;
+import org.jboss.cx.remoting.RequestContext;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * Utility methods for Remoting service providers.
+ */
+public final class SpiUtils {
+ private SpiUtils() {}
+
+ private static final Logger log = Logger.getLogger(SpiUtils.class);
+
+ /**
+ * Safely notify a reply handler of an exception.
+ *
+ * @param replyHandler the reply handler
+ * @param msg the message
+ * @param cause the cause
+ */
+ public static void safeHandleException(ReplyHandler<?> replyHandler, String msg, Throwable cause) {
+ try {
+ replyHandler.handleException(msg, cause);
+ } catch (Throwable t) {
+ log.error(t, "Failed to properly handle exception");
+ }
+ }
+
+ /**
+ * Safely notify a reply handler of a reply.
+ *
+ * @param <O> the reply type
+ * @param replyHandler the reply handler
+ * @param reply the reply
+ */
+ public static <O> void safeHandleReply(ReplyHandler<O> replyHandler, O reply) {
+ try {
+ replyHandler.handleReply(reply);
+ } catch (Throwable t) {
+ log.error(t, "Failed to properly handle reply");
+ }
+ }
+
+ /**
+ * Safely notify a reply handler of a cancellation.
+ *
+ * @param replyHandler the reply handler
+ */
+ public static void safeHandleCancellation(ReplyHandler<?> replyHandler) {
+ try {
+ replyHandler.handleCancellation();
+ } catch (Throwable t) {
+ log.error(t, "Failed to properly handle cancellation");
+ }
+ }
+
+ /**
+ * Safely notify a request listener's cancel handler of cancellation.
+ *
+ * @param handler the request cancel handler
+ * @param requestContext the request context
+ * @param mayInterrupt {@code true} if the request listener threads may be interrupted
+ */
+ public static <O> void safeNotifyCancellation(RequestCancelHandler<O> handler, RequestContext<O> requestContext, boolean mayInterrupt) {
+ try {
+ handler.notifyCancel(requestContext, mayInterrupt);
+ } catch (Throwable t) {
+ log.error(t, "Request cancel handler threw an exception when calling notifyCancel()");
+ }
+ }
+
+
+}
+
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-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -36,7 +36,7 @@
/**
* Receive a request from a remote system. This method is intended to be called by protocol handlers. If the
* request cannot be accepted for some reason, the
- * {@link org.jboss.cx.remoting.spi.remote.ReplyHandler#handleException(Throwable)}
+ * {@link ReplyHandler#handleException(String, Throwable)}
* method is called immediately.
*
* @param request the request
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/ReplyHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/ReplyHandler.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/ReplyHandler.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -38,9 +38,10 @@
/**
* Handle a remote exception.
*
+ * @param msg the message
* @param cause the cause
*/
- void handleException(Throwable cause);
+ void handleException(final String msg, Throwable cause);
/**
* Handle a cancellation request.
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-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -9,6 +9,8 @@
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.Session;
import org.jboss.cx.remoting.SessionListener;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
import org.jboss.cx.remoting.util.AttributeMap;
/**
@@ -36,13 +38,6 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public Session openSession(final URI remoteUri, final AttributeMap attributeMap, final RequestListener<?, ?> rootListener) throws RemotingException {
- return delegate.openSession(remoteUri, attributeMap, rootListener);
- }
-
- /**
- * {@inheritDoc} This implementation calls the same method on the delegate object.
- */
public String getName() {
return delegate.getName();
}
@@ -50,14 +45,14 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> Client<I, O> createClient(final RequestListener<I, O> requestListener) {
+ public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) {
return delegate.createClient(requestListener);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> ClientSource<I, O> createService(final RequestListener<I, O> requestListener) {
+ public <I, O> RemoteServiceEndpoint<I,O> createService(final RequestListener<I, O> requestListener) {
return delegate.createService(requestListener);
}
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/build.xml 2008-07-03 00:44:19 UTC (rev 4342)
@@ -285,6 +285,7 @@
<path refid="util.classpath"/>
<path refid="version.classpath"/>
<pathelement location="${lib.jboss-serialization.local}"/>
+ <pathelement location="${lib.xnio-api.local}"/>
</classpath>
</javac>
<touch file="core/target/main/.lastcompile" verbose="false"/>
@@ -561,6 +562,7 @@
<path refid="srp.classpath"/>
<path refid="standalone.classpath"/>
<path refid="util.classpath"/>
+ <pathelement location="${lib.xnio-api.local}"/>
</classpath>
</javac>
<touch file="samples/target/main/.lastcompile" verbose="false"/>
@@ -636,6 +638,7 @@
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<path refid="util.classpath"/>
+ <pathelement location="${lib.xnio-api.local}"/>
</classpath>
</javac>
<touch file="srp/target/main/.lastcompile" verbose="false"/>
@@ -982,8 +985,10 @@
<doctitle><![CDATA[<h1>JBoss Remoting 3</h1>]]></doctitle>
<bottom><![CDATA[<i>Copyright © 2008 JBoss, a division of Red Hat, Inc.</i>]]></bottom>
<link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
+ <link href="http://docs.jboss.org/xnio/1.0/api/"/>
<classpath>
<path refid="core.classpath"/>
+ <pathelement location="${lib.xnio-api.local}"/>
</classpath>
</javadoc>
</target>
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealClient.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealClient.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealClient.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,31 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import org.jboss.cx.remoting.Client;
-
-/**
- *
- */
-public abstract class AbstractRealClient<I, O> implements Client<I, O> {
-
- private ClientResponder<I,O> clientResponder;
- private ClassLoader classLoader;
-
- protected AbstractRealClient(final ClientResponder<I, O> clientResponder, final ClassLoader classLoader) {
- if (clientResponder == null) {
- throw new NullPointerException("clientResponder is null");
- }
- if (classLoader == null) {
- throw new NullPointerException("classLoader is null");
- }
- this.clientResponder = clientResponder;
- this.classLoader = classLoader;
- }
-
- protected ClientResponder<I, O> getContextServer() {
- return clientResponder;
- }
-
- public ClassLoader getClassLoader() {
- return classLoader;
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealClientSource.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealClientSource.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealClientSource.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,21 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import org.jboss.cx.remoting.ClientSource;
-
-/**
- *
- */
-public abstract class AbstractRealClientSource<I, O> implements ClientSource<I, O> {
- private ServiceResponder<I, O> serviceResponder;
-
- protected AbstractRealClientSource(final ServiceResponder<I, O> serviceResponder) {
- if (serviceResponder == null) {
- throw new NullPointerException("serviceResponder is null");
- }
- this.serviceResponder = serviceResponder;
- }
-
- public ServiceResponder<I, O> getServiceServer() {
- return serviceResponder;
- }
-}
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientContextImpl.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientContextImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -0,0 +1,56 @@
+/*
+ * 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.ClientContext;
+import org.jboss.cx.remoting.ServiceContext;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.CloseHandler;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.Executor;
+
+/**
+ *
+ */
+public final class ClientContextImpl implements ClientContext {
+
+ private Executor executor;
+
+ public ConcurrentMap<Object, Object> getAttributes() {
+ return null;
+ }
+
+ public ServiceContext getServiceContext() {
+ return null;
+ }
+
+ public void close() throws RemotingException {
+ }
+
+ public void addCloseHandler(final CloseHandler<ClientContext> clientContextCloseHandler) {
+ }
+
+ public Executor getExecutor() {
+ return executor;
+ }
+}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientInitiator.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientInitiator.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientInitiator.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,10 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import org.jboss.cx.remoting.RemotingException;
-
-/**
- *
- */
-public interface ClientInitiator {
- void handleClosing(boolean done) throws RemotingException;
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientMarker.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientMarker.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientMarker.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,27 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.io.Serializable;
-
-/**
- *
- */
-public final class ClientMarker implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private ClientIdentifier clientIdentifer;
-
- public ClientMarker() {
- }
-
- public ClientMarker(final ClientIdentifier clientIdentifer) {
- this.clientIdentifer = clientIdentifer;
- }
-
- public ClientIdentifier getClientIdentifer() {
- return clientIdentifer;
- }
-
- public void setContextIdentifer(final ClientIdentifier clientIdentifer) {
- this.clientIdentifer = clientIdentifer;
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientResponder.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientResponder.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientResponder.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,12 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import org.jboss.cx.remoting.RemotingException;
-
-/**
- *
- */
-public interface ClientResponder<I, O> {
- RequestResponder<I> createNewRequest(RequestInitiator<O> requestInitiator) throws RemotingException;
-
- void handleClose(boolean immediate, boolean cancel) throws RemotingException;
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceMarker.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceMarker.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceMarker.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,27 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.io.Serializable;
-
-/**
- *
- */
-public final class ClientSourceMarker implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private ServiceIdentifier serviceIdentifier;
-
- public ClientSourceMarker() {
- }
-
- public ClientSourceMarker(final ServiceIdentifier serviceIdentifier) {
- this.serviceIdentifier = serviceIdentifier;
- }
-
- public ServiceIdentifier getServiceIdentifier() {
- return serviceIdentifier;
- }
-
- public void setServiceIdentifier(final ServiceIdentifier serviceIdentifier) {
- this.serviceIdentifier = serviceIdentifier;
- }
-}
\ No newline at end of file
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,276 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Executor;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.ClientSource;
-import org.jboss.cx.remoting.Endpoint;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.RequestListener;
-import org.jboss.cx.remoting.Session;
-import org.jboss.cx.remoting.SessionListener;
-import org.jboss.cx.remoting.core.util.OrderedExecutorFactory;
-import org.jboss.xnio.log.Logger;
-import org.jboss.cx.remoting.util.AtomicStateMachine;
-import org.jboss.cx.remoting.util.AttributeMap;
-import org.jboss.cx.remoting.util.CollectionUtil;
-import org.jboss.cx.remoting.util.NamingThreadFactory;
-import org.jboss.cx.remoting.version.Version;
-
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-
-/**
- *
- */
-public class CoreEndpoint implements Endpoint {
-
- static {
- // Print Remoting "greeting" message
- Logger.getLogger("org.jboss.cx.remoting").info("JBoss Remoting version %s", Version.VERSION);
- }
-
- private enum State implements org.jboss.cx.remoting.util.State<State> {
- INITIAL,
- UP,
- DOWN;
-
- public boolean isReachable(final State dest) {
- return compareTo(dest) < 0;
- }
- }
-
- private String name;
-
- private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.INITIAL);
- private final Set<SessionListener> sessionListeners = CollectionUtil.synchronizedSet(new LinkedHashSet<SessionListener>());
-
- private OrderedExecutorFactory orderedExecutorFactory;
- private ExecutorService executorService;
-
- private final ConcurrentMap<Object, Object> endpointMap = CollectionUtil.concurrentMap();
- private final ConcurrentMap<String, CoreProtocolRegistration> protocolMap = CollectionUtil.concurrentMap();
- private final Set<CoreSession> sessions = CollectionUtil.synchronizedSet(CollectionUtil.<CoreSession>hashSet());
-
- public CoreEndpoint() {
- }
-
- // Dependencies
-
- private Executor executor;
-
- public Executor getExecutor() {
- return executor;
- }
-
- public Executor getOrderedExecutor() {
- return orderedExecutorFactory.getOrderedExecutor();
- }
-
- public void setExecutor(final Executor executor) {
- this.executor = executor;
- orderedExecutorFactory = new OrderedExecutorFactory(executor);
- }
-
- // Configuration
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- // Lifecycle
-
- public void create() {
- // todo security check
- }
-
- public void start() {
- // todo security check
- if (executor == null) {
- executorService = Executors.newCachedThreadPool(new NamingThreadFactory(Executors.defaultThreadFactory(), "Remoting endpoint %s"));
- setExecutor(executorService);
- }
- state.requireTransition(State.INITIAL, State.UP);
- }
-
- public void stop() {
- // todo security check
- if (executorService != null) {
- executorService.shutdown();
- executorService = null;
- }
- // todo
- }
-
- public void destroy() {
- executor = null;
- }
-
-
- // Endpoint implementation
-
- public ConcurrentMap<Object, Object> getAttributes() {
- return endpointMap;
- }
-
- public Session openSession(final URI uri, final AttributeMap attributeMap, final RequestListener<?, ?> rootListener) throws RemotingException {
- if (uri == null) {
- throw new NullPointerException("uri is null");
- }
- if (attributeMap == null) {
- throw new NullPointerException("attributeMap is null");
- }
- final String scheme = uri.getScheme();
- if (scheme == null) {
- throw new RemotingException("No scheme on remote endpoint URI");
- }
- state.requireHold(State.UP);
- try {
- final CoreProtocolRegistration registration = protocolMap.get(scheme);
- if (registration == null) {
- throw new RemotingException("No handler available for URI scheme \"" + scheme + "\"");
- }
- final ProtocolHandlerFactory factory = registration.getProtocolHandlerFactory();
- try {
- final CoreSession session = new CoreSession(CoreEndpoint.this);
- session.initializeClient(factory, uri, attributeMap, createClient(rootListener));
- sessions.add(session);
- final Session userSession = session.getUserSession();
- for (final SessionListener listener : sessionListeners) {
- executor.execute(new Runnable() {
- public void run() {
- listener.handleSessionOpened(userSession);
- }
- });
- }
- return userSession;
- } catch (IOException e) {
- RemotingException rex = new RemotingException("Failed to create protocol handler: " + e.getMessage());
- rex.setStackTrace(e.getStackTrace());
- throw rex;
- }
- } finally {
- state.release();
- }
- }
-
- public ProtocolContext openSession(final ProtocolHandler handler, final RequestListener<?, ?> rootListener) throws RemotingException {
- state.requireHold(State.UP);
- try {
- final CoreSession session = new CoreSession(CoreEndpoint.this);
- session.initializeServer(handler, rootListener == null ? null : createClient(rootListener));
- sessions.add(session);
- return session.getProtocolContext();
- } finally {
- state.release();
- }
- }
-
- public Registration registerProtocol(final String scheme, final ProtocolHandlerFactory protocolHandlerFactory) throws RemotingException, IllegalArgumentException {
- if (scheme == null) {
- throw new NullPointerException("scheme is null");
- }
- if (protocolHandlerFactory == null) {
- throw new NullPointerException("protocolHandlerFactory is null");
- }
- state.requireHold(State.UP);
- try {
- final CoreProtocolRegistration registration = new CoreProtocolRegistration(protocolHandlerFactory);
- protocolMap.put(scheme, registration);
- return registration;
- } finally {
- state.release();
- }
- }
-
- public <I, O> Client<I, O> createClient(RequestListener<I, O> requestListener) {
- final CoreInboundClient<I, O> inbound = new CoreInboundClient<I, O>(requestListener, executor);
- final CoreOutboundClient<I, O> outbound = new CoreOutboundClient<I, O>(executor);
- inbound.initialize(outbound.getClientInitiator());
- outbound.initialize(inbound.getClientResponder());
- return outbound.getUserContext();
- }
-
- public <I, O> ClientSource<I, O> createService(RequestListener<I, O> requestListener) {
- final CoreInboundService<I, O> inbound = new CoreInboundService<I, O>(requestListener, executor);
- final CoreOutboundService<I, O> outbound = new CoreOutboundService<I, O>(executor);
- inbound.initialize(outbound.getServiceClient());
- outbound.initialize(inbound.getServiceResponder());
- return outbound.getUserContextSource();
- }
-
- public void addSessionListener(final SessionListener sessionListener) {
- // TODO security check
- sessionListeners.add(sessionListener);
- }
-
- public void removeSessionListener(final SessionListener sessionListener) {
- // TODO security check
- sessionListeners.remove(sessionListener);
- }
-
- void removeSession(CoreSession coreSession) {
- synchronized (sessions) {
- if (!sessions.remove(coreSession)) {
- return;
- }
- sessions.notifyAll();
- }
- }
-
- public final class CoreProtocolRegistration implements Registration {
- private final ProtocolHandlerFactory protocolHandlerFactory;
-
- private CoreProtocolRegistration(final ProtocolHandlerFactory protocolHandlerFactory) {
- this.protocolHandlerFactory = protocolHandlerFactory;
- }
-
- public void start() {
- }
-
- public void stop() {
- }
-
- public void unregister() {
- }
-
- private ProtocolHandlerFactory getProtocolHandlerFactory() {
- return protocolHandlerFactory;
- }
- }
-
- public static final class SimpleClientCallbackHandler implements CallbackHandler {
- private final String userName;
- private final char[] password;
-
- public SimpleClientCallbackHandler(final String userName, final char[] password) {
- this.userName = userName;
- this.password = password;
- }
-
- public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
- for (Callback callback : callbacks) {
- if (callback instanceof NameCallback) {
- ((NameCallback) callback).setName(userName);
- } else if (callback instanceof PasswordCallback) {
- ((PasswordCallback) callback).setPassword(password);
- } else {
- throw new UnsupportedCallbackException(callback, "This handler only supports username/password callbacks");
- }
- }
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundClient.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundClient.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundClient.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,148 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.CloseHandler;
-import org.jboss.cx.remoting.ClientContext;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.RequestListener;
-import org.jboss.cx.remoting.ServiceContext;
-import org.jboss.xnio.log.Logger;
-import org.jboss.cx.remoting.util.AtomicStateMachine;
-import static org.jboss.cx.remoting.util.AtomicStateMachine.start;
-import org.jboss.cx.remoting.util.CollectionUtil;
-import static org.jboss.cx.remoting.util.CollectionUtil.synchronizedHashSet;
-
-/**
- *
- */
-public final class CoreInboundClient<I, O> {
- private static final Logger log = org.jboss.xnio.log.Logger.getLogger(CoreInboundClient.class);
-
- private final RequestListener<I, O> requestListener;
- private final Executor executor;
- private final ServiceContext serviceContext;
- private final Set<CoreInboundRequest<I, O>> requests = synchronizedHashSet();
- private final AtomicStateMachine<State> state = start(State.NEW);
- private final ClientContext clientContext = new UserClientContext();
-
- private ClientInitiator clientInitiator;
- private ConcurrentMap<Object, Object> attributes = CollectionUtil.concurrentMap();
-
- private enum State implements org.jboss.cx.remoting.util.State<State> {
- NEW,
- UP,
- STOPPING,
- DOWN;
-
- public boolean isReachable(final State dest) {
- return compareTo(dest) < 0;
- }
- }
-
- public CoreInboundClient(final RequestListener<I, O> requestListener, final Executor executor) {
- this.requestListener = requestListener;
- this.executor = executor;
- serviceContext = null;
- }
-
- public CoreInboundClient(final RequestListener<I, O> requestListener, final Executor executor, final ServiceContext serviceContext) {
- this.requestListener = requestListener;
- this.executor = executor;
- this.serviceContext = serviceContext;
- }
-
- public ClientResponder<I, O> getClientResponder() {
- return new Responder();
- }
-
- public void initialize(final ClientInitiator clientInitiator) {
- state.requireTransitionExclusive(State.NEW, State.UP);
- this.clientInitiator = clientInitiator;
- state.releaseDowngrade();
- try {
- if (requestListener != null) {
- requestListener.handleClientOpen(clientContext);
- }
- } finally {
- state.release();
- }
- }
-
- public void remove(final CoreInboundRequest<I, O> request) {
- final State current = state.getStateHold();
- try {
- requests.remove(request);
- if (current != State.STOPPING) {
- return;
- }
- } finally {
- state.release();
- }
- if (requests.isEmpty()) {
- state.transition(State.STOPPING, State.DOWN);
- }
- }
-
- // Accessors
-
- public ClientContext getClientContext() {
- return clientContext;
- }
-
- // Support classes
-
- public final class Responder implements ClientResponder<I, O> {
- private Responder() {
- }
-
- public RequestResponder<I> createNewRequest(final RequestInitiator<O> requestInitiator) throws RemotingException {
- if (state.inHold(State.UP)) try {
- final CoreInboundRequest<I, O> inboundRequest = new CoreInboundRequest<I, O>(requestListener, executor, clientContext);
- inboundRequest.initialize(requestInitiator);
- requests.add(inboundRequest);
- return inboundRequest.getRequestResponder();
- } finally {
- state.release();
- } else {
- throw new RemotingException("Client is not up");
- }
- }
-
- public void handleClose(final boolean immediate, final boolean cancel) throws RemotingException {
- if (state.transition(State.UP, State.STOPPING)) {
- clientInitiator.handleClosing(false);
- if (immediate || cancel) {
- for (CoreInboundRequest<I, O> inboundRequest : requests) {
- try {
- inboundRequest.getRequestResponder().handleCancelRequest(immediate );
- } catch (Exception e) {
- log.trace("Failed to notify inbound request of cancellation upon context close: %s", e);
- }
- }
- }
- }
- }
- }
-
- public final class UserClientContext implements ClientContext {
- private UserClientContext() {
- }
-
- public ConcurrentMap<Object, Object> getAttributes() {
- return attributes;
- }
-
- public ServiceContext getServiceContext() {
- return serviceContext;
- }
-
- public void close() throws RemotingException {
- clientInitiator.handleClosing(false);
- }
-
- public void addCloseHandler(final CloseHandler<ClientContext> contextContextCloseHandler) {
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,231 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.RequestCancelHandler;
-import org.jboss.cx.remoting.RequestContext;
-import org.jboss.cx.remoting.RequestListener;
-import org.jboss.cx.remoting.ClientContext;
-import org.jboss.cx.remoting.util.AtomicStateMachine;
-
-/**
- *
- */
-public final class CoreInboundRequest<I, O> {
- private static final org.jboss.xnio.log.Logger log = org.jboss.xnio.log.Logger.getLogger(CoreInboundRequest.class);
-
- private final RequestListener<I,O> requestListener;
- private final Executor executor;
- private final ClientContext clientContext;
-
- private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.INITIAL);
- private final UserRequestContext userRequestContext = new UserRequestContext();
- private final RequestResponder<I> request = new Request();
-
- private RequestInitiator<O> requestInitiator;
-
- /**
- * @protectedby {@code this}
- */
- private boolean mayInterrupt;
- /**
- * @protectedby {@code this}
- */
- private boolean cancel;
- /**
- * @protectedby {@code this}
- */
- private Set<Thread> tasks;
- /**
- * @protectedby {@code this}
- */
- private List<RequestCancelHandler<O>> cancelHandlers;
-
- public CoreInboundRequest(final RequestListener<I, O> requestListener, final Executor executor, final ClientContext clientContext) {
- this.requestListener = requestListener;
- this.executor = executor;
- this.clientContext = clientContext;
- }
-
- private enum State implements org.jboss.cx.remoting.util.State<State> {
- INITIAL,
- UNSENT,
- SENT,
- TERMINATED;
-
- public boolean isReachable(final State dest) {
- return compareTo(dest) < 0;
- }
- }
-
- public void initialize(final RequestInitiator<O> requestInitiator) {
- state.requireTransitionExclusive(State.INITIAL, State.UNSENT);
- this.requestInitiator = requestInitiator;
- state.releaseExclusive();
- }
-
- public RequestResponder<I> getRequestResponder() {
- return request;
- }
-
- /**
- * Execute the given command. The command will be sensitive to interruption if the request is cancelled.
- *
- * @param command the command to execute
- */
- private void executeTagged(final Runnable command) {
- executor.execute(new Runnable() {
- public void run() {
- final Thread thread = Thread.currentThread();
- synchronized(CoreInboundRequest.this) {
- if (tasks == null) {
- tasks = new HashSet<Thread>();
- }
- tasks.add(thread);
- }
- try {
- command.run();
- } finally {
- synchronized(CoreInboundRequest.this) {
- tasks.remove(thread);
- }
- }
- }
- });
- }
-
- public final class Request implements RequestResponder<I> {
- public void handleCancelRequest(final boolean mayInterrupt) {
- synchronized(CoreInboundRequest.this) {
- if (! cancel) {
- cancel = true;
- CoreInboundRequest.this.mayInterrupt |= mayInterrupt;
- if (mayInterrupt) {
- if (tasks != null) {
- for (Thread t : tasks) {
- t.interrupt();
- }
- }
- }
- if (cancelHandlers != null) {
- final Iterator<RequestCancelHandler<O>> i = cancelHandlers.iterator();
- while (i.hasNext()) {
- final RequestCancelHandler<O> handler = i.next();
- i.remove();
- executor.execute(new Runnable() {
- public void run() {
- handler.notifyCancel(userRequestContext, mayInterrupt);
- }
- });
- }
- }
- }
- }
- }
-
- public void handleRequest(final I request, final Executor streamExecutor) {
- executeTagged(new Runnable() {
- public void run() {
- try {
- requestListener.handleRequest(userRequestContext, request);
- } catch (InterruptedException e) {
- final boolean wasCancelled;
- synchronized(CoreInboundRequest.this) {
- wasCancelled = cancel;
- }
- if (state.transition(State.UNSENT, State.SENT)) {
- if (wasCancelled) {
- try {
- requestInitiator.handleCancelAcknowledge();
- } catch (RemotingException e1) {
- try {
- requestInitiator.handleException(new RemoteExecutionException("Failed to send a cancel ack to client: " + e1.toString(), e1));
- } catch (RemotingException e2) {
- log.debug("Tried and failed to send an exception (%s): %s", e1, e2);
- }
- }
- } else {
- try {
- requestInitiator.handleException(new RemoteExecutionException("Execution failed: " + e.toString(), e));
- } catch (RemotingException e1) {
- log.debug("Tried and failed to send an exception (%s): %s", e, e1);
- }
- }
- log.trace(e, "Request listener %s recevied an exception", requestListener);
- }
- } catch (Throwable e) {
- if (state.transition(State.UNSENT, State.SENT)) {
- try {
- if (e instanceof RemoteExecutionException) {
- requestInitiator.handleException((RemoteExecutionException) e);
- } else {
- requestInitiator.handleException(new RemoteExecutionException("Execution failed: " + e.toString(), e));
- }
- } catch (RemotingException e1) {
- log.debug("Tried and failed to send an exception (%s): %s", e, e1);
- }
- }
- log.trace(e, "Request listener %s recevied an exception", requestListener);
- }
- }
- });
- }
- }
-
- public final class UserRequestContext implements RequestContext<O> {
- private UserRequestContext() {}
-
- public ClientContext getContext() {
- return clientContext;
- }
-
- public boolean isCancelled() {
- synchronized(CoreInboundRequest.this) {
- return cancel;
- }
- }
-
- public void sendReply(final O reply) throws RemotingException, IllegalStateException {
- state.requireTransition(State.UNSENT, State.SENT);
- requestInitiator.handleReply(reply);
- }
-
- public void sendFailure(final String msg, final Throwable cause) throws RemotingException, IllegalStateException {
- state.requireTransition(State.UNSENT, State.SENT);
- final RemoteExecutionException rex = new RemoteExecutionException(msg, cause);
- rex.setStackTrace(cause.getStackTrace());
- requestInitiator.handleException(rex);
- }
-
- public void sendCancelled() throws RemotingException, IllegalStateException {
- state.requireTransition(State.UNSENT, State.SENT);
- requestInitiator.handleCancelAcknowledge();
- }
-
- public void addCancelHandler(final RequestCancelHandler<O> requestCancelHandler) {
- final boolean mayInterrupt;
- synchronized(CoreInboundRequest.this) {
- if (!cancel) {
- if (cancelHandlers == null) {
- cancelHandlers = new LinkedList<RequestCancelHandler<O>>();
- }
- cancelHandlers.add(requestCancelHandler);
- return;
- }
- // otherwise, unlock and notify now
- mayInterrupt = CoreInboundRequest.this.mayInterrupt;
- }
- requestCancelHandler.notifyCancel(this, mayInterrupt);
- }
-
- public void execute(final Runnable command) {
- executeTagged(command);
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,114 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.CloseHandler;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.RequestListener;
-import org.jboss.cx.remoting.ServiceContext;
-import org.jboss.cx.remoting.util.AtomicStateMachine;
-import static org.jboss.cx.remoting.util.AtomicStateMachine.start;
-import org.jboss.cx.remoting.util.CollectionUtil;
-
-/**
- *
- */
-public final class CoreInboundService<I, O> {
-
- private final RequestListener<I, O> requestListener;
- private final Executor executor;
-
- private final ServiceContext serviceContext = new UserServiceContext();
- private final AtomicStateMachine<State> state = start(State.INITIAL);
- private final ConcurrentMap<Object, Object> attributes = CollectionUtil.concurrentMap();
-
- private ServiceInitiator serviceInitiator;
- private final Set<CloseHandler<ServiceContext>> closeHandlers = CollectionUtil.synchronizedSet(new LinkedHashSet<CloseHandler<ServiceContext>>());
-
- private enum State implements org.jboss.cx.remoting.util.State<State> {
- INITIAL,
- UP,
- DOWN;
-
- public boolean isReachable(final State dest) {
- return compareTo(dest) < 0;
- }
- }
-
- public CoreInboundService(final RequestListener<I, O> requestListener, final Executor executor) {
- this.requestListener = requestListener;
- this.executor = executor;
- }
-
- public void initialize(final ServiceInitiator serviceInitiator) {
- state.requireTransitionExclusive(State.INITIAL, State.UP);
- this.serviceInitiator = serviceInitiator;
- state.releaseDowngrade();
- try {
- requestListener.handleServiceOpen(serviceContext);
- } finally {
- state.release();
- }
- }
-
- private void doClose() {
- if (state.transition(State.DOWN)) {
- synchronized (closeHandlers) {
- for (final CloseHandler<ServiceContext> closeHandler : closeHandlers) {
- executor.execute(new Runnable() {
- public void run() {
- closeHandler.handleClose(serviceContext);
- }
- });
- }
- closeHandlers.clear();
- }
- }
- }
-
- public ServiceResponder<I, O> getServiceResponder() {
- return new ServiceResponder<I, O>() {
- public void handleClose() throws RemotingException {
- doClose();
- }
-
- public ClientResponder<I, O> createNewClient(final ClientInitiator clientInitiator) {
- final CoreInboundClient<I, O> client = new CoreInboundClient<I, O>(requestListener, executor, serviceContext);
- client.initialize(clientInitiator);
- return client.getClientResponder();
- }
- };
- }
-
- public final class UserServiceContext implements ServiceContext {
- private UserServiceContext() {
- }
-
- public ConcurrentMap<Object, Object> getAttributes() {
- return attributes;
- }
-
- public void close() throws RemotingException {
- doClose();
- serviceInitiator.handleClosing();
- }
-
- public void addCloseHandler(final CloseHandler<ServiceContext> closeHandler) {
- final State current = state.getStateHold();
- try {
- switch (current) {
- case DOWN:
- closeHandler.handleClose(this);
- break;
- default:
- closeHandlers.add(closeHandler);
- break;
- }
- } finally {
- state.release();
- }
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundClient.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundClient.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundClient.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,182 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.CloseHandler;
-import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.FutureReply;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.RequestCompletionHandler;
-import org.jboss.cx.remoting.core.util.QueueExecutor;
-import org.jboss.cx.remoting.util.AtomicStateMachine;
-import org.jboss.cx.remoting.util.CollectionUtil;
-
-/**
- *
- */
-public final class CoreOutboundClient<I, O> {
- private static final org.jboss.xnio.log.Logger log = org.jboss.xnio.log.Logger.getLogger(CoreOutboundClient.class);
-
- private final ConcurrentMap<Object, Object> contextMap = CollectionUtil.concurrentMap();
- private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.INITIAL);
- private final ClientInitiator clientInitiator = new ClientInitiatorImpl();
- private final Set<CloseHandler<Client<I, O>>> closeHandlers = CollectionUtil.synchronizedSet(new LinkedHashSet<CloseHandler<Client<I, O>>>());
- private final Executor executor;
-
- private Client<I, O> userClient;
- private ClientResponder<I, O> clientResponder;
-
- public CoreOutboundClient(final Executor executor) {
- this.executor = executor;
- }
-
- public void initialize(final ClientResponder<I, O> clientResponder) {
- state.requireTransitionExclusive(State.INITIAL, State.UP);
- this.clientResponder = clientResponder;
- userClient = new UserClient();
- state.releaseExclusive();
- }
-
- private enum State implements org.jboss.cx.remoting.util.State<State> {
- INITIAL,
- UP,
- STOPPING,
- DOWN,;
-
- public boolean isReachable(final State dest) {
- return compareTo(dest) < 0;
- }
- }
-
- // Getters
-
- Client<I,O> getUserContext() {
- return userClient;
- }
-
- ClientInitiator getClientInitiator() {
- return clientInitiator;
- }
-
- // Other mgmt
-
- protected void finalize() throws Throwable {
- try {
- super.finalize();
- } finally {
- // todo close it
- log.trace("Leaked a context instance: %s", this);
- }
- }
-
- void invalidate() {
- // An extra instance was mistakenly created; we'll kill this one and quietly step away
- state.transition(State.DOWN);
- userClient = null;
- clientResponder = null;
- }
-
- public final class UserClient extends AbstractRealClient<I, O> {
-
- private UserClient() {
- super(clientResponder, Thread.currentThread().getContextClassLoader() /* TODO */);
- }
-
- private void doClose(final boolean immediate, final boolean cancel) throws RemotingException {
- state.waitForNot(State.INITIAL);
- if (state.transitionHold(State.UP, State.STOPPING)) try {
- synchronized (closeHandlers) {
- for (final CloseHandler<Client<I, O>> handler : closeHandlers) {
- executor.execute(new Runnable() {
- public void run() {
- handler.handleClose(UserClient.this);
- }
- });
- }
- closeHandlers.clear();
- }
- clientResponder.handleClose(immediate, cancel);
- } finally {
- state.release();
- }
- }
-
- public void close() throws RemotingException {
- doClose(false, false);
- }
-
- public void addCloseHandler(final CloseHandler<Client<I, O>> closeHandler) {
- final State current = state.getStateHold();
- try {
- switch (current) {
- case STOPPING:
- case DOWN:
- closeHandler.handleClose(this);
- break;
- default:
- closeHandlers.add(closeHandler);
- break;
- }
- } finally {
- state.release();
- }
- }
-
- public O invoke(final I request) throws RemotingException, RemoteExecutionException {
- state.requireHold(State.UP);
- try {
- final QueueExecutor queueExecutor = new QueueExecutor();
- final CoreOutboundRequest<I, O> outboundRequest = new CoreOutboundRequest<I, O>();
- final RequestResponder<I> requestResponder = clientResponder.createNewRequest(outboundRequest.getReplier());
- outboundRequest.setRequestResponder(requestResponder);
- requestResponder.handleRequest(request, queueExecutor);
- final FutureReply<O> futureReply = outboundRequest.getFutureReply();
- futureReply.addCompletionNotifier(new RequestCompletionHandler<O>() {
- public void notifyComplete(final FutureReply<O> futureReply) {
- queueExecutor.shutdown();
- }
- });
- queueExecutor.runQueue();
- return futureReply.get();
- } finally {
- state.release();
- }
- }
-
- public FutureReply<O> send(final I request) throws RemotingException {
- state.requireHold(State.UP);
- try {
- final CoreOutboundRequest<I, O> outboundRequest = new CoreOutboundRequest<I, O>();
- final RequestResponder<I> requestTerminus = clientResponder.createNewRequest(outboundRequest.getReplier());
- outboundRequest.setRequestResponder(requestTerminus);
- requestTerminus.handleRequest(request, executor);
- return outboundRequest.getFutureReply();
- } finally {
- state.release();
- }
- }
-
- public void sendOneWay(final I request) throws RemotingException {
- state.requireHold(State.UP);
- try {
- final RequestResponder<I> requestResponder = clientResponder.createNewRequest(null);
- requestResponder.handleRequest(request, executor);
- } finally {
- state.release();
- }
- }
-
- public ConcurrentMap<Object, Object> getAttributes() {
- return contextMap;
- }
- }
-
- public final class ClientInitiatorImpl implements ClientInitiator {
- public void handleClosing(boolean done) throws RemotingException {
- // todo - remote side is closing
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,266 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.TimeUnit;
-import org.jboss.cx.remoting.FutureReply;
-import org.jboss.cx.remoting.IndeterminateOutcomeException;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.RequestCompletionHandler;
-import org.jboss.xnio.log.Logger;
-import org.jboss.cx.remoting.util.AtomicStateMachine;
-
-/**
- *
- */
-public final class CoreOutboundRequest<I, O> {
-
- private static final org.jboss.xnio.log.Logger log = Logger.getLogger(CoreOutboundRequest.class);
-
- private RequestResponder<I> requestResponder;
-
- private final RequestInitiator<O> requestInitiator = new RequestInitiatorImpl();
- private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.WAITING);
- private final FutureReply<O> futureReply = new FutureReplyImpl();
-
- /* Protected by {@code state} */
- private O reply;
- /* Protected by {@code state} */
- private RemoteExecutionException exception;
- /* Protected by {@code state} */
- private List<RequestCompletionHandler<O>> handlers = Collections.synchronizedList(new LinkedList<RequestCompletionHandler<O>>());
-
- public CoreOutboundRequest() {
- }
-
- public RequestResponder<I> getRequester() {
- return requestResponder;
- }
-
- public void setRequestResponder(final RequestResponder<I> requestResponder) {
- this.requestResponder = requestResponder;
- }
-
- public FutureReply<O> getFutureReply() {
- return futureReply;
- }
-
- public RequestInitiator<O> getReplier() {
- return requestInitiator;
- }
-
- private enum State implements org.jboss.cx.remoting.util.State<State> {
- WAITING,
- DONE,
- EXCEPTION,
- CANCELLED,
- TERMINATED,;
-
- public boolean isReachable(final State dest) {
- switch (this) {
- case WAITING:
- case DONE:
- return compareTo(dest) < 0;
- default:
- return false;
- }
- }
- }
-
- /**
- * Complete the request. Call only with the monitor held, not in WAITING state.
- */
- private void complete() {
- final List<RequestCompletionHandler<O>> handlers = this.handlers;
- if (handlers != null) {
- this.handlers = null;
- final Iterator<RequestCompletionHandler<O>> iterator = handlers.iterator();
- while (iterator.hasNext()) {
- final RequestCompletionHandler<O> handler = iterator.next();
- try {
- handler.notifyComplete(futureReply);
- } catch (Throwable t) {
- log.trace(t, "Request completion notifier failed for notifier object %s", String.valueOf(handler));
- }
- iterator.remove();
- }
- }
- }
-
- public final class RequestInitiatorImpl implements RequestInitiator<O> {
- public void handleCancelAcknowledge() {
- if (state.transitionHold(State.WAITING, State.CANCELLED)) try {
- complete();
- } finally {
- state.release();
- }
- }
-
- public void handleReply(final O reply) {
- if (state.transitionExclusive(State.WAITING, State.DONE)) try {
- CoreOutboundRequest.this.reply = reply;
- } finally {
- state.releaseDowngrade();
- try {
- complete();
- } finally {
- state.release();
- }
- }
- }
-
- public void handleException(final RemoteExecutionException exception) {
- if (state.transitionExclusive(State.WAITING, State.EXCEPTION)) try {
- CoreOutboundRequest.this.exception = exception;
- } finally {
- state.releaseDowngrade();
- try {
- complete();
- } finally {
- state.release();
- }
- }
- }
- }
-
- public final class FutureReplyImpl implements FutureReply<O> {
-
- private FutureReplyImpl() {
- }
-
- public boolean cancel(final boolean mayInterruptIfRunning) {
- if (state.inHold(State.WAITING)) try {
- try {
- requestResponder.handleCancelRequest(mayInterruptIfRunning);
- } catch (RemotingException e) {
- return false;
- }
- } finally {
- state.release();
- }
- return state.waitForNot(State.WAITING) == State.CANCELLED;
- }
-
- public FutureReply<O> sendCancel(final boolean mayInterruptIfRunning) {
- if (state.inHold(State.WAITING)) try {
- try {
- requestResponder.handleCancelRequest(mayInterruptIfRunning);
- } catch (RemotingException e) {
- // do nothing
- }
- } finally {
- state.release();
- }
- return this;
- }
-
- public boolean isCancelled() {
- return state.in(State.CANCELLED);
- }
-
- public boolean isDone() {
- return state.in(State.DONE);
- }
-
- public O get() throws CancellationException, RemoteExecutionException {
- final State newState = state.waitForNotHold(State.WAITING);
- try {
- switch(newState) {
- case CANCELLED:
- throw new CancellationException("Request was cancelled");
- case EXCEPTION:
- throw exception;
- case DONE:
- return reply;
- case TERMINATED:
- throw new IndeterminateOutcomeException("Request terminated abruptly; outcome unknown");
- default:
- throw new IllegalStateException("Wrong state");
- }
- } finally {
- state.release();
- }
- }
-
- public O getInterruptibly() throws InterruptedException, CancellationException, RemoteExecutionException {
- final State newState = state.waitInterruptiblyForNotHold(State.WAITING);
- try {
- switch(newState) {
- case CANCELLED:
- throw new CancellationException("Request was cancelled");
- case EXCEPTION:
- throw exception;
- case DONE:
- return reply;
- case TERMINATED:
- throw new IndeterminateOutcomeException("Request terminated abruptly; outcome unknown");
- default:
- throw new IllegalStateException("Wrong state");
- }
- } finally {
- state.release();
- }
- }
-
- public O get(long timeout, TimeUnit unit) throws CancellationException, RemoteExecutionException {
- final State newState = state.waitForNotHold(State.WAITING, timeout, unit);
- try {
- switch (newState) {
- case CANCELLED:
- throw new CancellationException("Request was cancelled");
- case EXCEPTION:
- throw exception;
- case DONE:
- return reply;
- case TERMINATED:
- throw new IndeterminateOutcomeException("Request terminated abruptly; outcome unknown");
- }
- throw new IllegalStateException("Wrong state");
- } finally {
- state.release();
- }
- }
-
- public O getInterruptibly(final long timeout, final TimeUnit unit) throws InterruptedException, CancellationException, RemoteExecutionException {
- final State newState = state.waitInterruptiblyForNotHold(State.WAITING, timeout, unit);
- try {
- switch (newState) {
- case CANCELLED:
- throw new CancellationException("Request was cancelled");
- case EXCEPTION:
- throw exception;
- case DONE:
- return reply;
- case TERMINATED:
- throw new IndeterminateOutcomeException("Request terminated abruptly; outcome unknown");
- }
- throw new IllegalStateException("Wrong state");
- } finally {
- state.release();
- }
- }
-
- public FutureReply<O> addCompletionNotifier(RequestCompletionHandler<O> handler) {
- final State currentState = state.getStateHold();
- try {
- switch (currentState) {
- case CANCELLED:
- case DONE:
- case EXCEPTION:
- handler.notifyComplete(this);
- break;
- case WAITING:
- handlers.add(handler);
- break;
- }
- } finally {
- state.release();
- }
- return this;
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,117 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.CloseHandler;
-import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.ClientSource;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.xnio.log.Logger;
-import org.jboss.cx.remoting.util.AtomicStateMachine;
-import org.jboss.cx.remoting.util.CollectionUtil;
-
-/**
- *
- */
-public final class CoreOutboundService<I, O> {
- private static final Logger log = Logger.getLogger(CoreOutboundService.class);
-
- private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.INITIAL);
- private final ClientSource<I, O> userClientSource = new UserClientSource();
- private final ServiceInitiator serviceInitiator = new ServiceInitiatorImpl();
- private final Executor executor;
-
- private ServiceResponder<I,O> serviceResponder;
- private Set<CloseHandler<ClientSource<I,O>>> closeHandlers = CollectionUtil.synchronizedSet(new LinkedHashSet<CloseHandler<ClientSource<I, O>>>());
-
- public CoreOutboundService(final Executor executor) {
- this.executor = executor;
- }
-
- private enum State implements org.jboss.cx.remoting.util.State<State> {
- INITIAL,
- UP,
- CLOSING,
- DOWN;
-
- public boolean isReachable(final State dest) {
- return compareTo(dest) < 0;
- }
- }
-
- // Getters
-
- ClientSource<I, O> getUserContextSource() {
- return userClientSource;
- }
-
- public ServiceInitiator getServiceClient() {
- return serviceInitiator;
- }
-
- public void initialize(final ServiceResponder<I, O> serviceResponder) {
- state.requireTransitionExclusive(State.INITIAL, State.UP);
- this.serviceResponder = serviceResponder;
- state.releaseExclusive();
- }
-
- @SuppressWarnings ({"SerializableInnerClassWithNonSerializableOuterClass"})
- public final class UserClientSource extends AbstractRealClientSource<I, O> {
- protected UserClientSource() {
- super(serviceResponder);
- }
-
- private void doClose() throws RemotingException {
- state.waitForNot(State.INITIAL);
- if (state.transitionHold(State.UP, State.DOWN)) try {
- synchronized (closeHandlers) {
- for (final CloseHandler<ClientSource<I, O>> handler : closeHandlers) {
- executor.execute(new Runnable() {
- public void run() {
- handler.handleClose(UserClientSource.this);
- }
- });
- }
- closeHandlers.clear();
- }
- serviceResponder.handleClose();
- } finally {
- state.release();
- }
- }
-
- public void close() throws RemotingException {
- doClose();
- }
-
- public void addCloseHandler(final CloseHandler<ClientSource<I, O>> closeHandler) {
- final State current = state.getStateHold();
- try {
- switch (current) {
- case DOWN:
- closeHandler.handleClose(this);
- break;
- default:
- closeHandlers.add(closeHandler);
- break;
- }
- } finally {
- state.release();
- }
- }
-
- public Client<I, O> createContext() throws RemotingException {
- final CoreOutboundClient<I, O> client = new CoreOutboundClient<I, O>(executor);
- final ClientResponder<I, O> clientResponder = serviceResponder.createNewClient(client.getClientInitiator());
- client.initialize(clientResponder);
- return client.getUserContext();
- }
- }
-
- public final class ServiceInitiatorImpl implements ServiceInitiator {
- public void handleClosing() throws RemotingException {
- // todo - remote side is closing
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,819 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.CloseHandler;
-import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.Session;
-import org.jboss.cx.remoting.core.stream.DefaultStreamDetector;
-import org.jboss.xnio.log.Logger;
-import org.jboss.cx.remoting.util.ByteMessageInput;
-import org.jboss.cx.remoting.util.ByteMessageOutput;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.stream.StreamDetector;
-import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
-import org.jboss.cx.remoting.spi.marshal.MarshallerFactory;
-import org.jboss.cx.remoting.util.AtomicStateMachine;
-import org.jboss.cx.remoting.util.AttributeMap;
-import org.jboss.cx.remoting.util.CollectionUtil;
-
-/**
- * Three execution contexts:
- *
- * - Inbound protocol handler - controlled by server/network handler
- * - Context client context - controlled by user/container
- * - Local work handler - ExecutorService provided to Endpoint
- */
-public final class CoreSession {
- private static final Logger log = Logger.getLogger(CoreSession.class);
-
- private final ProtocolContextImpl protocolContext = new ProtocolContextImpl();
- private final UserSession userSession = new UserSession();
-
- // stream serialization detectors - immutable (for now?)
- private final List<StreamDetector> streamDetectors;
- private List<ObjectResolver> resolvers = new ArrayList<ObjectResolver>();
- private MarshallerFactory marshallerFactory;
-
- // Contexts and services that are available on the remote end of this session
- // In these paris, the Server points to the ProtocolHandler, and the Client points to...whatever
- private final ConcurrentMap<ClientIdentifier, ClientContextPair> clientContexts = CollectionUtil.concurrentMap();
- private final ConcurrentMap<ServiceIdentifier, ClientServicePair> clientServices = CollectionUtil.concurrentMap();
-
- // Contexts and services that are available on this end of this session
- // In these pairs, the Client points to the ProtocolHandler, and the Server points to... whatever
- private final ConcurrentMap<ClientIdentifier, ServerContextPair> serverContexts = CollectionUtil.concurrentMap();
- private final ConcurrentMap<ServiceIdentifier, ServerServicePair> serverServices = CollectionUtil.concurrentMap();
-
- // streams - strong references, only clean up if a close message is sent or received
- private final ConcurrentMap<StreamIdentifier, CoreStream> streams = CollectionUtil.concurrentMap();
-
- // don't GC the endpoint while a session lives
- private final CoreEndpoint endpoint;
- private final Executor executor;
- private final Set<CloseHandler<Session>> closeHandlers = CollectionUtil.synchronizedSet(new LinkedHashSet<CloseHandler<Session>>());
-
- /** The protocol handler. Set on NEW -> CONNECTING */
- private ProtocolHandler protocolHandler;
- /** The remote endpoint name. Set on CONNECTING -> UP */
- private String remoteEndpointName;
- /** The root context. Set on CONNECTING -> UP */
- private Client<?, ?> rootClient;
-
- private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.NEW);
- private ObjectResolver resolver; // todo - initialize to a composite resolver
-
- // Constructors
-
- CoreSession(final CoreEndpoint endpoint) {
- if (endpoint == null) {
- throw new NullPointerException("endpoint is null");
- }
- this.endpoint = endpoint;
- executor = endpoint.getExecutor();
- // todo - make stream detectors pluggable
- streamDetectors = java.util.Collections.singletonList(DefaultStreamDetector.INSTANCE);
- }
-
- UserSession getUserSession() {
- state.waitForHold(State.UP);
- try {
- return userSession;
- } finally {
- state.release();
- }
- }
-
- public MarshallerFactory getMarshallerFactory() {
- return marshallerFactory;
- }
-
- public void setMarshallerFactory(final MarshallerFactory marshallerFactory) {
- this.marshallerFactory = marshallerFactory;
- }
-
- public void addFirstResolver(ObjectResolver resolver) {
- resolvers.add(0, resolver);
- }
-
- public void addLastResolver(ObjectResolver resolver) {
- resolvers.add(resolver);
- }
-
-
- // Initializers
-
- private <I, O> void doInitialize(final ProtocolHandler protocolHandler, final Client<I, O> rootClient) {
- if (protocolHandler == null) {
- throw new NullPointerException("protocolHandler is null");
- }
- this.protocolHandler = protocolHandler;
- if (rootClient instanceof AbstractRealClient) {
- final AbstractRealClient<I, O> abstractRealContext = (AbstractRealClient<I, O>) rootClient;
- // Forward local context
- final ClientIdentifier localIdentifier = protocolHandler.getLocalRootClientIdentifier();
- if (localIdentifier == null) {
- throw new NullPointerException("localIdentifier is null");
- }
- final ProtocolClientInitiatorImpl<I, O> contextClient = new ProtocolClientInitiatorImpl<I, O>(localIdentifier);
- serverContexts.put(localIdentifier, new ServerContextPair<I, O>(contextClient, abstractRealContext.getContextServer()));
- log.trace("Initialized session with local context %s", localIdentifier);
- }
- // Forward remote context
- final ClientIdentifier remoteIdentifier = protocolHandler.getRemoteRootClientIdentifier();
- if (remoteIdentifier == null) {
- throw new NullPointerException("remoteIdentifier is null");
- }
- final ProtocolClientResponderImpl<I, O> contextServer = new ProtocolClientResponderImpl<I,O>(remoteIdentifier);
- final CoreOutboundClient<I, O> coreOutboundClient = new CoreOutboundClient<I, O>(executor);
- clientContexts.put(remoteIdentifier, new ClientContextPair<I, O>(coreOutboundClient.getClientInitiator(), contextServer, remoteIdentifier));
- coreOutboundClient.initialize(contextServer);
- this.rootClient = coreOutboundClient.getUserContext();
- log.trace("Initialized session with remote context %s", remoteIdentifier);
- }
-
- <I, O> void initializeServer(final ProtocolHandler protocolHandler, final Client<I, O> rootClient) {
- if (protocolHandler == null) {
- throw new NullPointerException("protocolHandler is null");
- }
- boolean ok = false;
- state.requireTransitionExclusive(State.NEW, State.CONNECTING);
- try {
- doInitialize(protocolHandler, rootClient);
- ok = true;
- } finally {
- state.releaseExclusive();
- if (! ok) {
- state.transition(State.DOWN);
- }
- }
- }
-
- <I, O> void initializeClient(final ProtocolHandlerFactory protocolHandlerFactory, final URI remoteUri, final AttributeMap attributeMap, final Client<I, O> rootClient) throws IOException {
- if (protocolHandlerFactory == null) {
- throw new NullPointerException("protocolHandlerFactory is null");
- }
- boolean ok = false;
- state.requireTransitionExclusive(State.NEW, State.CONNECTING);
- try {
- doInitialize(protocolHandlerFactory.createHandler(protocolContext, remoteUri, attributeMap), rootClient);
- ok = true;
- } finally {
- state.releaseExclusive();
- if (! ok) {
- state.transition(State.DOWN);
- }
- }
- }
-
- public ProtocolContext getProtocolContext() {
- return protocolContext;
- }
-
- public ProtocolHandler getProtocolHandler() {
- return protocolHandler;
- }
-
- // State mgmt
-
- private enum State implements org.jboss.cx.remoting.util.State<State> {
- NEW,
- CONNECTING,
- UP,
- STOPPING,
- DOWN;
-
- public boolean isReachable(final State dest) {
- return compareTo(dest) < 0;
- }
- }
-
- // Client mgmt
-
- // User session impl
-
- public final class UserSession implements Session {
- private UserSession() {}
-
- private final ConcurrentMap<Object, Object> sessionMap = CollectionUtil.concurrentMap();
-
- public void close() throws RemotingException {
- // todo - maybe drain the session first?
- shutdown();
- state.waitFor(State.DOWN);
- }
-
- public void addCloseHandler(final CloseHandler<Session> closeHandler) {
- final State current = state.getStateHold();
- try {
- switch (current) {
- case DOWN:
- case STOPPING:
- closeHandler.handleClose(this);
- break;
- default:
- closeHandlers.add(closeHandler);
- }
- } finally {
- state.release();
- }
- }
-
- public ConcurrentMap<Object, Object> getAttributes() {
- return sessionMap;
- }
-
- public String getLocalEndpointName() {
- return endpoint.getName();
- }
-
- public String getRemoteEndpointName() {
- return remoteEndpointName;
- }
-
- @SuppressWarnings ({"unchecked"})
- public <I, O> Client<I, O> getRootClient() {
- return (Client<I, O>) rootClient;
- }
- }
-
- // Protocol context
-
- @SuppressWarnings ({"unchecked"})
- private static <O> void doSendReply(RequestInitiator<O> requestInitiator, Object data) throws RemotingException {
- requestInitiator.handleReply((O)data);
- }
-
- // Lifecycle
-
- private void shutdown() {
- if (state.transition(State.UP, State.STOPPING)) {
- for (final CloseHandler<Session> closeHandler : closeHandlers) {
- executor.execute(new Runnable() {
- public void run() {
- closeHandler.handleClose(userSession);
- }
- });
- }
- closeHandlers.clear();
- try {
- log.trace("Initiating session shutdown");
- protocolHandler.closeSession();
- } catch (IOException e) {
- log.trace(e, "Protocol handler session close failed");
- } finally {
- endpoint.removeSession(this);
- }
- }
- }
-
- public final class ProtocolContextImpl implements ProtocolContext {
-
- public void closeSession() {
- shutdown();
- if (state.transition(State.STOPPING, State.DOWN)) {
- log.trace("Session shut down");
- }
- }
-
- public ObjectMessageOutput getMessageOutput(ByteMessageOutput target) throws IOException {
- if (target == null) {
- throw new NullPointerException("target is null");
- }
- return marshallerFactory.createMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getMarshalingSink(target);
- }
-
- public ObjectMessageOutput getMessageOutput(ByteMessageOutput target, Executor streamExecutor) throws IOException {
- if (target == null) {
- throw new NullPointerException("target is null");
- }
- if (streamExecutor == null) {
- throw new NullPointerException("streamExecutor is null");
- }
- return marshallerFactory.createMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getMarshalingSink(target);
- }
-
- public ObjectMessageInput getMessageInput(ByteMessageInput source) throws IOException {
- if (source == null) {
- throw new NullPointerException("source is null");
- }
- return marshallerFactory.createMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getUnmarshalingSource(source);
- }
-
- public String getLocalEndpointName() {
- return endpoint.getName();
- }
-
- public void receiveClientClose(ClientIdentifier remoteClientIdentifier, final boolean immediate, final boolean cancel, final boolean interrupt) {
- if (remoteClientIdentifier == null) {
- throw new NullPointerException("remoteClientIdentifier is null");
- }
- final ServerContextPair contextPair = serverContexts.remove(remoteClientIdentifier);
- // todo - do the whole close operation
- try {
- contextPair.clientResponder.handleClose(immediate, cancel);
- } catch (RemotingException e) {
- log.trace(e, "Failed to forward a context close");
- }
- }
-
- public void closeStream(StreamIdentifier streamIdentifier) {
- if (streamIdentifier == null) {
- throw new NullPointerException("streamIdentifier is null");
- }
- final CoreStream coreStream = streams.remove(streamIdentifier);
- try {
- coreStream.getStreamSerializer().handleClose();
- } catch (IOException e) {
- log.trace(e, "Failed to close the stream");
- }
- }
-
- public void receiveServiceClose(ServiceIdentifier serviceIdentifier) {
- if (serviceIdentifier == null) {
- throw new NullPointerException("serviceIdentifier is null");
- }
- final ServerServicePair servicePair = serverServices.remove(serviceIdentifier);
- try {
- servicePair.serviceResponder.handleClose();
- } catch (RemotingException e) {
- log.trace(e, "Failed to forward a service close");
- }
- }
-
- @SuppressWarnings ({"unchecked"})
- public void receiveOpenedContext(ServiceIdentifier remoteServiceIdentifier, ClientIdentifier remoteClientIdentifier) {
- if (remoteServiceIdentifier == null) {
- throw new NullPointerException("remoteServiceIdentifier is null");
- }
- if (remoteClientIdentifier == null) {
- throw new NullPointerException("remoteClientIdentifier is null");
- }
- try {
- // This operation needs to be idempotent
- if (! serverContexts.containsKey(remoteClientIdentifier)) {
- final ServerServicePair servicePair = serverServices.get(remoteServiceIdentifier);
- final ProtocolClientInitiatorImpl contextClient = new ProtocolClientInitiatorImpl(remoteClientIdentifier);
- final ClientResponder clientResponder = servicePair.serviceResponder.createNewClient(contextClient);
- if (serverContexts.putIfAbsent(remoteClientIdentifier, new ServerContextPair(contextClient, clientResponder)) != null) {
- clientResponder.handleClose(true, true);
- }
- }
- } catch (RemotingException e) {
- log.trace(e, "Failed to add a context to a service");
- }
- }
-
- public void receiveServiceClosing(ServiceIdentifier serviceIdentifier) {
- if (serviceIdentifier == null) {
- throw new NullPointerException("serviceIdentifier is null");
- }
- final ClientServicePair servicePair = clientServices.get(serviceIdentifier);
- try {
- servicePair.serviceInitiator.handleClosing();
- } catch (RemotingException e) {
- log.trace(e, "Failed to signal that a service was closing on the remote side");
- }
- }
-
- public void receiveClientClosing(ClientIdentifier clientIdentifier, boolean done) {
- if (clientIdentifier == null) {
- throw new NullPointerException("clientIdentifier is null");
- }
- final ClientContextPair contextPair = clientContexts.get(clientIdentifier);
- try {
- contextPair.clientInitiator.handleClosing(done);
- } catch (RemotingException e) {
- log.trace(e, "Failed to signal that a context was closing on the remote side");
- }
- }
-
- public void receiveReply(ClientIdentifier clientIdentifier, RequestIdentifier requestIdentifier, Object reply) {
- if (clientIdentifier == null) {
- throw new NullPointerException("clientIdentifier is null");
- }
- if (requestIdentifier == null) {
- throw new NullPointerException("requestIdentifier is null");
- }
- final ClientContextPair contextPair = clientContexts.get(clientIdentifier);
- if (contextPair == null) {
- log.trace("Got reply for request %s on unknown context %s", requestIdentifier, clientIdentifier);
- } else {
- final ProtocolClientResponderImpl<?, ?> contextServer = contextPair.contextServerRef.get();
- if (contextServer == null) {
- log.trace("Got reply for request %s on unknown recently leaked context %s", requestIdentifier, clientIdentifier);
- } else {
- final RequestInitiator<?> requestInitiator = (RequestInitiator<?>) contextServer.requests.get(requestIdentifier);
- if (requestInitiator == null) {
- log.trace("Got reply for unknown request %s on context %s", requestIdentifier, clientIdentifier);
- } else try {
- doSendReply(requestInitiator, reply);
- } catch (RemotingException e) {
- log.trace(e, "Failed to receive a reply");
- }
- }
- }
- }
-
- public void receiveException(ClientIdentifier clientIdentifier, RequestIdentifier requestIdentifier, RemoteExecutionException exception) {
- if (clientIdentifier == null) {
- throw new NullPointerException("clientIdentifier is null");
- }
- if (requestIdentifier == null) {
- throw new NullPointerException("requestIdentifier is null");
- }
- if (exception == null) {
- throw new NullPointerException("exception is null");
- }
- final ClientContextPair contextPair = clientContexts.get(clientIdentifier);
- if (contextPair == null) {
- log.trace("Got exception reply for request %s on unknown context %s", requestIdentifier, clientIdentifier);
- } else {
- final ProtocolClientResponderImpl<?, ?> contextServer = contextPair.contextServerRef.get();
- if (contextServer == null) {
- log.trace("Got exception reply for request %s on unknown recently leaked context %s", requestIdentifier, clientIdentifier);
- } else {
- final RequestInitiator<?> requestInitiator = (RequestInitiator<?>) contextServer.requests.get(requestIdentifier);
- if (requestInitiator == null) {
- log.trace("Got exception reply for unknown request %s on context %s", requestIdentifier, clientIdentifier);
- } else try {
- requestInitiator.handleException(exception);
- } catch (RemotingException e) {
- log.trace(e, "Failed to receive an exception reply");
- }
- }
- }
- }
-
- public void receiveCancelAcknowledge(ClientIdentifier clientIdentifier, RequestIdentifier requestIdentifier) {
- if (clientIdentifier == null) {
- throw new NullPointerException("clientIdentifier is null");
- }
- if (requestIdentifier == null) {
- throw new NullPointerException("requestIdentifier is null");
- }
- final ClientContextPair contextPair = clientContexts.get(clientIdentifier);
- if (contextPair == null) {
- log.trace("Got cancellation acknowledgement for request %s on unknown context %s", requestIdentifier, clientIdentifier);
- } else {
- final ProtocolClientResponderImpl<?, ?> contextServer = contextPair.contextServerRef.get();
- if (contextServer == null) {
- log.trace("Got cancellation acknowledgement for request %s on unknown recently leaked context %s", requestIdentifier, clientIdentifier);
- } else {
- final RequestInitiator<?> requestInitiator = (RequestInitiator<?>) contextServer.requests.get(requestIdentifier);
- if (requestInitiator == null) {
- log.trace("Got cancellation acknowledgement for unknown request %s on context %s", requestIdentifier, clientIdentifier);
- } else try {
- requestInitiator.handleCancelAcknowledge();
- } catch (RemotingException e) {
- log.trace(e, "Failed to receive a cancellation acknowledgement");
- }
- }
- }
- }
-
- public void receiveCancelRequest(ClientIdentifier remoteClientIdentifier, RequestIdentifier requestIdentifier, boolean mayInterrupt) {
- if (remoteClientIdentifier == null) {
- throw new NullPointerException("remoteClientIdentifier is null");
- }
- if (requestIdentifier == null) {
- throw new NullPointerException("requestIdentifier is null");
- }
- final ServerContextPair contextPair = serverContexts.get(remoteClientIdentifier);
- final RequestResponder<?> requestResponder = (RequestResponder<?>) contextPair.contextClient.requests.get(requestIdentifier);
- try {
- requestResponder.handleCancelRequest(mayInterrupt);
- } catch (RemotingException e) {
- log.trace(e, "Failed to receive a cancellation request");
- }
- }
-
- public void receiveStreamData(StreamIdentifier streamIdentifier, ObjectMessageInput data) {
- if (streamIdentifier == null) {
- throw new NullPointerException("streamIdentifier is null");
- }
- if (data == null) {
- throw new NullPointerException("data is null");
- }
- final CoreStream coreStream = streams.get(streamIdentifier);
- if (coreStream == null) {
- log.trace("Received stream data on an unknown context %s", streamIdentifier);
- } else {
- coreStream.receiveStreamData(data);
- }
- }
-
- @SuppressWarnings ({"unchecked"})
- public void receiveRemoteSideReady(String remoteEndpointName) {
- state.waitFor(State.CONNECTING);
- state.requireTransitionExclusive(State.CONNECTING, State.UP);
- try {
- CoreSession.this.remoteEndpointName = remoteEndpointName;
- } finally {
- state.releaseExclusive();
- }
- }
-
- @SuppressWarnings ({"unchecked"})
- public void receiveRequest(final ClientIdentifier remoteClientIdentifier, final RequestIdentifier requestIdentifier, final Object request) {
- if (remoteClientIdentifier == null) {
- throw new NullPointerException("remoteClientIdentifier is null");
- }
- if (requestIdentifier == null) {
- throw new NullPointerException("requestIdentifier is null");
- }
- final ServerContextPair contextPair = serverContexts.get(remoteClientIdentifier);
- if (contextPair == null) {
- log.trace("Received a request on an unknown context %s", remoteClientIdentifier);
- return;
- }
- try {
- final RequestInitiator requestInitiator = contextPair.contextClient.addClient(requestIdentifier);
- final RequestResponder requestResponder = contextPair.clientResponder.createNewRequest(requestInitiator);
- requestResponder.handleRequest(request, executor);
- } catch (RemotingException e) {
- e.printStackTrace();
- }
- }
- }
-
- private final class WeakProtocolContextServerReference<I, O> extends WeakReference<ProtocolClientResponderImpl<I, O>> {
- private final ClientContextPair<I, O> contextPair;
-
- private WeakProtocolContextServerReference(ProtocolClientResponderImpl<I, O> referent, ClientContextPair<I, O> contextPair) {
- super(referent);
- this.contextPair = contextPair;
- }
-
- public ProtocolClientResponderImpl<I, O> get() {
- return super.get();
- }
-
- public boolean enqueue() {
- try {
- clientContexts.remove(contextPair.clientIdentifier, contextPair);
- // todo close?
- } finally {
- return super.enqueue();
- }
- }
- }
-
- private final class ClientContextPair<I, O> {
- private final ClientInitiator clientInitiator;
- private final WeakProtocolContextServerReference<I, O> contextServerRef;
- private final ClientIdentifier clientIdentifier;
-
- private ClientContextPair(final ClientInitiator clientInitiator, final ProtocolClientResponderImpl<I, O> contextServer, final ClientIdentifier clientIdentifier) {
- this.clientInitiator = clientInitiator;
- this.clientIdentifier = clientIdentifier;
- contextServerRef = new WeakProtocolContextServerReference<I, O>(contextServer, this);
- // todo - auto-cleanup
- }
- }
-
- private static final class ServerContextPair<I, O> {
- private final ProtocolClientInitiatorImpl<I, O> contextClient;
- private final ClientResponder<I, O> clientResponder;
-
- private ServerContextPair(final ProtocolClientInitiatorImpl<I, O> contextClient, final ClientResponder<I, O> clientResponder) {
- if (contextClient == null) {
- throw new NullPointerException("clientInitiator is null");
- }
- if (clientResponder == null) {
- throw new NullPointerException("clientResponder is null");
- }
- this.contextClient = contextClient;
- this.clientResponder = clientResponder;
- }
- }
-
- private static final class ClientServicePair<I, O> {
- private final ServiceInitiator serviceInitiator;
- private final ProtocolServiceResponderImpl<I, O> serviceServer;
-
- private ClientServicePair(final ServiceInitiator serviceInitiator, final ProtocolServiceResponderImpl<I, O> serviceServer) {
- if (serviceInitiator == null) {
- throw new NullPointerException("serviceInitiator is null");
- }
- if (serviceServer == null) {
- throw new NullPointerException("serviceResponder is null");
- }
- this.serviceInitiator = serviceInitiator;
- this.serviceServer = serviceServer;
- }
- }
-
- private static final class ServerServicePair<I, O> {
- private final ProtocolServiceInitiatorImpl serviceClient;
- private final ServiceResponder<I, O> serviceResponder;
-
- private ServerServicePair(final ProtocolServiceInitiatorImpl serviceClient, final ServiceResponder<I, O> serviceResponder) {
- if (serviceClient == null) {
- throw new NullPointerException("serviceInitiator is null");
- }
- if (serviceResponder == null) {
- throw new NullPointerException("serviceResponder is null");
- }
- this.serviceClient = serviceClient;
- this.serviceResponder = serviceResponder;
- }
- }
-
- private final class ProtocolServiceInitiatorImpl implements ServiceInitiator {
- private final ServiceIdentifier serviceIdentifier;
-
- public ProtocolServiceInitiatorImpl(final ServiceIdentifier serviceIdentifier) {
- if (serviceIdentifier == null) {
- throw new NullPointerException("serviceIdentifier is null");
- }
- this.serviceIdentifier = serviceIdentifier;
- }
-
- public void handleClosing() throws RemotingException {
- try {
- protocolHandler.sendServiceClosing(serviceIdentifier);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send service closing message: " + e.getMessage(), e);
- }
- }
- }
-
- private final class ProtocolServiceResponderImpl<I, O> implements ServiceResponder<I, O> {
- private final ServiceIdentifier serviceIdentifier;
-
- public ProtocolServiceResponderImpl(final ServiceIdentifier serviceIdentifier) {
- this.serviceIdentifier = serviceIdentifier;
- }
-
- public void handleClose() throws RemotingException {
- try {
- protocolHandler.sendServiceClose(serviceIdentifier);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send service close message: " + e.getMessage(), e);
- }
- }
-
- public ClientResponder<I, O> createNewClient(final ClientInitiator clientInitiator) throws RemotingException {
- try {
- final ClientIdentifier clientIdentifier = protocolHandler.openClient(serviceIdentifier);
- if (clientIdentifier == null) {
- throw new NullPointerException("clientIdentifier is null");
- }
- clientContexts.put(clientIdentifier, new ClientContextPair<I, O>(clientInitiator, new ProtocolClientResponderImpl<I, O>(clientIdentifier), clientIdentifier));
- return new ProtocolClientResponderImpl<I, O>(clientIdentifier);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to open a context: " + e.getMessage(), e);
- }
- }
- }
-
- private final class ProtocolClientInitiatorImpl<I, O> implements ClientInitiator {
- private final ClientIdentifier clientIdentifier;
- private final ConcurrentMap<RequestIdentifier, RequestResponder<I>> requests = CollectionUtil.concurrentMap();
-
- public ProtocolClientInitiatorImpl(final ClientIdentifier clientIdentifier) {
- this.clientIdentifier = clientIdentifier;
- }
-
- public void handleClosing(boolean done) throws RemotingException {
- try {
- if (state.inHold(State.UP)) {
- protocolHandler.sendClientClosing(clientIdentifier, done);
- }
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send context closing message: " + e.getMessage(), e);
- }
- }
-
- private RequestInitiator<O> addClient(RequestIdentifier identifier) {
- return new ProtocolRequestInitiatorImpl<O>(clientIdentifier, identifier);
- }
-
- private final class ProtocolRequestInitiatorImpl<O> implements RequestInitiator<O> {
- private final ClientIdentifier clientIdentifer;
- private final RequestIdentifier requestIdentifer;
-
- public ProtocolRequestInitiatorImpl(final ClientIdentifier clientIdentifer, final RequestIdentifier requestIdentifer) {
- this.clientIdentifer = clientIdentifer;
- this.requestIdentifer = requestIdentifer;
- }
-
- public void handleReply(final O reply) throws RemotingException {
- try {
- protocolHandler.sendReply(clientIdentifer, requestIdentifer, reply);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send a reply: " + e.getMessage(), e);
- } finally {
- requests.remove(requestIdentifer);
- }
- }
-
- public void handleException(final RemoteExecutionException cause) throws RemotingException {
- try {
- protocolHandler.sendException(clientIdentifer, requestIdentifer, cause);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send an exception: " + e.getMessage(), e);
- } finally {
- requests.remove(requestIdentifer);
- }
- }
-
- public void handleCancelAcknowledge() throws RemotingException {
- try {
- protocolHandler.sendCancelAcknowledge(clientIdentifer, requestIdentifer);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send a cancel acknowledgement: " + e.getMessage(), e);
- } finally {
- requests.remove(requestIdentifer);
- }
- }
- }
- }
-
- private final class ProtocolClientResponderImpl<I, O> implements ClientResponder<I, O> {
- private final ClientIdentifier clientIdentifier;
- private final ConcurrentMap<RequestIdentifier, RequestInitiator<O>> requests = CollectionUtil.concurrentMap();
-
- public ProtocolClientResponderImpl(final ClientIdentifier clientIdentifier) {
- this.clientIdentifier = clientIdentifier;
- }
-
- public RequestResponder<I> createNewRequest(final RequestInitiator<O> requestInitiator) throws RemotingException {
- try {
- final RequestIdentifier requestIdentifier = protocolHandler.openRequest(clientIdentifier);
- if (requestIdentifier == null) {
- throw new NullPointerException("requestIdentifier is null");
- }
- requests.put(requestIdentifier, requestInitiator);
- return new ProtocolRequestResponderImpl(requestIdentifier);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to open a request: " + e.getMessage(), e);
- }
- }
-
- public void handleClose(final boolean immediate, final boolean cancel) throws RemotingException {
- try {
- protocolHandler.sendClientClose(clientIdentifier, immediate, cancel, false);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send context close message: " + e.getMessage(), e);
- }
- }
-
- private final class ProtocolRequestResponderImpl implements RequestResponder<I> {
- private final RequestIdentifier requestIdentifier;
-
- public ProtocolRequestResponderImpl(final RequestIdentifier requestIdentifier) {
- this.requestIdentifier = requestIdentifier;
- }
-
- public void handleRequest(final I request, final Executor streamExecutor) throws RemotingException {
- try {
- protocolHandler.sendRequest(clientIdentifier, requestIdentifier, request, streamExecutor);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send a request: " + e.getMessage(), e);
- }
- }
-
- public void handleCancelRequest(final boolean mayInterrupt) throws RemotingException {
- try {
- protocolHandler.sendCancelRequest(clientIdentifier, requestIdentifier, mayInterrupt);
- } catch (RemotingException e) {
- throw e;
- } catch (IOException e) {
- throw new RemotingException("Failed to send a cancel request: " + e.getMessage(), e);
- }
- }
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreStream.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreStream.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreStream.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,100 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.io.IOException;
-import java.util.concurrent.Executor;
-import org.jboss.xnio.log.Logger;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
-
-/**
- *
- */
-public final class CoreStream {
- private static final Logger log = Logger.getLogger(CoreStream.class);
-
- private final CoreSession coreSession;
- private final Executor executor;
- private final StreamIdentifier streamIdentifier;
- private final StreamSerializer streamSerializer;
-
- private final ProtocolHandler protocolHandler;
-
- private final StreamContext streamContext;
-
- /**
- * A new stream (local side). The {@code executor} must specify an executor that is guaranteed to execute all tasks in order.
- *
- * @param coreSession the session
- * @param executor the executor to use to handle data
- * @param streamIdentifier the stream identifier
- * @param streamSerializerFactory the stream serializer
- * @param local the local side
- */
- CoreStream(final CoreSession coreSession, final Executor executor, final StreamIdentifier streamIdentifier, final StreamSerializerFactory streamSerializerFactory, final Object local) throws IOException {
- this.coreSession = coreSession;
- this.executor = executor;
- this.streamIdentifier = streamIdentifier;
- protocolHandler = coreSession.getProtocolHandler();
- streamContext = new StreamContextImpl();
- streamSerializer = streamSerializerFactory.getLocalSide(streamContext, local);
- }
-
- /**
- * A new stream (remote side). The {@code executor} must specify an executor that is guaranteed to execute all tasks in order.
- *
- * @param coreSession the session
- * @param executor the executor to use to handle data
- * @param streamIdentifier the stream identifier
- * @param streamSerializerFactory the stream serializer
- */
- CoreStream(final CoreSession coreSession, final Executor executor, final StreamIdentifier streamIdentifier, final StreamSerializerFactory streamSerializerFactory) throws IOException {
- this.coreSession = coreSession;
- this.executor = executor;
- this.streamIdentifier = streamIdentifier;
- protocolHandler = coreSession.getProtocolHandler();
- streamContext = new StreamContextImpl();
- streamSerializer = streamSerializerFactory.getRemoteSide(streamContext);
- }
-
- public void receiveStreamData(final ObjectMessageInput data) {
- executor.execute(new Runnable() {
- public void run() {
- try {
- streamSerializer.handleData(data);
- } catch (Exception e) {
- log.trace(e, "Stream failed to handle incoming data (%s)", data);
- }
- }
- });
- }
-
- public RemoteStreamSerializer getRemoteSerializer() {
- return (RemoteStreamSerializer) streamSerializer;
- }
-
- public StreamSerializer getStreamSerializer() {
- return streamSerializer;
- }
-
- // stream context
-
- private final class StreamContextImpl implements StreamContext {
-
- private StreamContextImpl() {
- }
-
- public ObjectMessageOutput writeMessage() throws IOException {
- return protocolHandler.sendStreamData(streamIdentifier, executor);
- }
-
- public void close() throws IOException {
- try {
- protocolHandler.closeStream(streamIdentifier);
- } finally {
- // todo clean up stream
-// coreSession.removeStream(streamIdentifier);
- }
- }
- }
-}
Copied: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java (from rev 4339, remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java)
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -0,0 +1,132 @@
+package org.jboss.cx.remoting.core;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import org.jboss.cx.remoting.Endpoint;
+import org.jboss.cx.remoting.RequestListener;
+import org.jboss.cx.remoting.SessionListener;
+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.util.AtomicStateMachine;
+import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.cx.remoting.util.NamingThreadFactory;
+import org.jboss.cx.remoting.version.Version;
+import org.jboss.xnio.log.Logger;
+
+/**
+ *
+ */
+public class EndpointImpl implements Endpoint {
+
+ static {
+ // Print Remoting "greeting" message
+ Logger.getLogger("org.jboss.cx.remoting").info("JBoss Remoting version %s", Version.VERSION);
+ }
+
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
+ INITIAL,
+ UP,
+ DOWN;
+
+ public boolean isReachable(final State dest) {
+ return compareTo(dest) < 0;
+ }
+ }
+
+ private String name;
+
+ private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.INITIAL);
+ private final Set<SessionListener> sessionListeners = CollectionUtil.synchronizedSet(new LinkedHashSet<SessionListener>());
+
+ private OrderedExecutorFactory orderedExecutorFactory;
+ private ExecutorService executorService;
+
+ private final ConcurrentMap<Object, Object> endpointMap = CollectionUtil.concurrentMap();
+
+ public EndpointImpl() {
+ }
+
+ // Dependencies
+
+ private Executor executor;
+
+ public Executor getExecutor() {
+ return executor;
+ }
+
+ public Executor getOrderedExecutor() {
+ return orderedExecutorFactory.getOrderedExecutor();
+ }
+
+ public void setExecutor(final Executor executor) {
+ this.executor = executor;
+ orderedExecutorFactory = new OrderedExecutorFactory(executor);
+ }
+
+ // Configuration
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ // Lifecycle
+
+ public void create() {
+ // todo security check
+ }
+
+ public void start() {
+ // todo security check
+ if (executor == null) {
+ executorService = Executors.newCachedThreadPool(new NamingThreadFactory(Executors.defaultThreadFactory(), "Remoting endpoint %s"));
+ setExecutor(executorService);
+ }
+ state.requireTransition(State.INITIAL, State.UP);
+ }
+
+ public void stop() {
+ // todo security check
+ if (executorService != null) {
+ executorService.shutdown();
+ executorService = null;
+ }
+ // todo
+ }
+
+ public void destroy() {
+ executor = null;
+ }
+
+ // Endpoint implementation
+
+ public ConcurrentMap<Object, Object> getAttributes() {
+ return endpointMap;
+ }
+
+ public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) {
+ return new RemoteClientEndpointLocalImpl<I, O>(this, requestListener);
+ }
+
+ public <I, O> RemoteServiceEndpoint<I, O> createService(final RequestListener<I, O> requestListener) {
+ return new RemoteServiceEndpointLocalImpl<I, O>(this, requestListener);
+ }
+
+ public void addSessionListener(final SessionListener sessionListener) {
+ // TODO security check
+ sessionListeners.add(sessionListener);
+ }
+
+ public void removeSessionListener(final SessionListener sessionListener) {
+ // TODO security check
+ sessionListeners.remove(sessionListener);
+ }
+}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientInitiator.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientInitiator.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientInitiator.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,9 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-/**
- *
- */
-public interface ProtocolClientInitiator<I, O> extends ClientInitiator {
- RequestInitiator<O> addRequest(RequestIdentifier requestIdentifier);
-
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientResponder.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientResponder.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientResponder.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,8 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-/**
- *
- */
-public interface ProtocolClientResponder<I, O> extends ClientResponder<I, O> {
- RequestInitiator<O> getRequestClient(RequestIdentifier requestIdentifier);
-}
Added: 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 (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -0,0 +1,98 @@
+/*
+ * 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.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
+import org.jboss.cx.remoting.spi.remote.ReplyHandler;
+import org.jboss.cx.remoting.spi.remote.Handle;
+import org.jboss.cx.remoting.spi.SpiUtils;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.Client;
+import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.RequestListener;
+import org.jboss.cx.remoting.RemoteExecutionException;
+import org.jboss.xnio.log.Logger;
+import java.util.concurrent.Executor;
+
+/**
+ *
+ */
+public final class RemoteClientEndpointLocalImpl<I, O> implements RemoteClientEndpoint<I, O> {
+
+ private final EndpointImpl endpointImpl;
+ private final RequestListener<I, O> requestListener;
+ private final Executor executor;
+ private final ClientContextImpl clientContext = new ClientContextImpl();
+
+ private static final Logger log = Logger.getLogger(RemoteClientEndpointLocalImpl.class);
+
+ public RemoteClientEndpointLocalImpl(final EndpointImpl endpointImpl, final RequestListener<I, O> requestListener) {
+ this.endpointImpl = endpointImpl;
+ this.requestListener = requestListener;
+ executor = endpointImpl.getExecutor();
+ }
+
+ public RemoteClientEndpointLocalImpl(final EndpointImpl endpointImpl, final RemoteServiceEndpointLocalImpl<I, O> service, final RequestListener<I, O> requestListener) {
+ this.endpointImpl = endpointImpl;
+ this.requestListener = requestListener;
+ executor = endpointImpl.getExecutor();
+ }
+
+ public RemoteRequestContext receiveRequest(final I request, final ReplyHandler<O> replyHandler) {
+ final RequestContextImpl<O> context = new RequestContextImpl<O>(replyHandler, clientContext);
+ executor.execute(new Runnable() {
+ public void run() {
+ try {
+ requestListener.handleRequest(context, request);
+ } catch (RemoteExecutionException e) {
+ SpiUtils.safeHandleException(replyHandler, e.getMessage(), e.getCause());
+ } catch (Throwable t) {
+ SpiUtils.safeHandleException(replyHandler, "Unexpected exception in request listener", t);
+ }
+ }
+ });
+ return new RemoteRequestContext() {
+ public void cancel() {
+ context.cancel();
+ }
+ };
+ }
+
+ public Handle<RemoteClientEndpoint<I, O>> getHandle() throws RemotingException {
+ return null;
+ }
+
+ public Client<I, O> getClient() throws RemotingException {
+ return null;
+ }
+
+ public void autoClose() {
+ }
+
+ public void close() throws RemotingException {
+ }
+
+ public void addCloseHandler(final CloseHandler<RemoteClientEndpoint<I, O>> handler) {
+ }
+}
Added: 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 (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -0,0 +1,66 @@
+/*
+ * 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.spi.remote.RemoteServiceEndpoint;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.remote.Handle;
+import org.jboss.cx.remoting.RequestListener;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.ClientSource;
+import org.jboss.cx.remoting.CloseHandler;
+
+/**
+ *
+ */
+public final class RemoteServiceEndpointLocalImpl<I, O> implements RemoteServiceEndpoint<I, O> {
+
+ private final EndpointImpl endpointImpl;
+ private final RequestListener<I, O> requestListener;
+
+ public RemoteServiceEndpointLocalImpl(final EndpointImpl endpointImpl, final RequestListener<I, O> requestListener) {
+ this.endpointImpl = endpointImpl;
+ this.requestListener = requestListener;
+ }
+
+ public RemoteClientEndpoint<I, O> openClient() throws RemotingException {
+ return new RemoteClientEndpointLocalImpl<I, O>(endpointImpl, this, requestListener);
+ }
+
+ public Handle<RemoteServiceEndpoint<I, O>> getHandle() throws RemotingException {
+ return null;
+ }
+
+ public ClientSource<I, O> getClientSource() throws RemotingException {
+ return null;
+ }
+
+ public void autoClose() {
+ }
+
+ public void close() throws RemotingException {
+ }
+
+ public void addCloseHandler(final CloseHandler<RemoteServiceEndpoint<I, O>> handler) {
+ }
+}
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -0,0 +1,119 @@
+/*
+ * 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.RequestContext;
+import org.jboss.cx.remoting.ClientContext;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.RequestCancelHandler;
+import org.jboss.cx.remoting.core.util.TaggingExecutor;
+import org.jboss.cx.remoting.spi.remote.ReplyHandler;
+import org.jboss.cx.remoting.spi.SpiUtils;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ *
+ */
+public final class RequestContextImpl<O> implements RequestContext<O> {
+
+ private final AtomicBoolean closed = new AtomicBoolean();
+ private final Object cancelLock = new Object();
+ private final ReplyHandler<O> replyHandler;
+ private final ClientContextImpl clientContext;
+
+ private final AtomicBoolean cancelled = new AtomicBoolean();
+ // @protectedby cancelLock
+ private Set<RequestCancelHandler<O>> cancelHandlers;
+ private final TaggingExecutor executor;
+
+ RequestContextImpl(final ReplyHandler<O> replyHandler, final ClientContextImpl clientContext) {
+ this.replyHandler = replyHandler;
+ this.clientContext = clientContext;
+ executor = new TaggingExecutor(clientContext.getExecutor());
+ }
+
+ public ClientContext getContext() {
+ return clientContext;
+ }
+
+ public boolean isCancelled() {
+ return cancelled.get();
+ }
+
+ public void sendReply(final O reply) throws RemotingException, IllegalStateException {
+ if (! closed.getAndSet(true)) {
+ replyHandler.handleReply(reply);
+ } else {
+ throw new IllegalStateException("Reply already sent");
+ }
+ }
+
+ public void sendFailure(final String msg, final Throwable cause) throws RemotingException, IllegalStateException {
+ if (! closed.getAndSet(true)) {
+ replyHandler.handleException(msg, cause);
+ } else {
+ throw new IllegalStateException("Reply already sent");
+ }
+ }
+
+ public void sendCancelled() throws RemotingException, IllegalStateException {
+ if (! closed.getAndSet(true)) {
+ replyHandler.handleCancellation();
+ } else {
+ throw new IllegalStateException("Reply already sent");
+ }
+ }
+
+ public void addCancelHandler(final RequestCancelHandler<O> handler) {
+ synchronized (cancelLock) {
+ if (cancelled.get()) {
+ SpiUtils.safeNotifyCancellation(handler, this, false);
+ } else {
+ if (cancelHandlers == null) {
+ cancelHandlers = new HashSet<RequestCancelHandler<O>>();
+ }
+ cancelHandlers.add(handler);
+ }
+ }
+ }
+
+ public void execute(final Runnable command) {
+ executor.execute(command);
+ }
+
+ protected void cancel() {
+ if (! cancelled.getAndSet(true)) {
+ synchronized (cancelLock) {
+ if (cancelHandlers != null) {
+ for (RequestCancelHandler<O> handler : cancelHandlers) {
+ SpiUtils.safeNotifyCancellation(handler, this, false);
+ }
+ cancelHandlers = null;
+ }
+ }
+ executor.interruptAll();
+ }
+ }
+}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestInitiator.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestInitiator.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestInitiator.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,17 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RemotingException;
-
-/**
- *
- */
-public interface RequestInitiator<O> {
- // Outbound protocol messages
-
- void handleReply(final O reply) throws RemotingException;
-
- void handleException(final RemoteExecutionException cause) throws RemotingException;
-
- void handleCancelAcknowledge() throws RemotingException;
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestResponder.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestResponder.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestResponder.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,16 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.RemotingException;
-
-/**
- *
- */
-public interface RequestResponder<I> {
-
- // Outbound protocol messages
-
- void handleRequest(I request, final Executor streamExecutor) throws RemotingException;
-
- void handleCancelRequest(boolean mayInterrupt) throws RemotingException;
-}
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceContextImpl.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceContextImpl.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.core;
+
+import org.jboss.cx.remoting.ServiceContext;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.CloseHandler;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ *
+ */
+public final class ServiceContextImpl implements ServiceContext {
+
+ public ConcurrentMap<Object, Object> getAttributes() {
+ return null;
+ }
+
+ public void close() throws RemotingException {
+ }
+
+ public void addCloseHandler(final CloseHandler<ServiceContext> serviceContextCloseHandler) {
+ }
+}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceInitiator.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceInitiator.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceInitiator.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,10 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import org.jboss.cx.remoting.RemotingException;
-
-/**
- *
- */
-public interface ServiceInitiator {
- void handleClosing() throws RemotingException;
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceResponder.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceResponder.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ServiceResponder.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,12 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import org.jboss.cx.remoting.RemotingException;
-
-/**
- *
- */
-public interface ServiceResponder<I, O> {
- void handleClose() throws RemotingException;
-
- ClientResponder<I, O> createNewClient(ClientInitiator clientInitiator) throws RemotingException;
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/StreamMarker.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/StreamMarker.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/StreamMarker.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,51 +0,0 @@
-package org.jboss.cx.remoting.core;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
-
-/**
- *
- */
-public final class StreamMarker implements Externalizable {
-
- private static final long serialVersionUID = 1L;
-
- private Class<? extends StreamSerializerFactory> factoryClass;
- private StreamIdentifier streamIdentifier;
-
- public StreamMarker(final Class<? extends StreamSerializerFactory> factoryClass, final StreamIdentifier streamIdentifier) {
- if (factoryClass == null) {
- throw new NullPointerException("factoryClass is null");
- }
- if (streamIdentifier == null) {
- throw new NullPointerException("streamIdentifier is null");
- }
- this.factoryClass = factoryClass;
- this.streamIdentifier = streamIdentifier;
- }
-
- public StreamMarker() {
- }
-
- public Class<? extends StreamSerializerFactory> getFactoryClass() {
- return factoryClass;
- }
-
- public StreamIdentifier getStreamIdentifier() {
- return streamIdentifier;
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(factoryClass);
- out.writeObject(streamIdentifier);
- }
-
- @SuppressWarnings ({"unchecked"})
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- factoryClass = (Class<? extends StreamSerializerFactory>) in.readObject();
- streamIdentifier = (StreamIdentifier) in.readObject();
- }
-}
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-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarhsaller.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,43 +1,155 @@
package org.jboss.cx.remoting.core.marshal;
import java.io.IOException;
+import java.io.ObjectStreamClass;
+import java.nio.ByteBuffer;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+import java.util.HashMap;
import org.jboss.cx.remoting.spi.marshal.Marshaller;
import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
-import org.jboss.cx.remoting.util.ByteMessageInput;
-import org.jboss.cx.remoting.util.ByteMessageOutput;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
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 {
+public class JBossSerializationMarhsaller implements Marshaller<ByteBuffer> {
private static final long serialVersionUID = -8197192536466706414L;
+ private final BufferAllocator<ByteBuffer> allocator;
private final ObjectResolver resolver;
private final ClassLoader classLoader;
- public JBossSerializationMarhsaller(final ObjectResolver resolver, final ClassLoader classLoader) {
+ public JBossSerializationMarhsaller(final BufferAllocator<ByteBuffer> allocator, final ObjectResolver resolver, final ClassLoader classLoader) {
+ this.allocator = allocator;
this.resolver = resolver;
this.classLoader = classLoader;
}
- public ObjectMessageOutput getMessageOutput(final ByteMessageOutput byteMessageOutput) throws IOException {
- return new JBossSerializationObjectMessageOutput(resolver, byteMessageOutput);
+ public ObjectSink<Object> getMarshalingSink(final ObjectSink<ByteBuffer> bufferSink) throws IOException {
+ return new MarshalingSink(bufferSink, allocator, resolver);
}
- public ObjectMessageInput getMessageInput(final ByteMessageInput byteMessageInput) throws IOException {
- return new JBossSerializationObjectMessageInput(resolver, byteMessageInput, classLoader);
+ public ObjectSource<Object> getUnmarshalingSource(final ObjectSource<ByteBuffer> bufferSource) throws IOException {
+ return new MarshalingSource(bufferSource, allocator, resolver, classLoader);
}
- public ObjectSink getMarshalingSink(final ObjectSink bufferSink) throws IOException {
- return null;
+ 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 void accept(final Object instance) throws IOException {
+ stream.writeObject(instance);
+ }
+
+ public void flush() throws IOException {
+ stream.flush();
+ }
+
+ public void close() throws IOException {
+ stream.close();
+ }
}
- public ObjectSource getUnmarshalingSource(final ObjectSource bufferSource) throws IOException {
- return null;
+ 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));
+ enableReplaceObject(true);
+ this.resolver = resolver;
+ }
+
+ protected Object replaceObject(final Object obj) throws IOException {
+ 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-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarshallerFactory.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,16 +1,18 @@
package org.jboss.cx.remoting.core.marshal;
import java.io.IOException;
+import java.nio.ByteBuffer;
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;
/**
*
*/
-public class JBossSerializationMarshallerFactory implements MarshallerFactory {
+public class JBossSerializationMarshallerFactory implements MarshallerFactory<ByteBuffer> {
- public Marshaller createRootMarshaller(final ObjectResolver resolver, final ClassLoader classLoader) throws IOException {
- return new JBossSerializationMarhsaller(resolver, classLoader);
+ public Marshaller<ByteBuffer> createMarshaller(final BufferAllocator<ByteBuffer> allocator, final ObjectResolver resolver, final ClassLoader classLoader) throws IOException {
+ return new JBossSerializationMarhsaller(allocator, resolver, classLoader);
}
}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationObjectMessageInput.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationObjectMessageInput.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationObjectMessageInput.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,108 +0,0 @@
-package org.jboss.cx.remoting.core.marshal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectStreamClass;
-import java.lang.reflect.Proxy;
-import java.util.HashMap;
-import java.util.Map;
-import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
-import org.jboss.cx.remoting.util.ByteMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.serial.io.JBossObjectInputStream;
-
-/**
- *
- */
-public class JBossSerializationObjectMessageInput extends JBossObjectInputStream implements ObjectMessageInput {
-
- private final ObjectResolver resolver;
- private final ByteMessageInput dataMessageInput;
-
- public JBossSerializationObjectMessageInput(final ObjectResolver resolver, final ByteMessageInput dataMessageInput, final ClassLoader classLoader) throws IOException {
- super(new InputStream() {
-
- public int read(final byte b[]) throws IOException {
- return dataMessageInput.read(b);
- }
-
- public int read(final byte b[], final int off, final int len) throws IOException {
- return dataMessageInput.read(b, off, len);
- }
-
- public int available() throws IOException {
- return dataMessageInput.remaining();
- }
-
- public void close() throws IOException {
- dataMessageInput.close();
- }
-
- public boolean markSupported() {
- return false;
- }
-
- public int read() throws IOException {
- return dataMessageInput.read();
- }
- }, classLoader);
- if (resolver == null) {
- throw new NullPointerException("resolver is null");
- }
- if (dataMessageInput == null) {
- throw new NullPointerException("dataMessageInput is null");
- }
- if (classLoader == null) {
- throw new NullPointerException("classLoader is null");
- }
- enableResolveObject(true);
- this.resolver = resolver;
- this.dataMessageInput = dataMessageInput;
- }
-
- public int remaining() {
- return dataMessageInput.remaining();
- }
-
- protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
- final String name = desc.getName();
- ClassLoader classLoader = getClassLoader();
- 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 ClassLoader classLoader = getClassLoader();
- 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);
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationObjectMessageOutput.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationObjectMessageOutput.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationObjectMessageOutput.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,58 +0,0 @@
-package org.jboss.cx.remoting.core.marshal;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
-import org.jboss.cx.remoting.util.ByteMessageOutput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.serial.io.JBossObjectOutputStream;
-
-/**
- *
- */
-public class JBossSerializationObjectMessageOutput extends JBossObjectOutputStream implements ObjectMessageOutput {
-
- private final ObjectResolver resolver;
- private final ByteMessageOutput dataMessageOutput;
-
- public JBossSerializationObjectMessageOutput(final ObjectResolver resolver, final ByteMessageOutput dataMessageOutput) throws IOException {
- super(new OutputStream() {
- public void write(final int b) throws IOException {
- dataMessageOutput.write(b);
- }
-
- public void write(final byte b[]) throws IOException {
- dataMessageOutput.write(b);
- }
-
- public void write(final byte b[], final int off, final int len) throws IOException {
- dataMessageOutput.write(b, off, len);
- }
-
- public void flush() throws IOException {
- dataMessageOutput.flush();
- }
-
- public void close() throws IOException {
- dataMessageOutput.close();
- }
- });
- enableReplaceObject(true);
- this.resolver = resolver;
- this.dataMessageOutput = dataMessageOutput;
- }
-
- public void commit() throws IOException {
- flush();
- dataMessageOutput.commit();
- }
-
- public int getBytesWritten() throws IOException {
- flush();
- return dataMessageOutput.getBytesWritten();
- }
-
- protected Object replaceObject(final Object obj) throws IOException {
- return resolver.writeReplace(obj);
- }
-}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/StreamResolver.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/StreamResolver.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/StreamResolver.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -2,7 +2,6 @@
import java.io.IOException;
import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.core.StreamMarker;
import org.jboss.cx.remoting.core.util.OrderedExecutorFactory;
import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
@@ -29,11 +28,7 @@
}
public Object readResolve(final Object original) throws IOException {
- if (original instanceof StreamMarker) {
- StreamMarker streamMarker = (StreamMarker) original;
- return null;
- } else {
- return original;
- }
+ // todo
+ return null;
}
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/service/ClassLoaderResourceListener.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/service/ClassLoaderResourceListener.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/service/ClassLoaderResourceListener.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -31,7 +31,7 @@
this.classLoader = classLoader;
}
- public void handleRequest(final RequestContext<ClassLoaderResourceReply> requestContext, final ClassLoaderResourceRequest request) throws RemoteExecutionException, InterruptedException {
+ public void handleRequest(final RequestContext<ClassLoaderResourceReply> requestContext, final ClassLoaderResourceRequest request) throws RemoteExecutionException {
try {
final Enumeration<URL> urlResources = classLoader.getResources(request.getName());
final Enumeration<RemoteResource> actualResources = CollectionUtil.translate(urlResources, new Translator<URL, RemoteResource>() {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/service/ServiceLocatorListener.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/service/ServiceLocatorListener.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/service/ServiceLocatorListener.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -45,7 +45,7 @@
private final ConcurrentMap<String, ConcurrentMap<String, ClientSource<?, ?>>> deployments = syncMap();
- public void handleRequest(final RequestContext<ServiceReply<I, O>> requestContext, final ServiceRequest<I, O> request) throws RemoteExecutionException, InterruptedException {
+ public void handleRequest(final RequestContext<ServiceReply<I, O>> requestContext, final ServiceRequest<I, O> request) throws RemoteExecutionException {
final URI uri = request.getUri();
final ServiceURI serviceURI = new ServiceURI(uri);
final String endpointName = serviceURI.getEndpointName();
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/DefaultStreamDetector.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/DefaultStreamDetector.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/DefaultStreamDetector.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -22,9 +22,9 @@
} else if (candidate instanceof ObjectSource) {
return new ObjectSourceStreamSerializerFactory();
} else if (candidate instanceof ObjectSink) {
- return new ObjectSinkStreamSerializerFactory();
+ return null;
} else if (candidate instanceof Iterator) {
- return new IteratorStreamSerializerFactory();
+ return null;
} else {
return null;
}
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-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/InputStreamStreamSerializerFactory.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -44,7 +44,8 @@
}
public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
- return new RemoteInputStream(taskList, futureChannel);
+// return new RemoteInputStream(taskList, futureChannel);
+ return null;
}
public BufferAllocator<ByteBuffer> getAllocator() {
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/IteratorStreamSerializerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/IteratorStreamSerializerFactory.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/IteratorStreamSerializerFactory.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,29 +0,0 @@
-package org.jboss.cx.remoting.core.stream;
-
-import java.io.IOException;
-import java.util.Iterator;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
-import org.jboss.cx.remoting.stream.ObjectSource;
-import org.jboss.cx.remoting.stream.Streams;
-import org.jboss.xnio.channels.StreamChannel;
-import org.jboss.xnio.IoHandler;
-import org.jboss.xnio.Client;
-
-/**
- *
- */
-public final class IteratorStreamSerializerFactory implements StreamSerializerFactory {
-
- private static final long serialVersionUID = 5106872230130868988L;
-
- private
-
- public IoHandler<? super StreamChannel> getLocalSide(final Object localSide) throws IOException {
- return null;
- }
-
- public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
- return null;
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSinkStreamSerializerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSinkStreamSerializerFactory.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSinkStreamSerializerFactory.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,100 +0,0 @@
-package org.jboss.cx.remoting.core.stream;
-
-import java.io.IOException;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
-import org.jboss.cx.remoting.stream.ObjectSink;
-
-/**
- *
- */
-public final class ObjectSinkStreamSerializerFactory implements StreamSerializerFactory {
- public StreamSerializer getLocalSide(StreamContext context, Object local) throws IOException {
- return new StreamSerializerImpl(context, (ObjectSink<?>)local);
- }
-
- public RemoteStreamSerializer getRemoteSide(StreamContext context) throws IOException {
- return new RemoteStreamSerializerImpl(context);
- }
-
- /**
- * KEEP IN ORDER.
- */
- private enum MessageType {
- DATA,
- FLUSH,
- }
-
- public static final class StreamSerializerImpl implements StreamSerializer {
- private final StreamContext context;
- private final ObjectSink<?> objectSink;
-
- public StreamSerializerImpl(final StreamContext context, final ObjectSink<?> objectSink) {
- this.context = context;
- this.objectSink = objectSink;
- }
-
- public void handleOpen() throws IOException {
- }
-
- @SuppressWarnings ({"unchecked"})
- public void handleData(ObjectMessageInput data) throws IOException {
- MessageType messageType = MessageType.values()[data.read()];
- switch (messageType) {
- case DATA:
- try {
- ((ObjectSink)objectSink).accept(data.readObject());
- } catch (ClassNotFoundException e) {
- throw new IOException("Cannot deserialize object from message (class not found): " + e.toString());
- }
- break;
- case FLUSH:
- objectSink.flush();
- break;
- }
- }
-
- public void handleClose() throws IOException {
- objectSink.flush();
- }
- }
-
- public static final class RemoteStreamSerializerImpl implements RemoteStreamSerializer {
- private final StreamContext context;
-
- public RemoteStreamSerializerImpl(final StreamContext context) {
- this.context = context;
- }
-
- public ObjectSink<?> getRemoteInstance() {
- return new ObjectSink<Object>() {
- public void accept(final Object instance) throws IOException {
- final ObjectMessageOutput msg = context.writeMessage();
- msg.write(MessageType.DATA.ordinal());
- msg.writeObject(instance);
- msg.commit();
- }
-
- public void flush() throws IOException {
- final ObjectMessageOutput msg = context.writeMessage();
- msg.write(MessageType.FLUSH.ordinal());
- msg.commit();
- }
-
- public void close() throws IOException {
- flush();
- }
- };
- }
-
- public void handleOpen() throws IOException {
- }
-
- public void handleData(ObjectMessageInput data) throws IOException {
- }
-
- public void handleClose() throws IOException {
- }
- }
-}
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-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -50,6 +50,10 @@
public static class LocalHandler implements IoHandler<StreamSinkChannel> {
private final ObjectSource objectSource;
+ public LocalHandler(final ObjectSource source) {
+ objectSource = source;
+ }
+
public void handleOpened(final StreamSinkChannel channel) {
if (channel.getOptions().contains(CommonOptions.TCP_NODELAY)) try {
channel.setOption(CommonOptions.TCP_NODELAY, Boolean.TRUE);
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/DecodingBuilder.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/DecodingBuilder.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/DecodingBuilder.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -73,6 +73,7 @@
stringBuilder.append(flip(holder));
holder.clear();
} while (oflow);
+ return this;
}
public static final ByteBuffer EMPTY = ByteBuffer.allocate(0);
@@ -84,6 +85,7 @@
stringBuilder.append(flip(holder));
holder.clear();
} while (oflow);
+ return this;
}
public String toString() {
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/TaggingExecutor.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/TaggingExecutor.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/TaggingExecutor.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -0,0 +1,75 @@
+/*
+ * 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.util;
+
+import java.util.concurrent.Executor;
+import java.util.Set;
+import org.jboss.cx.remoting.util.CollectionUtil;
+
+/**
+ *
+ */
+public final class TaggingExecutor implements Executor {
+
+ private final Set<Task> tasks = CollectionUtil.synchronizedHashSet();
+ private final Executor executor;
+
+ public TaggingExecutor(final Executor executor) {
+ this.executor = executor;
+ }
+
+ private final class Task implements Runnable {
+ private volatile Thread thread;
+ private final Runnable runnable;
+
+ private Task(final Runnable runnable) {
+ this.runnable = runnable;
+ }
+
+ public void run() {
+ thread = Thread.currentThread();
+ tasks.add(this);
+ try {
+ runnable.run();
+ } finally {
+ tasks.remove(this);
+ thread = null;
+ }
+ }
+ }
+
+ public void execute(final Runnable command) {
+ executor.execute(new Task(command));
+ }
+
+ public void interruptAll() {
+ synchronized (tasks) {
+ for (Task task : tasks) {
+ final Thread thread = task.thread;
+ if (thread != null) {
+ thread.interrupt();
+ }
+ }
+ }
+ }
+}
Modified: remoting3/trunk/mc-deployers/src/main/java/org/jboss/cx/remoting/beans/SessionBean.java
===================================================================
--- remoting3/trunk/mc-deployers/src/main/java/org/jboss/cx/remoting/beans/SessionBean.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/mc-deployers/src/main/java/org/jboss/cx/remoting/beans/SessionBean.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -47,7 +47,7 @@
}
public void start() throws RemotingException {
- session = endpoint.openSession(destination, attributeMap, null);
+// session = endpoint.openSession(destination, attributeMap, null);
}
public void stop() throws RemotingException {
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,51 +0,0 @@
-package org.jboss.cx.remoting.samples.simple;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.security.Security;
-import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.Endpoint;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.Remoting;
-import org.jboss.cx.remoting.Session;
-import org.jboss.cx.remoting.core.security.sasl.Provider;
-import org.jboss.cx.remoting.jrpp.JrppServer;
-import org.jboss.cx.remoting.util.AttributeMap;
-import org.jboss.xnio.IoUtils;
-
-/**
- *
- */
-public final class JrppBasicExampleMain {
-
- public static void main(String[] args) throws IOException, RemoteExecutionException, URISyntaxException {
- Security.addProvider(new Provider());
- final StringRot13RequestListener listener = new StringRot13RequestListener();
- final Endpoint endpoint = Remoting.createEndpoint("simple");
- try {
- final JrppServer jrppServer = Remoting.addJrppServer(endpoint, new InetSocketAddress(12345), listener, AttributeMap.EMPTY);
- try {
- Session session = endpoint.openSession(new URI("jrpp://localhost:12345"), AttributeMap.EMPTY, null);
- try {
- final Client<String,String> client = session.getRootClient();
- try {
- final String original = "The Secret Message\n";
- final String result = client.invoke(original);
- System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), result.trim());
- } finally {
- IoUtils.safeClose(client);
- }
- } finally {
- IoUtils.safeClose(session);
- }
- } finally {
- jrppServer.stop();
- jrppServer.destroy();
- }
- } finally {
- Remoting.closeEndpoint(endpoint);
- }
- }
-}
\ No newline at end of file
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,70 +0,0 @@
-package org.jboss.cx.remoting.samples.simple;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.net.InetSocketAddress;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.security.Security;
-import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.Endpoint;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.Remoting;
-import org.jboss.cx.remoting.Session;
-import org.jboss.cx.remoting.core.security.sasl.Provider;
-import org.jboss.cx.remoting.jrpp.JrppServer;
-import org.jboss.cx.remoting.util.AttributeMap;
-import org.jboss.xnio.IoUtils;
-
-/**
- *
- */
-public final class JrppStreamExampleMain {
-
- public static void main(String[] args) throws IOException, RemoteExecutionException, URISyntaxException {
- Security.addProvider(new Provider());
- final StreamingRot13RequestListener listener = new StreamingRot13RequestListener();
- final Endpoint endpoint = Remoting.createEndpoint("simple");
- try {
- final JrppServer jrppServer = Remoting.addJrppServer(endpoint, new InetSocketAddress(12345), listener, AttributeMap.EMPTY);
- try {
- Session session = endpoint.openSession(new URI("jrpp://localhost:12345"), AttributeMap.EMPTY, listener);
- try {
- final Client<Reader,Reader> client = session.getRootClient();
- try {
- final String original = "The Secret Message\n";
- final StringReader originalReader = new StringReader(original);
- try {
- final Reader reader = client.send(originalReader).get();
- try {
- final BufferedReader bufferedReader = new BufferedReader(reader);
- try {
- final String secretLine = bufferedReader.readLine();
- System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), secretLine);
- } finally {
- IoUtils.safeClose(bufferedReader);
- }
- } finally {
- IoUtils.safeClose(reader);
- }
- } finally {
- IoUtils.safeClose(originalReader);
- }
- } finally {
- IoUtils.safeClose(client);
- }
- } finally {
- IoUtils.safeClose(session);
- }
- } finally {
- jrppServer.stop();
- jrppServer.destroy();
- }
- } finally {
- Remoting.closeEndpoint(endpoint);
- }
-
- }
-}
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -19,7 +19,7 @@
final StringRot13RequestListener listener = new StringRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
- final Client<String,String> client = endpoint.createClient(listener);
+ final Client<String,String> client = endpoint.createClient(listener).getClient();
try {
final String original = "The Secret Message\n";
final String result = client.invoke(original);
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -17,12 +17,15 @@
*/
public final class LocalStreamExampleMain {
+ private LocalStreamExampleMain() {
+ }
+
public static void main(String[] args) throws IOException, RemoteExecutionException {
Security.addProvider(new Provider());
final StreamingRot13RequestListener listener = new StreamingRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
- final Client<Reader,Reader> client = endpoint.createClient(listener);
+ final Client<Reader,Reader> client = endpoint.createClient(listener).getClient();
try {
final String original = "The Secret Message\n";
final StringReader originalReader = new StringReader(original);
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StreamingRot13RequestListener.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StreamingRot13RequestListener.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StreamingRot13RequestListener.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -12,7 +12,7 @@
*/
public final class StreamingRot13RequestListener extends AbstractRequestListener<Reader, Reader> {
- public void handleRequest(final RequestContext<Reader> readerRequestContext, final Reader request) throws RemoteExecutionException, InterruptedException {
+ public void handleRequest(final RequestContext<Reader> readerRequestContext, final Reader request) throws RemoteExecutionException {
try {
readerRequestContext.sendReply(new Reader() {
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StringRot13RequestListener.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StringRot13RequestListener.java 2008-07-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StringRot13RequestListener.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -10,7 +10,7 @@
*/
public final class StringRot13RequestListener extends AbstractRequestListener<String, String> {
- public void handleRequest(final RequestContext<String> readerRequestContext, final String request) throws RemoteExecutionException, InterruptedException {
+ public void handleRequest(final RequestContext<String> readerRequestContext, final String request) throws RemoteExecutionException {
try {
StringBuilder b = new StringBuilder(request.length());
for (int i = 0; i < request.length(); i ++) {
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-02 22:54:29 UTC (rev 4341)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03 00:44:19 UTC (rev 4342)
@@ -1,61 +1,28 @@
package org.jboss.cx.remoting;
import java.io.IOException;
-import java.net.SocketAddress;
import java.util.concurrent.ConcurrentMap;
-import org.jboss.cx.remoting.core.CoreEndpoint;
-import org.jboss.cx.remoting.core.protocol.LocalProtocolHandlerFactory;
-import org.jboss.cx.remoting.jrpp.JrppProtocolSupport;
-import org.jboss.cx.remoting.jrpp.JrppServer;
-import org.jboss.cx.remoting.util.AttributeMap;
+import org.jboss.cx.remoting.core.EndpointImpl;
/**
*
*/
public final class Remoting {
- private static final String JRPP_SUPPORT_KEY = "org.jboss.cx.remoting.standalone.jrpp.support";
-
// lifecycle lock
private static final Object lifecycle = new Object();
public static Endpoint createEndpoint(String name) throws IOException {
synchronized (lifecycle) {
boolean ok = false;
- final CoreEndpoint coreEndpoint = new CoreEndpoint();
- coreEndpoint.setName(name);
- coreEndpoint.create();
+ final EndpointImpl endpointImpl = new EndpointImpl();
+ endpointImpl.setName(name);
+ endpointImpl.create();
try {
- coreEndpoint.start();
- try {
- LocalProtocolHandlerFactory.addTo(coreEndpoint);
- final JrppProtocolSupport jrppProtocolSupport = new JrppProtocolSupport();
- jrppProtocolSupport.setEndpoint(coreEndpoint);
- jrppProtocolSupport.create();
- try {
- jrppProtocolSupport.start();
- try {
- final ConcurrentMap<Object, Object> attributes = coreEndpoint.getAttributes();
- attributes.put(JRPP_SUPPORT_KEY, jrppProtocolSupport);
- ok = true;
- return coreEndpoint;
- } finally {
- if (! ok) {
- jrppProtocolSupport.stop();
- }
- }
- } finally {
- if (! ok) {
- jrppProtocolSupport.destroy();
- }
- }
- } finally {
- if (! ok) {
- coreEndpoint.stop();
- }
- }
+ endpointImpl.start();
+ return endpointImpl;
} finally {
if (! ok) {
- coreEndpoint.destroy();
+ endpointImpl.destroy();
}
}
}
@@ -63,42 +30,15 @@
public static void closeEndpoint(Endpoint endpoint) {
synchronized (lifecycle) {
- if (endpoint instanceof CoreEndpoint) {
- final CoreEndpoint coreEndpoint = (CoreEndpoint) endpoint;
- final ConcurrentMap<Object, Object> attributes = coreEndpoint.getAttributes();
- final JrppProtocolSupport jrppProtocolSupport = (JrppProtocolSupport) attributes.remove(JRPP_SUPPORT_KEY);
- coreEndpoint.stop();
- coreEndpoint.destroy();
- if (jrppProtocolSupport != null) {
- jrppProtocolSupport.stop();
- jrppProtocolSupport.destroy();
- }
+ if (endpoint instanceof EndpointImpl) {
+ final EndpointImpl endpointImpl = (EndpointImpl) endpoint;
+ final ConcurrentMap<Object, Object> attributes = endpointImpl.getAttributes();
+ endpointImpl.stop();
+ endpointImpl.destroy();
}
}
}
- public static JrppServer addJrppServer(Endpoint endpoint, SocketAddress address, RequestListener<?, ?> rootRequestListener, AttributeMap attributeMap) throws IOException {
- synchronized (lifecycle) {
- boolean ok = false;
- final JrppServer jrppServer = new JrppServer();
- jrppServer.setProtocolSupport((JrppProtocolSupport) endpoint.getAttributes().get(JRPP_SUPPORT_KEY));
- jrppServer.setSocketAddress(address);
- jrppServer.setAttributeMap(attributeMap);
- jrppServer.setEndpoint(endpoint);
- jrppServer.setRootListener(rootRequestListener);
- jrppServer.create();
- try {
- jrppServer.start();
- ok = true;
- return jrppServer;
- } finally {
- if (! ok) {
- jrppServer.destroy();
- }
- }
- }
- }
-
// privates
private Remoting() { /* empty */ }
16 years, 4 months
JBoss Remoting SVN: r4341 - in remoting3/trunk/api/src/main/java/org/jboss/cx/remoting: spi and 2 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-02 18:54:29 -0400 (Wed, 02 Jul 2008)
New Revision: 4341
Added:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/
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/RemoteRequestContext.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/remote/ReplyHandler.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferOutputStream.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
Log:
New, improved, slimmed-down, simplified, more flexible protocol SPI
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-01 14:45:17 UTC (rev 4340)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -6,7 +6,6 @@
* @param <T> the type that is passed to the close handler
*/
public interface Closeable<T> extends java.io.Closeable {
- // TODO - do we need an async close method?
/**
* Close, waiting for any outstanding processing to finish.
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-01 14:45:17 UTC (rev 4340)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -3,6 +3,8 @@
import java.net.URI;
import java.util.concurrent.ConcurrentMap;
import org.jboss.cx.remoting.util.AttributeMap;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
/**
* A potential participant in a JBoss Remoting communications relationship.
@@ -44,7 +46,7 @@
String getName();
/**
- * Create a client that can be used to invoke a request listener on this endpoint. The client may be passed to a
+ * Create a client endpoint that can be used to receive incoming requests on this endpoint. The client may be passed to a
* remote endpoint as part of a request or a reply, or it may be used locally.
*
* You must have the TODO permission to invoke this method.
@@ -54,7 +56,7 @@
* @param requestListener the request listener
* @return the client
*/
- <I, O> Client<I, O> createClient(RequestListener<I, O> requestListener);
+ <I, O> RemoteClientEndpoint<I, O> createClient(RequestListener<I, O> requestListener);
/**
* Create a client source that can be used to acquire clients associated with a request listener on this endpoint.
@@ -68,7 +70,7 @@
* @param requestListener the request listener
* @return the context source
*/
- <I, O> ClientSource<I, O> createService(RequestListener<I, O> requestListener);
+ <I, O> RemoteServiceEndpoint<I, O> createService(RequestListener<I, O> requestListener);
/**
* Add a listener that is notified when a session is created.
Added: 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 (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.spi.remote;
+
+import org.jboss.cx.remoting.Closeable;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.CloseHandler;
+
+/**
+ * A handle to a local resource.
+ */
+public interface Handle<T> extends Closeable<Handle<T>> {
+
+ /**
+ * Get the resource.
+ *
+ * @return the resource
+ */
+ T getResource();
+
+ /**
+ * Close this reference.
+ *
+ * @throws RemotingException if the close failed
+ */
+ void close() throws RemotingException;
+
+ /**
+ * Add a handler that is invoked when this handle is closed.
+ *
+ * @param handler the handler
+ */
+ void addCloseHandler(final CloseHandler<Handle<T>> handler);
+}
Added: 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 (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.spi.remote;
+
+import org.jboss.cx.remoting.Closeable;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.Client;
+
+/**
+ * A remote client endpoint, which can be passed to remote endpoints. Remote systems can then use the client endpoint
+ * to make invocations, or they may pass the client endpoint on to other remote systems.
+ */
+public interface RemoteClientEndpoint<I, O> extends Closeable<RemoteClientEndpoint<I, O>> {
+
+ /**
+ * Receive a request from a remote system. This method is intended to be called by protocol handlers. If the
+ * request cannot be accepted for some reason, the
+ * {@link org.jboss.cx.remoting.spi.remote.ReplyHandler#handleException(Throwable)}
+ * method is called immediately.
+ *
+ * @param request the request
+ * @param replyHandler a handler for the reply
+ * @return a context which may be used to cancel the request
+ */
+ RemoteRequestContext receiveRequest(I request, ReplyHandler<O> replyHandler);
+
+ /**
+ * Get a handle to this client endpoint. The client endpoint will not auto-close as long as there is at least
+ * one open handle or local client instance. If a handle is "leaked", it will be closed
+ * automatically if/when the garbage collector invokes its {@link Object#finalize()} method, with a log message
+ * warning of the leak.
+ *
+ * @return the handle
+ * @throws RemotingException if a handle could not be acquired
+ */
+ 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();
+
+ /**
+ * Close this client endpoint. The outcome of any outstanding requests is not defined, though implementations
+ * should make an effort to cancel any outstanding requests.
+ *
+ * @throws RemotingException if the client endpoint could not be closed
+ */
+ void close() throws RemotingException;
+
+ /**
+ * Add a handler that is called when the client endpoint is closed.
+ *
+ * @param handler the handler to be called
+ */
+ void addCloseHandler(final CloseHandler<RemoteClientEndpoint<I, O>> handler);
+}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -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.remote;
+
+/**
+ * The context of an outstanding remote request. This instance should be discarded when a reply (of any sort)
+ * is received for the request.
+ */
+public interface RemoteRequestContext {
+
+ /**
+ * Signal that the request should be cancelled, if possible.
+ */
+ void cancel();
+}
Added: 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 (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.spi.remote;
+
+import org.jboss.cx.remoting.Closeable;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.ClientSource;
+
+/**
+ * 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.
+ */
+public interface RemoteServiceEndpoint<I, O> extends Closeable<RemoteServiceEndpoint<I, O>> {
+
+ /**
+ * Create a client endpoint for the service corresponding to this service endpoint.
+ *
+ * @return a client endpoint
+ * @throws RemotingException if a client could not be opened
+ */
+ RemoteClientEndpoint<I, O> openClient() throws RemotingException;
+
+ /**
+ * Get a handle to this service endpoint. The service endpoint will not auto-close as long as there is at least
+ * one open handle,remote client endpoint, or client source. If a handle is "leaked", it will be closed
+ * automatically if/when the garbage collector invokes its {@link Object#finalize()} method, with a log message
+ * warning of the leak.
+ *
+ * @return the handle
+ * @throws RemotingException if a handle could not be acquired
+ */
+ 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.
+ */
+ void autoClose();
+
+ /**
+ * Close this service endpoint immediately.
+ */
+ void close() throws RemotingException;
+
+ /**
+ * Add a handler that is called when the service endpoint is closed.
+ *
+ * @param handler the handler to be called
+ */
+ void addCloseHandler(final CloseHandler<RemoteServiceEndpoint<I, O>> handler);
+}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/ReplyHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/ReplyHandler.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/ReplyHandler.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.spi.remote;
+
+/**
+ * A handler for replies from a request. The handler should respect the first invocation made on it, and ignore
+ * any subsequent invocations.
+ */
+public interface ReplyHandler<O> {
+
+ /**
+ * Handle a successful reply.
+ *
+ * @param reply the reply
+ */
+ void handleReply(O reply);
+
+ /**
+ * Handle a remote exception.
+ *
+ * @param cause the cause
+ */
+ void handleException(Throwable cause);
+
+ /**
+ * Handle a cancellation request.
+ */
+ void handleCancellation();
+}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -0,0 +1,121 @@
+/*
+ * 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.stream;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import org.jboss.xnio.BufferAllocator;
+import org.jboss.xnio.IoUtils;
+
+/**
+ * An input stream that reads from byte buffers. Instances of this class are not safe to use concurrently from
+ * multiple threads.
+ */
+public final class ByteBufferInputStream extends InputStream {
+ private final ObjectSource<ByteBuffer> bufferSource;
+ private final BufferAllocator<ByteBuffer> allocator;
+
+ private boolean closed;
+ private ByteBuffer current;
+
+ public ByteBufferInputStream(final ObjectSource<ByteBuffer> bufferSource, final BufferAllocator<ByteBuffer> allocator) {
+ this.bufferSource = bufferSource;
+ this.allocator = allocator;
+ }
+
+ public int read() throws IOException {
+ if (closed) {
+ return -1;
+ }
+ ByteBuffer buffer = getBuffer();
+ if (buffer == null) {
+ return -1;
+ }
+ try {
+ return buffer.get() & 0xff;
+ } finally {
+ if (! buffer.hasRemaining()) {
+ current = null;
+ allocator.free(buffer);
+ }
+ }
+ }
+
+ public int read(final byte[] b, int off, int len) throws IOException {
+ if (closed) {
+ return -1;
+ }
+ int t = 0;
+ while (len > 0) {
+ ByteBuffer buffer = getBuffer();
+ if (buffer == null) {
+ return t == 0 ? -1 : t;
+ }
+ final int rem = Math.min(len, buffer.remaining());
+ if (rem > 0) {
+ buffer.get(b, off, rem);
+ off += rem;
+ len -= rem;
+ t += rem;
+ }
+ if (! buffer.hasRemaining()) {
+ current = null;
+ allocator.free(buffer);
+ }
+ }
+ return t;
+ }
+
+ public int available() throws IOException {
+ final ByteBuffer buffer = current;
+ return (buffer == null ? 0 : buffer.remaining());
+ }
+
+ public void close() throws IOException {
+ try {
+ final ByteBuffer buffer = current;
+ current = null;
+ allocator.free(buffer);
+ bufferSource.close();
+ } finally {
+ closed = true;
+ IoUtils.safeClose(bufferSource);
+ }
+ }
+
+ private ByteBuffer getBuffer() throws IOException {
+ final ByteBuffer buffer = current;
+ if (buffer == null) {
+ if (bufferSource.hasNext()) {
+ final ByteBuffer newBuffer = bufferSource.next();
+ current = newBuffer;
+ return newBuffer;
+ } else {
+ return null;
+ }
+ } else {
+ return buffer;
+ }
+ }
+}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferOutputStream.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferOutputStream.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferOutputStream.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -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.stream;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import org.jboss.xnio.BufferAllocator;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.Buffers;
+
+/**
+ * An output stream that writes to buffers. Instances of this class are not normally safe to use from multiple threads
+ * concurrently.
+ */
+public final class ByteBufferOutputStream extends OutputStream {
+ private final ObjectSink<ByteBuffer> bufferSink;
+ private final BufferAllocator<ByteBuffer> allocator;
+
+ private ByteBuffer current;
+ private boolean closed;
+
+ /**
+ * Construct a new stream instance.
+ *
+ * @param bufferSink the buffer sink to which full buffers will be written
+ * @param allocator the allocator from which empty buffers will be allocated
+ */
+ public ByteBufferOutputStream(final ObjectSink<ByteBuffer> bufferSink, final BufferAllocator<ByteBuffer> allocator) {
+ this.bufferSink = bufferSink;
+ this.allocator = allocator;
+ }
+
+ private ByteBuffer getBuffer() throws IOException {
+ final ByteBuffer buffer = current;
+ if (buffer == null) {
+ ByteBuffer newbuf = allocator.allocate();
+ if (newbuf == null) {
+ throw new IOException("No buffers available");
+ }
+ current = newbuf;
+ return newbuf;
+ } else {
+ return buffer;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void write(final int b) throws IOException {
+ if (closed) {
+ throw new IOException("Write to closed outputstream");
+ }
+ final ByteBuffer buffer = getBuffer();
+ buffer.put((byte)b);
+ if (! buffer.hasRemaining()) {
+ localFlush();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void write(final byte[] b, int off, int len) throws IOException {
+ if (closed) {
+ throw new IOException("Write to closed outputstream");
+ }
+ do {
+ final ByteBuffer buffer = getBuffer();
+ final int rem = Math.min(len, buffer.remaining());
+ buffer.put(b, off, rem);
+ if (! buffer.hasRemaining()) {
+ localFlush();
+ }
+ len -= rem; off += rem;
+ } while (len > 0);
+ }
+
+ private void localFlush() throws IOException {
+ if (closed) {
+ throw new IOException("Flush on closed outputstream");
+ }
+ final ByteBuffer buffer = current;
+ if (buffer != null) try {
+ bufferSink.accept(Buffers.flip(buffer));
+ } finally {
+ current = null;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void flush() throws IOException {
+ localFlush();
+ bufferSink.flush();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException {
+ if (! closed) try {
+ flush();
+ bufferSink.close();
+ } finally {
+ closed = true;
+ IoUtils.safeClose(bufferSink);
+ }
+ }
+}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -0,0 +1,161 @@
+/*
+ * 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.stream;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.CharBuffer;
+import org.jboss.xnio.BufferAllocator;
+import org.jboss.xnio.IoUtils;
+
+/**
+ * A reader that reads from char buffers. Instances of this class are not safe to use concurrently from
+ * multiple threads.
+ */
+public final class CharBufferReader extends Reader {
+ private final ObjectSource<CharBuffer> bufferSource;
+ private final BufferAllocator<CharBuffer> allocator;
+
+ private boolean closed;
+ private CharBuffer current;
+
+ public CharBufferReader(final ObjectSource<CharBuffer> bufferSource, final BufferAllocator<CharBuffer> allocator) {
+ this.bufferSource = bufferSource;
+ this.allocator = allocator;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int read() throws IOException {
+ if (closed) {
+ return -1;
+ }
+ CharBuffer buffer = getBuffer();
+ if (buffer == null) {
+ return -1;
+ }
+ try {
+ return buffer.get() & 0xff;
+ } finally {
+ if (! buffer.hasRemaining()) {
+ current = null;
+ allocator.free(buffer);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int read(final char[] cbuf, int off, int len) throws IOException {
+ if (closed) {
+ return -1;
+ }
+ int t = 0;
+ while (len > 0) {
+ CharBuffer buffer = getBuffer();
+ if (buffer == null) {
+ return t == 0 ? -1 : t;
+ }
+ final int rem = Math.min(len, buffer.remaining());
+ if (rem > 0) {
+ buffer.get(cbuf, off, rem);
+ off += rem;
+ len -= rem;
+ t += rem;
+ }
+ if (! buffer.hasRemaining()) {
+ current = null;
+ allocator.free(buffer);
+ }
+ }
+ return t;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException {
+ try {
+ final CharBuffer buffer = current;
+ current = null;
+ allocator.free(buffer);
+ bufferSource.close();
+ } finally {
+ closed = true;
+ IoUtils.safeClose(bufferSource);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int read(final CharBuffer target) throws IOException {
+ if (closed) {
+ return -1;
+ }
+ int t = 0;
+ int len = target.remaining();
+ while (len > 0) {
+ CharBuffer buffer = getBuffer();
+ if (buffer == null) {
+ return t == 0 ? -1 : t;
+ }
+ final int rem = Math.min(len, buffer.remaining());
+ if (rem > 0) {
+ buffer.read(target);
+ len -= rem;
+ t += rem;
+ }
+ if (! buffer.hasRemaining()) {
+ current = null;
+ allocator.free(buffer);
+ }
+ }
+ return t;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean ready() throws IOException {
+ final CharBuffer buffer = current;
+ return buffer != null && buffer.hasRemaining();
+ }
+
+ private CharBuffer getBuffer() throws IOException {
+ final CharBuffer buffer = current;
+ if (buffer == null) {
+ if (bufferSource.hasNext()) {
+ final CharBuffer newBuffer = bufferSource.next();
+ current = newBuffer;
+ return newBuffer;
+ } else {
+ return null;
+ }
+ } else {
+ return buffer;
+ }
+ }
+}
\ No newline at end of file
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java 2008-07-02 22:54:29 UTC (rev 4341)
@@ -0,0 +1,150 @@
+/*
+ * 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.stream;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.CharBuffer;
+import org.jboss.xnio.BufferAllocator;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.Buffers;
+
+/**
+ * A writer that writes to buffers. Instances of this class are not normally safe to use from multiple threads
+ * concurrently.
+ */
+public final class CharBufferWriter extends Writer {
+ private final ObjectSink<CharBuffer> bufferSink;
+ private final BufferAllocator<CharBuffer> allocator;
+
+ private CharBuffer current;
+ private boolean closed;
+
+ /**
+ * Construct a new stream instance.
+ *
+ * @param bufferSink the buffer sink to which full buffers will be written
+ * @param allocator the allocator from which empty buffers will be allocated
+ */
+ public CharBufferWriter(final ObjectSink<CharBuffer> bufferSink, final BufferAllocator<CharBuffer> allocator) {
+ this.bufferSink = bufferSink;
+ this.allocator = allocator;
+ }
+
+ private CharBuffer getBuffer() throws IOException {
+ final CharBuffer buffer = current;
+ if (buffer == null) {
+ CharBuffer newbuf = allocator.allocate();
+ if (newbuf == null) {
+ throw new IOException("No buffers available");
+ }
+ current = newbuf;
+ return newbuf;
+ } else {
+ return buffer;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void write(final int b) throws IOException {
+ if (closed) {
+ throw new IOException("Write to closed writer");
+ }
+ final CharBuffer buffer = getBuffer();
+ buffer.put((char)b);
+ if (! buffer.hasRemaining()) {
+ localFlush();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void write(final char[] b, int off, int len) throws IOException {
+ if (closed) {
+ throw new IOException("Write to closed writer");
+ }
+ do {
+ final CharBuffer buffer = getBuffer();
+ final int rem = Math.min(len, buffer.remaining());
+ buffer.put(b, off, rem);
+ if (! buffer.hasRemaining()) {
+ localFlush();
+ }
+ len -= rem; off += rem;
+ } while (len > 0);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void write(final String str, int off, int len) throws IOException {
+ if (closed) {
+ throw new IOException("Write to closed writer");
+ }
+ do {
+ final CharBuffer buffer = getBuffer();
+ final int rem = Math.min(len, buffer.remaining());
+ buffer.put(str, off, rem);
+ if (! buffer.hasRemaining()) {
+ localFlush();
+ }
+ len -= rem; off += rem;
+ } while (len > 0);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void flush() throws IOException {
+ localFlush();
+ bufferSink.flush();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException {
+ if (! closed) try {
+ flush();
+ bufferSink.close();
+ } finally {
+ closed = true;
+ IoUtils.safeClose(bufferSink);
+ }
+ }
+
+ private void localFlush() throws IOException {
+ if (closed) {
+ throw new IOException("Flush on closed writer");
+ }
+ final CharBuffer buffer = current;
+ if (buffer != null) try {
+ bufferSink.accept(Buffers.flip(buffer));
+ } finally {
+ current = null;
+ }
+ }
+}
\ No newline at end of file
16 years, 4 months
JBoss Remoting SVN: r4340 - remoting3/trunk.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-01 10:45:17 -0400 (Tue, 01 Jul 2008)
New Revision: 4340
Removed:
remoting3/trunk/http-mina-client/
remoting3/trunk/http-mina-server/
remoting3/trunk/log-jboss/
remoting3/trunk/log-jul/
remoting3/trunk/mina-sasl/
Log:
More cleanup
16 years, 4 months
JBoss Remoting SVN: r4339 - in remoting3/trunk: core/src/main/java/org/jboss/cx/remoting/core and 13 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-01 10:40:05 -0400 (Tue, 01 Jul 2008)
New Revision: 4339
Added:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/DecodingBuilder.java
Removed:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/ClientResolver.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/ClientSourceResolver.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/
remoting3/trunk/jrpp/
remoting3/trunk/log-jboss/src/main/java/org/jboss/cx/remoting/log/Logger.java
remoting3/trunk/log-jul/src/main/java/org/jboss/cx/remoting/log/Logger.java
remoting3/trunk/mina-sasl/src/main/java/org/apache/mina/filter/sasl/
Modified:
remoting3/trunk/build.xml
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientMarker.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceMarker.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundClient.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundClient.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreStream.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientInitiator.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientResponder.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClassLoader.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/StreamMarker.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/protocol/LocalProtocolHandler.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandlerFactory.java
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/IteratorStreamSerializerFactory.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSinkStreamSerializerFactory.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
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/QueueExecutor.java
remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java
remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/AbstractHttpUrlChannel.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpSaslClientImpl.java
remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpSaslServerImpl.java
remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpVerifier.java
remoting3/trunk/version/src/main/java/org/jboss/cx/remoting/version/Version.java
Log:
More long pent-up refactoring - remove JRPP (for now), logging goes to XNIO, integrate XNIO generally, protocol SPI simplification
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/build.xml 2008-07-01 14:40:05 UTC (rev 4339)
@@ -139,18 +139,6 @@
<get src="${remote.license.dir}/${lib.jbossxb.license}.txt" dest="${lib.jbossxb.local}.license.txt" usetimestamp="true" ignoreerrors="false"/>
</target>
- <!-- External library: MINA -->
-
- <target name="lib.mina-check">
- <available property="lib.mina.exists" file="${lib.mina.local}"/>
- </target>
-
- <target name="lib.mina" depends="lib.mina-check" unless="lib.mina.exists">
- <mkdir dir="${local.repository}/${lib.mina.dir}"/>
- <get src="${lib.mina.remote}" dest="${lib.mina.local}" usetimestamp="true" ignoreerrors="false"/>
- <get src="${remote.license.dir}/${lib.mina.license}.txt" dest="${lib.mina.local}.license.txt" usetimestamp="true" ignoreerrors="false"/>
- </target>
-
<!-- External library: Servlet API 2.4 -->
<target name="lib.servlet-check">
@@ -294,7 +282,6 @@
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<path refid="api.classpath"/>
- <path refid="log-jul.classpath"/>
<path refid="util.classpath"/>
<path refid="version.classpath"/>
<pathelement location="${lib.jboss-serialization.local}"/>
@@ -307,55 +294,12 @@
<delete dir="core/target"/>
</target>
- <target name="core" description="Build the core module" depends="lib.jboss-serialization,api,log-jul,util,version,core.compile">
+ <target name="core" description="Build the core module" depends="lib.jboss-serialization,api,util,version,core.compile">
<path id="core.classpath">
<pathelement location="core/target/main/classes"/>
</path>
</target>
- <!-- jrpp module -->
-
- <target name="jrpp.compile.depcheck">
- <mkdir dir="jrpp/target/main"/>
- <uptodate property="jrpp.compile.uptodate" targetfile="jrpp/target/main/.lastcompile">
- <srcfiles dir="jrpp/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="jrpp.compile" depends="jrpp.compile.depcheck" unless="jrpp.compile.uptodate">
- <mkdir dir="jrpp/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="jrpp/src/main/java"
- destdir="jrpp/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="api.classpath"/>
- <path refid="log-jul.classpath"/>
- <path refid="mina-sasl.classpath"/>
- <path refid="util.classpath"/>
- <pathelement location="${lib.mina.local}"/>
- </classpath>
- </javac>
- <touch file="jrpp/target/main/.lastcompile" verbose="false"/>
- </target>
-
- <target name="jrpp.clean">
- <delete dir="jrpp/target"/>
- </target>
-
- <target name="jrpp" description="Build the jrpp module" depends="lib.mina,api,log-jul,mina-sasl,util,jrpp.compile">
- <path id="jrpp.classpath">
- <pathelement location="jrpp/target/main/classes"/>
- </path>
- </target>
-
<!-- http module -->
<target name="http.compile.depcheck">
@@ -380,7 +324,6 @@
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<path refid="api.classpath"/>
- <path refid="log-jul.classpath"/>
<path refid="util.classpath"/>
</classpath>
</javac>
@@ -391,96 +334,12 @@
<delete dir="http/target"/>
</target>
- <target name="http" description="Build the http module" depends="api,log-jul,util,http.compile">
+ <target name="http" description="Build the http module" depends="api,util,http.compile">
<path id="http.classpath">
<pathelement location="http/target/main/classes"/>
</path>
</target>
- <!-- http-mina-client module -->
-
- <target name="http-mina-client.compile.depcheck">
- <mkdir dir="http-mina-client/target/main"/>
- <uptodate property="http-mina-client.compile.uptodate" targetfile="http-mina-client/target/main/.lastcompile">
- <srcfiles dir="http-mina-client/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="http-mina-client.compile" depends="http-mina-client.compile.depcheck" unless="http-mina-client.compile.uptodate">
- <mkdir dir="http-mina-client/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="http-mina-client/src/main/java"
- destdir="http-mina-client/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="api.classpath"/>
- <path refid="http.classpath"/>
- <path refid="util.classpath"/>
- <pathelement location="${lib.mina.local}"/>
- </classpath>
- </javac>
- <touch file="http-mina-client/target/main/.lastcompile" verbose="false"/>
- </target>
-
- <target name="http-mina-client.clean">
- <delete dir="http-mina-client/target"/>
- </target>
-
- <target name="http-mina-client" description="Build the http-mina-client module" depends="api,http,util,http-mina-client.compile">
- <path id="http-mina-client.classpath">
- <pathelement location="http-mina-client/target/main/classes"/>
- </path>
- </target>
-
- <!-- http-mina-server module -->
-
- <target name="http-mina-server.compile.depcheck">
- <mkdir dir="http-mina-server/target/main"/>
- <uptodate property="http-mina-server.compile.uptodate" targetfile="http-mina-server/target/main/.lastcompile">
- <srcfiles dir="http-mina-server/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="http-mina-server.compile" depends="http-mina-server.compile.depcheck" unless="http-mina-server.compile.uptodate">
- <mkdir dir="http-mina-server/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="http-mina-server/src/main/java"
- destdir="http-mina-server/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="api.classpath"/>
- <path refid="http.classpath"/>
- <path refid="util.classpath"/>
- <pathelement location="${lib.mina.local}"/>
- </classpath>
- </javac>
- <touch file="http-mina-server/target/main/.lastcompile" verbose="false"/>
- </target>
-
- <target name="http-mina-server.clean">
- <delete dir="http-mina-server/target"/>
- </target>
-
- <target name="http-mina-server" description="Build the http-mina-server module" depends="api,http,util,http-mina-server.compile">
- <path id="http-mina-server.classpath">
- <pathelement location="http-mina-server/target/main/classes"/>
- </path>
- </target>
-
<!-- http-se6 module -->
<target name="http-se6.httpserver.builtin-check">
@@ -608,7 +467,6 @@
<classpath>
<path refid="api.classpath"/>
<path refid="http.classpath"/>
- <path refid="log-jul.classpath"/>
<path refid="util.classpath"/>
</classpath>
</javac>
@@ -619,87 +477,12 @@
<delete dir="http-urlconnection/target"/>
</target>
- <target name="http-urlconnection" description="Build the http-urlconnection module" depends="api,http,log-jul,util,http-urlconnection.compile">
+ <target name="http-urlconnection" description="Build the http-urlconnection module" depends="api,http,util,http-urlconnection.compile">
<path id="http-urlconnection.classpath">
<pathelement location="http-urlconnection/target/main/classes"/>
</path>
</target>
- <!-- log-jboss module -->
-
- <target name="log-jboss.compile.depcheck">
- <mkdir dir="log-jboss/target/main"/>
- <uptodate property="log-jboss.compile.uptodate" targetfile="log-jboss/target/main/.lastcompile">
- <srcfiles dir="log-jboss/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="log-jboss.compile" depends="log-jboss.compile.depcheck" unless="log-jboss.compile.uptodate">
- <mkdir dir="log-jboss/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="log-jboss/src/main/java"
- destdir="log-jboss/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <pathelement location="${lib.jboss-common-logging-spi.local}"/>
- </classpath>
- </javac>
- <touch file="log-jboss/target/main/.lastcompile" verbose="false"/>
- </target>
-
- <target name="log-jboss.clean">
- <delete dir="log-jboss/target"/>
- </target>
-
- <target name="log-jboss" description="Build the log-jboss module" depends="lib.jboss-common-logging-spi,log-jboss.compile">
- <path id="log-jboss.classpath">
- <pathelement location="log-jboss/target/main/classes"/>
- </path>
- </target>
-
- <!-- log-jul module -->
-
- <target name="log-jul.compile.depcheck">
- <mkdir dir="log-jul/target/main"/>
- <uptodate property="log-jul.compile.uptodate" targetfile="log-jul/target/main/.lastcompile">
- <srcfiles dir="log-jul/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="log-jul.compile" depends="log-jul.compile.depcheck" unless="log-jul.compile.uptodate">
- <mkdir dir="log-jul/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="log-jul/src/main/java"
- destdir="log-jul/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- </javac>
- <touch file="log-jul/target/main/.lastcompile" verbose="false"/>
- </target>
-
- <target name="log-jul.clean">
- <delete dir="log-jul/target"/>
- </target>
-
- <target name="log-jul" description="Build the log-jul module" depends="log-jul.compile">
- <path id="log-jul.classpath">
- <pathelement location="log-jul/target/main/classes"/>
- </path>
- </target>
-
<!-- mc-deployers module -->
<target name="mc-deployers.compile.depcheck">
@@ -725,7 +508,6 @@
<classpath>
<path refid="api.classpath"/>
<path refid="core.classpath"/>
- <path refid="log-jboss.classpath"/>
<path refid="util.classpath"/>
<pathelement location="${lib.jaxb-api.local}"/>
<pathelement location="${lib.jboss-common-logging-spi.local}"/>
@@ -746,51 +528,12 @@
<delete dir="mc-deployers/target"/>
</target>
- <target name="mc-deployers" description="Build the mc-deployers module" depends="lib.jaxb-api,lib.jboss-common-core,lib.jboss-common-logging-spi,lib.jboss-deployers-core-spi,lib.jboss-deployers-spi,lib.jboss-deployers-structure-spi,lib.jbossmc-kernel,lib.jbossmc-dependency,lib.jboss-managed,lib.jbossxb,api,core,log-jboss,util,mc-deployers.compile">
+ <target name="mc-deployers" description="Build the mc-deployers module" depends="lib.jaxb-api,lib.jboss-common-core,lib.jboss-common-logging-spi,lib.jboss-deployers-core-spi,lib.jboss-deployers-spi,lib.jboss-deployers-structure-spi,lib.jbossmc-kernel,lib.jbossmc-dependency,lib.jboss-managed,lib.jbossxb,api,core,util,mc-deployers.compile">
<path id="mc-deployers.classpath">
<pathelement location="mc-deployers/target/main/classes"/>
</path>
</target>
- <!-- mina-sasl module -->
-
- <target name="mina-sasl.compile.depcheck">
- <mkdir dir="mina-sasl/target/main"/>
- <uptodate property="mina-sasl.compile.uptodate" targetfile="mina-sasl/target/main/.lastcompile">
- <srcfiles dir="mina-sasl/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="mina-sasl.compile" depends="mina-sasl.compile.depcheck" unless="mina-sasl.compile.uptodate">
- <mkdir dir="mina-sasl/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="mina-sasl/src/main/java"
- destdir="mina-sasl/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <pathelement location="${lib.mina.local}"/>
- </classpath>
- </javac>
- <touch file="mina-sasl/target/main/.lastcompile" verbose="false"/>
- </target>
-
- <target name="mina-sasl.clean">
- <delete dir="mina-sasl/target"/>
- </target>
-
- <target name="mina-sasl" description="Build the mina-sasl module" depends="lib.mina,mina-sasl.compile">
- <path id="mina-sasl.classpath">
- <pathelement location="mina-sasl/target/main/classes"/>
- </path>
- </target>
-
<!-- samples module -->
<target name="samples.compile.depcheck">
@@ -815,7 +558,6 @@
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<path refid="api.classpath"/>
- <path refid="jrpp.classpath"/>
<path refid="srp.classpath"/>
<path refid="standalone.classpath"/>
<path refid="util.classpath"/>
@@ -828,7 +570,7 @@
<delete dir="samples/target"/>
</target>
- <target name="samples" description="Build the samples module" depends="api,jrpp,srp,standalone,util,samples.compile">
+ <target name="samples" description="Build the samples module" depends="api,srp,standalone,util,samples.compile">
<path id="samples.classpath">
<pathelement location="samples/target/main/classes"/>
</path>
@@ -893,7 +635,6 @@
debug="true">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
- <path refid="log-jul.classpath"/>
<path refid="util.classpath"/>
</classpath>
</javac>
@@ -904,7 +645,7 @@
<delete dir="srp/target"/>
</target>
- <target name="srp" description="Build the SRP SASL module" depends="log-jul,util,srp.compile">
+ <target name="srp" description="Build the SRP SASL module" depends="util,srp.compile">
<path id="srp.classpath">
<pathelement location="srp/target/main/classes"/>
</path>
@@ -935,8 +676,6 @@
<classpath>
<path refid="api.classpath"/>
<path refid="core.classpath"/>
- <path refid="log-jul.classpath"/>
- <path refid="jrpp.classpath"/>
<path refid="util.classpath"/>
</classpath>
</javac>
@@ -947,7 +686,7 @@
<delete dir="standalone/target"/>
</target>
- <target name="standalone" description="Build the standalone module" depends="api,core,jrpp,log-jul,util,standalone.compile">
+ <target name="standalone" description="Build the standalone module" depends="api,core,util,standalone.compile">
<path id="standalone.classpath">
<pathelement location="standalone/target/main/classes"/>
</path>
@@ -1094,7 +833,6 @@
debug="true">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
- <path refid="log-jul.classpath"/>
</classpath>
</javac>
<touch file="util/target/main/.lastcompile" verbose="false"/>
@@ -1104,7 +842,7 @@
<delete dir="util/target"/>
</target>
- <target name="util" description="Build the utilities module" depends="log-jul,util.compile">
+ <target name="util" description="Build the utilities module" depends="util.compile">
<path id="util.classpath">
<pathelement location="util/target/main/classes"/>
</path>
@@ -1175,7 +913,7 @@
</jar>
</target>
- <target name="core-jar" description="Build the Core JAR" depends="core,log-jboss,version">
+ <target name="core-jar" description="Build the Core JAR" depends="core,version">
<delete file="jboss-remoting-core.jar"/>
<jar jarfile="jboss-remoting-core.jar">
<manifest>
@@ -1192,42 +930,13 @@
<zipfileset dir="core/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
- <zipfileset dir="log-jboss/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
<zipfileset dir="version/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
</jar>
</target>
- <target name="jrpp-jar" description="Build the JRPP JAR" depends="jrpp,mina-sasl,srp,version">
- <delete file="jboss-remoting-jrpp.jar"/>
- <jar jarfile="jboss-remoting-jrpp.jar">
- <manifest>
- <attribute name="Created-By" value="${java.vm.version} (${java.vm.vendor})"/>
- <attribute name="Specification-Title" value="JBoss Remoting"/>
- <attribute name="Specification-Version" value="${version}"/>
- <attribute name="Specification-Vendor" value="JBoss (http://www.jboss.org/)"/>
- <attribute name="Implementation-Title" value="JBoss Remoting (JRPP)"/>
- <attribute name="Implementation-URL" value="http://labs.jboss.org/jbossremoting/"/>
- <attribute name="Implementation-Version" value="${version}"/>
- <attribute name="Implementation-Vendor" value="JBoss, a division of Red Hat, Inc."/>
- <attribute name="Implementation-Vendor-Id" value="http://www.jboss.org"/>
- </manifest>
- <zipfileset dir="jrpp/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- <zipfileset dir="mina-sasl/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- <zipfileset dir="srp/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- </jar>
- </target>
-
- <target name="standalone-jar" description="Build the standalone JAR" depends="api,core,jrpp,log-jul,srp,standalone,util,version">
+ <target name="standalone-jar" description="Build the standalone JAR" depends="api,core,srp,standalone,util,version">
<delete file="jboss-remoting-standalone.jar"/>
<jar jarfile="jboss-remoting-standalone.jar">
<manifest>
@@ -1247,12 +956,6 @@
<zipfileset dir="core/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
- <zipfileset dir="jrpp/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
- <zipfileset dir="log-jul/target/main/classes">
- <include name="**/*.class"/>
- </zipfileset>
<zipfileset dir="srp/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
@@ -1269,7 +972,7 @@
<!-- JAVADOCS -->
<!-- ============================================== -->
- <target name="api-javadoc" depends="api,core,jrpp,log-jul,standalone,util">
+ <target name="api-javadoc" depends="api,core,standalone,util">
<delete dir="api/target/main/docs"/>
<mkdir dir="api/target/main/docs"/>
<javadoc destdir="api/target/main/docs" author="false" version="false" use="false" windowtitle="JBoss Remoting API">
@@ -1280,9 +983,7 @@
<bottom><![CDATA[<i>Copyright © 2008 JBoss, a division of Red Hat, Inc.</i>]]></bottom>
<link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
<classpath>
- <path refid="log-jul.classpath"/>
<path refid="core.classpath"/>
- <path refid="jrpp.classpath"/>
</classpath>
</javadoc>
</target>
@@ -1298,34 +999,22 @@
<!-- http -->
- <target name="all-http" description="Build all HTTP targets" depends="http,http-mina-client,http-mina-server,http-se6,http-servlet,http-urlconnection"/>
+ <target name="all-http" description="Build all HTTP targets" depends="http,http-se6,http-servlet,http-urlconnection"/>
- <target name="clean-http" description="Clean all HTTP targets" depends="http.clean,http-mina-client.clean,http-mina-server.clean,http-se6.clean,http-servlet.clean,http-urlconnection.clean"/>
+ <target name="clean-http" description="Clean all HTTP targets" depends="http.clean,http-se6.clean,http-servlet.clean,http-urlconnection.clean"/>
- <!-- jrpp -->
-
- <target name="all-jrpp" description="Build all JRPP targets" depends="jrpp,mina-sasl,sasl-null,srp"/>
-
- <target name="clean-jrpp" description="Clean all JRPP targets" depends="jrpp.clean,mina-sasl.clean,sasl-null.clean,srp.clean"/>
-
- <!-- log -->
-
- <target name="all-log" description="Build all log targets" depends="log-jboss,log-jul"/>
-
- <target name="clean-log" description="Clean all log targets" depends="log-jboss.clean,log-jul.clean"/>
-
<!-- JARs: These should be the third-to-last targets in the file -->
<target name="all-jars" description="Build all the JARs" depends="api-jar,core-jar,standalone-jar"/>
<!-- fetch: These should be the second-to-last targets in the file -->
- <target name="all-fetch" description="Pre-fetch all external libraries" depends="lib.jboss-common-core,lib.jboss-common-logging-spi,lib.jboss-deployers-core-spi,lib.jboss-deployers-spi,lib.jboss-deployers-structure-spi,lib.jbossmc-kernel,lib.jboss-managed,lib.jbossxb,lib.mina,lib.servlet"/>
+ <target name="all-fetch" description="Pre-fetch all external libraries" depends="lib.jboss-common-core,lib.jboss-common-logging-spi,lib.jboss-deployers-core-spi,lib.jboss-deployers-spi,lib.jboss-deployers-structure-spi,lib.jbossmc-kernel,lib.jboss-managed,lib.jbossxb,lib.servlet"/>
<!-- all: These should be the last targets in the file -->
- <target name="all" description="Build everything" depends="all-core,all-http,all-log,all-jars,api-javadoc"/>
+ <target name="all" description="Build everything" depends="all-core,all-jars,api-javadoc"/>
- <target name="clean" description="Clean out all build files" depends="clean-core,clean-http,clean-jrpp,clean-log"/>
+ <target name="clean" description="Clean out all build files" depends="clean-core,clean-http"/>
</project>
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientMarker.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientMarker.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientMarker.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,7 +1,6 @@
package org.jboss.cx.remoting.core;
import java.io.Serializable;
-import org.jboss.cx.remoting.spi.protocol.ClientIdentifier;
/**
*
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceMarker.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceMarker.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceMarker.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,7 +1,6 @@
package org.jboss.cx.remoting.core;
import java.io.Serializable;
-import org.jboss.cx.remoting.spi.protocol.ServiceIdentifier;
/**
*
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -16,11 +16,7 @@
import org.jboss.cx.remoting.Session;
import org.jboss.cx.remoting.SessionListener;
import org.jboss.cx.remoting.core.util.OrderedExecutorFactory;
-import org.jboss.cx.remoting.log.Logger;
-import org.jboss.cx.remoting.spi.Registration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
+import org.jboss.xnio.log.Logger;
import org.jboss.cx.remoting.util.AtomicStateMachine;
import org.jboss.cx.remoting.util.AttributeMap;
import org.jboss.cx.remoting.util.CollectionUtil;
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundClient.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundClient.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundClient.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -8,7 +8,7 @@
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.ServiceContext;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
import org.jboss.cx.remoting.util.AtomicStateMachine;
import static org.jboss.cx.remoting.util.AtomicStateMachine.start;
import org.jboss.cx.remoting.util.CollectionUtil;
@@ -18,7 +18,7 @@
*
*/
public final class CoreInboundClient<I, O> {
- private static final Logger log = Logger.getLogger(CoreInboundClient.class);
+ private static final Logger log = org.jboss.xnio.log.Logger.getLogger(CoreInboundClient.class);
private final RequestListener<I, O> requestListener;
private final Executor executor;
@@ -142,9 +142,6 @@
clientInitiator.handleClosing(false);
}
- public void closeImmediate() throws RemotingException {
- }
-
public void addCloseHandler(final CloseHandler<ClientContext> contextContextCloseHandler) {
}
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -12,14 +12,13 @@
import org.jboss.cx.remoting.RequestContext;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.ClientContext;
-import org.jboss.cx.remoting.log.Logger;
import org.jboss.cx.remoting.util.AtomicStateMachine;
/**
*
*/
public final class CoreInboundRequest<I, O> {
- private static final Logger log = Logger.getLogger(CoreInboundRequest.class);
+ private static final org.jboss.xnio.log.Logger log = org.jboss.xnio.log.Logger.getLogger(CoreInboundRequest.class);
private final RequestListener<I,O> requestListener;
private final Executor executor;
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -95,11 +95,6 @@
serviceInitiator.handleClosing();
}
- public void closeImmediate() throws RemotingException {
- doClose();
- serviceInitiator.handleClosing();
- }
-
public void addCloseHandler(final CloseHandler<ServiceContext> closeHandler) {
final State current = state.getStateHold();
try {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundClient.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundClient.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundClient.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -11,7 +11,6 @@
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.RequestCompletionHandler;
import org.jboss.cx.remoting.core.util.QueueExecutor;
-import org.jboss.cx.remoting.log.Logger;
import org.jboss.cx.remoting.util.AtomicStateMachine;
import org.jboss.cx.remoting.util.CollectionUtil;
@@ -19,7 +18,7 @@
*
*/
public final class CoreOutboundClient<I, O> {
- private static final Logger log = Logger.getLogger(CoreOutboundClient.class);
+ private static final org.jboss.xnio.log.Logger log = org.jboss.xnio.log.Logger.getLogger(CoreOutboundClient.class);
private final ConcurrentMap<Object, Object> contextMap = CollectionUtil.concurrentMap();
private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.INITIAL);
@@ -109,10 +108,6 @@
doClose(false, false);
}
- public void closeImmediate() throws RemotingException {
- doClose(true, true);
- }
-
public void addCloseHandler(final CloseHandler<Client<I, O>> closeHandler) {
final State current = state.getStateHold();
try {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -11,7 +11,7 @@
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.RequestCompletionHandler;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
import org.jboss.cx.remoting.util.AtomicStateMachine;
/**
@@ -19,7 +19,7 @@
*/
public final class CoreOutboundRequest<I, O> {
- private static final Logger log = Logger.getLogger(CoreOutboundRequest.class);
+ private static final org.jboss.xnio.log.Logger log = Logger.getLogger(CoreOutboundRequest.class);
private RequestResponder<I> requestResponder;
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -7,7 +7,7 @@
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
import org.jboss.cx.remoting.util.AtomicStateMachine;
import org.jboss.cx.remoting.util.CollectionUtil;
@@ -85,10 +85,6 @@
doClose();
}
- public void closeImmediate() throws RemotingException {
- doClose();
- }
-
public void addCloseHandler(final CloseHandler<ClientSource<I, O>> closeHandler) {
final State current = state.getStateHold();
try {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,16 +1,11 @@
package org.jboss.cx.remoting.core;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectStreamClass;
-import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.net.URI;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
@@ -20,31 +15,18 @@
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.Session;
import org.jboss.cx.remoting.core.stream.DefaultStreamDetector;
-import org.jboss.cx.remoting.core.util.DelegatingObjectInput;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
import org.jboss.cx.remoting.util.ByteMessageInput;
import org.jboss.cx.remoting.util.ByteMessageOutput;
import org.jboss.cx.remoting.util.ObjectMessageInput;
import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.protocol.ClientIdentifier;
-import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
-import org.jboss.cx.remoting.spi.protocol.RequestIdentifier;
-import org.jboss.cx.remoting.spi.protocol.ServiceIdentifier;
-import org.jboss.cx.remoting.spi.protocol.StreamIdentifier;
import org.jboss.cx.remoting.spi.stream.StreamDetector;
-import org.jboss.cx.remoting.spi.stream.StreamSerializer;
-import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
import org.jboss.cx.remoting.spi.marshal.MarshallerFactory;
import org.jboss.cx.remoting.util.AtomicStateMachine;
import org.jboss.cx.remoting.util.AttributeMap;
import org.jboss.cx.remoting.util.CollectionUtil;
-import org.jboss.serial.io.JBossObjectInputStream;
-import org.jboss.serial.io.JBossObjectOutputStream;
-
/**
* Three execution contexts:
*
@@ -231,11 +213,6 @@
state.waitFor(State.DOWN);
}
- public void closeImmediate() throws RemotingException {
- shutdown();
- state.waitFor(State.DOWN);
- }
-
public void addCloseHandler(final CloseHandler<Session> closeHandler) {
final State current = state.getStateHold();
try {
@@ -313,7 +290,7 @@
if (target == null) {
throw new NullPointerException("target is null");
}
- return marshallerFactory.createRootMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getMessageOutput(target);
+ return marshallerFactory.createMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getMarshalingSink(target);
}
public ObjectMessageOutput getMessageOutput(ByteMessageOutput target, Executor streamExecutor) throws IOException {
@@ -323,14 +300,14 @@
if (streamExecutor == null) {
throw new NullPointerException("streamExecutor is null");
}
- return marshallerFactory.createRootMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getMessageOutput(target);
+ return marshallerFactory.createMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getMarshalingSink(target);
}
public ObjectMessageInput getMessageInput(ByteMessageInput source) throws IOException {
if (source == null) {
throw new NullPointerException("source is null");
}
- return marshallerFactory.createRootMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getMessageInput(source);
+ return marshallerFactory.createMarshaller(resolver, getClass().getClassLoader() /* todo this is WRONG */).getUnmarshalingSource(source);
}
public String getLocalEndpointName() {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreStream.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreStream.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreStream.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -2,14 +2,9 @@
import java.io.IOException;
import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
import org.jboss.cx.remoting.util.ObjectMessageInput;
import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
-import org.jboss.cx.remoting.spi.protocol.StreamIdentifier;
-import org.jboss.cx.remoting.spi.stream.RemoteStreamSerializer;
-import org.jboss.cx.remoting.spi.stream.StreamContext;
-import org.jboss.cx.remoting.spi.stream.StreamSerializer;
import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
/**
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientInitiator.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientInitiator.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientInitiator.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,7 +1,5 @@
package org.jboss.cx.remoting.core;
-import org.jboss.cx.remoting.spi.protocol.RequestIdentifier;
-
/**
*
*/
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientResponder.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientResponder.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ProtocolClientResponder.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,7 +1,5 @@
package org.jboss.cx.remoting.core;
-import org.jboss.cx.remoting.spi.protocol.RequestIdentifier;
-
/**
*
*/
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClassLoader.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClassLoader.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClassLoader.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -6,18 +6,17 @@
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.log.Logger;
import org.jboss.cx.remoting.service.ClassLoaderResourceReply;
import org.jboss.cx.remoting.service.ClassLoaderResourceRequest;
import org.jboss.cx.remoting.service.RemoteResource;
import org.jboss.cx.remoting.stream.ObjectSource;
-import org.jboss.cx.remoting.util.IoUtil;
+import org.jboss.xnio.IoUtils;
/**
*
*/
public final class RemoteClassLoader extends SecureClassLoader {
- private static final Logger log = Logger.getLogger(RemoteClassLoader.class);
+ private static final org.jboss.xnio.log.Logger log = org.jboss.xnio.log.Logger.getLogger(RemoteClassLoader.class);
private final Client<ClassLoaderResourceRequest, ClassLoaderResourceReply> loaderClient;
@@ -50,10 +49,10 @@
for (int t = 0; t < size; t += stream.read(bytes, t, size - t));
return defineClass(name, bytes, 0, size);
} finally {
- IoUtil.closeSafely(stream);
+ IoUtils.safeClose(stream);
}
} finally {
- IoUtil.closeSafely(source);
+ IoUtils.safeClose(source);
}
} catch (RemotingException e) {
throw new ClassNotFoundException("Cannot load class " + name + " due to an invocation failure", e);
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/StreamMarker.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/StreamMarker.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/StreamMarker.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -4,7 +4,6 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import org.jboss.cx.remoting.spi.protocol.StreamIdentifier;
import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
/**
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/ClientResolver.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/ClientResolver.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/ClientResolver.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,36 +0,0 @@
-package org.jboss.cx.remoting.core.marshal;
-
-import java.io.IOException;
-import org.jboss.cx.remoting.core.AbstractRealClient;
-import org.jboss.cx.remoting.core.ClientMarker;
-import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
-import org.jboss.cx.remoting.spi.protocol.ClientIdentifier;
-
-/**
- *
- */
-public final class ClientResolver implements ObjectResolver {
-
- private static final long serialVersionUID = 7850552704308592325L;
-
- public Object writeReplace(final Object original) throws IOException {
- if (original instanceof AbstractRealClient) {
- AbstractRealClient client = (AbstractRealClient) original;
-
- return null;
- } else {
- return original;
- }
- }
-
- public Object readResolve(final Object original) throws IOException {
- if (original instanceof ClientMarker) {
- ClientMarker clientMarker = (ClientMarker) original;
- ClientIdentifier clientIdentifier = clientMarker.getClientIdentifer();
-
- return null;
- } else {
- return original;
- }
- }
-}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/ClientSourceResolver.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/ClientSourceResolver.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/ClientSourceResolver.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,21 +0,0 @@
-package org.jboss.cx.remoting.core.marshal;
-
-import java.io.IOException;
-import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
-
-/**
- *
- */
-public final class ClientSourceResolver implements ObjectResolver {
-
- private static final long serialVersionUID = 7850552704308592325L;
-
- public Object writeReplace(final Object original) throws IOException {
- return null;
- }
-
- public Object readResolve(final Object original) throws IOException {
-
- return null;
- }
-}
\ No newline at end of file
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-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JBossSerializationMarhsaller.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -7,6 +7,8 @@
import org.jboss.cx.remoting.util.ByteMessageOutput;
import org.jboss.cx.remoting.util.ObjectMessageInput;
import org.jboss.cx.remoting.util.ObjectMessageOutput;
+import org.jboss.cx.remoting.stream.ObjectSink;
+import org.jboss.cx.remoting.stream.ObjectSource;
/**
*
@@ -30,4 +32,12 @@
public ObjectMessageInput getMessageInput(final ByteMessageInput byteMessageInput) throws IOException {
return new JBossSerializationObjectMessageInput(resolver, byteMessageInput, classLoader);
}
+
+ public ObjectSink getMarshalingSink(final ObjectSink bufferSink) throws IOException {
+ return null;
+ }
+
+ public ObjectSource getUnmarshalingSource(final ObjectSource bufferSource) throws IOException {
+ return null;
+ }
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandler.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandler.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandler.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -4,14 +4,6 @@
import java.util.concurrent.Executor;
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.protocol.ClientIdentifier;
-import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
-import org.jboss.cx.remoting.spi.protocol.RequestIdentifier;
-import org.jboss.cx.remoting.spi.protocol.ServiceIdentifier;
-import org.jboss.cx.remoting.spi.protocol.SimpleClientIdentifier;
-import org.jboss.cx.remoting.spi.protocol.SimpleRequestIdentifier;
-import org.jboss.cx.remoting.spi.protocol.StreamIdentifier;
/**
*
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandlerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandlerFactory.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandlerFactory.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -5,10 +5,6 @@
import java.util.concurrent.ConcurrentMap;
import org.jboss.cx.remoting.Endpoint;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.spi.Registration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
import org.jboss.cx.remoting.util.AttributeMap;
import org.jboss.cx.remoting.util.CollectionUtil;
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-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/InputStreamStreamSerializerFactory.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -2,185 +2,438 @@
import java.io.IOException;
import java.io.InputStream;
-import java.util.LinkedList;
-import org.jboss.cx.remoting.log.Logger;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.stream.RemoteStreamSerializer;
-import org.jboss.cx.remoting.spi.stream.StreamContext;
-import org.jboss.cx.remoting.spi.stream.StreamSerializer;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import org.jboss.xnio.log.Logger;
import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
+import org.jboss.cx.remoting.core.util.DecodingBuilder;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.xnio.channels.StreamSinkChannel;
+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.IoUtils;
+import org.jboss.xnio.BufferAllocator;
+import org.jboss.xnio.IoFuture;
+import static org.jboss.xnio.Buffers.skip;
+import static org.jboss.xnio.Buffers.flip;
/**
+ * An input stream serializer. The input stream transfer protocol consists of two types of "chunks": data and error.
+ * A data chunk starts with an ASCII {@code 'd'}, followed by a two-byte (unsigned) length field (a value of
+ * {@code 0x0000} indicates a 65536-byte chunk), followed by the actual data. An error chunk consists of a series of
+ * UTF-8 bytes representing a description of the error, followed by the end of the stream.
*
+ * Normally data chunks are transferred over the stream until the original {@link InputStream} is exhausted, at which time
+ * the proxy stream will return a {@code -1} for the EOF condition.
*/
public final class InputStreamStreamSerializerFactory implements StreamSerializerFactory {
- private static final Logger log = Logger.getLogger(InputStreamStreamSerializerFactory.class);
+ private static final long serialVersionUID = -3198623117987624799L;
+ private static final Logger log = org.jboss.xnio.log.Logger.getLogger(InputStreamStreamSerializerFactory.class);
+
+ private BufferAllocator<ByteBuffer> allocator;
+
public InputStreamStreamSerializerFactory() {
// no-arg constructor required
}
- public StreamSerializer getLocalSide(StreamContext context, Object local) throws IOException {
+ public IoHandler<StreamSinkChannel> getLocalSide(final Object localSide) throws IOException {
+ return new LocalHandler((InputStream) localSide, allocator);
+ }
- return new StreamSerializerImpl(context, (InputStream)local);
+ public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
+ return new RemoteInputStream(taskList, futureChannel);
}
- public RemoteStreamSerializer getRemoteSide(final StreamContext context) throws IOException {
- return new RemoteStreamSerializerImpl(context);
+ public BufferAllocator<ByteBuffer> getAllocator() {
+ return allocator;
}
- private enum Type {
- DATA,
- END,
+ public void setAllocator(final BufferAllocator<ByteBuffer> allocator) {
+ this.allocator = allocator;
}
- private static final int BUF_LEN = 512;
+ private static final byte DATA_CHUNK = (byte) 'd';
+ private static final byte ERROR = (byte) 'e';
- private final static class StreamSerializerImpl implements StreamSerializer {
- private final StreamContext context;
+ public static final class LocalHandler implements IoHandler<StreamSinkChannel> {
+
+ // @protectedby {@code this}
private final InputStream inputStream;
+ private final BufferAllocator<ByteBuffer> allocator;
+ private volatile ByteBuffer current;
+ private volatile boolean eof;
- public StreamSerializerImpl(final StreamContext context, final InputStream inputStream) throws IOException {
- this.context = context;
+ private LocalHandler(final InputStream inputStream, final BufferAllocator<ByteBuffer> allocator) {
this.inputStream = inputStream;
+ this.allocator = allocator;
}
- public void handleOpen() throws IOException {
- sendNext();
+ private boolean fillBuffer() throws IOException {
+ final ByteBuffer buffer = allocator.allocate();
+ buffer.put(DATA_CHUNK);
+ buffer.putShort((short) 0);
+ final int cnt;
+ if (buffer.hasArray()) {
+ final byte[] a = buffer.array();
+ final int off = buffer.arrayOffset();
+ final int rem = Math.min(buffer.remaining(), 65536);
+ cnt = inputStream.read(a, off, rem);
+ if (cnt == -1) {
+ return false;
+ }
+ skip(current, cnt);
+ } else {
+ final int rem = Math.min(buffer.remaining(), 65536);
+ final byte[] a = new byte[rem];
+ cnt = inputStream.read(a);
+ if (cnt == -1) {
+ return false;
+ }
+ current.put(a);
+ }
+ buffer.putShort(1, (short) cnt);
+ current = flip(buffer);
+ return true;
}
- public void handleData(ObjectMessageInput data) throws IOException {
- sendNext();
+ private void prepareChunk(final StreamSinkChannel channel) {
+ try {
+ eof = fillBuffer();
+ } catch (Throwable e) {
+ try {
+ current = ByteBuffer.wrap(("e" + e.getMessage()).getBytes("utf-8"));
+ } catch (UnsupportedEncodingException e1) {
+ current = ByteBuffer.wrap(new byte[] { ERROR });
+ }
+ eof = true;
+ }
+ channel.resumeWrites();
}
- private void sendNext() throws IOException {
- final ObjectMessageOutput output = context.writeMessage();
- final byte[] bytes = new byte[BUF_LEN];
- int i, t;
- boolean end = false;
- for (t = 0; t < BUF_LEN; t += i) {
- i = inputStream.read(bytes);
- if (i == -1) {
- end = true;
- break;
+ public void handleOpened(final StreamSinkChannel channel) {
+ if (channel.getOptions().contains(CommonOptions.TCP_NODELAY)) {
+ try {
+ channel.setOption(CommonOptions.TCP_NODELAY, Boolean.TRUE);
+ } catch (IOException e) {
+ // not too big a deal; just skip it
+ log.trace(e, "Failed to enable TCP_NODELAY");
}
}
- if (t > 0) {
- log.trace("Sending DATA message, %d bytes", t);
- output.write(Type.DATA.ordinal());
- output.writeInt(t);
- output.write(bytes, 0, t);
+ prepareChunk(channel);
+ }
+
+ public void handleReadable(final StreamSinkChannel channel) {
+ // not called on a sink channel
+ }
+
+ public void handleWritable(final StreamSinkChannel channel) {
+ while (current.hasRemaining()) {
+ try {
+ final int c = channel.write(current);
+ if (c == 0) {
+ channel.resumeWrites();
+ return;
+ }
+ } catch (IOException e) {
+ log.debug("Channel write failed: %s", e);
+ IoUtils.safeClose(channel);
+ }
}
- if (end) {
- log.trace("Sending END message");
- output.write(Type.END.ordinal());
+ if (eof) {
+ IoUtils.safeClose(channel);
+ } else {
+ prepareChunk(channel);
}
- output.commit();
}
- public void handleClose() throws IOException {
+ public void handleClosed(final StreamSinkChannel channel) {
+ synchronized (this) {
+ IoUtils.safeClose(inputStream);
+ }
}
}
- private final static class RemoteStreamSerializerImpl implements RemoteStreamSerializer {
+ public static final class RemoteHandler implements IoHandler<StreamSourceChannel> {
- private final StreamContext context;
- private LinkedList<Entry> messageQueue = new LinkedList<Entry>();
+ private enum DecoderState {
+ NEW_CHUNK,
+ IN_ERROR,
+ IN_DATA,
+ }
- private final class Entry {
- private final Type type;
- private final byte[] msg;
- private int i;
+ private final RemoteInputStream remoteInputStream;
+ private final ByteBuffer initialBuffer = ByteBuffer.allocate(5);
- public Entry(final byte[] msg) {
- this.msg = msg;
- type = Type.DATA;
+ private volatile ByteBuffer dataBuffer = null;
+
+ private volatile DecodingBuilder exceptionBuilder;
+ private volatile DecoderState decoderState = DecoderState.NEW_CHUNK;
+
+ private RemoteHandler(final RemoteInputStream remoteInputStream, final BufferAllocator<ByteBuffer> allocator) {
+ this.remoteInputStream = remoteInputStream;
+ }
+
+ public void handleOpened(final StreamSourceChannel channel) {
+ channel.resumeReads();
+ }
+
+ public void handleReadable(final StreamSourceChannel channel) {
+ try {
+ for (;;) switch (decoderState) {
+ case NEW_CHUNK: {
+ int n = channel.read(initialBuffer);
+ if (n == -1) {
+ IoUtils.safeClose(channel);
+ return;
+ }
+ if (n == 0) {
+ remoteInputStream.scheduleResumeReads(channel);
+ return;
+ }
+ if (initialBuffer.get(0) == DATA_CHUNK) {
+ if (initialBuffer.hasRemaining()) {
+ handleReadable(channel);
+ return;
+ }
+ initialBuffer.flip();
+ initialBuffer.get();
+ final int length = (initialBuffer.getShort() - 1) & 0xffff + 1;
+ dataBuffer = ByteBuffer.allocate(length);
+ decoderState = DecoderState.IN_DATA;
+ break;
+ } else if (initialBuffer.get(0) == ERROR) {
+ decoderState = DecoderState.IN_ERROR;
+ initialBuffer.flip();
+ initialBuffer.get();
+ exceptionBuilder.append(initialBuffer);
+ initialBuffer.clear();
+ break;
+ } else {
+ remoteInputStream.acceptException("Received garbage from remote side");
+ IoUtils.safeClose(channel);
+ return;
+ }
+ }
+ case IN_ERROR: {
+ ByteBuffer buffer = ByteBuffer.allocate(256);
+ int n = channel.read(buffer);
+ if (n == -1) {
+ remoteInputStream.acceptException(exceptionBuilder.finish().toString());
+ exceptionBuilder = null;
+ IoUtils.safeClose(channel);
+ return;
+ }
+ if (n == 0) {
+ remoteInputStream.scheduleResumeReads(channel);
+ return;
+ }
+ exceptionBuilder.append(buffer);
+ break;
+ }
+ case IN_DATA: {
+ if (! dataBuffer.hasRemaining()) {
+ dataBuffer.flip();
+ remoteInputStream.acceptBuffer(dataBuffer);
+ dataBuffer = null;
+ decoderState = DecoderState.NEW_CHUNK;
+ }
+ int n = channel.read(dataBuffer);
+ if (n == -1) {
+ IoUtils.safeClose(channel);
+ return;
+ }
+ if (n == 0) {
+ remoteInputStream.scheduleResumeReads(channel);
+ return;
+ }
+ break;
+ }
+ }
+ } catch (IOException e) {
+ remoteInputStream.acceptException("Read from remote input stream failed: " + e.getMessage());
+ IoUtils.safeClose(channel);
}
+ }
- public Entry() {
- type = Type.END;
- msg = null;
+ public void handleWritable(final StreamSourceChannel channel) {
+ }
+
+ public void handleClosed(final StreamSourceChannel channel) {
+ remoteInputStream.acceptEof();
+ }
+ }
+
+ public static final class RemoteInputStream extends InputStream {
+
+ private enum StreamState {
+ RUNNING,
+ EOF,
+ CLOSED,
+ }
+
+ private final IoFuture<StreamSourceChannel> futureChannel;
+ private final BufferAllocator<ByteBuffer> allocator;
+
+ private final Object lock = new Object();
+
+ // @protectedby lock
+ private StreamState state;
+ private ByteBuffer current;
+ private ByteBuffer next;
+ private String pendingException;
+ private boolean pendingResumeReads = false;
+
+ private RemoteInputStream(final IoFuture<StreamSourceChannel> futureChannel, final BufferAllocator<ByteBuffer> allocator) {
+ this.futureChannel = futureChannel;
+ this.allocator = allocator;
+ }
+
+ protected void acceptBuffer(ByteBuffer buffer) {
+ synchronized (lock) {
+ if (! buffer.hasRemaining()) {
+ throw new IllegalArgumentException("empty buffer");
+ }
+ if (state == StreamState.CLOSED) {
+ allocator.free(buffer);
+ }
+ if (current == null) {
+ current = buffer;
+ lock.notifyAll();
+ } else if (next == null) {
+ next = buffer;
+ } else {
+ throw new IllegalStateException();
+ }
}
}
- public RemoteStreamSerializerImpl(final StreamContext context) {
- this.context = context;
+ protected void acceptException(String exception) {
+ synchronized (lock) {
+ pendingException = exception;
+ if (current == null) {
+ lock.notifyAll();
+ }
+ }
}
- public InputStream getRemoteInstance() {
- return new InputStream() {
+ protected void acceptEof() {
+ synchronized (lock) {
+ if (state == StreamState.RUNNING) {
+ state = StreamState.EOF;
+ if (current == null) {
+ lock.notifyAll();
+ }
+ }
+ }
+ }
- public int read() throws IOException {
- boolean intr = Thread.interrupted();
+ protected void scheduleResumeReads(StreamSourceChannel channel) {
+ synchronized (lock) {
+ if (state == StreamState.CLOSED || state == StreamState.EOF) {
+ return;
+ }
+ if (next == null || current == null) {
+ channel.resumeReads();
+ } else {
+ pendingResumeReads = true;
+ }
+ }
+ }
+
+ private ByteBuffer getCurrent() throws IOException {
+ boolean intr = false;
+ try {
+ while (current == null) {
+ if (pendingException != null) {
+ throw new IOException(pendingException);
+ } else if (state == StreamState.EOF) {
+ return null;
+ }
try {
- synchronized(messageQueue) {
- for (;;) {
- if (messageQueue.size() == 0) {
- context.writeMessage().commit();
- do {
- try {
- messageQueue.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- } while (messageQueue.size() == 0);
- }
- final RemoteStreamSerializerImpl.Entry first = messageQueue.getFirst();
- switch (first.type) {
- case DATA:
- if (first.msg.length <= first.i) {
- messageQueue.removeFirst();
- } else {
- return first.msg[first.i ++] & 0xff;
- }
- default:
- return -1;
- }
- }
- }
- } finally {
- if (intr) {
- Thread.currentThread().interrupt();
- }
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
}
}
- };
+ return current;
+ } finally {
+ if (intr) {
+ Thread.currentThread().interrupt();
+ }
+ }
}
- public void handleOpen() throws IOException {
+ public int read() throws IOException {
+ synchronized (lock) {
+ if (state == StreamState.CLOSED) {
+ return -1;
+ }
+ final ByteBuffer buffer = getCurrent();
+ if (buffer == null) {
+ return -1;
+ }
+ final byte v = buffer.get();
+ if (! buffer.hasRemaining()) {
+ current = next;
+ next = null;
+ allocator.free(buffer);
+ if (pendingResumeReads) {
+ futureChannel.get().resumeReads();
+ pendingResumeReads = false;
+ }
+ }
+ return v & 0xff;
+ }
}
- public void handleData(ObjectMessageInput data) throws IOException {
- synchronized(messageQueue) {
- for (;;) {
- final int d = data.read();
- if (d == -1) {
- break;
+ public int read(final byte b[], final int off, final int len) throws IOException {
+ synchronized (lock) {
+ if (state == StreamState.CLOSED) {
+ return -1;
+ }
+ final ByteBuffer buffer = getCurrent();
+ if (buffer == null) {
+ return -1;
+ }
+ final int cnt = Math.min(buffer.remaining(), len);
+ buffer.get(b, off, cnt);
+ if (! buffer.hasRemaining()) {
+ current = next;
+ next = null;
+ allocator.free(buffer);
+ if (pendingResumeReads) {
+ futureChannel.get().resumeReads();
+ pendingResumeReads = false;
}
- Type t = Type.values()[d];
- switch (t) {
- case DATA:
- int l = data.readInt();
- byte[] bytes = new byte[l];
- data.read(bytes);
- log.trace("Received DATA message; %d bytes", bytes.length);
- messageQueue.add(new Entry(bytes));
- break;
- case END:
- log.trace("Received END message");
- messageQueue.add(new Entry());
- break;
+ }
+ return cnt;
+ }
+ }
+
+ public void close() throws IOException {
+ synchronized (lock) {
+ if (state != StreamState.CLOSED) {
+ if (current != null) {
+ allocator.free(current);
+ current = null;
}
+ if (next != null) {
+ allocator.free(next);
+ next = null;
+ }
+ state = StreamState.CLOSED;
+ futureChannel.get().close();
}
- messageQueue.notifyAll();
}
}
- public void handleClose() throws IOException {
- synchronized(messageQueue) {
- messageQueue.add(new Entry());
+ public int available() throws IOException {
+ synchronized (lock) {
+ return current == null ? 0 : current.remaining() + (next == null ? 0 : next.remaining());
}
}
}
-}
+}
\ No newline at end of file
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/IteratorStreamSerializerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/IteratorStreamSerializerFactory.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/IteratorStreamSerializerFactory.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -3,68 +3,27 @@
import java.io.IOException;
import java.util.Iterator;
import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.spi.stream.RemoteStreamSerializer;
-import org.jboss.cx.remoting.spi.stream.StreamContext;
-import org.jboss.cx.remoting.spi.stream.StreamSerializer;
import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
import org.jboss.cx.remoting.stream.ObjectSource;
import org.jboss.cx.remoting.stream.Streams;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.xnio.IoHandler;
+import org.jboss.xnio.Client;
/**
*
*/
public final class IteratorStreamSerializerFactory implements StreamSerializerFactory {
- private final ObjectSourceStreamSerializerFactory other = new ObjectSourceStreamSerializerFactory();
- public StreamSerializer getLocalSide(StreamContext context, Object local) throws IOException {
- return other.getLocalSide(context, Streams.getIteratorObjectSource((Iterator<?>)local));
- }
+ private static final long serialVersionUID = 5106872230130868988L;
- public RemoteStreamSerializer getRemoteSide(StreamContext context) throws IOException {
- return new RemoteStreamSerializerImpl(other.getRemoteSide(context), context);
+ private
+
+ public IoHandler<? super StreamChannel> getLocalSide(final Object localSide) throws IOException {
+ return null;
}
- public static final class RemoteStreamSerializerImpl implements RemoteStreamSerializer {
- private final RemoteStreamSerializer other;
- private final StreamContext context;
-
- public RemoteStreamSerializerImpl(final RemoteStreamSerializer other, final StreamContext context) {
- this.other = other;
- this.context = context;
- }
-
- public Iterator<Object> getRemoteInstance() {
- final ObjectSource<?> objectSource = (ObjectSource<?>) other.getRemoteInstance();
- return new Iterator<Object>() {
- public boolean hasNext() {
- try {
- return objectSource.hasNext();
- } catch (IOException e) {
- throw new IllegalStateException("Illegal state: " + e.toString());
- }
- }
-
- public Object next() {
- try {
- return objectSource.next();
- } catch (IOException e) {
- throw new IllegalStateException("Illegal state: " + e.toString());
- }
- }
-
- public void remove() {
- throw new UnsupportedOperationException("remove()");
- }
- };
- }
-
- public void handleOpen() throws IOException {
- }
-
- public void handleData(ObjectMessageInput data) throws IOException {
- }
-
- public void handleClose() throws IOException {
- }
+ public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
+ return null;
}
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSinkStreamSerializerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSinkStreamSerializerFactory.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSinkStreamSerializerFactory.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -3,9 +3,6 @@
import java.io.IOException;
import org.jboss.cx.remoting.util.ObjectMessageInput;
import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.stream.RemoteStreamSerializer;
-import org.jboss.cx.remoting.spi.stream.StreamContext;
-import org.jboss.cx.remoting.spi.stream.StreamSerializer;
import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
import org.jboss.cx.remoting.stream.ObjectSink;
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-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -6,185 +6,83 @@
import java.util.Queue;
import org.jboss.cx.remoting.util.ObjectMessageInput;
import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.stream.RemoteStreamSerializer;
-import org.jboss.cx.remoting.spi.stream.StreamContext;
-import org.jboss.cx.remoting.spi.stream.StreamSerializer;
import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
+import org.jboss.cx.remoting.spi.marshal.MarshallerFactory;
import org.jboss.cx.remoting.stream.ObjectSource;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.xnio.channels.StreamSourceChannel;
+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.IoUtils;
+import org.jboss.xnio.log.Logger;
/**
*
*/
public final class ObjectSourceStreamSerializerFactory implements StreamSerializerFactory {
- public StreamSerializer getLocalSide(final StreamContext context, final Object local) throws IOException {
- return new StreamSerializerImpl(context, (ObjectSource<?>) local);
- }
- public RemoteStreamSerializer getRemoteSide(final StreamContext context) throws IOException {
- return new RemoteStreamSerializerImpl(context);
- }
+ private static final long serialVersionUID = -7485283009011459281L;
- private static final class StreamSerializerImpl implements StreamSerializer {
- private final StreamContext streamContext;
- private final ObjectSource<?> objectSource;
+ private static final Logger log = Logger.getLogger(ObjectSourceStreamSerializerFactory.class);
- public StreamSerializerImpl(final StreamContext streamContext, final ObjectSource<?> objectSource) throws IOException {
- this.streamContext = streamContext;
- this.objectSource = objectSource;
- }
- public void handleOpen() throws IOException {
- transmitNext();
- }
+ private MarshallerFactory marshallerFactory;
- public void handleData(ObjectMessageInput data) throws IOException {
- transmitNext();
- }
+ public MarshallerFactory getMarshallerFactory() {
+ return marshallerFactory;
+ }
- public void handleClose() throws IOException {
- objectSource.close();
- }
+ public void setMarshallerFactory(final MarshallerFactory marshallerFactory) {
+ this.marshallerFactory = marshallerFactory;
+ }
- private void transmitNext() throws IOException {
- final ObjectMessageOutput msg = streamContext.writeMessage();
- final boolean hasNext = objectSource.hasNext();
- msg.writeBoolean(hasNext);
- if (hasNext) {
- msg.writeObject(objectSource.next());
- msg.writeBoolean(objectSource.hasNext());
- }
- msg.commit();
- msg.close();
- }
+ public IoHandler<? super StreamChannel> getLocalSide(final Object localSide) throws IOException {
+
+ return null;
+ }
+ public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
+ return null;
}
- private static final class RemoteStreamSerializerImpl implements RemoteStreamSerializer {
+ public static class LocalHandler implements IoHandler<StreamSinkChannel> {
+ private final ObjectSource objectSource;
- private enum Type {
- ITEM,
- EXCEPTION,
- CLOSE,
- END,
+ public void handleOpened(final StreamSinkChannel channel) {
+ if (channel.getOptions().contains(CommonOptions.TCP_NODELAY)) try {
+ channel.setOption(CommonOptions.TCP_NODELAY, Boolean.TRUE);
+ } catch (Exception e) {
+ log.trace("Error setting TCP_NODELAY option: %s", e.getMessage());
+ }
+ channel.resumeWrites();
}
- private class Message {
- private final Type type;
- private final Object data;
+ public void handleReadable(final StreamSinkChannel channel) {
+ // not invoked
+ }
- public Message(final Type type, final Object data) {
- this.type = type;
- this.data = data;
- }
+ public void handleWritable(final StreamSinkChannel channel) {
}
- private final Queue<Message> messageQueue = new LinkedList<Message>();
-
- private final StreamContext context;
-
- public RemoteStreamSerializerImpl(final StreamContext context) {
- this.context = context;
+ public void handleClosed(final StreamSinkChannel channel) {
+ IoUtils.safeClose(objectSource);
}
+ }
- public ObjectSource getRemoteInstance() {
- return new ObjectSource() {
- public boolean hasNext() throws IOException {
- boolean intr = Thread.interrupted();
- try {
- synchronized(messageQueue) {
- while (messageQueue.isEmpty()) {
- try {
- messageQueue.wait();
- } catch (InterruptedException e) {
- intr = true;
- Thread.interrupted();
- }
- }
- final Message msg = messageQueue.peek();
- return msg.type != Type.END;
- }
- } finally {
- if (intr) Thread.currentThread().interrupt();
- }
- }
+ public static class RemoteHandler implements IoHandler<StreamSourceChannel> {
- public Object next() throws IOException {
- boolean intr = Thread.interrupted();
- try {
- synchronized(messageQueue) {
- while (messageQueue.isEmpty()) {
- try {
- messageQueue.wait();
- } catch (InterruptedException e) {
- intr = true;
- Thread.interrupted();
- }
- }
- final Message msg = messageQueue.remove();
- final ObjectMessageOutput omsg;
- switch (msg.type) {
- case ITEM:
- omsg = context.writeMessage();
- omsg.commit();
- omsg.close();
- return msg.data;
- case EXCEPTION:
- omsg = context.writeMessage();
- omsg.commit();
- omsg.close();
- throw (IOException) msg.data;
- case END:
- messageQueue.add(msg);
- throw new NoSuchElementException("next() past end of iterator");
- case CLOSE:
- messageQueue.add(msg);
- throw new IOException("Channel closed");
- }
- throw new IllegalStateException("wrong state");
- }
- } finally {
- if (intr) Thread.currentThread().interrupt();
- }
- }
-
- public void close() throws IOException {
- context.close();
- synchronized(messageQueue) {
- messageQueue.clear();
- messageQueue.add(new Message(Type.CLOSE, null));
- }
- }
- };
+ public void handleOpened(final StreamSourceChannel channel) {
}
- public void handleOpen() throws IOException {
+ public void handleReadable(final StreamSourceChannel channel) {
}
- @SuppressWarnings ({"unchecked"})
- public void handleData(ObjectMessageInput data) throws IOException {
- synchronized(messageQueue) {
- if (! data.readBoolean()) {
- messageQueue.add(new Message(Type.END, null));
- } else {
- final Object obj;
- try {
- obj = data.readObject();
- messageQueue.add(new Message(Type.ITEM, obj));
- } catch (ClassNotFoundException e) {
- messageQueue.add(new Message(Type.EXCEPTION, new IOException("Failed to load class for next item: " + e.toString())));
- }
- if (! data.readBoolean()) {
- messageQueue.add(new Message(Type.END, null));
- }
- }
- }
+ public void handleWritable(final StreamSourceChannel channel) {
}
- public void handleClose() throws IOException {
- synchronized(messageQueue) {
- messageQueue.add(new Message(Type.CLOSE, null));
- }
+ public void handleClosed(final StreamSourceChannel channel) {
}
-
}
}
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-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/OutputStreamStreamSerailizerFactory.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -2,126 +2,227 @@
import java.io.IOException;
import java.io.OutputStream;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.stream.RemoteStreamSerializer;
-import org.jboss.cx.remoting.spi.stream.StreamContext;
-import org.jboss.cx.remoting.spi.stream.StreamSerializer;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.util.concurrent.Semaphore;
import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
+import org.jboss.xnio.channels.StreamChannel;
+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.BufferAllocator;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.log.Logger;
/**
* Stream serializer for {@link java.io.OutputStream} instances.
*/
public final class OutputStreamStreamSerailizerFactory implements StreamSerializerFactory {
- public StreamSerializer getLocalSide(StreamContext context, Object local) throws IOException {
- return new StreamSerializerImpl((OutputStream)local);
- }
- public RemoteStreamSerializer getRemoteSide(StreamContext context) throws IOException {
- return new RemoteStreamSerializerImpl(context);
+ private static final Logger log = Logger.getLogger(OutputStreamStreamSerailizerFactory.class);
+
+ private static final long serialVersionUID = -5934238025840749071L;
+
+ public IoHandler<? super StreamChannel> getLocalSide(final Object localSide) throws IOException {
+ return new LocalHandler((OutputStream) localSide, new BufferAllocator<ByteBuffer>() {
+ public ByteBuffer allocate() {
+ return ByteBuffer.allocate(512);
+ }
+
+ public void free(final ByteBuffer byteBuffer) {
+ }
+ });
}
- /**
- * KEEP IN ORDER.
- */
- private enum MessageType {
- DATA,
- FLUSH,
+ public Object getRemoteSide(final Client<StreamChannel> remoteClient) throws IOException {
+ final RemoteHandler handler = new RemoteHandler(new BufferAllocator<ByteBuffer>() {
+ public ByteBuffer allocate() {
+ return ByteBuffer.allocate(512);
+ }
+
+ public void free(final ByteBuffer byteBuffer) {
+ }
+ });
+ final IoFuture<StreamChannel> futureChannel = remoteClient.connect(handler);
+ return new RemoteOutputStream(handler, futureChannel);
}
- private static final class StreamSerializerImpl implements StreamSerializer {
+ public static final class LocalHandler implements IoHandler<StreamSourceChannel> {
+
private final OutputStream outputStream;
+ private final BufferAllocator<ByteBuffer> allocator;
- public StreamSerializerImpl(final OutputStream outputStream) {
+ public LocalHandler(final OutputStream outputStream, final BufferAllocator<ByteBuffer> allocator) {
this.outputStream = outputStream;
+ this.allocator = allocator;
}
- public void handleOpen() throws IOException {
+ public void handleOpened(final StreamSourceChannel channel) {
+ channel.resumeReads();
}
- public void handleData(ObjectMessageInput data) throws IOException {
- MessageType messageType = MessageType.values()[data.read()];
- switch (messageType) {
- case DATA:
- for (int i = data.read(); i != -1; i = data.read()) {
- outputStream.write(i);
+ public void handleReadable(final StreamSourceChannel channel) {
+ ByteBuffer buffer = allocator.allocate();
+ try {
+ for (;; buffer.clear()) {
+ final int c = channel.read(buffer);
+ if (c == 0) {
+ channel.resumeReads();
+ return;
+ } else if (c == -1) {
+ IoUtils.safeClose(channel);
+ log.trace("Remote output stream closed normally");
+ } else {
+ buffer.flip();
+ if (buffer.hasArray()) {
+ outputStream.write(buffer.array(), buffer.arrayOffset(), buffer.remaining());
+ } else {
+ final byte[] bytes = new byte[buffer.remaining()];
+ buffer.get(bytes);
+ outputStream.write(bytes);
+ }
}
- break;
- case FLUSH:
- outputStream.flush();
- break;
+ }
+ } catch (IOException e) {
+ IoUtils.safeClose(channel);
+ log.trace("Remote output stream closed due to exception: %s", e.getMessage());
+ } finally {
+ allocator.free(buffer);
}
}
- public void handleClose() throws IOException {
- // Don't automatically close.
- outputStream.flush();
+ public void handleWritable(final StreamSourceChannel channel) {
}
+
+ public void handleClosed(final StreamSourceChannel channel) {
+ IoUtils.safeClose(outputStream);
+ }
}
- private static final int BUFFER_SIZE = 4096;
+ public static final class RemoteHandler implements IoHandler<StreamSinkChannel> {
- private static final class RemoteStreamSerializerImpl implements RemoteStreamSerializer {
- private final StreamContext context;
- private final Object monitor = new Object();
- private ObjectMessageOutput current;
+ private final Semaphore semaphore = new Semaphore(0);
+ private final BufferAllocator<ByteBuffer> allocator;
- public RemoteStreamSerializerImpl(final StreamContext context) {
- this.context = context;
+ private volatile boolean closed;
+ private volatile ByteBuffer buffer;
+
+ private RemoteHandler(final BufferAllocator<ByteBuffer> allocator) {
+ this.allocator = allocator;
}
- public OutputStream getRemoteInstance() {
- return new OutputStream() {
- public void write(int b) throws IOException {
- synchronized(monitor) {
- if (current == null) {
- current = context.writeMessage();
- }
- current.write(b);
- if (current.getBytesWritten() > BUFFER_SIZE) {
- flush();
- }
- }
- }
+ public void handleOpened(final StreamSinkChannel channel) {
+ // block sends until the channel is up
+ semaphore.release();
+ }
- public void write(byte b[], int off, int len) throws IOException {
- synchronized(monitor) {
- if (current == null) {
- current = context.writeMessage();
- }
- current.write(b, off, len);
- if (current.getBytesWritten() > BUFFER_SIZE) {
- flush();
- }
- }
- }
+ public void handleReadable(final StreamSinkChannel channel) {
+ }
- public void flush() throws IOException {
- synchronized(monitor) {
- if (current != null) {
- current.commit();
- current = null;
+ public void handleWritable(final StreamSinkChannel channel) {
+ final ByteBuffer buffer = this.buffer;
+ if (buffer != null) {
+ try {
+ while (buffer.hasRemaining()) {
+ if (channel.write(buffer) == 0) {
+ channel.resumeWrites();
+ return;
}
}
+ } catch (IOException e) {
+ log.trace("Send exception: %s", e.getMessage());
+ IoUtils.safeClose(channel);
+ semaphore.release();
}
+ this.buffer = null;
+ allocator.free(buffer);
+ }
+ }
- public void close() throws IOException {
- synchronized(monitor) {
- context.close();
- }
- }
- };
+ public void handleClosed(final StreamSinkChannel channel) {
+ closed = true;
+ final ByteBuffer buffer = this.buffer;
+ if (buffer != null) {
+ this.buffer = null;
+ allocator.free(buffer);
+ }
}
- public void handleOpen() throws IOException {
+ private void send(final ByteBuffer buffer) throws IOException {
+ if (closed) {
+ throw new IOException("Channel closed");
+ }
+ semaphore.acquireUninterruptibly();
+ if (closed) {
+ semaphore.release();
+ allocator.free(buffer);
+ throw new IOException("Channel closed");
+ }
+ this.buffer = buffer;
}
+ }
- public void handleData(ObjectMessageInput data) throws IOException {
- // ignore
+ public static final class RemoteOutputStream extends OutputStream {
+
+ private final RemoteHandler handler;
+ private final IoFuture<? extends Channel> futureChannel;
+ private ByteBuffer buffer;
+
+ public RemoteOutputStream(final RemoteHandler handler, final IoFuture<? extends Channel> futureChannel) {
+ this.handler = handler;
+ this.futureChannel = futureChannel;
}
- public void handleClose() throws IOException {
- // ignore
+ public void write(final int b) throws IOException {
+ if (handler.closed) {
+ throw new IOException("Channel closed");
+ }
+ if (buffer == null) {
+ buffer = handler.allocator.allocate();
+ }
+ buffer.put((byte)b);
+ if (! buffer.hasRemaining()) {
+ flush();
+ }
}
+
+ public void write(final byte[] bytes, int offset, int length) throws IOException {
+ if (handler.closed) {
+ throw new IOException("Channel closed");
+ }
+ if (buffer == null) {
+ buffer = handler.allocator.allocate();
+ }
+ while (length > 0) {
+ int size = Math.min(buffer.remaining(), length);
+ buffer.put(bytes, offset, size);
+ length -= size; offset += size;
+ if (! buffer.hasRemaining()) {
+ flush();
+ }
+ }
+ }
+
+ public void flush() throws IOException {
+ try {
+ handler.send(buffer);
+ } finally {
+ buffer = null;
+ }
+ }
+
+ public void close() throws IOException {
+ final Channel channel;
+ try {
+ channel = futureChannel.get();
+ } catch (IOException ex) {
+ // throwing this exception would cause close() to appear to not be idempotent
+ log.trace("No channel to close: %s", ex.getMessage());
+ return;
+ }
+ channel.close();
+ }
}
}
Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/DecodingBuilder.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/DecodingBuilder.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/DecodingBuilder.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -0,0 +1,98 @@
+/*
+ * 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.util;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.Charset;
+import java.nio.charset.CodingErrorAction;
+import static org.jboss.xnio.Buffers.flip;
+
+/**
+ *
+ */
+public final class DecodingBuilder {
+ private final StringBuilder stringBuilder;
+ private final CharsetDecoder decoder;
+ private final CharBuffer holder;
+
+ public DecodingBuilder() {
+ this(64);
+ }
+
+ public DecodingBuilder(String charset) {
+ this(charset, 64);
+ }
+
+ public DecodingBuilder(Charset charset) {
+ this(charset, 64);
+ }
+
+ public DecodingBuilder(Charset charset, int bufsize) {
+ stringBuilder = new StringBuilder();
+ decoder = charset.newDecoder();
+ holder = CharBuffer.allocate(bufsize);
+ decoder.onMalformedInput(CodingErrorAction.REPLACE);
+ decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ decoder.replaceWith("?");
+ }
+
+ public DecodingBuilder(int bufsize) {
+ this(Charset.defaultCharset(), bufsize);
+ }
+
+ public DecodingBuilder(String charset, int bufsize) {
+ this(Charset.forName(charset), bufsize);
+ }
+
+ public DecodingBuilder append(ByteBuffer buffer) {
+ boolean oflow;
+ do {
+ oflow = decoder.decode(buffer, holder, false).isOverflow();
+ stringBuilder.append(flip(holder));
+ holder.clear();
+ } while (oflow);
+ }
+
+ public static final ByteBuffer EMPTY = ByteBuffer.allocate(0);
+
+ public DecodingBuilder finish() {
+ boolean oflow;
+ do {
+ oflow = decoder.decode(EMPTY, holder, true).isOverflow();
+ stringBuilder.append(flip(holder));
+ holder.clear();
+ } while (oflow);
+ }
+
+ public String toString() {
+ boolean oflow;
+ do {
+ oflow = decoder.flush(holder).isOverflow();
+ stringBuilder.append(flip(holder));
+ holder.clear();
+ } while (oflow);
+ return stringBuilder.toString();
+ }
+}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/QueueExecutor.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/QueueExecutor.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/util/QueueExecutor.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -3,7 +3,7 @@
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
/**
* An executor designed to run all submitted tasks in the current thread. The queue is run continuously
@@ -12,7 +12,7 @@
* shut down.
*/
public final class QueueExecutor implements Executor {
- private static final Logger log = Logger.getLogger(QueueExecutor.class);
+ private static final Logger log = org.jboss.xnio.log.Logger.getLogger(QueueExecutor.class);
private final Queue<Runnable> queue = new LinkedList<Runnable>();
Modified: remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java
===================================================================
--- remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -9,14 +9,12 @@
import java.security.SecureRandom;
import org.jboss.cx.remoting.http.AbstractHttpChannel;
import org.jboss.cx.remoting.http.HttpMessageWriter;
-import org.jboss.cx.remoting.http.cookie.Cookie;
-import org.jboss.cx.remoting.http.cookie.CookieParser;
import org.jboss.cx.remoting.http.RemotingHttpChannelContext;
import org.jboss.cx.remoting.http.RemotingHttpServerContext;
import org.jboss.cx.remoting.util.AbstractOutputStreamByteMessageOutput;
import org.jboss.cx.remoting.util.CollectionUtil;
-import org.jboss.cx.remoting.util.IoUtil;
import org.jboss.cx.remoting.util.InputStreamByteMessageInput;
+import org.jboss.xnio.IoUtils;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpContext;
@@ -139,7 +137,7 @@
context.processInboundMessage(new InputStreamByteMessageInput(inputStream, -1));
}
} finally {
- IoUtil.closeSafely(inputStream);
+ IoUtils.safeClose(inputStream);
}
if (needToSetSession) {
final StringBuilder setCookieBuilder = new StringBuilder(60);
@@ -164,7 +162,7 @@
}
});
} finally {
- IoUtil.closeSafely(outputStream);
+ IoUtils.safeClose(outputStream);
}
}
Modified: remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/AbstractHttpUrlChannel.java
===================================================================
--- remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/AbstractHttpUrlChannel.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/AbstractHttpUrlChannel.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -12,14 +12,13 @@
import java.util.concurrent.FutureTask;
import java.util.concurrent.Future;
import org.jboss.cx.remoting.http.AbstractHttpChannel;
-import org.jboss.cx.remoting.http.cookie.CookieClientSession;
import org.jboss.cx.remoting.http.HttpMessageWriter;
import org.jboss.cx.remoting.http.RemotingHttpChannelContext;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
import org.jboss.cx.remoting.util.AbstractOutputStreamByteMessageOutput;
-import org.jboss.cx.remoting.util.IoUtil;
import org.jboss.cx.remoting.util.NamingThreadFactory;
import org.jboss.cx.remoting.util.InputStreamByteMessageInput;
+import org.jboss.xnio.IoUtils;
/**
*
@@ -181,10 +180,10 @@
try {
channelContext.processInboundMessage(new InputStreamByteMessageInput(inputStream, -1));
} finally {
- IoUtil.closeSafely(inputStream);
+ IoUtils.safeClose(inputStream);
}
} finally {
- IoUtil.closeSafely(outputStream);
+ IoUtils.safeClose(outputStream);
}
} catch (IOException e) {
// probably a HTTP error occurred, so let's consume it
@@ -195,7 +194,7 @@
while (errorStream.read() > -1);
errorStream.close();
} finally {
- IoUtil.closeSafely(errorStream);
+ IoUtils.safeClose(errorStream);
} else {
log.trace(e, "Connection failed but there is no error stream");
}
Deleted: remoting3/trunk/log-jboss/src/main/java/org/jboss/cx/remoting/log/Logger.java
===================================================================
--- remoting3/trunk/log-jboss/src/main/java/org/jboss/cx/remoting/log/Logger.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/log-jboss/src/main/java/org/jboss/cx/remoting/log/Logger.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,86 +0,0 @@
-package org.jboss.cx.remoting.log;
-
-/**
- *
- */
-public final class Logger {
-
- @SuppressWarnings ({"NonConstantLogger"})
- private org.jboss.logging.Logger logger;
-
- private Logger(final String name) {
- logger = org.jboss.logging.Logger.getLogger(name);
- }
-
- public static Logger getLogger(final String name) {
- return new Logger(name);
- }
-
- public static Logger getLogger(final Class claxx) {
- return new Logger(claxx.getName());
- }
-
- public boolean isTrace() {
- return logger.isTraceEnabled();
- }
-
- public void error(String msg) {
- logger.error(msg);
- }
-
- public void error(Throwable ex, String msg, Object... params) {
- logger.error(String.format(msg, params), ex);
- }
-
- public void error(String msg, Object... params) {
- logger.error(String.format(msg, params));
- }
-
- public void warn(String msg) {
- logger.warn(msg);
- }
-
- public void warn(Throwable ex, String msg, Object... params) {
- logger.warn(String.format(msg, params), ex);
- }
-
- public void warn(String msg, Object... params) {
- logger.warn(String.format(msg, params));
- }
-
- public void info(String msg) {
- logger.info(msg);
- }
-
- public void info(Throwable ex, String msg, Object... params) {
- logger.info(String.format(msg, params), ex);
- }
-
- public void info(String msg, Object... params) {
- logger.info(String.format(msg, params));
- }
-
- public void debug(String msg) {
- logger.debug(msg);
- }
-
- public void debug(Throwable ex, String msg, Object... params) {
- logger.debug(String.format(msg, params), ex);
- }
-
- public void debug(String msg, Object... params) {
- logger.debug(String.format(msg, params));
- }
-
- public void trace(String msg) {
- logger.trace(msg);
- }
-
- public void trace(Throwable ex, String msg, Object... params) {
- logger.trace(String.format(msg, params), ex);
- }
-
- public void trace(String msg, Object... params) {
- logger.trace(String.format(msg, params));
- }
-}
Deleted: remoting3/trunk/log-jul/src/main/java/org/jboss/cx/remoting/log/Logger.java
===================================================================
--- remoting3/trunk/log-jul/src/main/java/org/jboss/cx/remoting/log/Logger.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/log-jul/src/main/java/org/jboss/cx/remoting/log/Logger.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,122 +0,0 @@
-package org.jboss.cx.remoting.log;
-
-import java.util.logging.LogRecord;
-
-
-/**
- *
- */
-public final class Logger {
- public static final class Level extends java.util.logging.Level {
-
- private static final long serialVersionUID = 9150446594030531854L;
-
- protected Level(final String name, final int value) {
- super(name, value);
- }
- }
-
- public static final Level TRACE = new Level("TRACE", 400);
- public static final Level DEBUG = new Level("DEBUG", 500);
- public static final Level INFO = new Level("INFO", 800);
- public static final Level WARN = new Level("WARN", 900);
- public static final Level ERROR = new Level("ERROR", 1000);
-
- @SuppressWarnings ({"NonConstantLogger"})
- private final java.util.logging.Logger logger;
- private final String name;
-
- private Logger(final String name) {
- this.name = name;
- logger = java.util.logging.Logger.getLogger(name);
- }
-
- public static Logger getLogger(final String name) {
- return new Logger(name);
- }
-
- public static Logger getLogger(final Class claxx) {
- return new Logger(claxx.getName());
- }
-
- public boolean isTrace() {
- return logger.isLoggable(TRACE);
- }
-
- private void doLog(Level level, String msg, Throwable ex, Object[] params) {
- if (logger.isLoggable(level)) {
- final String fmtMsg;
- if (params != null && params.length > 0) {
- fmtMsg = String.format(msg, params);
- } else {
- fmtMsg = msg;
- }
- LogRecord record = new LogRecord(level, fmtMsg);
- record.setLoggerName(name);
- if (ex != null) record.setThrown(ex);
- record.setSourceMethodName("");
- record.setSourceClassName("");
- logger.log(record);
- }
- }
-
- public void error(String msg) {
- doLog(ERROR, msg, null, null);
- }
-
- public void error(Throwable ex, String msg, Object... params) {
- doLog(ERROR, msg, ex, params);
- }
-
- public void error(String msg, Object... params) {
- doLog(ERROR, msg, null, params);
- }
-
- public void warn(String msg) {
- doLog(WARN, msg, null, null);
- }
-
- public void warn(Throwable ex, String msg, Object... params) {
- doLog(WARN, msg, ex, params);
- }
-
- public void warn(String msg, Object... params) {
- doLog(WARN, msg, null, params);
- }
-
- public void info(String msg) {
- doLog(INFO, msg, null, null);
- }
-
- public void info(Throwable ex, String msg, Object... params) {
- doLog(INFO, msg, ex, params);
- }
-
- public void info(String msg, Object... params) {
- doLog(INFO, msg, null, params);
- }
-
- public void debug(String msg) {
- doLog(DEBUG, msg, null, null);
- }
-
- public void debug(Throwable ex, String msg, Object... params) {
- doLog(DEBUG, msg, ex, params);
- }
-
- public void debug(String msg, Object... params) {
- doLog(DEBUG, msg, null, params);
- }
-
- public void trace(String msg) {
- doLog(TRACE, msg, null, null);
- }
-
- public void trace(Throwable ex, String msg, Object... params) {
- doLog(TRACE, msg, ex, params);
- }
-
- public void trace(String msg, Object... params) {
- doLog(TRACE, msg, null, params);
- }
-}
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -13,7 +13,7 @@
import org.jboss.cx.remoting.core.security.sasl.Provider;
import org.jboss.cx.remoting.jrpp.JrppServer;
import org.jboss.cx.remoting.util.AttributeMap;
-import org.jboss.cx.remoting.util.IoUtil;
+import org.jboss.xnio.IoUtils;
/**
*
@@ -35,10 +35,10 @@
final String result = client.invoke(original);
System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), result.trim());
} finally {
- IoUtil.closeSafely(client);
+ IoUtils.safeClose(client);
}
} finally {
- IoUtil.closeSafely(session);
+ IoUtils.safeClose(session);
}
} finally {
jrppServer.stop();
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -16,7 +16,7 @@
import org.jboss.cx.remoting.core.security.sasl.Provider;
import org.jboss.cx.remoting.jrpp.JrppServer;
import org.jboss.cx.remoting.util.AttributeMap;
-import org.jboss.cx.remoting.util.IoUtil;
+import org.jboss.xnio.IoUtils;
/**
*
@@ -44,19 +44,19 @@
final String secretLine = bufferedReader.readLine();
System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), secretLine);
} finally {
- IoUtil.closeSafely(bufferedReader);
+ IoUtils.safeClose(bufferedReader);
}
} finally {
- IoUtil.closeSafely(reader);
+ IoUtils.safeClose(reader);
}
} finally {
- IoUtil.closeSafely(originalReader);
+ IoUtils.safeClose(originalReader);
}
} finally {
- IoUtil.closeSafely(client);
+ IoUtils.safeClose(client);
}
} finally {
- IoUtil.closeSafely(session);
+ IoUtils.safeClose(session);
}
} finally {
jrppServer.stop();
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -7,7 +7,7 @@
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.Remoting;
import org.jboss.cx.remoting.core.security.sasl.Provider;
-import org.jboss.cx.remoting.util.IoUtil;
+import org.jboss.xnio.IoUtils;
/**
*
@@ -25,7 +25,7 @@
final String result = client.invoke(original);
System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), result.trim());
} finally {
- IoUtil.closeSafely(client);
+ IoUtils.safeClose(client);
}
} finally {
Remoting.closeEndpoint(endpoint);
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -10,7 +10,7 @@
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.Remoting;
import org.jboss.cx.remoting.core.security.sasl.Provider;
-import org.jboss.cx.remoting.util.IoUtil;
+import org.jboss.xnio.IoUtils;
/**
*
@@ -34,16 +34,16 @@
final String secretLine = bufferedReader.readLine();
System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), secretLine);
} finally {
- IoUtil.closeSafely(bufferedReader);
+ IoUtils.safeClose(bufferedReader);
}
} finally {
- IoUtil.closeSafely(reader);
+ IoUtils.safeClose(reader);
}
} finally {
- IoUtil.closeSafely(originalReader);
+ IoUtils.safeClose(originalReader);
}
} finally {
- IoUtil.closeSafely(client);
+ IoUtils.safeClose(client);
}
} finally {
Remoting.closeEndpoint(endpoint);
Modified: remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpSaslClientImpl.java
===================================================================
--- remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpSaslClientImpl.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpSaslClientImpl.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -11,7 +11,7 @@
import java.util.Random;
import java.util.Set;
import org.jboss.cx.remoting.util.CollectionUtil;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
import javax.crypto.NoSuchPaddingException;
import javax.security.auth.callback.Callback;
Modified: remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpSaslServerImpl.java
===================================================================
--- remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpSaslServerImpl.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpSaslServerImpl.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -15,7 +15,7 @@
import java.util.Set;
import org.jboss.cx.remoting.util.Base64DecodingException;
import org.jboss.cx.remoting.util.CollectionUtil;
-import org.jboss.cx.remoting.log.Logger;
+import org.jboss.xnio.log.Logger;
import javax.crypto.NoSuchPaddingException;
import javax.security.auth.callback.Callback;
Modified: remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpVerifier.java
===================================================================
--- remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpVerifier.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/SrpVerifier.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -11,7 +11,7 @@
import java.util.Random;
import java.util.Set;
import org.jboss.cx.remoting.util.Base64DecodingException;
-import org.jboss.cx.remoting.util.IoUtil;
+import org.jboss.cx.remoting.util.Base64Util;
/**
*
@@ -59,7 +59,7 @@
}
String messageDigestName = digestNameBuilder.toString();
ByteBuffer target = ByteBuffer.allocate(512);
- IoUtil.base64Decode(source, target);
+ Base64Util.base64Decode(source, target);
target.flip();
int length;
byte[] byteData;
@@ -191,7 +191,7 @@
writeIntegerBytes(safePrime.toByteArray(), byteData);
writeIntegerBytes(verifier.toByteArray(), byteData);
byteData.flip();
- IoUtil.base64Encode(byteData, target);
+ Base64Util.base64Encode(byteData, target);
}
private void writeIntegerBytes(final byte[] integerBytes, final ByteBuffer byteData) {
Modified: remoting3/trunk/version/src/main/java/org/jboss/cx/remoting/version/Version.java
===================================================================
--- remoting3/trunk/version/src/main/java/org/jboss/cx/remoting/version/Version.java 2008-07-01 14:01:12 UTC (rev 4338)
+++ remoting3/trunk/version/src/main/java/org/jboss/cx/remoting/version/Version.java 2008-07-01 14:40:05 UTC (rev 4339)
@@ -1,15 +1,23 @@
package org.jboss.cx.remoting.version;
/**
- *
+ * The version of Remoting.
*/
public final class Version {
private Version() {
}
+ /**
+ * The version.
+ */
public static final String VERSION = "3.0.0-M3";
+ /**
+ * Print the version to {@code System.out}.
+ *
+ * @param args ignored
+ */
public static void main(String[] args) {
System.out.print(VERSION);
}
16 years, 4 months
JBoss Remoting SVN: r4338 - in remoting3/trunk/api/src/main/java/org/jboss/cx/remoting: spi/wrapper and 1 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-01 10:01:12 -0400 (Tue, 01 Jul 2008)
New Revision: 4338
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/AbstractRequestListener.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.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/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/SessionWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/package-info.java
Log:
minor fixes & javadoc
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/AbstractRequestListener.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/AbstractRequestListener.java 2008-07-01 03:44:29 UTC (rev 4337)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/AbstractRequestListener.java 2008-07-01 14:01:12 UTC (rev 4338)
@@ -2,6 +2,9 @@
/**
* A simple request listener implementation that implements all methods with no-operation implementations.
+ *
+ * @param <I> the request type
+ * @param <O> the reply type
*/
public abstract class AbstractRequestListener<I, O> implements RequestListener<I, O> {
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-01 03:44:29 UTC (rev 4337)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java 2008-07-01 14:01:12 UTC (rev 4338)
@@ -16,13 +16,6 @@
void close() throws RemotingException;
/**
- * Close immediately. Any outstanding processing is immediately aborted.
- *
- * @throws RemotingException if the close failed
- */
- void closeImmediate() throws RemotingException;
-
- /**
* Add a handler that will be called upon close. The handler may be called before or after the close acutally
* takes place.
*
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-01 03:44:29 UTC (rev 4337)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-01 14:01:12 UTC (rev 4338)
@@ -49,6 +49,8 @@
*
* You must have the TODO permission to invoke this method.
*
+ * @param <I> the request type
+ * @param <O> the reply type
* @param requestListener the request listener
* @return the client
*/
@@ -61,6 +63,8 @@
*
* You must have the TODO permission to invoke this method.
*
+ * @param <I> the request type
+ * @param <O> the reply type
* @param requestListener the request listener
* @return the context source
*/
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-01 03:44:29 UTC (rev 4337)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java 2008-07-01 14:01:12 UTC (rev 4338)
@@ -33,13 +33,6 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void closeImmediate() throws RemotingException {
- delegate.closeImmediate();
- }
-
- /**
- * {@inheritDoc} This implementation calls the same method on the delegate object.
- */
public void addCloseHandler(final CloseHandler<ClientSource<I, O>> closeHandler) {
delegate.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
public void handleClose(final ClientSource<I, O> closed) {
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-01 03:44:29 UTC (rev 4337)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java 2008-07-01 14:01:12 UTC (rev 4338)
@@ -35,13 +35,6 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void closeImmediate() throws RemotingException {
- delegate.closeImmediate();
- }
-
- /**
- * {@inheritDoc} This implementation calls the same method on the delegate object.
- */
public void addCloseHandler(final CloseHandler<Client<I, O>> closeHandler) {
delegate.addCloseHandler(new CloseHandler<Client<I, O>>() {
public void handleClose(final Client<I, O> closed) {
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/SessionWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/SessionWrapper.java 2008-07-01 03:44:29 UTC (rev 4337)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/SessionWrapper.java 2008-07-01 14:01:12 UTC (rev 4338)
@@ -31,13 +31,6 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void closeImmediate() throws RemotingException {
- delegate.closeImmediate();
- }
-
- /**
- * {@inheritDoc} This implementation calls the same method on the delegate object.
- */
public void addCloseHandler(final CloseHandler<Session> closeHandler) {
delegate.addCloseHandler(new CloseHandler<Session>() {
public void handleClose(final Session closed) {
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/package-info.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/package-info.java 2008-07-01 03:44:29 UTC (rev 4337)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/package-info.java 2008-07-01 14:01:12 UTC (rev 4338)
@@ -1,4 +1,4 @@
/**
* Stream-related API classes.
*/
-package org.jboss.cx.remoting.spi.stream;
+package org.jboss.cx.remoting.stream;
16 years, 4 months
JBoss Remoting SVN: r4337 - remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-06-30 23:44:29 -0400 (Mon, 30 Jun 2008)
New Revision: 4337
Added:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/Base64Util.java
Removed:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java
Log:
More reorg
Copied: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/Base64Util.java (from rev 4025, remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java)
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/Base64Util.java (rev 0)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/Base64Util.java 2008-07-01 03:44:29 UTC (rev 4337)
@@ -0,0 +1,151 @@
+package org.jboss.cx.remoting.util;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+
+/**
+ *
+ */
+public final class Base64Util {
+
+ private Base64Util() {
+ }
+
+ /**
+ * Base-64 decode a character buffer into a byte buffer.
+ *
+ * @param source the base-64 encoded source material
+ * @param target the target for the decoded data
+ * @throws Base64DecodingException if the source data is not in base-64 format
+ */
+ public static void base64Decode(CharBuffer source, ByteBuffer target) throws Base64DecodingException {
+ int triad;
+ while (source.hasRemaining()) {
+ triad = 0;
+ char ch = source.get();
+ if (ch >= 'A' && ch <= 'Z') {
+ triad |= (ch - 'A') << 18;
+ } else if (ch >= 'a' && ch <= 'z') {
+ triad |= (ch - 'a' + 26) << 18;
+ } else if (ch >= '0' && ch <= '9') {
+ triad |= (ch - '0' + 52) << 18;
+ } else if (ch == '+' || ch == '-') {
+ triad |= 62 << 18;
+ } else if (ch == '/' || ch == '_') {
+ triad |= 63 << 18;
+ } else if (ch == '=') {
+ throw new Base64DecodingException("Unexpected padding encountered");
+ }
+ if (! source.hasRemaining()) {
+ throw new Base64DecodingException("Unexpected end of source data");
+ }
+
+ ch = source.get();
+ if (ch >= 'A' && ch <= 'Z') {
+ triad |= (ch - 'A') << 12;
+ } else if (ch >= 'a' && ch <= 'z') {
+ triad |= (ch - 'a' + 26) << 12;
+ } else if (ch >= '0' && ch <= '9') {
+ triad |= (ch - '0' + 52) << 12;
+ } else if (ch == '+' || ch == '-') {
+ triad |= 62 << 12;
+ } else if (ch == '/' || ch == '_') {
+ triad |= 63 << 12;
+ } else if (ch == '=') {
+ throw new Base64DecodingException("Unexpected padding encountered");
+ }
+ if (! source.hasRemaining()) {
+ throw new Base64DecodingException("Unexpected end of source data");
+ }
+
+ ch = source.get();
+ if (ch >= 'A' && ch <= 'Z') {
+ triad |= (ch - 'A') << 6;
+ } else if (ch >= 'a' && ch <= 'z') {
+ triad |= (ch - 'a' + 26) << 6;
+ } else if (ch >= '0' && ch <= '9') {
+ triad |= (ch - '0' + 52) << 6;
+ } else if (ch == '+' || ch == '-') {
+ triad |= 62 << 6;
+ } else if (ch == '/' || ch == '_') {
+ triad |= 63 << 6;
+ } else if (ch == '=') {
+ if (source.hasRemaining() && source.get() == '=') {
+ if (! source.hasRemaining()) {
+ target.put((byte) (triad >> 16));
+ return;
+ } else {
+ throw new Base64DecodingException("Extra data after padding");
+ }
+ } else {
+ throw new Base64DecodingException("Unexpected end of source data");
+ }
+ }
+
+ ch = source.get();
+ if (ch >= 'A' && ch <= 'Z') {
+ triad |= ch - 'A';
+ } else if (ch >= 'a' && ch <= 'z') {
+ triad |= ch - 'a' + 26;
+ } else if (ch >= '0' && ch <= '9') {
+ triad |= ch - '0' + 52;
+ } else if (ch == '+' || ch == '-') {
+ triad |= 62;
+ } else if (ch == '/' || ch == '_') {
+ triad |= 63;
+ } else if (ch == '=') {
+ if (! source.hasRemaining()) {
+ target.putShort((short) (triad >> 8));
+ return;
+ } else {
+ throw new Base64DecodingException("Extra data after padding");
+ }
+ }
+
+ target.put((byte) (triad >> 16));
+ target.putShort((short) triad);
+ }
+ }
+
+ private static final char[] base64table = new char[] {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '+', '/',
+ };
+
+ /**
+ * Base-64 encode a byte buffer into a character buffer.
+ *
+ * @param source the binary data to encode
+ * @param target the target for the encoded material
+ */
+ public static void base64Encode(ByteBuffer source, CharBuffer target) {
+ int idx = 0;
+ while (source.hasRemaining()) {
+ int b = source.get() & 0xff;
+ target.put(base64table[b >>> 2]);
+ idx = b << 4 & 0x3f;
+ if (! source.hasRemaining()) {
+ target.put(base64table[idx]);
+ target.put("==");
+ return;
+ }
+ b = source.get() & 0xff;
+ target.put(base64table[idx | (b >>> 4)]);
+ idx = b << 2 & 0x3f;
+ if (! source.hasRemaining()) {
+ target.put(base64table[idx]);
+ target.put('=');
+ return;
+ }
+ b = source.get() & 0xff;
+ target.put(base64table[idx | (b >>> 6)]);
+ target.put(base64table[b & 0x3f]);
+ }
+ }
+}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java 2008-07-01 03:12:13 UTC (rev 4336)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java 2008-07-01 03:44:29 UTC (rev 4337)
@@ -1,165 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.Closeable;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import org.jboss.cx.remoting.log.Logger;
-
-/**
- *
- */
-public final class IoUtil {
- private static final Logger log = Logger.getLogger(IoUtil.class);
-
- /**
- * Base-64 decode a character buffer into a byte buffer.
- *
- * @param source the base-64 encoded source material
- * @param target the target for the decoded data
- * @throws Base64DecodingException if the source data is not in base-64 format
- */
- public static void base64Decode(CharBuffer source, ByteBuffer target) throws Base64DecodingException {
- int triad;
- while (source.hasRemaining()) {
- triad = 0;
- char ch = source.get();
- if (ch >= 'A' && ch <= 'Z') {
- triad |= (ch - 'A') << 18;
- } else if (ch >= 'a' && ch <= 'z') {
- triad |= (ch - 'a' + 26) << 18;
- } else if (ch >= '0' && ch <= '9') {
- triad |= (ch - '0' + 52) << 18;
- } else if (ch == '+' || ch == '-') {
- triad |= 62 << 18;
- } else if (ch == '/' || ch == '_') {
- triad |= 63 << 18;
- } else if (ch == '=') {
- throw new Base64DecodingException("Unexpected padding encountered");
- }
- if (! source.hasRemaining()) {
- throw new Base64DecodingException("Unexpected end of source data");
- }
-
- ch = source.get();
- if (ch >= 'A' && ch <= 'Z') {
- triad |= (ch - 'A') << 12;
- } else if (ch >= 'a' && ch <= 'z') {
- triad |= (ch - 'a' + 26) << 12;
- } else if (ch >= '0' && ch <= '9') {
- triad |= (ch - '0' + 52) << 12;
- } else if (ch == '+' || ch == '-') {
- triad |= 62 << 12;
- } else if (ch == '/' || ch == '_') {
- triad |= 63 << 12;
- } else if (ch == '=') {
- throw new Base64DecodingException("Unexpected padding encountered");
- }
- if (! source.hasRemaining()) {
- throw new Base64DecodingException("Unexpected end of source data");
- }
-
- ch = source.get();
- if (ch >= 'A' && ch <= 'Z') {
- triad |= (ch - 'A') << 6;
- } else if (ch >= 'a' && ch <= 'z') {
- triad |= (ch - 'a' + 26) << 6;
- } else if (ch >= '0' && ch <= '9') {
- triad |= (ch - '0' + 52) << 6;
- } else if (ch == '+' || ch == '-') {
- triad |= 62 << 6;
- } else if (ch == '/' || ch == '_') {
- triad |= 63 << 6;
- } else if (ch == '=') {
- if (source.hasRemaining() && source.get() == '=') {
- if (! source.hasRemaining()) {
- target.put((byte) (triad >> 16));
- return;
- } else {
- throw new Base64DecodingException("Extra data after padding");
- }
- } else {
- throw new Base64DecodingException("Unexpected end of source data");
- }
- }
-
- ch = source.get();
- if (ch >= 'A' && ch <= 'Z') {
- triad |= ch - 'A';
- } else if (ch >= 'a' && ch <= 'z') {
- triad |= ch - 'a' + 26;
- } else if (ch >= '0' && ch <= '9') {
- triad |= ch - '0' + 52;
- } else if (ch == '+' || ch == '-') {
- triad |= 62;
- } else if (ch == '/' || ch == '_') {
- triad |= 63;
- } else if (ch == '=') {
- if (! source.hasRemaining()) {
- target.putShort((short) (triad >> 8));
- return;
- } else {
- throw new Base64DecodingException("Extra data after padding");
- }
- }
-
- target.put((byte) (triad >> 16));
- target.putShort((short) triad);
- }
- }
-
- private static final char[] base64table = new char[] {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
- 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
- 'w', 'x', 'y', 'z', '0', '1', '2', '3',
- '4', '5', '6', '7', '8', '9', '+', '/',
- };
-
- /**
- * Base-64 encode a byte buffer into a character buffer.
- *
- * @param source the binary data to encode
- * @param target the target for the encoded material
- */
- public static void base64Encode(ByteBuffer source, CharBuffer target) {
- int idx = 0;
- while (source.hasRemaining()) {
- int b = source.get() & 0xff;
- target.put(base64table[b >>> 2]);
- idx = b << 4 & 0x3f;
- if (! source.hasRemaining()) {
- target.put(base64table[idx]);
- target.put("==");
- return;
- }
- b = source.get() & 0xff;
- target.put(base64table[idx | (b >>> 4)]);
- idx = b << 2 & 0x3f;
- if (! source.hasRemaining()) {
- target.put(base64table[idx]);
- target.put('=');
- return;
- }
- b = source.get() & 0xff;
- target.put(base64table[idx | (b >>> 6)]);
- target.put(base64table[b & 0x3f]);
- }
- }
-
- /**
- * Close a resource without throwing an exception. If the underlying {@code close} throws an exception, log
- * it. For use in {@code finally} blocks.
- *
- * @param c the resource to close
- */
- public static void closeSafely(Closeable c) {
- try {
- c.close();
- } catch (Throwable t) {
- log.trace(t, "Closing %s failed", c);
- }
- }
-}
16 years, 4 months
JBoss Remoting SVN: r4336 - remoting3/trunk.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-06-30 23:12:13 -0400 (Mon, 30 Jun 2008)
New Revision: 4336
Modified:
remoting3/trunk/build.properties
remoting3/trunk/build.xml
Log:
Add XNIO; remove jrpp from primary build
Modified: remoting3/trunk/build.properties
===================================================================
--- remoting3/trunk/build.properties 2008-07-01 03:11:31 UTC (rev 4335)
+++ remoting3/trunk/build.properties 2008-07-01 03:12:13 UTC (rev 4336)
@@ -155,3 +155,11 @@
lib.trove.path=${lib.trove.dir}/${lib.trove.name}
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.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}/
+lib.xnio-api.path=${lib.xnio-api.dir}/${lib.xnio-api.name}
+lib.xnio-api.local=${local.repository}/${lib.xnio-api.path}
+lib.xnio-api.remote=${remote.repository}/${lib.xnio-api.path}
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-07-01 03:11:31 UTC (rev 4335)
+++ remoting3/trunk/build.xml 2008-07-01 03:12:13 UTC (rev 4336)
@@ -175,6 +175,18 @@
<get src="${remote.license.dir}/${lib.sun-httpserver.license}.txt" dest="${lib.sun-httpserver.local}.license.txt" usetimestamp="true" ignoreerrors="false"/>
</target>
+ <!-- External library: XNIO -->
+
+ <target name="lib.xnio-api-check">
+ <available property="lib.xnio-api.exists" file="${lib.xnio-api.local}"/>
+ </target>
+
+ <target name="lib.xnio-api" depends="lib.xnio-api-check" unless="lib.xnio-api.exists">
+ <mkdir dir="${local.repository}/${lib.xnio-api.dir}"/>
+ <get src="${lib.xnio-api.remote}" dest="${lib.xnio-api.local}" usetimestamp="true" ignoreerrors="false"/>
+ <get src="${remote.license.dir}/${lib.xnio-api.license}.txt" dest="${lib.xnio-api.local}.license.txt" usetimestamp="true" ignoreerrors="false"/>
+ </target>
+
<!-- ============================================== -->
<!-- MODULES - Keep in alpha order by target name -->
<!-- ============================================== -->
@@ -202,6 +214,7 @@
debug="true">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
+ <pathelement location="${lib.xnio-api.local}"/>
<path refid="util.classpath"/>
</classpath>
</javac>
@@ -212,7 +225,7 @@
<delete dir="api/target"/>
</target>
- <target name="api" description="Build the API module" depends="util,api.compile">
+ <target name="api" description="Build the API module" depends="lib.xnio-api,util,api.compile">
<path id="api.classpath">
<pathelement location="api/target/main/classes"/>
</path>
@@ -1303,7 +1316,7 @@
<!-- JARs: These should be the third-to-last targets in the file -->
- <target name="all-jars" description="Build all the JARs" depends="api-jar,core-jar,jrpp-jar,standalone-jar"/>
+ <target name="all-jars" description="Build all the JARs" depends="api-jar,core-jar,standalone-jar"/>
<!-- fetch: These should be the second-to-last targets in the file -->
@@ -1311,7 +1324,7 @@
<!-- all: These should be the last targets in the file -->
- <target name="all" description="Build everything" depends="all-core,all-http,all-jrpp,all-log,all-jars,api-javadoc"/>
+ <target name="all" description="Build everything" depends="all-core,all-http,all-log,all-jars,api-javadoc"/>
<target name="clean" description="Clean out all build files" depends="clean-core,clean-http,clean-jrpp,clean-log"/>
16 years, 4 months
JBoss Remoting SVN: r4335 - remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-06-30 23:11:31 -0400 (Mon, 30 Jun 2008)
New Revision: 4335
Modified:
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
Minor cleanups
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-01 03:07:01 UTC (rev 4334)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-01 03:11:31 UTC (rev 4335)
@@ -7,21 +7,18 @@
import org.jboss.cx.remoting.core.protocol.LocalProtocolHandlerFactory;
import org.jboss.cx.remoting.jrpp.JrppProtocolSupport;
import org.jboss.cx.remoting.jrpp.JrppServer;
-import org.jboss.cx.remoting.log.Logger;
import org.jboss.cx.remoting.util.AttributeMap;
/**
*
*/
public final class Remoting {
- private static final Logger log = Logger.getLogger(Remoting.class);
-
private static final String JRPP_SUPPORT_KEY = "org.jboss.cx.remoting.standalone.jrpp.support";
// lifecycle lock
private static final Object lifecycle = new Object();
- public static <I, O> Endpoint createEndpoint(String name) throws IOException {
+ public static Endpoint createEndpoint(String name) throws IOException {
synchronized (lifecycle) {
boolean ok = false;
final CoreEndpoint coreEndpoint = new CoreEndpoint();
16 years, 4 months
JBoss Remoting SVN: r4334 - in remoting3/trunk/api/src/main/java/org/jboss/cx/remoting: service and 5 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-06-30 23:07:01 -0400 (Mon, 30 Jun 2008)
New Revision: 4334
Added:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/package-info.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/package-info.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/package-info.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/package-info.java
Removed:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/UnknownIdentifierException.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/Registration.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/RemoteStreamSerializer.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamContext.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializer.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/AbstractRequestListener.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientContext.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/CloseHandler.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/IOExceptionCarrier.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/IndeterminateOutcomeException.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemoteExecutionException.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemotingException.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemotingExceptionCarrier.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCancelHandler.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCompletionHandler.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestContext.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestListener.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ServiceContext.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Session.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/SessionListener.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/service/package-info.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/CompositeObjectResolver.java
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/stream/StreamDetector.java
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/wrapper/ClientSourceWrapper.java
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/EndpointWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/RequestContextWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/SessionWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSink.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSinkWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSource.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSourceWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/Streams.java
Log:
Another big API overhaul. This one will break things for a while.
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/AbstractRequestListener.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/AbstractRequestListener.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/AbstractRequestListener.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,18 +1,31 @@
package org.jboss.cx.remoting;
/**
- *
+ * A simple request listener implementation that implements all methods with no-operation implementations.
*/
public abstract class AbstractRequestListener<I, O> implements RequestListener<I, O> {
+
+ /**
+ * {@inheritDoc} This implementation performs no operation.
+ */
public void handleClientOpen(final ClientContext context) {
}
+ /**
+ * {@inheritDoc} This implementation performs no operation.
+ */
public void handleServiceOpen(final ServiceContext context) {
}
+ /**
+ * {@inheritDoc} This implementation performs no operation.
+ */
public void handleServiceClose(final ServiceContext context) {
}
+ /**
+ * {@inheritDoc} This implementation performs no operation.
+ */
public void handleClientClose(final ClientContext context) {
}
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -4,6 +4,9 @@
/**
* A communications client. The client may be associated with state maintained by the local and/or remote side.
+ *
+ * @param <I> the request type
+ * @param <O> the reply type
*/
public interface Client<I, O> extends Closeable<Client<I, O>> {
/**
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientContext.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientContext.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -3,7 +3,7 @@
import java.util.concurrent.ConcurrentMap;
/**
- *
+ * The server context for a single remote client instance.
*/
public interface ClientContext extends Closeable<ClientContext> {
/**
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -2,6 +2,9 @@
/**
* A source for new Remoting contexts.
+ *
+ * @param <I> the request type
+ * @param <O> the reply type
*/
public interface ClientSource<I, O> extends Closeable<ClientSource<I, O>> {
/**
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/CloseHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/CloseHandler.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/CloseHandler.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,8 +1,16 @@
package org.jboss.cx.remoting;
/**
+ * A handler which is notified of a resource close.
*
+ * @param <T> the type of resource
*/
public interface CloseHandler<T> {
+
+ /**
+ * Receive a notification that the resource was closed.
+ *
+ * @param closed the closed resource
+ */
void handleClose(T closed);
}
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,7 +1,9 @@
package org.jboss.cx.remoting;
/**
+ * A Remoting resource that can be closed.
*
+ * @param <T> the type that is passed to the close handler
*/
public interface Closeable<T> extends java.io.Closeable {
// TODO - do we need an async close method?
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -2,10 +2,6 @@
import java.net.URI;
import java.util.concurrent.ConcurrentMap;
-import org.jboss.cx.remoting.spi.Registration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
import org.jboss.cx.remoting.util.AttributeMap;
/**
@@ -41,17 +37,6 @@
Session openSession(URI remoteUri, AttributeMap attributeMap, RequestListener<?, ?> rootListener) throws RemotingException;
/**
- * Open an inbound session from another endpoint. Used by protocol handlers.
- *
- * You must have the TODO permission to invoke this method.
- *
- * @param handler the protocol handler to use
- * @param rootListener the root request listener for this end of the session
- * @return the protocol context
- */
- ProtocolContext openSession(ProtocolHandler handler, RequestListener<?, ?> rootListener) throws RemotingException;
-
- /**
* Get the name of this endpoint.
*
* @return the endpoint name, or {@code null} if there is no name
@@ -59,20 +44,6 @@
String getName();
/**
- * Register a protocol specification for this endpoint.
- *
- * You must have the TODO permission to invoke this method.
- *
- * @param scheme the URI scheme
- * @param protocolHandlerFactory the protocol handler factory
- * @return a registration that may be used to control this deployment
- *
- * @throws RemotingException if the protocol registration failed
- * @throws IllegalArgumentException if the specification failed validation
- */
- Registration registerProtocol(String scheme, ProtocolHandlerFactory protocolHandlerFactory) throws RemotingException, IllegalArgumentException;
-
- /**
* Create a client that can be used to invoke a request listener on this endpoint. The client may be passed to a
* remote endpoint as part of a request or a reply, or it may be used locally.
*
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -9,6 +9,8 @@
* <p/>
* In addition to representing the invocation results, this interface allows the user to cancel the request, or schedule
* an asynchronous callback for when the request completes.
+ *
+ * @param <T> the result type of the future operation
*/
public interface FutureReply<T> extends Future<T> {
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/IOExceptionCarrier.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/IOExceptionCarrier.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/IOExceptionCarrier.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -3,13 +3,26 @@
import java.io.IOException;
/**
- *
+ * A runtime exception that carries an {@link java.io.IOException} as a cause.
*/
public class IOExceptionCarrier extends RuntimeException {
+
+ private static final long serialVersionUID = -1602940590696531671L;
+
+ /**
+ * Construct a new carrier.
+ *
+ * @param cause the nested cause
+ */
public IOExceptionCarrier(IOException cause) {
super(cause);
}
+ /**
+ * Get the cause.
+ *
+ * @return the cause
+ */
public IOException getCause() {
return (IOException) super.getCause();
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/IndeterminateOutcomeException.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/IndeterminateOutcomeException.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/IndeterminateOutcomeException.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,20 +1,47 @@
package org.jboss.cx.remoting;
/**
- *
+ * An exception that is thrown when an operation terminates in such a way that the outcome cannot be known.
*/
public class IndeterminateOutcomeException extends RemoteExecutionException {
+
+ private static final long serialVersionUID = 6304843915977033800L;
+
+ /**
+ * Constructs a <tt>IndeterminateOutcomeException</tt> with no detail message. The cause is not initialized, and may
+ * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}.
+ */
public IndeterminateOutcomeException() {
}
+ /**
+ * Constructs a <tt>IndeterminateOutcomeException</tt> with the specified detail message. The cause is not initialized,
+ * and may subsequently be initialized by a call to {@link #initCause(Throwable) initCause}.
+ *
+ * @param msg the detail message
+ */
public IndeterminateOutcomeException(String msg) {
super(msg);
}
+ /**
+ * Constructs a <tt>IndeterminateOutcomeException</tt> with the specified cause. The detail message is set to:
+ * <pre>
+ * (cause == null ? null : cause.toString())</pre>
+ * (which typically contains the class and detail message of <tt>cause</tt>).
+ *
+ * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
+ */
public IndeterminateOutcomeException(Throwable cause) {
super(cause);
}
+ /**
+ * Constructs a <tt>IndeterminateOutcomeException</tt> with the specified detail message and cause.
+ *
+ * @param msg the detail message
+ * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
+ */
public IndeterminateOutcomeException(String msg, Throwable cause) {
super(msg, cause);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemoteExecutionException.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemoteExecutionException.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemoteExecutionException.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -3,25 +3,64 @@
import java.util.concurrent.ExecutionException;
/**
- *
+ * Exception thrown when execution of a remote operation fails for some reason.
*/
public class RemoteExecutionException extends ExecutionException {
+ private static final long serialVersionUID = 3580395686019440048L;
+
+ /**
+ * Constructs a <tt>RemoteExecutionException</tt> with no detail message.
+ * The cause is not initialized, and may subsequently be
+ * initialized by a call to {@link #initCause(Throwable) initCause}.
+ */
public RemoteExecutionException() {
}
+ /**
+ * Constructs a <tt>RemoteExecutionException</tt> with the specified detail
+ * message. The cause is not initialized, and may subsequently be
+ * initialized by a call to {@link #initCause(Throwable) initCause}.
+ *
+ * @param msg the detail message
+ */
public RemoteExecutionException(String msg) {
super(msg);
}
+ /**
+ * Constructs a <tt>RemoteExecutionException</tt> with the specified cause.
+ * The detail message is set to:
+ * <pre>
+ * (cause == null ? null : cause.toString())</pre>
+ * (which typically contains the class and detail message of
+ * <tt>cause</tt>).
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method)
+ */
public RemoteExecutionException(Throwable cause) {
super(cause);
}
+ /**
+ * Constructs a <tt>RemoteExecutionException</tt> with the specified detail
+ * message and cause.
+ *
+ * @param msg the detail message
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method)
+ */
public RemoteExecutionException(String msg, Throwable cause) {
super(msg, cause);
}
+ /**
+ * Rethrow the cause, if it is a runtime exception. This is a convenience method to extract a runtime exception
+ * from a remote execution exception.
+ *
+ * @throws RuntimeException the cause
+ */
public final void throwRuntime() throws RuntimeException {
final Throwable cause = getCause();
if (cause instanceof RuntimeException) {
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemotingException.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemotingException.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemotingException.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -3,39 +3,49 @@
import java.io.IOException;
/**
- *
+ * A general Remoting exception.
*/
public class RemotingException extends IOException {
+
+ private static final long serialVersionUID = 1540716301579397423L;
+
+ /**
+ * Constructs a <tt>RemotingException</tt> with no detail message. The cause is not initialized, and may subsequently be
+ * initialized by a call to {@link #initCause(Throwable) initCause}.
+ */
public RemotingException() {
}
- public RemotingException(String s) {
- super(s);
+ /**
+ * Constructs a <tt>RemotingException</tt> with the specified detail message. The cause is not initialized, and may
+ * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}.
+ *
+ * @param msg the detail message
+ */
+ public RemotingException(String msg) {
+ super(msg);
}
- public RemotingException(String s, Throwable cause) {
- super(getCauseString(s, cause));
- setStackTrace(cause.getStackTrace());
+ /**
+ * Constructs a <tt>RemotingException</tt> with the specified cause. The detail message is set to:
+ * <pre>
+ * (cause == null ? null : cause.toString())</pre>
+ * (which typically contains the class and detail message of <tt>cause</tt>).
+ *
+ * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
+ */
+ public RemotingException(Throwable cause) {
+ initCause(cause);
}
- public RemoteExecutionException getExecutionException() {
- final RemoteExecutionException ex = new RemoteExecutionException(getMessage(), this);
- ex.setStackTrace(getStackTrace());
- return ex;
+ /**
+ * Constructs a <tt>RemotingException</tt> with the specified detail message and cause.
+ *
+ * @param msg the detail message
+ * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
+ */
+ public RemotingException(String msg, Throwable cause) {
+ super(msg);
+ initCause(cause);
}
-
- private static String getCauseString(String ourMsg, Throwable cause) {
- final String message = cause.getMessage();
- final String className = cause.getClass().getName();
- final StringBuilder builder = new StringBuilder(40);
- builder.append(ourMsg);
- builder.append(" (Caused by an exception of type ");
- builder.append(className);
- if (message != null) {
- builder.append(" with message: ");
- builder.append(message);
- }
- builder.append(")");
- return builder.toString();
- }
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemotingExceptionCarrier.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemotingExceptionCarrier.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemotingExceptionCarrier.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,13 +1,26 @@
package org.jboss.cx.remoting;
/**
- *
+ * A runtime exception that carries a {@link org.jboss.cx.remoting.RemotingException} as a cause.
*/
public class RemotingExceptionCarrier extends IOExceptionCarrier {
+
+ private static final long serialVersionUID = -1326735788761007331L;
+
+ /**
+ * Construct a new carrier.
+ *
+ * @param cause the nested cause
+ */
public RemotingExceptionCarrier(RemotingException cause) {
super(cause);
}
+ /**
+ * Get the cause.
+ *
+ * @return the cause
+ */
public RemotingException getCause() {
return (RemotingException) super.getCause();
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCancelHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCancelHandler.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCancelHandler.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,8 +1,17 @@
package org.jboss.cx.remoting;
/**
+ * A handler for request listeners to receive a notification when a request was cancelled.
*
+ * @param <O> the reply type
*/
public interface RequestCancelHandler<O> {
+
+ /**
+ * Receive notification that the request was cancelled.
+ *
+ * @param requestContext the request context
+ * @param mayInterrupt the value of the cancellation {@code mayInterrupt} flag
+ */
void notifyCancel(RequestContext<O> requestContext, boolean mayInterrupt);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCompletionHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCompletionHandler.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCompletionHandler.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,8 +1,16 @@
package org.jboss.cx.remoting;
/**
+ * A handler for receiving notification of request completion on the client side.
*
+ * @param <T> the reply type
*/
public interface RequestCompletionHandler<T> {
+
+ /**
+ * Receive notification that the request was completed, was cancelled, or has failed.
+ *
+ * @param futureReply the future result
+ */
void notifyComplete(FutureReply<T> futureReply);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestContext.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestContext.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -4,6 +4,8 @@
/**
* The context of a single request.
+ *
+ * @param <O> the reply type
*/
public interface RequestContext<O> extends Executor {
/**
@@ -52,7 +54,7 @@
* Add a notifier to be called if a cancel request is received. The notifier may be called from the current thread
* or a different thread. If the request has already been cancelled, the notifier will be called immediately.
*
- * @param handler
+ * @param handler the cancel handler
*/
void addCancelHandler(RequestCancelHandler<O> handler);
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestListener.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestListener.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestListener.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,7 +1,10 @@
package org.jboss.cx.remoting;
/**
+ * A request listener. Implementations of this interface will reply to client requests.
*
+ * @param <I> the request type
+ * @param <O> the reply type
*/
public interface RequestListener<I, O> {
/**
@@ -44,7 +47,7 @@
/**
* Handle the close of a client.
*
- * @param context
+ * @param context the client context
*/
void handleClientClose(ClientContext context);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ServiceContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ServiceContext.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ServiceContext.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -3,8 +3,15 @@
import java.util.concurrent.ConcurrentMap;
/**
- *
+ * The server-side context of a service. Used to hold state relating to a service (known as a {@code ContextSource} on
+ * the client side).
*/
public interface ServiceContext extends Closeable<ServiceContext> {
+
+ /**
+ * Get an attribute map which can be used to cache arbitrary state on the server side.
+ *
+ * @return the attribute map
+ */
ConcurrentMap<Object, Object> getAttributes();
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Session.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Session.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Session.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -40,6 +40,8 @@
/**
* Get the root client for this session.
*
+ * @param <I> the request type
+ * @param <O> the reply type
* @return the root client
*/
<I, O> Client<I, O> getRootClient();
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/SessionListener.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/SessionListener.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/SessionListener.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,8 +1,14 @@
package org.jboss.cx.remoting;
/**
- *
+ * A session listener. Called when a session is opened on an endpoint.
*/
public interface SessionListener {
+
+ /**
+ * Receive notification that the session was opened.
+ *
+ * @param session the new session
+ */
void handleSessionOpened(Session session);
}
Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/UnknownIdentifierException.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/UnknownIdentifierException.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/UnknownIdentifierException.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,17 +0,0 @@
-package org.jboss.cx.remoting;
-
-/**
- *
- */
-public class UnknownIdentifierException extends RemotingException {
- public UnknownIdentifierException() {
- }
-
- public UnknownIdentifierException(String msg) {
- super(msg);
- }
-
- public UnknownIdentifierException(String msg, Throwable cause) {
- super(msg, cause);
- }
-}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/service/package-info.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/service/package-info.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/service/package-info.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,4 +1,4 @@
/**
*
*/
-package org.jboss.cx.remoting.service;
\ No newline at end of file
+package org.jboss.cx.remoting.service;
Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/Registration.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/Registration.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/Registration.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,23 +0,0 @@
-package org.jboss.cx.remoting.spi;
-
-/**
- *
- */
-public interface Registration {
- /**
- * Activate this registration by placing it into the "started" state. In this state,
- * no reconfiguration may be done.
- */
- void start();
-
- /**
- * Deactivate this registration by placing it into the "stopped" state. In this state, the
- * registration may be reconfigured.
- */
- void stop();
-
- /**
- * Permanently remove this registration. Unreserves any resources associated with the registration.
- */
- void unregister();
-}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/CompositeObjectResolver.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/CompositeObjectResolver.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/CompositeObjectResolver.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -6,7 +6,7 @@
import org.jboss.cx.remoting.util.CollectionUtil;
/**
- *
+ * An object resolver that resolves objects by running through a fixed series of nested resolvers.
*/
public final class CompositeObjectResolver implements ObjectResolver {
@@ -14,10 +14,19 @@
private final List<ObjectResolver> resolvers;
+ /**
+ * Construct a new composite resolver. The given list is copied.
+ *
+ * @param resolvers the resolver list
+ */
public CompositeObjectResolver(List<ObjectResolver> resolvers) {
this.resolvers = Collections.unmodifiableList(CollectionUtil.arrayList(resolvers));
}
+ /**
+ * {@inheritDoc} This implementation runs through the series of nested resovlers and calls the {@code writeReplace}
+ * method on each.
+ */
public Object writeReplace(Object object) throws IOException {
for (ObjectResolver resolver : resolvers) {
object = resolver.writeReplace(object);
@@ -25,6 +34,10 @@
return object;
}
+ /**
+ * {@inheritDoc} This implementation runs through the series of nested resovlers and calls the {@code readResolve}
+ * method on each.
+ */
public Object readResolve(Object object) throws IOException {
for (ObjectResolver resolver : CollectionUtil.reverse(resolvers)) {
object = resolver.readResolve(object);
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -2,33 +2,36 @@
import java.io.IOException;
import java.io.Serializable;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.util.ByteMessageOutput;
-import org.jboss.cx.remoting.util.ByteMessageInput;
+import java.nio.Buffer;
+import org.jboss.cx.remoting.stream.ObjectSink;
+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}.
+ *
+ * @param <T> the type of buffer that the marshaller uses, typically {@link java.nio.ByteBuffer} or {@link java.nio.CharBuffer}
*/
-public interface Marshaller extends Serializable {
+public interface Marshaller<T extends Buffer> extends Serializable {
/**
- * Get a message writer that marshals to the given stream.
+ * 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 byteMessageOutput the target stream
- * @return the message writer
- * @throws IOException if an error occurs
+ * @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
*/
- ObjectMessageOutput getMessageOutput(ByteMessageOutput byteMessageOutput) throws IOException;
+ ObjectSink<Object> getMarshalingSink(ObjectSink<T> bufferSink) throws IOException;
/**
- * Get a message reader that unmarshals from the given stream.
+ * 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 byteMessageInput the source stream
- * @return the message reader
- * @throws IOException if an error occurs
+ * @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
*/
- ObjectMessageInput getMessageInput(ByteMessageInput byteMessageInput) throws IOException;
+ ObjectSource<Object> getUnmarshalingSource(ObjectSource<T> bufferSource) 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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/MarshallerFactory.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,10 +1,24 @@
package org.jboss.cx.remoting.spi.marshal;
import java.io.IOException;
+import java.nio.Buffer;
+import org.jboss.xnio.BufferAllocator;
/**
+ * A factory to produce marshallers.
*
+ * @param <T> the type of buffer that the marshaller uses, typically {@link java.nio.ByteBuffer} or {@link java.nio.CharBuffer}
*/
-public interface MarshallerFactory {
- Marshaller createRootMarshaller(ObjectResolver resolver, ClassLoader classLoader) throws IOException;
+public interface MarshallerFactory<T extends Buffer> {
+
+ /**
+ * 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;
}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/package-info.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/package-info.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/package-info.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -0,0 +1,7 @@
+/**
+ * Classes related to marshalling.
+ * <p/>
+ * Due to the strangeness of the English language, we have "marshal", "marshaled", and "marshaling", yet we have
+ * "marshaller".
+ */
+package org.jboss.cx.remoting.spi.marshal;
Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/RemoteStreamSerializer.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/RemoteStreamSerializer.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/RemoteStreamSerializer.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,8 +0,0 @@
-package org.jboss.cx.remoting.spi.stream;
-
-/**
- *
- */
-public interface RemoteStreamSerializer extends StreamSerializer {
- Object getRemoteInstance();
-}
Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamContext.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamContext.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,26 +0,0 @@
-package org.jboss.cx.remoting.spi.stream;
-
-import java.io.Closeable;
-import java.io.IOException;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-
-/**
- *
- */
-public interface StreamContext extends Closeable {
-
- /**
- * Write a message. The message is sent if/when the returned {@code MessageOutput} instance is committed.
- *
- * @return the message output instance
- * @throws IOException if an error occurs
- */
- ObjectMessageOutput writeMessage() throws IOException;
-
- /**
- * Indicate that this stream is exhausted.
- *
- * @throws IOException if the notification did not succeed
- */
- void close() throws IOException;
-}
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamDetector.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -6,7 +6,7 @@
public interface StreamDetector {
/**
* Detect a stream type. If the candidate is a stream type recognized by this detector,
- * return the class of the factory to use. The factory class should have a no-arg constructor.
+ * return the factory to use.
*
* @param candidate the candidate object
* @return the stream serializer factory, or {@code null} if this object is not recognized
Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializer.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializer.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializer.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,31 +0,0 @@
-package org.jboss.cx.remoting.spi.stream;
-
-import java.io.IOException;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-
-/**
- *
- */
-public interface StreamSerializer {
- /**
- * Handle the startup of the stream.
- *
- * @throws IOException if an error occurs
- */
- void handleOpen() throws IOException;
-
- /**
- * Handle an incoming message from the remote side.
- *
- * @param data the message
- * @throws IOException if the stream data cannot be handled
- */
- void handleData(ObjectMessageInput data) throws IOException;
-
- /**
- * Handle a close from the remote side.
- *
- * @throws IOException if an error occurs
- */
- void handleClose() throws IOException;
-}
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/StreamSerializerFactory.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -1,12 +1,16 @@
package org.jboss.cx.remoting.spi.stream;
+import org.jboss.xnio.IoHandler;
+import org.jboss.xnio.Client;
+import org.jboss.xnio.channels.StreamChannel;
import java.io.IOException;
+import java.io.Serializable;
/**
*
*/
-public interface StreamSerializerFactory {
- StreamSerializer getLocalSide(StreamContext context, Object local) throws IOException;
+public interface StreamSerializerFactory extends Serializable {
+ IoHandler<? super StreamChannel> getLocalSide(Object localSide) throws IOException;
- RemoteStreamSerializer getRemoteSide(StreamContext context) throws IOException;
+ Object getRemoteSide(Client<StreamChannel> remoteClient) throws IOException;
}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/package-info.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/package-info.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/stream/package-info.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -0,0 +1,4 @@
+/**
+ * Classes related to streaming.
+ */
+package org.jboss.cx.remoting.spi.stream;
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -6,23 +6,40 @@
import org.jboss.cx.remoting.RemotingException;
/**
+ * A simple delegating wrapper for client sources.
*
+ * @param <I> the request type
+ * @param <O> the reply type
*/
public class ClientSourceWrapper<I, O> implements ClientSource<I, O> {
private final ClientSource<I, O> delegate;
+ /**
+ * Construct a new instance. Calls will be sent to the given {@code delegate} by default.
+ *
+ * @param delegate the delegate client instance
+ */
protected ClientSourceWrapper(ClientSource<I, O> delegate) {
this.delegate = delegate;
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void close() throws RemotingException {
delegate.close();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void closeImmediate() throws RemotingException {
delegate.closeImmediate();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void addCloseHandler(final CloseHandler<ClientSource<I, O>> closeHandler) {
delegate.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
public void handleClose(final ClientSource<I, O> closed) {
@@ -31,6 +48,9 @@
});
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public Client<I, O> createContext() throws RemotingException {
return delegate.createContext();
}
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -8,23 +8,40 @@
import org.jboss.cx.remoting.RemotingException;
/**
+ * A simple delegating wrapper for clients.
*
+ * @param <I> the request type
+ * @param <O> the reply type
*/
public class ClientWrapper<I, O> implements Client<I, O> {
protected final Client<I, O> delegate;
+ /**
+ * Construct a new instance. Calls will be sent to the given {@code delegate} by default.
+ *
+ * @param delegate the delegate client instance
+ */
protected ClientWrapper(final Client<I, O> delegate) {
this.delegate = delegate;
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void close() throws RemotingException {
delegate.close();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void closeImmediate() throws RemotingException {
delegate.closeImmediate();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void addCloseHandler(final CloseHandler<Client<I, O>> closeHandler) {
delegate.addCloseHandler(new CloseHandler<Client<I, O>>() {
public void handleClose(final Client<I, O> closed) {
@@ -33,22 +50,37 @@
});
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public O invoke(final I request) throws RemotingException, RemoteExecutionException {
return delegate.invoke(request);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public FutureReply<O> send(final I request) throws RemotingException {
return delegate.send(request);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void sendOneWay(final I request) throws RemotingException {
delegate.sendOneWay(request);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public ConcurrentMap<Object, Object> getAttributes() {
return delegate.getAttributes();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public ClassLoader getClassLoader() {
return delegate.getClassLoader();
}
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-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -9,54 +9,68 @@
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.Session;
import org.jboss.cx.remoting.SessionListener;
-import org.jboss.cx.remoting.spi.Registration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
import org.jboss.cx.remoting.util.AttributeMap;
/**
- *
+ * A simple delegating wrapper for endpoints.
*/
public class EndpointWrapper implements Endpoint {
protected final Endpoint delegate;
- protected EndpointWrapper(final Endpoint endpoint) {
- delegate = endpoint;
+ /**
+ * Construct a new instance. Calls will be sent to the given {@code delegate} by default.
+ *
+ * @param delegate the delegate client instance
+ */
+ protected EndpointWrapper(final Endpoint delegate) {
+ this.delegate = delegate;
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public ConcurrentMap<Object, Object> getAttributes() {
return delegate.getAttributes();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public Session openSession(final URI remoteUri, final AttributeMap attributeMap, final RequestListener<?, ?> rootListener) throws RemotingException {
return delegate.openSession(remoteUri, attributeMap, rootListener);
}
- public ProtocolContext openSession(final ProtocolHandler handler, final RequestListener<?, ?> rootListener) throws RemotingException {
- return delegate.openSession(handler, rootListener);
- }
-
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public String getName() {
return delegate.getName();
}
- public Registration registerProtocol(String scheme, ProtocolHandlerFactory protocolHandlerFactory) throws RemotingException, IllegalArgumentException {
- return delegate.registerProtocol(scheme, protocolHandlerFactory);
- }
-
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public <I, O> Client<I, O> createClient(final RequestListener<I, O> requestListener) {
return delegate.createClient(requestListener);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public <I, O> ClientSource<I, O> createService(final RequestListener<I, O> requestListener) {
return delegate.createService(requestListener);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void addSessionListener(final SessionListener sessionListener) {
delegate.addSessionListener(sessionListener);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void removeSessionListener(final SessionListener sessionListener) {
delegate.removeSessionListener(sessionListener);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/RequestContextWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/RequestContextWrapper.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/RequestContextWrapper.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -6,39 +6,67 @@
import org.jboss.cx.remoting.ClientContext;
/**
+ * A simple delegating wrapper for request context instances.
*
+ * @param <O> the reply type
*/
public class RequestContextWrapper<O> implements RequestContext<O> {
protected final RequestContext<O> delegate;
+ /**
+ * Construct a new instance. Calls will be sent to the given {@code delegate} by default.
+ *
+ * @param delegate the delegate client instance
+ */
protected RequestContextWrapper(final RequestContext<O> delegate) {
this.delegate = delegate;
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public ClientContext getContext() {
return delegate.getContext();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public boolean isCancelled() {
return delegate.isCancelled();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void sendReply(O reply) throws RemotingException, IllegalStateException {
delegate.sendReply(reply);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void sendFailure(String msg, Throwable cause) throws RemotingException, IllegalStateException {
delegate.sendFailure(msg, cause);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void sendCancelled() throws RemotingException, IllegalStateException {
delegate.sendCancelled();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void addCancelHandler(final RequestCancelHandler<O> requestCancelHandler) {
delegate.addCancelHandler(requestCancelHandler);
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void execute(final Runnable command) {
delegate.execute(command);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/SessionWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/SessionWrapper.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/SessionWrapper.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -7,23 +7,37 @@
import org.jboss.cx.remoting.Session;
/**
- *
+ * A simple delegating wrapper for clients.
*/
public class SessionWrapper implements Session {
protected final Session delegate;
+ /**
+ * Construct a new instance. Calls will be sent to the given {@code delegate} by default.
+ *
+ * @param delegate the delegate client instance
+ */
protected SessionWrapper(final Session delegate) {
this.delegate = delegate;
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void close() throws RemotingException {
delegate.close();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void closeImmediate() throws RemotingException {
delegate.closeImmediate();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public void addCloseHandler(final CloseHandler<Session> closeHandler) {
delegate.addCloseHandler(new CloseHandler<Session>() {
public void handleClose(final Session closed) {
@@ -32,18 +46,30 @@
});
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public ConcurrentMap<Object, Object> getAttributes() {
return delegate.getAttributes();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public String getLocalEndpointName() {
return delegate.getLocalEndpointName();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public String getRemoteEndpointName() {
return delegate.getRemoteEndpointName();
}
+ /**
+ * {@inheritDoc} This implementation calls the same method on the delegate object.
+ */
public <I, O> Client<I, O> getRootClient() {
return delegate.getRootClient();
}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/package-info.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/package-info.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/package-info.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -0,0 +1,4 @@
+/**
+ * Wrapper classes for various API elements.
+ */
+package org.jboss.cx.remoting.spi.wrapper;
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSink.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSink.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSink.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -5,9 +5,18 @@
import java.io.Flushable;
/**
+ * A streaming sink for objects.
*
+ * @param <T> the object type
*/
public interface ObjectSink<T> extends Flushable, Closeable {
+
+ /**
+ * Accept an object.
+ *
+ * @param instance the object to accept
+ * @throws IOException if an error occurs
+ */
void accept(T instance) throws IOException;
/**
@@ -17,5 +26,10 @@
*/
void flush() throws IOException;
+ /**
+ * Close the sink.
+ *
+ * @throws IOException if an error occurs
+ */
void close() throws IOException;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSinkWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSinkWrapper.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSinkWrapper.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -6,23 +6,12 @@
*
*/
public class ObjectSinkWrapper<T> implements ObjectSink<T> {
- private ObjectSink<T> target;
+ private final ObjectSink<T> target;
- protected ObjectSinkWrapper() {
- }
-
public ObjectSinkWrapper(final ObjectSink<T> target) {
this.target = target;
}
- protected final ObjectSink<T> getTarget() {
- return target;
- }
-
- protected final void setTarget(final ObjectSink<T> target) {
- this.target = target;
- }
-
public void accept(final T instance) throws IOException {
target.accept(instance);
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSource.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSource.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSource.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -5,6 +5,8 @@
/**
* A streaming source for objects.
+ *
+ * @param <T> the object type
*/
public interface ObjectSource<T> extends Closeable {
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSourceWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSourceWrapper.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ObjectSourceWrapper.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -6,23 +6,12 @@
*
*/
public class ObjectSourceWrapper<T> implements ObjectSource<T> {
- private ObjectSource<T> target;
+ private final ObjectSource<T> target;
- protected ObjectSourceWrapper() {
- }
-
public ObjectSourceWrapper(final ObjectSource<T> target) {
this.target = target;
}
- protected ObjectSource<T> getTarget() {
- return target;
- }
-
- protected void setTarget(final ObjectSource<T> target) {
- this.target = target;
- }
-
public boolean hasNext() throws IOException {
return target.hasNext();
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/Streams.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/Streams.java 2008-06-28 01:39:06 UTC (rev 4333)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/Streams.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -8,20 +8,41 @@
import java.util.NoSuchElementException;
/**
- *
+ * Handy utility methods for stream types.
*/
public final class Streams {
private Streams() {
}
+ /**
+ * Get an object sink that appends to a collection.
+ *
+ * @param <T> the collection object type
+ * @param target the target collection
+ * @return an object sink
+ */
public static <T> ObjectSink<T> getCollectionObjectSink(Collection<T> target) {
return new CollectionObjectSink<T>(target);
}
+ /**
+ * Get an object source that reads from an iterator.
+ *
+ * @param <T> the iterator object type
+ * @param iterator the iterater to read from
+ * @return an object source
+ */
public static <T> ObjectSource<T> getIteratorObjectSource(Iterator<T> iterator) {
return new IteratorObjectSource<T>(iterator);
}
+ /**
+ * Get an object source that reads from an enumeration.
+ *
+ * @param <T> the enumeration object type
+ * @param enumeration the enumeration to read from
+ * @return an object source
+ */
public static <T> ObjectSource<T> getEnumerationObjectSource(Enumeration<T> enumeration) {
return new EnumerationObjectSource<T>(enumeration);
}
Added: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/package-info.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/package-info.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/package-info.java 2008-07-01 03:07:01 UTC (rev 4334)
@@ -0,0 +1,4 @@
+/**
+ * Stream-related API classes.
+ */
+package org.jboss.cx.remoting.spi.stream;
16 years, 4 months