JBoss Remoting SVN: r5575 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-30 23:22:09 -0400 (Fri, 30 Oct 2009)
New Revision: 5575
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
Log:
Unused fields
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-31 03:21:28 UTC (rev 5574)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-31 03:22:09 UTC (rev 5575)
@@ -59,12 +59,6 @@
import org.jboss.xnio.Result;
import org.jboss.xnio.TranslatingResult;
import org.jboss.xnio.WeakCloseable;
-import org.jboss.marshalling.ClassTable;
-import org.jboss.marshalling.ObjectTable;
-import org.jboss.marshalling.ClassExternalizerFactory;
-import org.jboss.marshalling.ClassResolver;
-import org.jboss.marshalling.ObjectResolver;
-import org.jboss.marshalling.MarshallerFactory;
/**
*
@@ -125,13 +119,6 @@
private final ConcurrentMap[] providerMaps = new ConcurrentMap[ProtocolServiceType.getServiceTypes().length];
- private final ConcurrentMap<String, MarshallerFactory> marshallerFactories = concurrentMap();
- private final ConcurrentMap<String, ClassTable> classTables = concurrentMap();
- private final ConcurrentMap<String, ObjectTable> objectTables = concurrentMap();
- private final ConcurrentMap<String, ClassExternalizerFactory> classExternalizerFactories = concurrentMap();
- private final ConcurrentMap<String, ClassResolver> classResolvers = concurrentMap();
- private final ConcurrentMap<String, ObjectResolver> objectResolvers = concurrentMap();
-
private static final EndpointPermission CREATE_ENDPOINT_PERM = new EndpointPermission("createEndpoint");
private static final EndpointPermission CREATE_REQUEST_HANDLER_PERM = new EndpointPermission("createRequestHandler");
private static final EndpointPermission REGISTER_SERVICE_PERM = new EndpointPermission("registerService");
15 years, 1 month
JBoss Remoting SVN: r5574 - in remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3: spi and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-30 23:21:28 -0400 (Fri, 30 Oct 2009)
New Revision: 5574
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java
Log:
Consolidate the different protocol service type registration methods into one. This allows us to add more types later on without adding methods to the interface.
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-10-31 03:21:28 UTC (rev 5574)
@@ -6,14 +6,9 @@
import org.jboss.remoting3.spi.ConnectionProviderFactory;
import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.remoting3.spi.ConnectionProviderRegistration;
+import org.jboss.remoting3.spi.ProtocolServiceType;
import org.jboss.xnio.IoFuture;
import org.jboss.xnio.OptionMap;
-import org.jboss.marshalling.ClassTable;
-import org.jboss.marshalling.ObjectTable;
-import org.jboss.marshalling.ClassExternalizerFactory;
-import org.jboss.marshalling.ClassResolver;
-import org.jboss.marshalling.ObjectResolver;
-import org.jboss.marshalling.MarshallerFactory;
/**
* A potential participant in a JBoss Remoting communications relationship.
@@ -196,78 +191,18 @@
<T> ConnectionProviderRegistration<T> addConnectionProvider(String uriScheme, ConnectionProviderFactory<T> providerFactory) throws DuplicateRegistrationException;
/**
- * Register a named marshalling protocol.
- * <p/>
- * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
+ * Register a protocol service.
*
- * @param name the protocol name
- * @param marshallerFactory the implementation
+ * @param type the type of service being registered
+ * @param name the name of the protocol provider
+ * @param provider the provider instance
+ * @param <T> the provider type
* @return a handle which may be used to remove the registration
* @throws DuplicateRegistrationException if there is already a protocol registered to that name
*/
- Registration addMarshallingProtocol(String name, MarshallerFactory marshallerFactory) throws DuplicateRegistrationException;
+ <T> Registration addProtocolService(ProtocolServiceType<T> type, String name, T provider) throws DuplicateRegistrationException;
/**
- * Register a named class table for marshalling.
- * <p/>
- * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
- *
- * @param name the protocol name
- * @param classTable the class table
- * @return a handle which may be used to remove the registration
- * @throws DuplicateRegistrationException if there is already a class table registered to that name
- */
- Registration addUserClassTable(String name, ClassTable classTable) throws DuplicateRegistrationException;
-
- /**
- * Register a named object table for marshalling.
- * <p/>
- * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
- *
- * @param name the protocol name
- * @param objectTable the object table
- * @return a handle which may be used to remove the registration
- * @throws DuplicateRegistrationException if there is already an object table registered to that name
- */
- Registration addUserObjectTable(String name, ObjectTable objectTable) throws DuplicateRegistrationException;
-
- /**
- * Register a named class externalizer factory for marshalling.
- * <p/>
- * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
- *
- * @param name the protocol name
- * @param classExternalizerFactory the class externalizer factory
- * @return a handle which may be used to remove the registration
- * @throws DuplicateRegistrationException if there is already a class externalizer factory registered to that name
- */
- Registration addUserExternalizerFactory(String name, ClassExternalizerFactory classExternalizerFactory) throws DuplicateRegistrationException;
-
- /**
- * Register a named class resolver for marshalling.
- * <p/>
- * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
- *
- * @param name the protocol name
- * @param classResolver the class resolver
- * @return a handle which may be used to remove the registration
- * @throws DuplicateRegistrationException if there is already a class resolver registered to that name
- */
- Registration addUserClassResolver(String name, ClassResolver classResolver) throws DuplicateRegistrationException;
-
- /**
- * Register a named object resolver for marshalling.
- * <p/>
- * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
- *
- * @param name the protocol name
- * @param objectResolver the class resolver
- * @return a handle which may be used to remove the registration
- * @throws DuplicateRegistrationException if there is already an object resolver registered to that name
- */
- Registration addUserObjectResolver(String name, ObjectResolver objectResolver) throws DuplicateRegistrationException;
-
- /**
* Flags which can be passed in to listener registration methods.
*/
enum ListenerFlag {
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-31 03:21:28 UTC (rev 5574)
@@ -47,6 +47,7 @@
import org.jboss.remoting3.spi.RequestHandlerConnector;
import org.jboss.remoting3.spi.ConnectionProviderRegistration;
import org.jboss.remoting3.spi.ConnectionHandlerContext;
+import org.jboss.remoting3.spi.ProtocolServiceType;
import org.jboss.xnio.log.Logger;
import org.jboss.xnio.Cancellable;
import org.jboss.xnio.FailedIoFuture;
@@ -121,6 +122,9 @@
private final ConcurrentMap<String, ConcurrentMap<String, ServiceRegistration>> registeredLocalServices = concurrentMap(serviceRegistrationLock);
private final ConcurrentMap<String, ConnectionProvider<?>> connectionProviders = concurrentMap();
+
+ private final ConcurrentMap[] providerMaps = new ConcurrentMap[ProtocolServiceType.getServiceTypes().length];
+
private final ConcurrentMap<String, MarshallerFactory> marshallerFactories = concurrentMap();
private final ConcurrentMap<String, ClassTable> classTables = concurrentMap();
private final ConcurrentMap<String, ObjectTable> objectTables = concurrentMap();
@@ -137,8 +141,11 @@
private static final EndpointPermission ADD_CONNECTION_PROVIDER_PERM = new EndpointPermission("addConnectionProvider");
private static final EndpointPermission ADD_MARSHALLING_PROTOCOL_PERM = new EndpointPermission("addMarshallingProtocol");
- public EndpointImpl(final Executor executor, final String name) {
+ EndpointImpl(final Executor executor, final String name) {
super(executor);
+ for (int i = 0; i < providerMaps.length; i++) {
+ providerMaps[i] = concurrentMap();
+ }
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(CREATE_ENDPOINT_PERM);
@@ -158,7 +165,10 @@
return executor;
}
- // Endpoint implementation
+ @SuppressWarnings({ "unchecked" })
+ private <T> ConcurrentMap<String, T> getMapFor(ProtocolServiceType<T> type) {
+ return (ConcurrentMap<String, T>)providerMaps[type.getIndex()];
+ }
public String getName() {
return name;
@@ -510,30 +520,10 @@
return new MapRegistration<T>(map, name, target);
}
- public Registration addMarshallingProtocol(final String name, final MarshallerFactory marshallerFactory) throws DuplicateRegistrationException {
- return addMarshallingRegistration(name, marshallerFactory, marshallerFactories, "Marshalling protocol factory");
+ public <T> Registration addProtocolService(final ProtocolServiceType<T> type, final String name, final T provider) throws DuplicateRegistrationException {
+ return addMarshallingRegistration(name, provider, getMapFor(type), type.getDescription());
}
- public Registration addUserClassTable(final String name, final ClassTable classTable) throws DuplicateRegistrationException {
- return addMarshallingRegistration(name, classTable, classTables, "Class table");
- }
-
- public Registration addUserObjectTable(final String name, final ObjectTable objectTable) throws DuplicateRegistrationException {
- return addMarshallingRegistration(name, objectTable, objectTables, "Object table");
- }
-
- public Registration addUserExternalizerFactory(final String name, final ClassExternalizerFactory classExternalizerFactory) throws DuplicateRegistrationException {
- return addMarshallingRegistration(name, classExternalizerFactory, classExternalizerFactories, "Class externalizer factory");
- }
-
- public Registration addUserClassResolver(final String name, final ClassResolver classResolver) throws DuplicateRegistrationException {
- return addMarshallingRegistration(name, classResolver, classResolvers, "Class resolver");
- }
-
- public Registration addUserObjectResolver(final String name, final ObjectResolver objectResolver) throws DuplicateRegistrationException {
- return addMarshallingRegistration(name, objectResolver, objectResolvers, "Object resolver");
- }
-
public String toString() {
return "endpoint \"" + name + "\" <" + Integer.toHexString(hashCode()) + ">";
}
@@ -663,6 +653,10 @@
public void accept(final ConnectionHandlerFactory connectionHandlerFactory) {
connectionHandlerFactory.createInstance(localConnectionContext);
}
+
+ public <T> Iterable<Map.Entry<String, T>> getProtocolServiceProviders(final ProtocolServiceType<T> serviceType) {
+ return getMapFor(serviceType).entrySet();
+ }
}
private final ConnectionHandler loopbackConnectionHandler = new LoopbackConnectionHandler();
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-10-31 03:21:28 UTC (rev 5574)
@@ -103,4 +103,16 @@
* required.
*/
public static final Option<Boolean> REQUIRE_SECURE = Option.simple(Options.class, "REQUIRE_SECURE", Boolean.class);
+
+ public static final Option<Integer> MAX_TRANSMIT_SIZE = Option.simple(Options.class, "MAX_TRANSMIT_SIZE", Integer.class);
+
+ public static final Option<Integer> MAX_RECEIVE_SIZE = Option.simple(Options.class, "MAX_RECEIVE_SIZE", Integer.class);
+
+ public static final Option<Integer> TRANSMIT_WINDOW_SIZE = Option.simple(Options.class, "TRANSMIT_WINDOW_SIZE", Integer.class);
+
+ public static final Option<Integer> RECEIVE_WINDOW_SIZE = Option.simple(Options.class, "RECEIVE_WINDOW_SIZE", Integer.class);
+
+ public static final Option<Integer> MAX_OUTBOUND_CHANNELS = Option.simple(Options.class, "MAX_OUTBOUND_CHANNELS", Integer.class);
+
+ public static final Option<Integer> MAX_INBOUND_CHANNELS = Option.simple(Options.class, "MAX_INBOUND_CHANNELS", Integer.class);
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-10-31 03:21:28 UTC (rev 5574)
@@ -35,6 +35,7 @@
import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.remoting3.spi.RemotingServiceDescriptor;
import org.jboss.remoting3.spi.ConnectionProviderFactory;
+import org.jboss.remoting3.spi.ProtocolServiceType;
import org.jboss.xnio.CloseableExecutor;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.OptionMap;
@@ -117,15 +118,15 @@
if (serviceType == ConnectionProviderFactory.class) {
endpoint.addConnectionProvider(name, (ConnectionProviderFactory<?>) service);
} else if (serviceType == ClassTable.class) {
- endpoint.addUserClassTable(name, (ClassTable) service);
+ endpoint.addProtocolService(ProtocolServiceType.CLASS_TABLE, name, (ClassTable) service);
} else if (serviceType == ObjectTable.class) {
- endpoint.addUserObjectTable(name, (ObjectTable) service);
+ endpoint.addProtocolService(ProtocolServiceType.OBJECT_TABLE, name, (ObjectTable) service);
} else if (serviceType == ClassResolver.class) {
- endpoint.addUserClassResolver(name, (ClassResolver) service);
+ endpoint.addProtocolService(ProtocolServiceType.CLASS_RESOLVER, name, (ClassResolver) service);
} else if (serviceType == ObjectResolver.class) {
- endpoint.addUserObjectResolver(name, (ObjectResolver) service);
+ endpoint.addProtocolService(ProtocolServiceType.OBJECT_RESOLVER, name, (ObjectResolver) service);
} else if (serviceType == ClassExternalizerFactory.class) {
- endpoint.addUserExternalizerFactory(name, (ClassExternalizerFactory) service);
+ endpoint.addProtocolService(ProtocolServiceType.CLASS_EXTERNALIZER_FACTORY, name, (ClassExternalizerFactory) service);
}
} catch (DuplicateRegistrationException e) {
log.debug("Duplicate registration for '" + name + "' of " + serviceType);
@@ -142,7 +143,7 @@
for (String name : found.keySet()) {
final MarshallerFactory marshallerFactory = found.get(name).getMarshallerFactory();
try {
- endpoint.addMarshallingProtocol(name, marshallerFactory);
+ endpoint.addProtocolService(ProtocolServiceType.MARSHALLER_FACTORY, name, marshallerFactory);
} catch (DuplicateRegistrationException e) {
log.debug("Duplicate registration for '" + name + "' of " + MarshallerFactory.class);
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java 2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java 2009-10-31 03:21:28 UTC (rev 5574)
@@ -23,6 +23,7 @@
package org.jboss.remoting3.spi;
import org.jboss.remoting3.HandleableCloseable;
+import java.util.Map;
/**
* A context for a connection provider which provides a means to accept a connection.
@@ -37,4 +38,13 @@
* @param connectionHandlerFactory the connection handler factory
*/
void accept(ConnectionHandlerFactory connectionHandlerFactory);
+
+ /**
+ * Get the currently-registered protocol service providers of the given type.
+ *
+ * @param serviceType the service type
+ * @param <T> the type of the provider interface
+ * @return the currently-registered providers
+ */
+ <T> Iterable<Map.Entry<String, T>> getProtocolServiceProviders(ProtocolServiceType<T> serviceType);
}
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java 2009-10-31 03:21:28 UTC (rev 5574)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3.spi;
+
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.ClassTable;
+import org.jboss.marshalling.ObjectTable;
+import org.jboss.marshalling.ClassResolver;
+import org.jboss.marshalling.ObjectResolver;
+import org.jboss.marshalling.ClassExternalizerFactory;
+import java.io.Serializable;
+
+public final class ProtocolServiceType<T> implements Serializable {
+
+ private final Class<T> valueClass;
+ private final String name;
+ private transient final int index;
+ private static final long serialVersionUID = -4972423526582260641L;
+ private final String description;
+
+ private ProtocolServiceType(Class<T> type, final String name, final String description, final int index) {
+ valueClass = type;
+ this.name = name;
+ this.description = description;
+ this.index = index;
+ }
+
+ public Class<T> getValueClass() {
+ return valueClass;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ protected Object readResolve() {
+ try {
+ return ProtocolServiceType.class.getField(name).get(null);
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot resolve service type object", e);
+ }
+ }
+
+ public static final ProtocolServiceType<MarshallerFactory> MARSHALLER_FACTORY;
+
+ public static final ProtocolServiceType<ClassTable> CLASS_TABLE;
+
+ public static final ProtocolServiceType<ObjectTable> OBJECT_TABLE;
+
+ public static final ProtocolServiceType<ClassResolver> CLASS_RESOLVER;
+
+ public static final ProtocolServiceType<ObjectResolver> OBJECT_RESOLVER;
+
+ public static final ProtocolServiceType<ClassExternalizerFactory> CLASS_EXTERNALIZER_FACTORY;
+
+ private static final ProtocolServiceType<?>[] SERVICE_TYPES;
+
+ public static ProtocolServiceType<?>[] getServiceTypes() {
+ return SERVICE_TYPES.clone();
+ }
+
+ public static ProtocolServiceType<?> getServiceType(int index) {
+ return SERVICE_TYPES[index];
+ }
+
+ static {
+ int index = 0;
+ SERVICE_TYPES = new ProtocolServiceType<?>[] {
+ MARSHALLER_FACTORY = new ProtocolServiceType<MarshallerFactory>(MarshallerFactory.class, "MARSHALLER_FACTORY", "Marshaller factory", index++),
+ CLASS_TABLE = new ProtocolServiceType<ClassTable>(ClassTable.class, "CLASS_TABLE", "Class table", index++),
+ OBJECT_TABLE = new ProtocolServiceType<ObjectTable>(ObjectTable.class, "OBJECT_TABLE", "Object table", index++),
+ CLASS_RESOLVER = new ProtocolServiceType<ClassResolver>(ClassResolver.class, "CLASS_RESOLVER", "Class resolver", index++),
+ OBJECT_RESOLVER = new ProtocolServiceType<ObjectResolver>(ObjectResolver.class, "OBJECT_RESOLVER", "Object resolver", index++),
+ CLASS_EXTERNALIZER_FACTORY = new ProtocolServiceType<ClassExternalizerFactory>(ClassExternalizerFactory.class, "CLASS_EXTERNALIZER_FACTORY", "Class externalizer factory", index++),
+ };
+ }
+
+ public String getDescription() {
+ return description;
+ }
+}
15 years, 1 month
JBoss Remoting SVN: r5573 - in remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3: spi and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-30 18:18:09 -0400 (Fri, 30 Oct 2009)
New Revision: 5573
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandlerContext.java
Removed:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandlerFactory.java
Log:
Rename ConnectionContext to ConnectionHandlerContext for consistency
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-28 01:44:11 UTC (rev 5572)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-30 22:18:09 UTC (rev 5573)
@@ -46,7 +46,7 @@
import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.remoting3.spi.RequestHandlerConnector;
import org.jboss.remoting3.spi.ConnectionProviderRegistration;
-import org.jboss.remoting3.spi.ConnectionContext;
+import org.jboss.remoting3.spi.ConnectionHandlerContext;
import org.jboss.xnio.log.Logger;
import org.jboss.xnio.Cancellable;
import org.jboss.xnio.FailedIoFuture;
@@ -564,7 +564,7 @@
}
}
- private final class LocalConnectionContext implements ConnectionContext {
+ private final class LocalConnectionContext implements ConnectionHandlerContext {
private final Connection connection;
LocalConnectionContext(final Connection connection) {
@@ -667,13 +667,13 @@
private final ConnectionHandler loopbackConnectionHandler = new LoopbackConnectionHandler();
private final Connection loopbackConnection = new LoopbackConnection();
- private final ConnectionContext localConnectionContext = new LocalConnectionContext(loopbackConnection);
+ private final ConnectionHandlerContext localConnectionContext = new LocalConnectionContext(loopbackConnection);
private final class LocalConnectionProvider implements ConnectionProvider<Void> {
public Cancellable connect(final URI uri, final OptionMap connectOptions, final Result<ConnectionHandlerFactory> result) throws IllegalArgumentException {
result.setResult(new ConnectionHandlerFactory() {
- public ConnectionHandler createInstance(final ConnectionContext context) {
+ public ConnectionHandler createInstance(final ConnectionHandlerContext context) {
return loopbackConnectionHandler;
}
});
@@ -748,7 +748,7 @@
private class LoopbackConnectionHandler implements ConnectionHandler {
public Cancellable open(final String serviceType, final String groupName, final org.jboss.xnio.Result<RequestHandler> result) {
- localConnectionContext.openService(serviceType, groupName, OptionMap.EMPTY, new ConnectionContext.ServiceResult() {
+ localConnectionContext.openService(serviceType, groupName, OptionMap.EMPTY, new ConnectionHandlerContext.ServiceResult() {
public void opened(final RequestHandler requestHandler, final OptionMap optionMap) {
result.setResult(requestHandler);
}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java 2009-10-28 01:44:11 UTC (rev 5572)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java 2009-10-30 22:18:09 UTC (rev 5573)
@@ -1,71 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3.spi;
-
-import org.jboss.xnio.OptionMap;
-
-/**
- * The context for connections to service incoming requests to open a client service.
- *
- * @remoting.consume
- */
-public interface ConnectionContext {
-
- /**
- * Open a service.
- *
- * @remoting.nonblocking
- *
- * @param serviceType the service type
- * @param groupName the service group name
- * @param optionMap the open options
- * @param serviceResult the result of the service open
- */
- void openService(String serviceType, String groupName, OptionMap optionMap, ServiceResult serviceResult);
-
- /**
- * Indicate that the remote side has terminated the connection, so the local side should be closed as well.
- *
- * @remoting.nonblocking
- */
- void remoteClosed();
-
- /**
- * The result acceptor for a service open request.
- */
- interface ServiceResult {
-
- /**
- * Called if the service was opened.
- *
- * @param requestHandler the opened request handler
- * @param optionMap the service's option map
- */
- void opened(RequestHandler requestHandler, OptionMap optionMap);
-
- /**
- * Called if no matching service was found.
- */
- void notFound();
- }
-}
Copied: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandlerContext.java (from rev 5572, remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java)
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandlerContext.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandlerContext.java 2009-10-30 22:18:09 UTC (rev 5573)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3.spi;
+
+import org.jboss.xnio.OptionMap;
+
+/**
+ * The context for connections to service incoming requests to open a client service.
+ *
+ * @remoting.consume
+ */
+public interface ConnectionHandlerContext {
+
+ /**
+ * Open a service.
+ *
+ * @remoting.nonblocking
+ *
+ * @param serviceType the service type
+ * @param groupName the service group name
+ * @param optionMap the open options
+ * @param serviceResult the result of the service open
+ */
+ void openService(String serviceType, String groupName, OptionMap optionMap, ServiceResult serviceResult);
+
+ /**
+ * Indicate that the remote side has terminated the connection, so the local side should be closed as well.
+ *
+ * @remoting.nonblocking
+ */
+ void remoteClosed();
+
+ /**
+ * The result acceptor for a service open request.
+ */
+ interface ServiceResult {
+
+ /**
+ * Called if the service was opened.
+ *
+ * @param requestHandler the opened request handler
+ * @param optionMap the service's option map
+ */
+ void opened(RequestHandler requestHandler, OptionMap optionMap);
+
+ /**
+ * Called if no matching service was found.
+ */
+ void notFound();
+ }
+}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandlerFactory.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandlerFactory.java 2009-10-28 01:44:11 UTC (rev 5572)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandlerFactory.java 2009-10-30 22:18:09 UTC (rev 5573)
@@ -36,5 +36,5 @@
* @param connectionContext the local connection handler for incoming requests
* @return the connection handler for outgoing requests
*/
- ConnectionHandler createInstance(ConnectionContext connectionContext);
+ ConnectionHandler createInstance(ConnectionHandlerContext connectionContext);
}
15 years, 1 month
JBoss Remoting SVN: r5572 - in remoting3/trunk: jboss-remoting/src/main/java/org/jboss/remoting3 and 3 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-27 21:44:11 -0400 (Tue, 27 Oct 2009)
New Revision: 5572
Added:
remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingNonBlockingTaglet.java
Removed:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/BasicMarshallingProtocol.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureResult.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/LocalServiceConfiguration.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocol.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/Result.java
Modified:
remoting3/trunk/jboss-remoting/pom.xml
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnectorImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureReplyImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/LocalRequestHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemotingServiceDescriptor.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandlerConnector.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExample2Main.java
remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingTypeTaglet.java
Log:
Commit the changes I was just talking about
Modified: remoting3/trunk/jboss-remoting/pom.xml
===================================================================
--- remoting3/trunk/jboss-remoting/pom.xml 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/pom.xml 2009-10-28 01:44:11 UTC (rev 5572)
@@ -37,13 +37,13 @@
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-api</artifactId>
- <version>2.0.0.CR3</version>
+ <version>2.0.0.CR4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>marshalling-api</artifactId>
- <version>1.1.0.GA</version>
+ <version>1.2.0.CR5-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -95,14 +95,14 @@
<docletArtifact>
<groupId>org.jboss.apiviz</groupId>
<artifactId>apiviz</artifactId>
- <version>1.2.5.GA</version>
+ <version>1.3.0.GA</version>
</docletArtifact>
<doctitle><![CDATA[JBoss Remoting ]]>${version}</doctitle>
<header><![CDATA[JBoss Remoting ]]>${version}</header>
<footer><![CDATA[JBoss Remoting ]]>${version}</footer>
<bottom><![CDATA[<i>Copyright © 2009 JBoss, a division of Red Hat, Inc.</i>]]></bottom>
<links>
- <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
+ <link>http://java.sun.com/javase/6/docs/</link>
</links>
</configuration>
</plugin>
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/BasicMarshallingProtocol.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/BasicMarshallingProtocol.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/BasicMarshallingProtocol.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -1,122 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3;
-
-import org.jboss.remoting3.spi.MarshallingProtocol;
-import org.jboss.marshalling.Unmarshaller;
-import org.jboss.marshalling.Marshaller;
-import org.jboss.marshalling.MarshallerFactory;
-import org.jboss.marshalling.MarshallingConfiguration;
-import org.jboss.marshalling.Marshalling;
-import org.jboss.marshalling.reflect.SunReflectiveCreator;
-import org.jboss.xnio.Pool;
-import org.jboss.xnio.OptionMap;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.io.IOException;
-
-/**
- * A marshalling protocol which wraps a {@link org.jboss.marshalling.MarshallerFactory}.
- */
-public final class BasicMarshallingProtocol implements MarshallingProtocol {
-
- private final MarshallerFactory marshallerFactory;
- private final int version;
-
- private static final SunReflectiveCreator creator = AccessController.doPrivileged(new PrivilegedAction<SunReflectiveCreator>() {
- public SunReflectiveCreator run() {
- return new SunReflectiveCreator();
- }
- });
-
- /**
- * Construct a new instance.
- *
- * @param marshallerFactory the marshaller factory to use
- * @param version the wire protocol version to specify
- */
- public BasicMarshallingProtocol(final MarshallerFactory marshallerFactory, final int version) {
- // todo: security check?
- this.marshallerFactory = marshallerFactory;
- this.version = version;
- }
-
- /** {@inheritDoc} */
- public Pool<Unmarshaller> getUnmarshallerPool(final Configuration configuration) {
- final MarshallingConfiguration config = buildConfig(configuration);
- return new Pool<Unmarshaller>() {
- public Unmarshaller allocate() {
- try {
- return marshallerFactory.createUnmarshaller(config);
- } catch (IOException e) {
- // todo log
- return null;
- }
- }
-
- public void free(final Unmarshaller resource) throws IllegalArgumentException {
- }
-
- public void discard(final Unmarshaller resource) {
- }
- };
- }
-
- /** {@inheritDoc} */
- public Pool<Marshaller> getMarshallerPool(final Configuration configuration) {
- final MarshallingConfiguration config = buildConfig(configuration);
- return new Pool<Marshaller>() {
- public Marshaller allocate() {
- try {
- return marshallerFactory.createMarshaller(config);
- } catch (IOException e) {
- // todo log
- return null;
- }
- }
-
- public void free(final Marshaller resource) throws IllegalArgumentException {
- }
-
- public void discard(final Marshaller resource) {
- }
- };
- }
-
- private MarshallingConfiguration buildConfig(final Configuration configuration) {
- final MarshallingConfiguration config = new MarshallingConfiguration();
- config.setCreator(creator);
- config.setStreamHeader(Marshalling.nullStreamHeader());
- config.setClassExternalizerFactory(configuration.getUserExternalizerFactory());
- config.setClassTable(configuration.getUserClassTable());
- config.setClassResolver(configuration.getUserClassResolver());
- config.setObjectResolver(configuration.getUserObjectResolver());
- config.setObjectTable(configuration.getUserObjectTable());
- final OptionMap optionMap = configuration.getOptionMap();
- config.setBufferSize(optionMap.get(Options.BUFFER_SIZE, 512));
- config.setClassCount(optionMap.get(Options.CLASS_COUNT, 64));
- config.setInstanceCount(optionMap.get(Options.INSTANCE_COUNT, 256));
- config.setVersion(version);
- return config;
- }
-}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnectorImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnectorImpl.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnectorImpl.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -22,10 +22,11 @@
package org.jboss.remoting3;
-import org.jboss.xnio.IoFuture;
import org.jboss.remoting3.spi.RequestHandlerConnector;
import org.jboss.remoting3.spi.RequestHandler;
-import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.FutureResult;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.TranslatingResult;
import java.io.Serializable;
import java.io.IOException;
@@ -52,18 +53,13 @@
if (clientContext != null) {
throw new SecurityException("Connector has not been sent");
}
- return new FutureResult<Client<I, O>, RequestHandler>() {
- private final Cancellable cancellable = requestHandlerConnector.createRequestHandler(getResult());
-
- protected Client<I, O> translate(final RequestHandler result) throws IOException {
- return endpoint.createClient(result, requestClass, replyClass);
+ final FutureResult<Client<I, O>> futureResult = new FutureResult<Client<I, O>>();
+ requestHandlerConnector.createRequestHandler(new TranslatingResult<RequestHandler, Client<I, O>>(futureResult) {
+ protected Client<I, O> translate(final RequestHandler input) throws IOException {
+ return endpoint.createClient(input, requestClass, replyClass);
}
-
- public IoFuture<Client<I, O>> cancel() {
- cancellable.cancel();
- return super.cancel();
- }
- };
+ });
+ return futureResult.getIoFuture();
}
public ClientContext getClientContext() {
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -6,7 +6,6 @@
import org.jboss.remoting3.spi.ConnectionProviderFactory;
import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.remoting3.spi.ConnectionProviderRegistration;
-import org.jboss.remoting3.spi.MarshallingProtocol;
import org.jboss.xnio.IoFuture;
import org.jboss.xnio.OptionMap;
import org.jboss.marshalling.ClassTable;
@@ -14,6 +13,7 @@
import org.jboss.marshalling.ClassExternalizerFactory;
import org.jboss.marshalling.ClassResolver;
import org.jboss.marshalling.ObjectResolver;
+import org.jboss.marshalling.MarshallerFactory;
/**
* A potential participant in a JBoss Remoting communications relationship.
@@ -45,19 +45,105 @@
* @return the request handler
* @throws IOException if an error occurs
*/
- <I, O> RequestHandler createLocalRequestHandler(RequestListener<I, O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException;
+ <I, O> RequestHandler createLocalRequestHandler(RequestListener<? super I, ? extends O> requestListener, Class<I> requestClass, Class<O> replyClass) throws IOException;
/**
- * Create a request handler source that can be used to acquire clients associated with a request listener on this endpoint.
- * <p/>
- * You must have the {@link org.jboss.remoting3.EndpointPermission registerService EndpointPermission} to invoke this method.
+ * Get a new service builder which can be used to register a service.
*
- * @param configuration the configuration to use
- * @throws IOException if an error occurs
+ * @return a new service builder
*/
- <I, O> Registration registerService(LocalServiceConfiguration<I, O> configuration) throws IOException;
+ ServiceBuilder<?, ?> serviceBuilder();
/**
+ * A service builder for new service registration.
+ *
+ * @param <I> the request type
+ * @param <O> the reply type
+ */
+ interface ServiceBuilder<I, O> {
+
+ /**
+ * Set the group name.
+ * @param groupName the group name
+ * @return this builder
+ */
+ ServiceBuilder<I, O> setGroupName(String groupName);
+
+ /**
+ * Set the service type string, which should follow the convention for package names (reversed domain names).
+ *
+ * @param serviceType the service type
+ * @return this builder
+ */
+ ServiceBuilder<I, O> setServiceType(String serviceType);
+
+ /**
+ * Clear the configured client listener and set a new request type.
+ *
+ * @param newRequestType the new request type's class
+ * @param <N> the new request type
+ * @return this builder, cast to include the new request type
+ */
+ <N> ServiceBuilder<N, O> setRequestType(Class<N> newRequestType);
+
+ /**
+ * Clear the configured client listener and set a new reply type.
+ *
+ * @param newReplyType the new reply type's class
+ * @param <N> the new reply type
+ * @return this builder, cast to include the new reply type
+ */
+ <N> ServiceBuilder<I, N> setReplyType(Class<N> newReplyType);
+
+ /**
+ * Set the request listener. The given listener may be configured to accept a superclass of the given
+ * request type, or a subclass of the given reply type, since they are compatible.
+ *
+ * @param clientListener the request listener
+ * @return this builder
+ */
+ ServiceBuilder<I, O> setClientListener(ClientListener<? super I, ? extends O> clientListener);
+
+ /**
+ * Set the option map for the service. The options may include, but are not limited to:
+ * <ul>
+ * <li>{@link Options#BUFFER_SIZE} - the recommended buffer size for marshallers to use for this service</li>
+ * <li>{@link Options#CLASS_COUNT} - the recommended class count for marshallers to use for this service</li>
+ * <li>{@link Options#INSTANCE_COUNT} - the recommended instance count for marshallers to use for this service</li>
+ * <li>{@link Options#METRIC} - the relative desirability or "distance" of this service</li>
+ * <li>{@link Options#MARSHALLING_PROTOCOLS} - the marshalling protocols which are allowed for this service,
+ * in order of decreasing preference; if none is given, all registered protocols will
+ * be made available</li>
+ * <li>{@link Options#MARSHALLING_CLASS_RESOLVERS} - the class resolvers which are allowed for this service,
+ * in order of decreasing preference; if none is given, the default class resolver is used</li>
+ * <li>{@link Options#MARSHALLING_CLASS_TABLES} - the class tables which are allowed for this service, in order
+ * of decreasing preference</li>
+ * <li>{@link Options#MARSHALLING_EXTERNALIZER_FACTORIES} - the class externalizer factories which are allowed
+ * for this service, in order of decreasing preference</li>
+ * <li>{@link Options#REMOTELY_VISIBLE} - {@code true} if this service should be remotely accessible,
+ * {@code false} otherwise (defaults to {@code true})</li>
+ * <li>{@link Options#REQUIRE_SECURE} - {@code true} if this service may only be accessed over a secure/encrypted
+ * channel; defaults to {@code false}, however this should be set to {@code true} if sensitive data (e.g.
+ * passwords) may be transmitted as part of a payload</li>
+ * </ul>
+ *
+ * @param optionMap the option map
+ * @return this builder
+ */
+ ServiceBuilder<I, O> setOptionMap(OptionMap optionMap);
+
+ /**
+ * Register the service.
+ * <p/>
+ * You must have the {@link org.jboss.remoting3.EndpointPermission registerService EndpointPermission} to invoke this method.
+ *
+ * @return a registration handle
+ * @throws IOException if a problem occurs with registration
+ */
+ Registration register() throws IOException;
+ }
+
+ /**
* Add a service registration listener which is called whenever a local service is registered.
* <p/>
* You must have the {@link org.jboss.remoting3.EndpointPermission addServiceListener EndpointPermission} to invoke this method.
@@ -81,7 +167,7 @@
* @return the client
* @throws IOException if an error occurs
*/
- <I, O> Client<I, O> createClient(RequestHandler handler, Class<I> requestClass, Class<O> replyClass) throws IOException;
+ <I, O> Client<I, O> createClient(RequestHandler handler, Class<I> requestClass, Class<O> replyClass) throws IOException;
/**
* Open a connection with a peer. Returns a future connection which may be used to cancel the connection attempt.
@@ -115,11 +201,11 @@
* You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
*
* @param name the protocol name
- * @param marshallingProtocol the implementation
+ * @param marshallerFactory the implementation
* @return a handle which may be used to remove the registration
* @throws DuplicateRegistrationException if there is already a protocol registered to that name
*/
- Registration addMarshallingProtocol(String name, MarshallingProtocol marshallingProtocol) throws DuplicateRegistrationException;
+ Registration addMarshallingProtocol(String name, MarshallerFactory marshallerFactory) throws DuplicateRegistrationException;
/**
* Register a named class table for marshalling.
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -45,31 +45,31 @@
import org.jboss.remoting3.spi.ConnectionProviderFactory;
import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.remoting3.spi.RequestHandlerConnector;
-import org.jboss.remoting3.spi.Result;
import org.jboss.remoting3.spi.ConnectionProviderRegistration;
-import org.jboss.remoting3.spi.MarshallingProtocol;
import org.jboss.remoting3.spi.ConnectionContext;
+import org.jboss.xnio.log.Logger;
import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.FailedIoFuture;
+import org.jboss.xnio.FinishedIoFuture;
+import org.jboss.xnio.FutureResult;
import org.jboss.xnio.IoFuture;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.Result;
+import org.jboss.xnio.TranslatingResult;
import org.jboss.xnio.WeakCloseable;
-import org.jboss.xnio.OptionMap;
-import org.jboss.xnio.FinishedIoFuture;
-import org.jboss.xnio.FailedIoFuture;
-import org.jboss.xnio.log.Logger;
import org.jboss.marshalling.ClassTable;
import org.jboss.marshalling.ObjectTable;
import org.jboss.marshalling.ClassExternalizerFactory;
import org.jboss.marshalling.ClassResolver;
import org.jboss.marshalling.ObjectResolver;
+import org.jboss.marshalling.MarshallerFactory;
/**
*
*/
final class EndpointImpl extends AbstractHandleableCloseable<Endpoint> implements Endpoint {
- private static final NullCancellable NULL_CANCELLABLE = new NullCancellable();
-
static {
// Print Remoting "greeting" message
Logger.getLogger("org.jboss.remoting").info("JBoss Remoting version %s", Version.VERSION);
@@ -121,7 +121,7 @@
private final ConcurrentMap<String, ConcurrentMap<String, ServiceRegistration>> registeredLocalServices = concurrentMap(serviceRegistrationLock);
private final ConcurrentMap<String, ConnectionProvider<?>> connectionProviders = concurrentMap();
- private final ConcurrentMap<String, MarshallingProtocol> marshallingProtocols = concurrentMap();
+ private final ConcurrentMap<String, MarshallerFactory> marshallerFactories = concurrentMap();
private final ConcurrentMap<String, ClassTable> classTables = concurrentMap();
private final ConcurrentMap<String, ObjectTable> objectTables = concurrentMap();
private final ConcurrentMap<String, ClassExternalizerFactory> classExternalizerFactories = concurrentMap();
@@ -164,15 +164,14 @@
return name;
}
- public <I, O> RequestHandler createLocalRequestHandler(final RequestListener<I, O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException {
+ public <I, O> RequestHandler createLocalRequestHandler(final RequestListener<? super I, ? extends O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(CREATE_REQUEST_HANDLER_PERM);
}
checkOpen();
final ClientContextImpl clientContext = new ClientContextImpl(executor, loopbackConnection);
- final LocalRequestHandler<I, O> localRequestHandler = new LocalRequestHandler<I, O>(executor,
- requestListener, clientContext, requestClass, replyClass);
+ final LocalRequestHandler<I, O> localRequestHandler = new LocalRequestHandler<I, O>(executor, requestListener, clientContext, requestClass, replyClass);
final WeakCloseable lrhCloseable = new WeakCloseable(localRequestHandler);
clientContext.addCloseHandler(new CloseHandler<ClientContext>() {
public void handleClose(final ClientContext closed) {
@@ -192,37 +191,161 @@
return localRequestHandler;
}
- public <I, O> Registration registerService(final LocalServiceConfiguration<I, O> configuration) throws IOException {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(REGISTER_SERVICE_PERM);
+ public ServiceBuilder<?, ?> serviceBuilder() {
+ return new ServiceBuilderImpl<Void, Void>();
+ }
+
+ private final class ServiceBuilderImpl<I, O> implements ServiceBuilder<I, O> {
+ private String groupName;
+ private String serviceType;
+ private Class<I> requestType;
+ private Class<O> replyType;
+ private ClientListener<? super I, ? extends O> clientListener;
+ private OptionMap optionMap = OptionMap.EMPTY;
+
+ public ServiceBuilder<I, O> setGroupName(final String groupName) {
+ this.groupName = groupName;
+ return this;
}
- if (configuration == null) {
- throw new NullPointerException("configuration is null");
+
+ public ServiceBuilder<I, O> setServiceType(final String serviceType) {
+ this.serviceType = serviceType;
+ return this;
}
- final String serviceType = configuration.getServiceType();
- final String groupName = configuration.getGroupName();
- final OptionMap optionMap = configuration.getOptionMap();
- final Integer metric = optionMap.get(Options.METRIC);
- if (metric != null && metric.intValue() < 0) {
- throw new IllegalArgumentException("metric must be greater than or equal to zero");
+
+ @SuppressWarnings({ "unchecked" })
+ public <N> ServiceBuilder<N, O> setRequestType(final Class<N> newRequestType) {
+ if (newRequestType == null) {
+ throw new NullPointerException("newRequestType is null");
+ }
+ clientListener = null;
+ ServiceBuilderImpl<N, O> castBuilder = (ServiceBuilderImpl<N, O>) this;
+ castBuilder.requestType = newRequestType;
+ return castBuilder;
}
- ServiceURI.validateServiceType(serviceType);
- ServiceURI.validateGroupName(groupName);
- checkOpen();
- final String canonServiceType = serviceType.toLowerCase();
- final String canonGroupName = groupName.toLowerCase();
- final Class<I> requestClass = configuration.getRequestClass();
- final Class<O> replyClass = configuration.getReplyClass();
- final ClientListener<I, O> clientListener = configuration.getClientListener();
- final Executor executor = this.executor;
- final ConcurrentMap<String, ConcurrentMap<String, ServiceRegistration>> registeredLocalServices = this.registeredLocalServices;
- final RequestHandlerConnector requestHandlerConnector = new RequestHandlerConnector() {
+
+ @SuppressWarnings({ "unchecked" })
+ public <N> ServiceBuilder<I, N> setReplyType(final Class<N> newReplyType) {
+ if (newReplyType == null) {
+ throw new NullPointerException("newReplyType is null");
+ }
+ clientListener = null;
+ ServiceBuilderImpl<I, N> castBuilder = (ServiceBuilderImpl<I, N>) this;
+ castBuilder.replyType = newReplyType;
+ return castBuilder;
+ }
+
+ public ServiceBuilder<I, O> setClientListener(final ClientListener<? super I, ? extends O> clientListener) {
+ if (requestType == null || replyType == null) {
+ throw new IllegalArgumentException("Must configure both request and reply type before setting the client listener");
+ }
+ this.clientListener = clientListener;
+ return this;
+ }
+
+ public ServiceBuilder<I, O> setOptionMap(final OptionMap optionMap) {
+ if (optionMap == null) {
+ throw new NullPointerException("optionMap is null");
+ }
+ this.optionMap = optionMap;
+ return this;
+ }
+
+ public Registration register() throws IOException {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPermission(REGISTER_SERVICE_PERM);
+ }
+ if (groupName == null) {
+ throw new NullPointerException("groupName is null");
+ }
+ if (serviceType == null) {
+ throw new NullPointerException("serviceType is null");
+ }
+ if (requestType == null) {
+ throw new NullPointerException("requestType is null");
+ }
+ if (replyType == null) {
+ throw new NullPointerException("replyType is null");
+ }
+ if (clientListener == null) {
+ throw new NullPointerException("clientListener is null");
+ }
+ final Integer metric = optionMap.get(Options.METRIC);
+ if (metric != null && metric.intValue() < 0) {
+ throw new IllegalArgumentException("metric must be greater than or equal to zero");
+ }
+ ServiceURI.validateServiceType(serviceType);
+ ServiceURI.validateGroupName(groupName);
+ checkOpen();
+ final String canonServiceType = serviceType.toLowerCase();
+ final String canonGroupName = groupName.toLowerCase();
+ final Executor executor = EndpointImpl.this.executor;
+ final ConcurrentMap<String, ConcurrentMap<String, ServiceRegistration>> registeredLocalServices = EndpointImpl.this.registeredLocalServices;
+ final RequestHandlerConnector requestHandlerConnector = new Connector();
+ final ServiceRegistration registration = new ServiceRegistration(serviceType, groupName, name, optionMap, requestHandlerConnector);
+ // this handle is used to remove the service registration
+ final Registration handle = new Registration() {
+ public void close() {
+ synchronized (serviceRegistrationLock) {
+ final ConcurrentMap<String, ServiceRegistration> submap = registeredLocalServices.get(serviceType);
+ if (submap != null) {
+ submap.remove(groupName, registration);
+ }
+ }
+ }
+ };
+ registration.setHandle(handle);
+ final Iterator<Map.Entry<Registration,ServiceRegistrationListener>> serviceListenerRegistrations;
+ final Object lock = serviceRegistrationLock;
+ synchronized (lock) {
+ // actually register the service, and while we have the lock, snag a copy of the registration listener list
+ final ConcurrentMap<String, ServiceRegistration> submap;
+ if (registeredLocalServices.containsKey(canonServiceType)) {
+ submap = registeredLocalServices.get(canonServiceType);
+ if (submap.containsKey(canonGroupName)) {
+ throw new ServiceRegistrationException("ListenerRegistration of service of type \"" + serviceType + "\" in group \"" + groupName + "\" duplicates an already-registered service's specification");
+ }
+ } else {
+ submap = concurrentMap(lock);
+ registeredLocalServices.put(canonServiceType, submap);
+ }
+ submap.put(canonGroupName, registration);
+ // snapshot
+ serviceListenerRegistrations = EndpointImpl.this.serviceListenerRegistrations.entrySet().iterator();
+ }
+ // notify all service listener registrations that were registered at the time the service was created
+ final ServiceRegistrationListener.ServiceInfo serviceInfo = new ServiceRegistrationListener.ServiceInfo();
+ serviceInfo.setGroupName(groupName);
+ serviceInfo.setServiceType(serviceType);
+ serviceInfo.setOptionMap(optionMap);
+ serviceInfo.setRegistrationHandle(handle);
+ serviceInfo.setRequestHandlerConnector(requestHandlerConnector);
+ executor.execute(new Runnable() {
+ public void run() {
+ final Iterator<Map.Entry<Registration,ServiceRegistrationListener>> iter = serviceListenerRegistrations;
+ while (iter.hasNext()) {
+ final Map.Entry<Registration,ServiceRegistrationListener> slr = iter.next();
+ try {
+ slr.getValue().serviceRegistered(slr.getKey(), serviceInfo.clone());
+ } catch (Throwable t) {
+ logListenerError(t);
+ }
+ }
+ }
+ });
+ return handle;
+ }
+
+ private class Connector implements RequestHandlerConnector {
+
+ Connector() {
+ }
+
public Cancellable createRequestHandler(final Result<RequestHandler> result) throws SecurityException {
try {
final ClientContextImpl clientContext = new ClientContextImpl(executor, loopbackConnection);
- final RequestListener<I, O> requestListener = clientListener.handleClientOpen(clientContext);
- final RequestHandler localRequestHandler = createLocalRequestHandler(requestListener, requestClass, replyClass);
+ final RequestHandler localRequestHandler = createLocalRequestHandler(clientListener.handleClientOpen(clientContext), requestType, replyType);
clientContext.addCloseHandler(new CloseHandler<ClientContext>() {
public void handleClose(final ClientContext closed) {
IoUtils.safeClose(localRequestHandler);
@@ -232,61 +355,9 @@
} catch (IOException e) {
result.setException(e);
}
- return NULL_CANCELLABLE;
+ return IoUtils.nullCancellable();
}
- };
- final ServiceRegistration registration = new ServiceRegistration(serviceType, groupName, name, optionMap, requestHandlerConnector);
- // this handle is used to remove the service registration
- final Registration handle = new Registration() {
- public void close() {
- synchronized (serviceRegistrationLock) {
- final ConcurrentMap<String, ServiceRegistration> submap = registeredLocalServices.get(serviceType);
- if (submap != null) {
- submap.remove(groupName, registration);
- }
- }
- }
- };
- registration.setHandle(handle);
- final Iterator<Map.Entry<Registration,ServiceRegistrationListener>> serviceListenerRegistrations;
- final Object lock = serviceRegistrationLock;
- synchronized (lock) {
- // actually register the service, and while we have the lock, snag a copy of the registration listener list
- final ConcurrentMap<String, ServiceRegistration> submap;
- if (registeredLocalServices.containsKey(canonServiceType)) {
- submap = registeredLocalServices.get(canonServiceType);
- if (submap.containsKey(canonGroupName)) {
- throw new ServiceRegistrationException("ListenerRegistration of service of type \"" + serviceType + "\" in group \"" + groupName + "\" duplicates an already-registered service's specification");
- }
- } else {
- submap = concurrentMap(lock);
- registeredLocalServices.put(canonServiceType, submap);
- }
- submap.put(canonGroupName, registration);
- // snapshot
- serviceListenerRegistrations = this.serviceListenerRegistrations.entrySet().iterator();
}
- // notify all service listener registrations that were registered at the time the service was created
- final ServiceRegistrationListener.ServiceInfo serviceInfo = new ServiceRegistrationListener.ServiceInfo();
- serviceInfo.setGroupName(groupName);
- serviceInfo.setServiceType(serviceType);
- serviceInfo.setOptionMap(optionMap);
- serviceInfo.setRegistrationHandle(handle);
- serviceInfo.setRequestHandlerConnector(requestHandlerConnector);
- executor.execute(new Runnable() {
- public void run() {
- final Iterator<Map.Entry<Registration,ServiceRegistrationListener>> iter = serviceListenerRegistrations;
- while (iter.hasNext()) {
- final Map.Entry<Registration,ServiceRegistrationListener> slr = iter.next();
- try {
- slr.getValue().serviceRegistered(slr.getKey(), serviceInfo.clone());
- } catch (Throwable t) {
- logListenerError(t);
- }
- }
- }
- });
- return handle;
}
private static void logListenerError(final Throwable t) {
@@ -383,13 +454,13 @@
if (connectionProvider == null) {
throw new UnknownURISchemeException("No connection provider for URI scheme \"" + scheme + "\" is installed");
}
- final FutureResult<Connection, ConnectionHandlerFactory> futureResult = new FutureResult<Connection, ConnectionHandlerFactory>() {
- protected Connection translate(final ConnectionHandlerFactory result) {
- return new ConnectionImpl(result);
+ final FutureResult<Connection> futureResult = new FutureResult<Connection>(executor);
+ futureResult.addCancelHandler(connectionProvider.connect(destination, connectOptions, new TranslatingResult<ConnectionHandlerFactory, Connection>(futureResult) {
+ protected Connection translate(final ConnectionHandlerFactory input) {
+ return new ConnectionImpl(input);
}
- };
- connectionProvider.connect(destination, connectOptions, futureResult.getResult());
- return futureResult;
+ }));
+ return futureResult.getIoFuture();
}
public <T> ConnectionProviderRegistration<T> addConnectionProvider(final String uriScheme, final ConnectionProviderFactory<T> providerFactory) {
@@ -439,8 +510,8 @@
return new MapRegistration<T>(map, name, target);
}
- public Registration addMarshallingProtocol(final String name, final MarshallingProtocol marshallingProtocol) throws DuplicateRegistrationException {
- return addMarshallingRegistration(name, marshallingProtocol, marshallingProtocols, "Marshalling protocol");
+ public Registration addMarshallingProtocol(final String name, final MarshallerFactory marshallerFactory) throws DuplicateRegistrationException {
+ return addMarshallingRegistration(name, marshallerFactory, marshallerFactories, "Marshalling protocol factory");
}
public Registration addUserClassTable(final String name, final ClassTable classTable) throws DuplicateRegistrationException {
@@ -467,16 +538,6 @@
return "endpoint \"" + name + "\" <" + Integer.toHexString(hashCode()) + ">";
}
- private <I, O> IoFuture<? extends Client<I, O>> doOpenClient(final ConnectionHandler connectionHandler, final String serviceType, final String groupName, final Class<I> requestClass, final Class<O> replyClass) {
- final FutureResult<Client<I, O>, RequestHandler> futureResult = new FutureResult<Client<I, O>, RequestHandler>() {
- protected Client<I, O> translate(final RequestHandler result) throws IOException {
- return createClient(result, requestClass, replyClass);
- }
- };
- connectionHandler.open(serviceType, groupName, futureResult.getResult());
- return futureResult;
- }
-
private static class MapRegistration<T> implements Registration {
private static final class Info<T> {
private final ConcurrentMap<String, T> map;
@@ -504,7 +565,12 @@
}
private final class LocalConnectionContext implements ConnectionContext {
+ private final Connection connection;
+ LocalConnectionContext(final Connection connection) {
+ this.connection = connection;
+ }
+
public void openService(final String serviceType, final String groupName, final OptionMap optionMap, final ServiceResult serviceResult) {
final String canonServiceType = serviceType.toLowerCase();
final String canonGroupName = groupName.toLowerCase();
@@ -529,21 +595,28 @@
}
}
registration.getRequestHandlerConnector().createRequestHandler(new Result<RequestHandler>() {
- public void setResult(final RequestHandler result) {
+ public boolean setResult(final RequestHandler result) {
serviceResult.opened(result, registration.getOptionMap());
+ return true;
}
- public void setException(final IOException exception) {
+ public boolean setException(final IOException exception) {
log.warn(exception, "Unexpected exception on service lookup");
serviceResult.notFound();
+ return true;
}
- public void setCancelled() {
+ public boolean setCancelled() {
log.warn("Unexpected cancellation on service lookup");
serviceResult.notFound();
+ return true;
}
});
}
+
+ public void remoteClosed() {
+ IoUtils.safeClose(connection);
+ }
}
private class ConnectionImpl extends AbstractHandleableCloseable<Connection> implements Connection {
@@ -551,7 +624,7 @@
private ConnectionImpl(final ConnectionHandlerFactory connectionHandlerFactory) {
super(EndpointImpl.this.executor);
- connectionHandler = connectionHandlerFactory.createInstance(localConnectionContext);
+ connectionHandler = connectionHandlerFactory.createInstance(new LocalConnectionContext(this));
}
protected void closeAction() throws IOException {
@@ -559,7 +632,13 @@
}
public <I, O> IoFuture<? extends Client<I, O>> openClient(final String serviceType, final String groupName, final Class<I> requestClass, final Class<O> replyClass) {
- return doOpenClient(connectionHandler, serviceType, groupName, requestClass, replyClass);
+ final FutureResult<Client<I, O>> futureResult = new FutureResult<Client<I, O>>();
+ futureResult.addCancelHandler(connectionHandler.open(serviceType, groupName, new TranslatingResult<RequestHandler, Client<I, O>>(futureResult) {
+ protected Client<I, O> translate(final RequestHandler input) throws IOException {
+ return createClient(input, requestClass, replyClass);
+ }
+ }));
+ return futureResult.getIoFuture();
}
public <I, O> ClientConnector<I, O> createClientConnector(final RequestListener<I, O> listener, final Class<I> requestClass, final Class<O> replyClass) throws IOException {
@@ -586,17 +665,10 @@
}
}
- private final ConnectionContext localConnectionContext = new LocalConnectionContext();
private final ConnectionHandler loopbackConnectionHandler = new LoopbackConnectionHandler();
private final Connection loopbackConnection = new LoopbackConnection();
+ private final ConnectionContext localConnectionContext = new LocalConnectionContext(loopbackConnection);
- // todo - move this into XNIO IoUtils
- private static class NullCancellable implements Cancellable {
- public Cancellable cancel() {
- return this;
- }
- }
-
private final class LocalConnectionProvider implements ConnectionProvider<Void> {
public Cancellable connect(final URI uri, final OptionMap connectOptions, final Result<ConnectionHandlerFactory> result) throws IllegalArgumentException {
@@ -604,9 +676,8 @@
public ConnectionHandler createInstance(final ConnectionContext context) {
return loopbackConnectionHandler;
}
-
});
- return NULL_CANCELLABLE;
+ return IoUtils.nullCancellable();
}
public Void getProviderInterface() {
@@ -617,21 +688,13 @@
private class LoopbackConnection implements Connection {
public <I, O> IoFuture<? extends Client<I, O>> openClient(final String serviceType, final String groupName, final Class<I> requestClass, final Class<O> replyClass) {
- final IoFuture.Manager<Client<I, O>> mgr = new IoFuture.Manager<Client<I, O>>();
- mgr.addCancelHandler(loopbackConnectionHandler.open(serviceType, groupName, new Result<RequestHandler>() {
- public void setResult(final RequestHandler result) {
- mgr.setResult(ClientImpl.create(result, executor, requestClass, replyClass));
+ final FutureResult<Client<I,O>> futureResult = new FutureResult<Client<I, O>>(executor);
+ futureResult.addCancelHandler(loopbackConnectionHandler.open(serviceType, groupName, new TranslatingResult<RequestHandler, Client<I, O>>(futureResult) {
+ protected Client<I, O> translate(final RequestHandler input) throws IOException {
+ return ClientImpl.create(input, executor, requestClass, replyClass);
}
-
- public void setException(final IOException exception) {
- mgr.setException(exception);
- }
-
- public void setCancelled() {
- mgr.finishCancel();
- }
}));
- return mgr.getIoFuture();
+ return futureResult.getIoFuture();
}
public <I, O> ClientConnector<I, O> createClientConnector(final RequestListener<I, O> listener, final Class<I> requestClass, final Class<O> replyClass) {
@@ -684,7 +747,7 @@
private class LoopbackConnectionHandler implements ConnectionHandler {
- public Cancellable open(final String serviceType, final String groupName, final Result<RequestHandler> result) {
+ public Cancellable open(final String serviceType, final String groupName, final org.jboss.xnio.Result<RequestHandler> result) {
localConnectionContext.openService(serviceType, groupName, OptionMap.EMPTY, new ConnectionContext.ServiceResult() {
public void opened(final RequestHandler requestHandler, final OptionMap optionMap) {
result.setResult(requestHandler);
@@ -694,15 +757,15 @@
result.setException(new ServiceNotFoundException(ServiceURI.create(serviceType, groupName, name), "No such service located"));
}
});
- return NULL_CANCELLABLE;
+ return IoUtils.nullCancellable();
}
public RequestHandlerConnector createConnector(final RequestHandler localHandler) {
// the loopback connection just returns the local handler directly as no forwarding is involved
return new RequestHandlerConnector() {
- public Cancellable createRequestHandler(final Result<RequestHandler> result) throws SecurityException {
+ public Cancellable createRequestHandler(final org.jboss.xnio.Result<RequestHandler> result) throws SecurityException {
result.setResult(localHandler);
- return NULL_CANCELLABLE;
+ return IoUtils.nullCancellable();
}
};
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureReplyImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureReplyImpl.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureReplyImpl.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -91,7 +91,7 @@
}
public void handleCancellation() {
- finishCancel();
+ setCancelled();
}
}
}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureResult.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureResult.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureResult.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -1,65 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3;
-
-import org.jboss.xnio.AbstractIoFuture;
-import org.jboss.remoting3.spi.Result;
-import java.io.IOException;
-
-abstract class FutureResult<T, X> extends AbstractIoFuture<T> {
- private final Result<X> result = new Result<X>() {
- public void setResult(final X result) {
- try {
- FutureResult.this.setResult(translate(result));
- } catch (IOException e) {
- FutureResult.this.setException(e);
- }
- }
-
- public void setException(final IOException exception) {
- FutureResult.this.setException(exception);
- }
-
- public void setCancelled() {
- finishCancel();
- }
- };
-
- abstract protected T translate(X result) throws IOException;
-
- Result<X> getResult() {
- return result;
- }
-
- protected boolean setException(final IOException exception) {
- return super.setException(exception);
- }
-
- protected boolean setResult(final T result) {
- return super.setResult(result);
- }
-
- protected boolean finishCancel() {
- return super.finishCancel();
- }
-}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/LocalRequestHandler.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/LocalRequestHandler.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/LocalRequestHandler.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -44,9 +44,10 @@
private static final Logger log = Logger.getLogger("org.jboss.remoting.listener");
- LocalRequestHandler(final Executor executor, final RequestListener<I, O> requestListener, final ClientContextImpl clientContext, final Class<I> requestClass, final Class<O> replyClass) {
+ @SuppressWarnings({ "unchecked" })
+ LocalRequestHandler(final Executor executor, final RequestListener<? super I, ? extends O> requestListener, final ClientContextImpl clientContext, final Class<I> requestClass, final Class<O> replyClass) {
super(executor);
- this.requestListener = requestListener;
+ this.requestListener = (RequestListener<I, O>) requestListener;
this.clientContext = clientContext;
this.requestClass = requestClass;
this.replyClass = replyClass;
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/LocalServiceConfiguration.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/LocalServiceConfiguration.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/LocalServiceConfiguration.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -1,153 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3;
-
-import org.jboss.xnio.OptionMap;
-
-/**
- * A configuration for a service to be deployed into the endpoint.
- *
- * @apiviz.exclude
- *
- * @param <I> the request type
- * @param <O> the reply type
- */
-public final class LocalServiceConfiguration<I, O> {
- private final ClientListener<I, O> clientListener;
- private final Class<I> requestClass;
- private final Class<O> replyClass;
- private String serviceType;
- private String groupName;
- private OptionMap optionMap = OptionMap.EMPTY;
-
- /**
- * Construct a new instance.
- *
- * @param clientListener the client listener
- * @param requestClass the request class
- * @param replyClass the reply class
- */
- public LocalServiceConfiguration(final ClientListener<I, O> clientListener, final Class<I> requestClass, final Class<O> replyClass) {
- this.clientListener = clientListener;
- this.requestClass = requestClass;
- this.replyClass = replyClass;
- }
-
- /**
- * Create a new instance.
- *
- * @param clientListener the client listener
- * @param requestClass the request class
- * @param replyClass the reply class
- * @param <I> the request type
- * @param <O> the reply type
- * @return a new configuration instance
- */
- public static <I, O> LocalServiceConfiguration<I, O> create(final ClientListener<I, O> clientListener, final Class<I> requestClass, final Class<O> replyClass) {
- return new LocalServiceConfiguration<I,O>(clientListener, requestClass, replyClass);
- }
-
- /**
- * Get the request listener for this service.
- *
- * @return the request listener
- */
- public ClientListener<I, O> getClientListener() {
- return clientListener;
- }
-
- /**
- * Get the request class.
- *
- * @return the request class
- */
- public Class<I> getRequestClass() {
- return requestClass;
- }
-
- /**
- * Get the reply class.
- *
- * @return the reply class
- */
- public Class<O> getReplyClass() {
- return replyClass;
- }
-
- /**
- * Get the service type.
- *
- * @return the service type
- */
- public String getServiceType() {
- return serviceType;
- }
-
- /**
- * Set the service type.
- *
- * @param serviceType the service type
- */
- public void setServiceType(final String serviceType) {
- this.serviceType = serviceType;
- }
-
- /**
- * Get the group name.
- *
- * @return the group name
- */
- public String getGroupName() {
- return groupName;
- }
-
- /**
- * Set the group name.
- *
- * @param groupName the group name
- */
- public void setGroupName(final String groupName) {
- this.groupName = groupName;
- }
-
- /**
- * Get the option map for the service.
- *
- * @return the option map
- */
- public OptionMap getOptionMap() {
- return optionMap;
- }
-
- /**
- * Set the option map for the service.
- *
- * @param optionMap the option map
- */
- public void setOptionMap(final OptionMap optionMap) {
- if (optionMap == null) {
- throw new NullPointerException("optionMap is null");
- }
- this.optionMap = optionMap;
- }
-}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -44,38 +44,32 @@
public static final Option<Boolean> LOAD_PROVIDERS = Option.simple(Options.class, "LOAD_PROVIDERS", Boolean.class);
/**
- * Request that the marshalling layer require the use of one of the listed marshalling protocols, in order of decreasing preference. If
- * not specified, use a default value. The marshaller {@code "default"} can be specified explicitly for this default value.
+ * Request that the marshalling layer require the use of one of the listed marshalling protocols, in order of decreasing preference.
*/
public static final Option<Sequence<String>> MARSHALLING_PROTOCOLS = Option.sequence(Options.class, "MARSHALLING_PROTOCOLS", String.class);
/**
- * Request that the marshalling layer require the presense of one of the listed user-defined class tables, in order of decreasing preference. If
- * not specified, no user class table should be used. The string {@code "none"} indicates no class table.
+ * Request that the marshalling layer require the presense of one of the listed user-defined class tables, in order of decreasing preference.
*/
public static final Option<Sequence<String>> MARSHALLING_CLASS_TABLES = Option.sequence(Options.class, "MARSHALLING_CLASS_TABLES", String.class);
/**
- * Request that the marshalling layer require the presense of one of the listed user-defined object tables, in order of decreasing preference. If
- * not specified, no user object table should be used. The string {@code "none"} indicates no object table.
+ * Request that the marshalling layer require the presense of one of the listed user-defined object tables, in order of decreasing preference.
*/
public static final Option<Sequence<String>> MARSHALLING_OBJECT_TABLES = Option.sequence(Options.class, "MARSHALLING_OBJECT_TABLES", String.class);
/**
- * Request that the marshalling layer require the presense of one of the listed class resolvers, in order of decreasing preference. If
- * not specified, classes are resolved on the remote side using a default strategy. The string {@code "default"} indicates the default class resolver.
+ * Request that the marshalling layer require the presense of one of the listed class resolvers, in order of decreasing preference.
*/
public static final Option<Sequence<String>> MARSHALLING_CLASS_RESOLVERS = Option.sequence(Options.class, "MARSHALLING_CLASS_RESOLVERS", String.class);
/**
- * Request that the marshalling layer require the presense of one of the listed object resolvers, in order of decreasing preference. If
- * not specified, no object substitution will take place. The string {@code "none"} indicates no object resolver.
+ * Request that the marshalling layer require the presense of one of the listed object resolvers, in order of decreasing preference.
*/
public static final Option<Sequence<String>> MARSHALLING_OBJECT_RESOLVERS = Option.sequence(Options.class, "MARSHALLING_OBJECT_RESOLVERS", String.class);
/**
- * Request that the marshalling layer require the presense of one of the listed user-defined externalizer factories, in order of decreasing preference. If
- * not specified, no user externalizer factory should be used. The string {@code "none"} indicates no externalizer factory.
+ * Request that the marshalling layer require the presense of one of the listed user-defined externalizer factories, in order of decreasing preference.
*/
public static final Option<Sequence<String>> MARSHALLING_EXTERNALIZER_FACTORIES = Option.sequence(Options.class, "MARSHALLING_EXTERNALIZER_FACTORIES", String.class);
@@ -85,7 +79,7 @@
public static final Option<Integer> METRIC = Option.simple(Options.class, "METRIC", Integer.class);
/**
- * Specify that the registered service should or should not be visible remotely. If not specified, defaults to {@code true}.
+ * Specify that the registered service should or should not be visible remotely.
*/
public static final Option<Boolean> REMOTELY_VISIBLE = Option.simple(Options.class, "REMOTELY_VISIBLE", Boolean.class);
@@ -103,4 +97,10 @@
* Specify the expected instance count for any configured marshaller or unmarshaller.
*/
public static final Option<Integer> INSTANCE_COUNT = Option.simple(Options.class, "INSTANCE_COUNT", Integer.class);
+
+ /**
+ * Specify whether the service may be accessed from connections which are unencrypted, or whether encryption is
+ * required.
+ */
+ public static final Option<Boolean> REQUIRE_SECURE = Option.simple(Options.class, "REQUIRE_SECURE", Boolean.class);
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -30,9 +30,10 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.ServiceLoader;
+import java.util.Map;
+import java.util.HashMap;
import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.remoting3.spi.RemotingServiceDescriptor;
-import org.jboss.remoting3.spi.MarshallingProtocol;
import org.jboss.remoting3.spi.ConnectionProviderFactory;
import org.jboss.xnio.CloseableExecutor;
import org.jboss.xnio.IoUtils;
@@ -43,6 +44,8 @@
import org.jboss.marshalling.ClassResolver;
import org.jboss.marshalling.ObjectResolver;
import org.jboss.marshalling.ClassExternalizerFactory;
+import org.jboss.marshalling.ProviderDescriptor;
+import org.jboss.marshalling.MarshallerFactory;
/**
* The standalone interface into Remoting. This class contains static methods that are useful to standalone programs
@@ -106,15 +109,13 @@
}
});
if (optionMap.get(Options.LOAD_PROVIDERS, true)) {
- for (RemotingServiceDescriptor descriptor : ServiceLoader.load(RemotingServiceDescriptor.class)) {
+ for (RemotingServiceDescriptor<?> descriptor : ServiceLoader.load(RemotingServiceDescriptor.class)) {
final String name = descriptor.getName();
- final Class serviceType = descriptor.getType();
+ final Class<?> serviceType = descriptor.getType();
final Object service = descriptor.getService();
try {
if (serviceType == ConnectionProviderFactory.class) {
endpoint.addConnectionProvider(name, (ConnectionProviderFactory<?>) service);
- } else if (serviceType == MarshallingProtocol.class) {
- endpoint.addMarshallingProtocol(name, (MarshallingProtocol) service);
} else if (serviceType == ClassTable.class) {
endpoint.addUserClassTable(name, (ClassTable) service);
} else if (serviceType == ObjectTable.class) {
@@ -127,9 +128,25 @@
endpoint.addUserExternalizerFactory(name, (ClassExternalizerFactory) service);
}
} catch (DuplicateRegistrationException e) {
- log.debug("Duplicate registration for '" + name + "' of type " + serviceType);
+ log.debug("Duplicate registration for '" + name + "' of " + serviceType);
}
}
+ final Map<String, ProviderDescriptor> found = new HashMap<String, ProviderDescriptor>();
+ for (ProviderDescriptor descriptor : ServiceLoader.load(ProviderDescriptor.class)) {
+ final String name = descriptor.getName();
+ // find the best one
+ if (! found.containsKey(name) || found.get(name).getSupportedVersions()[0] < descriptor.getSupportedVersions()[0]) {
+ found.put(name, descriptor);
+ }
+ }
+ for (String name : found.keySet()) {
+ final MarshallerFactory marshallerFactory = found.get(name).getMarshallerFactory();
+ try {
+ endpoint.addMarshallingProtocol(name, marshallerFactory);
+ } catch (DuplicateRegistrationException e) {
+ log.debug("Duplicate registration for '" + name + "' of " + MarshallerFactory.class);
+ }
+ }
}
return endpoint;
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionContext.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -26,12 +26,16 @@
/**
* The context for connections to service incoming requests to open a client service.
+ *
+ * @remoting.consume
*/
public interface ConnectionContext {
/**
* Open a service.
*
+ * @remoting.nonblocking
+ *
* @param serviceType the service type
* @param groupName the service group name
* @param optionMap the open options
@@ -40,6 +44,13 @@
void openService(String serviceType, String groupName, OptionMap optionMap, ServiceResult serviceResult);
/**
+ * Indicate that the remote side has terminated the connection, so the local side should be closed as well.
+ *
+ * @remoting.nonblocking
+ */
+ void remoteClosed();
+
+ /**
* The result acceptor for a service open request.
*/
interface ServiceResult {
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandler.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandler.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionHandler.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -24,6 +24,7 @@
import java.io.Closeable;
import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.Result;
/**
* A connection to a foreign endpoint. This interface is implemented by the protocol implementation.
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -23,6 +23,7 @@
package org.jboss.remoting3.spi;
import java.net.URI;
+import org.jboss.xnio.Result;
import org.jboss.xnio.Cancellable;
import org.jboss.xnio.OptionMap;
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocol.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocol.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocol.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -1,107 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3.spi;
-
-import org.jboss.marshalling.Marshaller;
-import org.jboss.marshalling.Unmarshaller;
-import org.jboss.marshalling.ClassTable;
-import org.jboss.marshalling.ObjectTable;
-import org.jboss.marshalling.ClassExternalizerFactory;
-import org.jboss.marshalling.ClassResolver;
-import org.jboss.marshalling.ObjectResolver;
-import org.jboss.xnio.Pool;
-import org.jboss.xnio.OptionMap;
-
-/**
- * A registered marshalling protocol.
- *
- * @remoting.implement
- */
-public interface MarshallingProtocol {
-
- /**
- * Get a configured unmarshaller pool.
- *
- * @param configuration the configuration to use
- * @return the pool
- */
- Pool<Unmarshaller> getUnmarshallerPool(Configuration configuration);
-
- /**
- * Get a configured marshaller pool.
- *
- * @param configuration the configuration to use
- * @return the pool
- */
- Pool<Marshaller> getMarshallerPool(Configuration configuration);
-
- /**
- * The configuration for a marshalling protocol.
- *
- * @remoting.consume
- */
- interface Configuration {
-
- /**
- * Get a user class table, if any.
- *
- * @return the user class table or {@code null} if none is configured
- */
- ClassTable getUserClassTable();
-
- /**
- * Get a user object table, if any.
- *
- * @return the user object table or {@code null} if none is configured
- */
- ObjectTable getUserObjectTable();
-
- /**
- * Get a user externalizer factory, if any.
- *
- * @return the user externalizer factory
- */
- ClassExternalizerFactory getUserExternalizerFactory();
-
- /**
- * Get a user class resolver, if any.
- *
- * @return the user class resolver
- */
- ClassResolver getUserClassResolver();
-
- /**
- * Get a user object resolver, if any.
- *
- * @return the user object resolver
- */
- ObjectResolver getUserObjectResolver();
-
- /**
- * Get the options to use for this marshaller configuration.
- *
- * @return the options
- */
- OptionMap getOptionMap();
- }
-}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemotingServiceDescriptor.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemotingServiceDescriptor.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemotingServiceDescriptor.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -36,7 +36,6 @@
/**
* Get the type of service provided by this descriptor. Only the following types are supported:
* <ul>
- * <li><code>{@link MarshallingProtocol}.class</code> - named marshalling protocol</li>
* <li><code>{@link ConnectionProviderFactory}.class</code> - named connection provider URI scheme</li>
* <li><code>{@link org.jboss.marshalling.ClassTable ClassTable}.class</code> - named marshalling class table</li>
* <li><code>{@link org.jboss.marshalling.ObjectTable ObjectTable}.class</code> - named marshalling object table</li>
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandlerConnector.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandlerConnector.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandlerConnector.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -37,5 +37,5 @@
* @return the cancellation handle
* @throws SecurityException if this is a forwarding connector, thrown if the connector was not forwarded or if this method is called more than one time
*/
- Cancellable createRequestHandler(Result<RequestHandler> result) throws SecurityException;
+ Cancellable createRequestHandler(org.jboss.xnio.Result<RequestHandler> result) throws SecurityException;
}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/Result.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/Result.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/Result.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -1,53 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3.spi;
-
-import java.io.IOException;
-
-/**
- * A handler for accepting the result of an operation. Used by protocol implementations to tell Remoting
- * the result of an operation.
- *
- * @param <T> the type of the result
- */
-public interface Result<T> {
-
- /**
- * Indicate a successful result, and hand in the result value.
- *
- * @param result the result value
- */
- void setResult(T result);
-
- /**
- * Indicate a failure, and hand in the exception.
- *
- * @param exception the exception
- */
- void setException(IOException exception);
-
- /**
- * Indicate a cancellation of the operation.
- */
- void setCancelled();
-}
Modified: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExample2Main.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExample2Main.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExample2Main.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -27,7 +27,6 @@
import org.jboss.remoting3.Endpoint;
import org.jboss.remoting3.Remoting;
import org.jboss.remoting3.Connection;
-import org.jboss.remoting3.LocalServiceConfiguration;
import org.jboss.remoting3.Registration;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.OptionMap;
@@ -43,10 +42,9 @@
public static void main(String[] args) throws Exception {
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
- final LocalServiceConfiguration<String, String> config = LocalServiceConfiguration.create(new StringRot13ClientListener(), String.class, String.class);
- config.setGroupName("main");
- config.setServiceType("simple.rot13");
- final Registration handle = endpoint.registerService(config);
+ final Registration handle = endpoint.serviceBuilder().setServiceType("simple.rot13").setGroupName("main")
+ .setRequestType(String.class).setReplyType(String.class).setClientListener(new StringRot13ClientListener())
+ .register();
try {
final Connection connection = endpoint.connect(new URI("local:///"), OptionMap.EMPTY).get();
try {
Copied: remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingNonBlockingTaglet.java (from rev 5492, remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingInternalTaglet.java)
===================================================================
--- remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingNonBlockingTaglet.java (rev 0)
+++ remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingNonBlockingTaglet.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3.taglet;
+
+import com.sun.javadoc.Tag;
+
+public final class RemotingNonBlockingTaglet extends RemotingTypeTaglet {
+
+ public String getName() {
+ return "remoting.nonblocking";
+ }
+
+ public String toString(final Tag tag) {
+ return "<p><b>Non-blocking method</b> - this method is expected to operate on a non-blocking basis. That is, " +
+ "the method is expected to return in a relatively short amount of time, and the result of the method is " +
+ "not expected to be available at the time this method returns. Instead, the " +
+ "method implementation should take whatever steps are necessary to initiate the operation asynchronously " +
+ "and then return. If a result is available immediately, it is allowed to report the result immediately.\n";
+ }
+}
\ No newline at end of file
Modified: remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingTypeTaglet.java
===================================================================
--- remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingTypeTaglet.java 2009-10-24 22:49:32 UTC (rev 5571)
+++ remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingTypeTaglet.java 2009-10-28 01:44:11 UTC (rev 5572)
@@ -86,5 +86,6 @@
add(tagletMap, new RemotingConsumeTaglet());
add(tagletMap, new RemotingImplementTaglet());
add(tagletMap, new RemotingInternalTaglet());
+ add(tagletMap, new RemotingNonBlockingTaglet());
}
}
15 years, 1 month
JBoss Remoting SVN: r5571 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-24 18:49:32 -0400 (Sat, 24 Oct 2009)
New Revision: 5571
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
Log:
Fix a problem where connection close is not passed on to the handler
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-23 22:30:53 UTC (rev 5570)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-24 22:49:32 UTC (rev 5571)
@@ -554,6 +554,10 @@
connectionHandler = connectionHandlerFactory.createInstance(localConnectionContext);
}
+ protected void closeAction() throws IOException {
+ connectionHandler.close();
+ }
+
public <I, O> IoFuture<? extends Client<I, O>> openClient(final String serviceType, final String groupName, final Class<I> requestClass, final Class<O> replyClass) {
return doOpenClient(connectionHandler, serviceType, groupName, requestClass, replyClass);
}
15 years, 1 month
JBoss Remoting SVN: r5570 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-23 18:30:53 -0400 (Fri, 23 Oct 2009)
New Revision: 5570
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
Log:
Prevent the problem where an executor task awaits termination of its own executor
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-10-23 22:24:45 UTC (rev 5569)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-10-23 22:30:53 UTC (rev 5570)
@@ -156,7 +156,16 @@
* @return a closeable executor
*/
public static CloseableExecutor createExecutor(final int maxThreads) {
- return IoUtils.closeableExecutor(new ThreadPoolExecutor(1, maxThreads, 30L, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50), OUR_THREAD_FACTORY, new ThreadPoolExecutor.CallerRunsPolicy()), 30L, TimeUnit.SECONDS);
+ final ThreadPoolExecutor executor = new ThreadPoolExecutor(1, maxThreads, 30L, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50), OUR_THREAD_FACTORY, new ThreadPoolExecutor.CallerRunsPolicy());
+ return new CloseableExecutor() {
+ public void close() throws IOException {
+ executor.shutdown();
+ }
+
+ public void execute(final Runnable command) {
+ executor.execute(command);
+ }
+ };
}
/**
15 years, 1 month
JBoss Remoting SVN: r5569 - in remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3: spi and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-23 18:24:45 -0400 (Fri, 23 Oct 2009)
New Revision: 5569
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/BasicMarshallingProtocol.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocol.java
Log:
Simplify service registration internals; add basic impl of MarshallingProtocol; add config options to marshalling configuration
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/BasicMarshallingProtocol.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/BasicMarshallingProtocol.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/BasicMarshallingProtocol.java 2009-10-23 22:24:45 UTC (rev 5569)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3;
+
+import org.jboss.remoting3.spi.MarshallingProtocol;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.MarshallingConfiguration;
+import org.jboss.marshalling.Marshalling;
+import org.jboss.marshalling.reflect.SunReflectiveCreator;
+import org.jboss.xnio.Pool;
+import org.jboss.xnio.OptionMap;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.io.IOException;
+
+/**
+ * A marshalling protocol which wraps a {@link org.jboss.marshalling.MarshallerFactory}.
+ */
+public final class BasicMarshallingProtocol implements MarshallingProtocol {
+
+ private final MarshallerFactory marshallerFactory;
+ private final int version;
+
+ private static final SunReflectiveCreator creator = AccessController.doPrivileged(new PrivilegedAction<SunReflectiveCreator>() {
+ public SunReflectiveCreator run() {
+ return new SunReflectiveCreator();
+ }
+ });
+
+ /**
+ * Construct a new instance.
+ *
+ * @param marshallerFactory the marshaller factory to use
+ * @param version the wire protocol version to specify
+ */
+ public BasicMarshallingProtocol(final MarshallerFactory marshallerFactory, final int version) {
+ // todo: security check?
+ this.marshallerFactory = marshallerFactory;
+ this.version = version;
+ }
+
+ /** {@inheritDoc} */
+ public Pool<Unmarshaller> getUnmarshallerPool(final Configuration configuration) {
+ final MarshallingConfiguration config = buildConfig(configuration);
+ return new Pool<Unmarshaller>() {
+ public Unmarshaller allocate() {
+ try {
+ return marshallerFactory.createUnmarshaller(config);
+ } catch (IOException e) {
+ // todo log
+ return null;
+ }
+ }
+
+ public void free(final Unmarshaller resource) throws IllegalArgumentException {
+ }
+
+ public void discard(final Unmarshaller resource) {
+ }
+ };
+ }
+
+ /** {@inheritDoc} */
+ public Pool<Marshaller> getMarshallerPool(final Configuration configuration) {
+ final MarshallingConfiguration config = buildConfig(configuration);
+ return new Pool<Marshaller>() {
+ public Marshaller allocate() {
+ try {
+ return marshallerFactory.createMarshaller(config);
+ } catch (IOException e) {
+ // todo log
+ return null;
+ }
+ }
+
+ public void free(final Marshaller resource) throws IllegalArgumentException {
+ }
+
+ public void discard(final Marshaller resource) {
+ }
+ };
+ }
+
+ private MarshallingConfiguration buildConfig(final Configuration configuration) {
+ final MarshallingConfiguration config = new MarshallingConfiguration();
+ config.setCreator(creator);
+ config.setStreamHeader(Marshalling.nullStreamHeader());
+ config.setClassExternalizerFactory(configuration.getUserExternalizerFactory());
+ config.setClassTable(configuration.getUserClassTable());
+ config.setClassResolver(configuration.getUserClassResolver());
+ config.setObjectResolver(configuration.getUserObjectResolver());
+ config.setObjectTable(configuration.getUserObjectTable());
+ final OptionMap optionMap = configuration.getOptionMap();
+ config.setBufferSize(optionMap.get(Options.BUFFER_SIZE, 512));
+ config.setClassCount(optionMap.get(Options.CLASS_COUNT, 64));
+ config.setInstanceCount(optionMap.get(Options.INSTANCE_COUNT, 256));
+ config.setVersion(version);
+ return config;
+ }
+}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java 2009-10-23 21:19:18 UTC (rev 5568)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java 2009-10-23 22:24:45 UTC (rev 5569)
@@ -26,6 +26,7 @@
import java.util.Set;
import java.util.Collection;
import java.util.HashMap;
+import java.util.IdentityHashMap;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static java.util.Collections.unmodifiableMap;
@@ -34,6 +35,7 @@
import java.util.concurrent.ConcurrentMap;
final class CopyOnWriteHashMap<K, V> implements ConcurrentMap<K, V> {
+ private final boolean identity;
private final Object writeLock;
private volatile Map<K, V> map = emptyMap();
@@ -42,6 +44,11 @@
}
CopyOnWriteHashMap(final Object writeLock) {
+ this(false, writeLock);
+ }
+
+ CopyOnWriteHashMap(final boolean identity, final Object writeLock) {
+ this.identity = identity;
this.writeLock = writeLock;
}
@@ -59,7 +66,7 @@
if (map.size() == 0) {
this.map = singletonMap(key, value);
} else {
- final HashMap<K, V> copy = new HashMap<K, V>(map);
+ final Map<K, V> copy = copy(map);
map.put(key, value);
this.map = copy;
}
@@ -78,7 +85,7 @@
if (map.size() == 1) {
this.map = emptyMap();
} else {
- final HashMap<K, V> copy = new HashMap<K, V>(map);
+ final Map<K, V> copy = copy(map);
map.remove(key);
this.map = copy;
}
@@ -100,7 +107,7 @@
if (map.size() == 1) {
this.map = singletonMap(key, newValue);
} else {
- final HashMap<K, V> copy = new HashMap<K, V>(map);
+ final Map<K, V> copy = copy(map);
map.put(key, newValue);
this.map = copy;
}
@@ -122,7 +129,7 @@
if (map.size() == 1) {
this.map = singletonMap(key, value);
} else {
- final HashMap<K, V> copy = new HashMap<K, V>(map);
+ final Map<K, V> copy = copy(map);
map.put(key, value);
this.map = copy;
}
@@ -164,7 +171,7 @@
if (map.size() == 0) {
this.map = singletonMap(key, value);
} else {
- final HashMap<K, V> copy = new HashMap<K, V>(map);
+ final Map<K, V> copy = copy(map);
map.put(key, value);
this.map = copy;
}
@@ -181,7 +188,7 @@
if (map.size() == 1) {
this.map = emptyMap();
} else {
- final HashMap<K, V> copy = new HashMap<K, V>(map);
+ final Map<K, V> copy = copy(map);
map.remove(key);
this.map = copy;
}
@@ -190,6 +197,10 @@
}
}
+ private Map<K, V> copy(final Map<K, V> map) {
+ return identity ? new IdentityHashMap<K,V>(map) : new HashMap<K, V>(map);
+ }
+
public void putAll(final Map<? extends K, ? extends V> m) {
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-23 21:19:18 UTC (rev 5568)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-23 22:24:45 UTC (rev 5569)
@@ -83,6 +83,10 @@
return new CopyOnWriteHashMap<K, V>(lock);
}
+ static <K, V> ConcurrentMap<K, V> concurrentIdentityMap(Object lock) {
+ return new CopyOnWriteHashMap<K, V>(true, lock);
+ }
+
static <T> Set<T> concurrentSet(Object lock) {
return Collections.<T>newSetFromMap(EndpointImpl.<T, Boolean>concurrentMap(lock));
}
@@ -113,7 +117,7 @@
*/
private final Object serviceRegistrationLock = new Object();
- private final Set<ListenerRegistration<ServiceRegistrationListener>> serviceListenerRegistrations = Collections.newSetFromMap(EndpointImpl.<ListenerRegistration<ServiceRegistrationListener>, Boolean>concurrentMap(serviceRegistrationLock));
+ private final ConcurrentMap<Registration, ServiceRegistrationListener> serviceListenerRegistrations = concurrentIdentityMap(serviceRegistrationLock);
private final ConcurrentMap<String, ConcurrentMap<String, ServiceRegistration>> registeredLocalServices = concurrentMap(serviceRegistrationLock);
private final ConcurrentMap<String, ConnectionProvider<?>> connectionProviders = concurrentMap();
@@ -244,7 +248,7 @@
}
};
registration.setHandle(handle);
- final Iterator<ListenerRegistration<ServiceRegistrationListener>> serviceListenerRegistrations;
+ final Iterator<Map.Entry<Registration,ServiceRegistrationListener>> serviceListenerRegistrations;
final Object lock = serviceRegistrationLock;
synchronized (lock) {
// actually register the service, and while we have the lock, snag a copy of the registration listener list
@@ -260,7 +264,7 @@
}
submap.put(canonGroupName, registration);
// snapshot
- serviceListenerRegistrations = this.serviceListenerRegistrations.iterator();
+ serviceListenerRegistrations = this.serviceListenerRegistrations.entrySet().iterator();
}
// notify all service listener registrations that were registered at the time the service was created
final ServiceRegistrationListener.ServiceInfo serviceInfo = new ServiceRegistrationListener.ServiceInfo();
@@ -271,12 +275,11 @@
serviceInfo.setRequestHandlerConnector(requestHandlerConnector);
executor.execute(new Runnable() {
public void run() {
- final Iterator<ListenerRegistration<ServiceRegistrationListener>> iter = serviceListenerRegistrations;
+ final Iterator<Map.Entry<Registration,ServiceRegistrationListener>> iter = serviceListenerRegistrations;
while (iter.hasNext()) {
- final ListenerRegistration<ServiceRegistrationListener> slr = iter.next();
- final ServiceRegistrationListener registrationListener = slr.getResource();
+ final Map.Entry<Registration,ServiceRegistrationListener> slr = iter.next();
try {
- registrationListener.serviceRegistered(slr, serviceInfo.clone());
+ slr.getValue().serviceRegistered(slr.getKey(), serviceInfo.clone());
} catch (Throwable t) {
logListenerError(t);
}
@@ -329,9 +332,13 @@
sm.checkPermission(ADD_SERVICE_LISTENER_PERM);
}
final List<ServiceRegistration> services;
- final ListenerRegistration<ServiceRegistrationListener> registration = new ListenerRegistration<ServiceRegistrationListener>(listener);
+ final Registration registration = new Registration() {
+ public void close() {
+ serviceListenerRegistrations.remove(this);
+ }
+ };
synchronized (serviceRegistrationLock) {
- serviceListenerRegistrations.add(registration);
+ serviceListenerRegistrations.put(registration, listener);
if (flags == null || ! flags.contains(ListenerFlag.INCLUDE_OLD)) {
// need to make a copy of the whole list
services = new ArrayList<ServiceRegistration>();
@@ -575,24 +582,6 @@
}
}
- private final class ListenerRegistration<T> implements Registration {
- private final T resource;
-
- private ListenerRegistration(final T resource) {
- this.resource = resource;
- }
-
- public void close() {
- synchronized (serviceRegistrationLock) {
- serviceListenerRegistrations.remove(this);
- }
- }
-
- T getResource() {
- return resource;
- }
- }
-
private final ConnectionContext localConnectionContext = new LocalConnectionContext();
private final ConnectionHandler loopbackConnectionHandler = new LoopbackConnectionHandler();
private final Connection loopbackConnection = new LoopbackConnection();
@@ -604,7 +593,7 @@
}
}
- final class LocalConnectionProvider implements ConnectionProvider<Void> {
+ private final class LocalConnectionProvider implements ConnectionProvider<Void> {
public Cancellable connect(final URI uri, final OptionMap connectOptions, final Result<ConnectionHandlerFactory> result) throws IllegalArgumentException {
result.setResult(new ConnectionHandlerFactory() {
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-10-23 21:19:18 UTC (rev 5568)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-10-23 22:24:45 UTC (rev 5569)
@@ -88,4 +88,19 @@
* Specify that the registered service should or should not be visible remotely. If not specified, defaults to {@code true}.
*/
public static final Option<Boolean> REMOTELY_VISIBLE = Option.simple(Options.class, "REMOTELY_VISIBLE", Boolean.class);
+
+ /**
+ * Specify the buffer size for any configured marshaller or unmarshaller.
+ */
+ public static final Option<Integer> BUFFER_SIZE = Option.simple(Options.class, "BUFFER_SIZE", Integer.class);
+
+ /**
+ * Specify the expected class count for any configured marshaller or unmarshaller.
+ */
+ public static final Option<Integer> CLASS_COUNT = Option.simple(Options.class, "CLASS_COUNT", Integer.class);
+
+ /**
+ * Specify the expected instance count for any configured marshaller or unmarshaller.
+ */
+ public static final Option<Integer> INSTANCE_COUNT = Option.simple(Options.class, "INSTANCE_COUNT", Integer.class);
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocol.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocol.java 2009-10-23 21:19:18 UTC (rev 5568)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocol.java 2009-10-23 22:24:45 UTC (rev 5569)
@@ -30,6 +30,7 @@
import org.jboss.marshalling.ClassResolver;
import org.jboss.marshalling.ObjectResolver;
import org.jboss.xnio.Pool;
+import org.jboss.xnio.OptionMap;
/**
* A registered marshalling protocol.
@@ -95,5 +96,12 @@
* @return the user object resolver
*/
ObjectResolver getUserObjectResolver();
+
+ /**
+ * Get the options to use for this marshaller configuration.
+ *
+ * @return the options
+ */
+ OptionMap getOptionMap();
}
}
15 years, 1 month
JBoss Remoting SVN: r5568 - in remoting3/trunk: samples/src/main/java/org/jboss/remoting3/samples/protocol/basic and 2 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-23 17:19:18 -0400 (Fri, 23 Oct 2009)
New Revision: 5568
Added:
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExample2Main.java
Removed:
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicConfiguration.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicHandlerReplyConsumer.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicProtocol.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicRequestHandler.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicServerReplyTransmitter.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicServerRequestConsumer.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/FutureBasicReply.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexClientExample.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexServerExample.java
remoting3/trunk/samples/src/test/java/org/jboss/remoting3/samples/protocol/basic/BasicTestCase.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistration.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java
Log:
Fix wildcard lookups of group name; make the samples work or nuke them; add a local-connect sample
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -34,9 +34,17 @@
import java.util.concurrent.ConcurrentMap;
final class CopyOnWriteHashMap<K, V> implements ConcurrentMap<K, V> {
- private final Object writeLock = new Object();
+ private final Object writeLock;
private volatile Map<K, V> map = emptyMap();
+ CopyOnWriteHashMap() {
+ this(new Object());
+ }
+
+ CopyOnWriteHashMap(final Object writeLock) {
+ this.writeLock = writeLock;
+ }
+
public V putIfAbsent(final K key, final V value) {
if (key == null) {
throw new NullPointerException("key is null");
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -55,7 +55,7 @@
* @param configuration the configuration to use
* @throws IOException if an error occurs
*/
- <I, O> SimpleCloseable registerService(LocalServiceConfiguration<I, O> configuration) throws IOException;
+ <I, O> Registration registerService(LocalServiceConfiguration<I, O> configuration) throws IOException;
/**
* Add a service registration listener which is called whenever a local service is registered.
@@ -66,7 +66,7 @@
* @param flags the flags to apply to the listener
* @return a handle which may be used to remove the listener registration
*/
- SimpleCloseable addServiceRegistrationListener(ServiceRegistrationListener listener, Set<ListenerFlag> flags);
+ Registration addServiceRegistrationListener(ServiceRegistrationListener listener, Set<ListenerFlag> flags);
/**
* Create a client that uses the given request handler to handle its requests.
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -25,7 +25,6 @@
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -33,14 +32,12 @@
import java.util.Map;
import java.util.Queue;
import java.util.Set;
+import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
import org.jboss.remoting3.spi.AbstractHandleableCloseable;
-import org.jboss.remoting3.spi.AbstractSimpleCloseable;
import org.jboss.remoting3.spi.ConnectionHandler;
import org.jboss.remoting3.spi.ConnectionHandlerFactory;
import org.jboss.remoting3.spi.ConnectionProvider;
@@ -82,6 +79,14 @@
return new CopyOnWriteHashMap<K, V>();
}
+ static <K, V> ConcurrentMap<K, V> concurrentMap(Object lock) {
+ return new CopyOnWriteHashMap<K, V>(lock);
+ }
+
+ static <T> Set<T> concurrentSet(Object lock) {
+ return Collections.<T>newSetFromMap(EndpointImpl.<T, Boolean>concurrentMap(lock));
+ }
+
static <K, V> Map<K, V> hashMap() {
return new HashMap<K, V>();
}
@@ -106,10 +111,10 @@
* Snapshot lock. Hold this lock while reading or updating {@link #serviceListenerRegistrations} or while updating
* {@link #registeredLocalServices}. Allows atomic snapshot of existing service registrations and listener add.
*/
- private final Lock serviceRegistrationLock = new ReentrantLock();
+ private final Object serviceRegistrationLock = new Object();
- private final Set<ListenerRegistration<ServiceRegistrationListener>> serviceListenerRegistrations = hashSet();
- private final Map<String, ServiceRegistration> registeredLocalServices = hashMap();
+ private final Set<ListenerRegistration<ServiceRegistrationListener>> serviceListenerRegistrations = Collections.newSetFromMap(EndpointImpl.<ListenerRegistration<ServiceRegistrationListener>, Boolean>concurrentMap(serviceRegistrationLock));
+ private final ConcurrentMap<String, ConcurrentMap<String, ServiceRegistration>> registeredLocalServices = concurrentMap(serviceRegistrationLock);
private final ConcurrentMap<String, ConnectionProvider<?>> connectionProviders = concurrentMap();
private final ConcurrentMap<String, MarshallingProtocol> marshallingProtocols = concurrentMap();
@@ -183,7 +188,7 @@
return localRequestHandler;
}
- public <I, O> SimpleCloseable registerService(final LocalServiceConfiguration<I, O> configuration) throws IOException {
+ public <I, O> Registration registerService(final LocalServiceConfiguration<I, O> configuration) throws IOException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(REGISTER_SERVICE_PERM);
@@ -201,12 +206,13 @@
ServiceURI.validateServiceType(serviceType);
ServiceURI.validateGroupName(groupName);
checkOpen();
- final String serviceKey = serviceType.toLowerCase() + ":" + groupName.toLowerCase();
+ final String canonServiceType = serviceType.toLowerCase();
+ final String canonGroupName = groupName.toLowerCase();
final Class<I> requestClass = configuration.getRequestClass();
final Class<O> replyClass = configuration.getReplyClass();
final ClientListener<I, O> clientListener = configuration.getClientListener();
final Executor executor = this.executor;
- final Map<String, ServiceRegistration> registeredLocalServices = this.registeredLocalServices;
+ final ConcurrentMap<String, ConcurrentMap<String, ServiceRegistration>> registeredLocalServices = this.registeredLocalServices;
final RequestHandlerConnector requestHandlerConnector = new RequestHandlerConnector() {
public Cancellable createRequestHandler(final Result<RequestHandler> result) throws SecurityException {
try {
@@ -227,54 +233,47 @@
};
final ServiceRegistration registration = new ServiceRegistration(serviceType, groupName, name, optionMap, requestHandlerConnector);
// this handle is used to remove the service registration
- final AbstractSimpleCloseable newHandle = new AbstractSimpleCloseable(executor) {
- protected void closeAction() throws IOException {
- final Lock lock = serviceRegistrationLock;
- lock.lock();
- try {
- registeredLocalServices.remove(serviceKey);
- } finally {
- lock.unlock();
+ final Registration handle = new Registration() {
+ public void close() {
+ synchronized (serviceRegistrationLock) {
+ final ConcurrentMap<String, ServiceRegistration> submap = registeredLocalServices.get(serviceType);
+ if (submap != null) {
+ submap.remove(groupName, registration);
+ }
}
}
};
- registration.setHandle(newHandle);
- final List<ListenerRegistration<ServiceRegistrationListener>> serviceListenerRegistrations;
- final Lock lock = serviceRegistrationLock;
- // actually register the service, and while we have the lock, snag a copy of the registration listener list
- lock.lock();
- try {
- if (registeredLocalServices.containsKey(serviceKey)) {
- throw new ServiceRegistrationException("ListenerRegistration of service of type \"" + serviceType + "\" in group \"" + groupName + "\" duplicates an already-registered service's specification");
+ registration.setHandle(handle);
+ final Iterator<ListenerRegistration<ServiceRegistrationListener>> serviceListenerRegistrations;
+ final Object lock = serviceRegistrationLock;
+ synchronized (lock) {
+ // actually register the service, and while we have the lock, snag a copy of the registration listener list
+ final ConcurrentMap<String, ServiceRegistration> submap;
+ if (registeredLocalServices.containsKey(canonServiceType)) {
+ submap = registeredLocalServices.get(canonServiceType);
+ if (submap.containsKey(canonGroupName)) {
+ throw new ServiceRegistrationException("ListenerRegistration of service of type \"" + serviceType + "\" in group \"" + groupName + "\" duplicates an already-registered service's specification");
+ }
+ } else {
+ submap = concurrentMap(lock);
+ registeredLocalServices.put(canonServiceType, submap);
}
- registeredLocalServices.put(serviceKey, registration);
- serviceListenerRegistrations = new ArrayList<ListenerRegistration<ServiceRegistrationListener>>(this.serviceListenerRegistrations);
- } finally {
- lock.unlock();
+ submap.put(canonGroupName, registration);
+ // snapshot
+ serviceListenerRegistrations = this.serviceListenerRegistrations.iterator();
}
- // this registration closes the service registration when the endpoint is closed
- final WeakCloseable lrhCloseable = new WeakCloseable(newHandle);
- final Key key = addCloseHandler(new CloseHandler<Object>() {
- public void handleClose(final Object closed) {
- IoUtils.safeClose(lrhCloseable);
- }
- });
- // this registration removes the prior registration if the service registration is closed
- newHandle.addCloseHandler(new CloseHandler<Object>() {
- public void handleClose(final Object closed) {
- key.remove();
- }
- });
// notify all service listener registrations that were registered at the time the service was created
final ServiceRegistrationListener.ServiceInfo serviceInfo = new ServiceRegistrationListener.ServiceInfo();
serviceInfo.setGroupName(groupName);
serviceInfo.setServiceType(serviceType);
serviceInfo.setOptionMap(optionMap);
- serviceInfo.setRegistrationHandle(newHandle);
+ serviceInfo.setRegistrationHandle(handle);
serviceInfo.setRequestHandlerConnector(requestHandlerConnector);
executor.execute(new Runnable() {
public void run() {
- for (final ListenerRegistration<ServiceRegistrationListener> slr : serviceListenerRegistrations) {
+ final Iterator<ListenerRegistration<ServiceRegistrationListener>> iter = serviceListenerRegistrations;
+ while (iter.hasNext()) {
+ final ListenerRegistration<ServiceRegistrationListener> slr = iter.next();
final ServiceRegistrationListener registrationListener = slr.getResource();
try {
registrationListener.serviceRegistered(slr, serviceInfo.clone());
@@ -284,7 +283,7 @@
}
}
});
- return newHandle;
+ return handle;
}
private static void logListenerError(final Throwable t) {
@@ -324,36 +323,45 @@
return client;
}
- public SimpleCloseable addServiceRegistrationListener(final ServiceRegistrationListener listener, final Set<ListenerFlag> flags) {
+ public Registration addServiceRegistrationListener(final ServiceRegistrationListener listener, final Set<ListenerFlag> flags) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(ADD_SERVICE_LISTENER_PERM);
}
+ final List<ServiceRegistration> services;
final ListenerRegistration<ServiceRegistrationListener> registration = new ListenerRegistration<ServiceRegistrationListener>(listener);
- final Lock lock = serviceRegistrationLock;
- final Collection<ServiceRegistration> services;
- lock.lock();
- try {
+ synchronized (serviceRegistrationLock) {
+ serviceListenerRegistrations.add(registration);
if (flags == null || ! flags.contains(ListenerFlag.INCLUDE_OLD)) {
- services = new ArrayList<ServiceRegistration>(registeredLocalServices.values());
+ // need to make a copy of the whole list
+ services = new ArrayList<ServiceRegistration>();
+ for (Map.Entry<String, ConcurrentMap<String, ServiceRegistration>> entry : registeredLocalServices.entrySet()) {
+ for (Map.Entry<String, ServiceRegistration> subEntry : entry.getValue().entrySet()) {
+ services.add(subEntry.getValue());
+ }
+ }
} else {
- services = Collections.emptySet();
+ services = null;
}
- } finally {
- lock.unlock();
}
- serviceListenerRegistrations.add(registration);
- for (ServiceRegistration service : services) {
- final ServiceRegistrationListener.ServiceInfo serviceInfo = new ServiceRegistrationListener.ServiceInfo();
- serviceInfo.setGroupName(service.getGroupName());
- serviceInfo.setOptionMap(service.getOptionMap());
- serviceInfo.setRegistrationHandle(service.getHandle());
- serviceInfo.setRequestHandlerConnector(service.getRequestHandlerConnector());
- serviceInfo.setServiceType(service.getServiceType());
- listener.serviceRegistered(registration, serviceInfo);
- if (! registration.isOpen()) {
- break;
- }
+ if (services != null) {
+ executor.execute(new Runnable() {
+ public void run() {
+ for (ServiceRegistration service : services) {
+ final ServiceRegistrationListener.ServiceInfo serviceInfo = new ServiceRegistrationListener.ServiceInfo();
+ serviceInfo.setGroupName(service.getGroupName());
+ serviceInfo.setOptionMap(service.getOptionMap());
+ serviceInfo.setRegistrationHandle(service.getHandle());
+ serviceInfo.setRequestHandlerConnector(service.getRequestHandlerConnector());
+ serviceInfo.setServiceType(service.getServiceType());
+ try {
+ listener.serviceRegistered(registration, serviceInfo);
+ } catch (Throwable t) {
+ logListenerError(t);
+ }
+ }
+ }
+ });
}
return registration;
}
@@ -491,26 +499,43 @@
private final class LocalConnectionContext implements ConnectionContext {
public void openService(final String serviceType, final String groupName, final OptionMap optionMap, final ServiceResult serviceResult) {
- final ServiceRegistration registration = registeredLocalServices.get(serviceType + ":" + groupName);
- if (registration != null) {
- registration.getRequestHandlerConnector().createRequestHandler(new Result<RequestHandler>() {
- public void setResult(final RequestHandler result) {
- serviceResult.opened(result, registration.getOptionMap());
- }
+ final String canonServiceType = serviceType.toLowerCase();
+ final String canonGroupName = groupName.toLowerCase();
+ final ConcurrentMap<String, ServiceRegistration> submap = registeredLocalServices.get(canonServiceType);
+ if (submap == null) {
+ serviceResult.notFound();
+ return;
+ }
+ final ServiceRegistration registration;
+ if (canonGroupName.equals("*")) {
+ final Iterator<Map.Entry<String, ServiceRegistration>> iter = submap.entrySet().iterator();
+ if (! iter.hasNext()) {
+ serviceResult.notFound();
+ return;
+ }
+ registration = iter.next().getValue();
+ } else {
+ registration = submap.get(canonGroupName);
+ if (registration == null) {
+ serviceResult.notFound();
+ return;
+ }
+ }
+ registration.getRequestHandlerConnector().createRequestHandler(new Result<RequestHandler>() {
+ public void setResult(final RequestHandler result) {
+ serviceResult.opened(result, registration.getOptionMap());
+ }
- public void setException(final IOException exception) {
- log.warn(exception, "Unexpected exception on service lookup");
- serviceResult.notFound();
- }
+ public void setException(final IOException exception) {
+ log.warn(exception, "Unexpected exception on service lookup");
+ serviceResult.notFound();
+ }
- public void setCancelled() {
- log.warn("Unexpected cancellation on service lookup");
- serviceResult.notFound();
- }
- });
- } else {
- serviceResult.notFound();
- }
+ public void setCancelled() {
+ log.warn("Unexpected cancellation on service lookup");
+ serviceResult.notFound();
+ }
+ });
}
}
@@ -550,28 +575,19 @@
}
}
- private final class ListenerRegistration<T> extends AbstractSimpleCloseable {
+ private final class ListenerRegistration<T> implements Registration {
private final T resource;
private ListenerRegistration(final T resource) {
- super(executor);
this.resource = resource;
}
- protected void closeAction() throws IOException {
- final Lock lock = serviceRegistrationLock;
- lock.lock();
- try {
+ public void close() {
+ synchronized (serviceRegistrationLock) {
serviceListenerRegistrations.remove(this);
- } finally {
- lock.unlock();
}
}
- protected boolean isOpen() {
- return super.isOpen();
- }
-
T getResource() {
return resource;
}
@@ -675,15 +691,16 @@
private class LoopbackConnectionHandler implements ConnectionHandler {
- public Cancellable open(final String serviceName, final String groupName, final Result<RequestHandler> result) {
- // the loopback connection opens a local service
- // local services are registered as RequestHandlerConnectors
- final ServiceRegistration registration = registeredLocalServices.get(serviceName + ":" + groupName);
- if (registration != null) {
- registration.getRequestHandlerConnector().createRequestHandler(result);
- } else {
- result.setException(new ServiceNotFoundException(ServiceURI.create(serviceName, groupName, name), "No such service located"));
- }
+ public Cancellable open(final String serviceType, final String groupName, final Result<RequestHandler> result) {
+ localConnectionContext.openService(serviceType, groupName, OptionMap.EMPTY, new ConnectionContext.ServiceResult() {
+ public void opened(final RequestHandler requestHandler, final OptionMap optionMap) {
+ result.setResult(requestHandler);
+ }
+
+ public void notFound() {
+ result.setException(new ServiceNotFoundException(ServiceURI.create(serviceType, groupName, name), "No such service located"));
+ }
+ });
return NULL_CANCELLABLE;
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistration.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistration.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistration.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -36,7 +36,7 @@
private final String endpointName;
private final OptionMap optionMap;
private final RequestHandlerConnector requestHandlerConnector;
- private volatile SimpleCloseable handle;
+ private volatile Registration handle;
ServiceRegistration(final String serviceType, final String groupName, final String endpointName, final OptionMap optionMap, final RequestHandlerConnector requestHandlerConnector) {
this.requestHandlerConnector = requestHandlerConnector;
@@ -86,11 +86,11 @@
return requestHandlerConnector;
}
- public SimpleCloseable getHandle() {
+ public Registration getHandle() {
return handle;
}
- void setHandle(final SimpleCloseable handle) {
+ void setHandle(final Registration handle) {
this.handle = handle;
}
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -23,7 +23,6 @@
package org.jboss.remoting3;
import org.jboss.remoting3.spi.RequestHandlerConnector;
-import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.xnio.OptionMap;
/**
@@ -40,7 +39,7 @@
* @param listenerHandle the handle to this listener
* @param info the servce information
*/
- void serviceRegistered(SimpleCloseable listenerHandle, ServiceInfo info);
+ void serviceRegistered(Registration listenerHandle, ServiceInfo info);
/**
* Information about a registered service.
@@ -51,7 +50,7 @@
private String serviceType;
private String groupName;
private RequestHandlerConnector requestHandlerConnector;
- private SimpleCloseable registrationHandle;
+ private Registration registrationHandle;
private OptionMap optionMap;
/**
@@ -137,7 +136,7 @@
*
* @return the registration handle
*/
- public SimpleCloseable getRegistrationHandle() {
+ public Registration getRegistrationHandle() {
return registrationHandle;
}
@@ -146,7 +145,7 @@
*
* @param registrationHandle the registration handle
*/
- public void setRegistrationHandle(final SimpleCloseable registrationHandle) {
+ public void setRegistrationHandle(final Registration registrationHandle) {
this.registrationHandle = registrationHandle;
}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicConfiguration.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicConfiguration.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicConfiguration.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,80 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.protocol.basic;
-
-import org.jboss.marshalling.MarshallerFactory;
-import org.jboss.marshalling.MarshallingConfiguration;
-import org.jboss.xnio.BufferAllocator;
-import java.util.concurrent.Executor;
-import java.nio.ByteBuffer;
-
-/**
- *
- */
-public final class BasicConfiguration {
- private MarshallerFactory marshallerFactory;
- private MarshallingConfiguration marshallingConfiguration;
- private int linkMetric;
- private Executor executor;
- private BufferAllocator<ByteBuffer> allocator;
-
- public MarshallerFactory getMarshallerFactory() {
- return marshallerFactory;
- }
-
- public void setMarshallerFactory(final MarshallerFactory marshallerFactory) {
- this.marshallerFactory = marshallerFactory;
- }
-
- public MarshallingConfiguration getMarshallingConfiguration() {
- return marshallingConfiguration;
- }
-
- public void setMarshallingConfiguration(final MarshallingConfiguration marshallingConfiguration) {
- this.marshallingConfiguration = marshallingConfiguration;
- }
-
- public int getLinkMetric() {
- return linkMetric;
- }
-
- public void setLinkMetric(final int linkMetric) {
- this.linkMetric = linkMetric;
- }
-
- public Executor getExecutor() {
- return executor;
- }
-
- public void setExecutor(final Executor executor) {
- this.executor = executor;
- }
-
- public BufferAllocator<ByteBuffer> getAllocator() {
- return allocator;
- }
-
- public void setAllocator(final BufferAllocator<ByteBuffer> allocator) {
- this.allocator = allocator;
- }
-}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicHandlerReplyConsumer.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicHandlerReplyConsumer.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicHandlerReplyConsumer.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,144 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.protocol.basic;
-
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.Lock;
-import java.util.Queue;
-import java.io.IOException;
-import org.jboss.marshalling.Unmarshaller;
-import org.jboss.xnio.channels.StreamChannel;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.log.Logger;
-import org.jboss.remoting3.spi.ReplyHandler;
-import org.jboss.remoting3.spi.SpiUtils;
-import org.jboss.remoting3.RemoteExecutionException;
-import org.jboss.remoting3.ReplyException;
-import org.jboss.remoting3.IndeterminateOutcomeException;
-
-/**
- *
- */
-final class BasicHandlerReplyConsumer implements Runnable {
-
- private static final Logger log = Logger.getLogger(BasicHandlerReplyConsumer.class);
-
- private final AtomicInteger replySequence;
- private final Unmarshaller unmarshaller;
- private final StreamChannel streamChannel;
- private final Lock reqLock;
- private final Queue<ReplyHandler> replyQueue;
-
- public BasicHandlerReplyConsumer(final Unmarshaller unmarshaller, final StreamChannel streamChannel, final Lock reqLock, final Queue<ReplyHandler> replyQueue) {
- this.unmarshaller = unmarshaller;
- this.streamChannel = streamChannel;
- this.reqLock = reqLock;
- this.replyQueue = replyQueue;
- replySequence = new AtomicInteger();
- }
-
- public void run() {
- try {
- for (;;) {
- final int type = unmarshaller.read();
- switch (type) {
- case -1: {
- // done.
- return;
- }
- case 1: {
- // reply - success
- reqLock.lock();
- try {
- replySequence.getAndIncrement();
- final ReplyHandler replyHandler = replyQueue.remove();
- final Object reply;
- try {
- reply = unmarshaller.readObject();
- } catch (Exception e) {
- SpiUtils.safeHandleException(replyHandler, new ReplyException("Failed to read reply from server", e));
- return;
- }
- SpiUtils.safeHandleReply(replyHandler, reply);
- break;
- } finally {
- reqLock.unlock();
- }
- }
- case 2: {
- // reply - cancelled
- reqLock.lock();
- try {
- final int id = unmarshaller.readInt();
- if (id != replySequence.getAndIncrement()) {
- replySequence.decrementAndGet();
- break;
- }
- final ReplyHandler replyHandler = replyQueue.remove();
- SpiUtils.safeHandleCancellation(replyHandler);
- break;
- } finally {
- reqLock.unlock();
- }
- }
- case 3: {
- // reply - exception
- reqLock.lock();
- try {
- replySequence.getAndIncrement();
- final ReplyHandler replyHandler = replyQueue.remove();
- final Throwable e;
- try {
- e = (Throwable) unmarshaller.readObject();
- } catch (Exception e2) {
- SpiUtils.safeHandleException(replyHandler, new RemoteExecutionException("Failed to read exception from server", e2));
- return;
- }
- SpiUtils.safeHandleException(replyHandler, new RemoteExecutionException("Remote execution failed", e));
- break;
- } finally {
- reqLock.unlock();
- }
- }
- default: {
- // invalid byte
- throw new IOException("Read an invalid byte from the server");
- }
- }
- }
- } catch (Exception e) {
- log.error(e, "Error receiving reply");
- } finally {
- IoUtils.safeClose(streamChannel);
- reqLock.lock();
- try {
- while (replyQueue.size() > 0) {
- ReplyHandler replyHandler = replyQueue.remove();
- SpiUtils.safeHandleException(replyHandler, new IndeterminateOutcomeException("Connection terminated; operation outcome unknown"));
- }
- } finally {
- reqLock.unlock();
- }
- }
- }
-}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicProtocol.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicProtocol.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicProtocol.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,82 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.protocol.basic;
-
-import org.jboss.remoting3.spi.RequestHandler;
-import org.jboss.remoting3.spi.ReplyHandler;
-import org.jboss.xnio.channels.StreamChannel;
-import org.jboss.xnio.channels.ChannelOutputStream;
-import org.jboss.xnio.channels.ChannelInputStream;
-import org.jboss.marshalling.MarshallingConfiguration;
-import org.jboss.marshalling.MarshallerFactory;
-import org.jboss.marshalling.Unmarshaller;
-import org.jboss.marshalling.Marshaller;
-import org.jboss.marshalling.Marshalling;
-import java.io.IOException;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-import java.util.concurrent.Executor;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.Queue;
-import java.util.LinkedList;
-
-/**
- * A very basic example protocol.
- */
-public final class BasicProtocol {
-
- private BasicProtocol() {
- }
-
- public static final void createServer(final Handle<RequestHandler> requestHandlerHandle, final StreamChannel streamChannel, final BasicConfiguration configuration) throws IOException {
- final RequestHandler requestHandler = requestHandlerHandle.getResource();
- final MarshallingConfiguration marshallerConfiguration = configuration.getMarshallingConfiguration();
- final MarshallerFactory marshallerFactory = configuration.getMarshallerFactory();
- final Marshaller marshaller = marshallerFactory.createMarshaller(marshallerConfiguration);
- final Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(marshallerConfiguration);
- final Executor executor = configuration.getExecutor();
- marshaller.start(Marshalling.createByteOutput(new ChannelOutputStream(streamChannel)));
- unmarshaller.start(Marshalling.createByteInput(new ChannelInputStream(streamChannel)));
- final BlockingQueue<FutureBasicReply> replyQueue = new LinkedBlockingQueue<FutureBasicReply>();
- // todo - handle rejected execution...
- executor.execute(new BasicServerReplyTransmitter(replyQueue, marshaller, streamChannel, requestHandlerHandle));
- // todo - handle rejected execution...
- executor.execute(new BasicServerRequestConsumer(unmarshaller, requestHandler, replyQueue, streamChannel, requestHandlerHandle));
- }
-
- public static final Handle<RequestHandler> createClient(final StreamChannel streamChannel, final BasicConfiguration configuration) throws IOException {
- final MarshallingConfiguration marshallerConfiguration = configuration.getMarshallingConfiguration();
- final MarshallerFactory marshallerFactory = configuration.getMarshallerFactory();
- final Marshaller marshaller = marshallerFactory.createMarshaller(marshallerConfiguration);
- final Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(marshallerConfiguration);
- final Executor executor = configuration.getExecutor();
- marshaller.start(Marshalling.createByteOutput(new ChannelOutputStream(streamChannel)));
- unmarshaller.start(Marshalling.createByteInput(new ChannelInputStream(streamChannel)));
- final Lock reqLock = new ReentrantLock();
- final Queue<ReplyHandler> replyQueue = new LinkedList<ReplyHandler>();
- // todo - handle rejected execution...
- executor.execute(new BasicHandlerReplyConsumer(unmarshaller, streamChannel, reqLock, replyQueue));
- return new BasicRequestHandler(reqLock, marshaller, replyQueue, streamChannel, executor).getHandle();
- }
-}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicRequestHandler.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicRequestHandler.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicRequestHandler.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,101 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.protocol.basic;
-
-import org.jboss.remoting3.spi.RequestHandler;
-import org.jboss.remoting3.spi.ReplyHandler;
-import org.jboss.remoting3.spi.RemoteRequestContext;
-import org.jboss.remoting3.spi.SpiUtils;
-import org.jboss.marshalling.Marshaller;
-import org.jboss.xnio.channels.StreamChannel;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.log.Logger;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.Executor;
-import java.util.Queue;
-import java.io.IOException;
-
-/**
- *
- */
-final class BasicRequestHandler extends AbstractAutoCloseable<RequestHandler> implements RequestHandler {
-
- private static final Logger log = Logger.getLogger("org.jboss.remoting.basic");
-
- private final AtomicInteger requestSequence;
- private final Lock reqLock;
- private final Marshaller marshaller;
- private final Queue<ReplyHandler> replyQueue;
- private final StreamChannel streamChannel;
-
- public BasicRequestHandler(final Lock reqLock, final Marshaller marshaller, final Queue<ReplyHandler> replyQueue, final StreamChannel streamChannel, final Executor executor) {
- super(executor);
- this.reqLock = reqLock;
- this.marshaller = marshaller;
- this.replyQueue = replyQueue;
- this.streamChannel = streamChannel;
- requestSequence = new AtomicInteger();
- }
-
- public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler replyHandler) {
- reqLock.lock();
- try {
- marshaller.write(2);
- marshaller.writeObject(request);
- marshaller.flush();
- final int id = requestSequence.getAndIncrement();
- replyQueue.add(replyHandler);
- return new RemoteRequestContext() {
- public RemoteRequestContext cancel() {
- reqLock.lock();
- try {
- marshaller.write(3);
- marshaller.writeInt(id);
- marshaller.flush();
- } catch (IOException e) {
- log.error(e, "Error writing cancel request");
- IoUtils.safeClose(BasicRequestHandler.this);
- } finally {
- reqLock.unlock();
- }
- return this;
- }
- };
- } catch (IOException e) {
- SpiUtils.safeHandleException(replyHandler, e);
- IoUtils.safeClose(this);
- return SpiUtils.getBlankRemoteRequestContext();
- } finally {
- reqLock.unlock();
- }
- }
-
- protected void closeAction() throws IOException {
- streamChannel.close();
- }
-
- public String toString() {
- return "basic protocol handler <" + Integer.toHexString(hashCode()) + ">";
- }
-}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicServerReplyTransmitter.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicServerReplyTransmitter.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicServerReplyTransmitter.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,90 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.protocol.basic;
-
-import java.util.concurrent.BlockingQueue;
-import org.jboss.marshalling.Marshaller;
-import org.jboss.xnio.channels.StreamChannel;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.log.Logger;
-import org.jboss.remoting3.spi.RequestHandler;
-
-/**
- *
- */
-final class BasicServerReplyTransmitter implements Runnable {
-
- private static final Logger log = Logger.getLogger(BasicServerReplyTransmitter.class);
-
- private final BlockingQueue<FutureBasicReply> replyQueue;
- private final Marshaller marshaller;
- private final StreamChannel streamChannel;
- private final Handle<RequestHandler> requestHandlerHandle;
-
- public BasicServerReplyTransmitter(final BlockingQueue<FutureBasicReply> replyQueue, final Marshaller marshaller, final StreamChannel streamChannel, final Handle<RequestHandler> requestHandlerHandle) {
- this.replyQueue = replyQueue;
- this.marshaller = marshaller;
- this.streamChannel = streamChannel;
- this.requestHandlerHandle = requestHandlerHandle;
- }
-
- public void run() {
- try {
- for (;;) {
- final FutureBasicReply futureBasicReply = replyQueue.take();
- OUT: for (;;) switch (futureBasicReply.awaitInterruptibly()) {
- case DONE: {
- marshaller.write(1);
- marshaller.writeObject(futureBasicReply.get());
- marshaller.flush();
- break OUT;
- }
- case CANCELLED: {
- marshaller.write(2);
- marshaller.writeInt(futureBasicReply.id);
- marshaller.flush();
- break OUT;
- }
- case FAILED: {
- marshaller.write(3);
- marshaller.writeObject(futureBasicReply.getException());
- marshaller.flush();
- break OUT;
- }
- case WAITING: {
- // spurious wakeup, try again
- continue;
- }
- }
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- log.trace(e, "Interrupted");
- } catch (Exception e) {
- log.error(e, "Error in reply transmitter");
- } finally {
- IoUtils.safeClose(streamChannel);
- IoUtils.safeClose(requestHandlerHandle);
- }
- }
-}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicServerRequestConsumer.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicServerRequestConsumer.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/BasicServerRequestConsumer.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,117 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.protocol.basic;
-
-import org.jboss.marshalling.Unmarshaller;
-import org.jboss.remoting3.spi.RequestHandler;
-import org.jboss.remoting3.spi.RemoteRequestContext;
-import org.jboss.remoting3.spi.ReplyHandler;
-import org.jboss.xnio.channels.StreamChannel;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.log.Logger;
-import java.util.concurrent.BlockingQueue;
-import java.io.IOException;
-
-/**
- *
- */
-final class BasicServerRequestConsumer implements Runnable {
-
- private static final Logger log = Logger.getLogger(BasicServerRequestConsumer.class);
-
- private final Unmarshaller unmarshaller;
- private final RequestHandler requestHandler;
- private final BlockingQueue<FutureBasicReply> replyQueue;
- private final StreamChannel streamChannel;
- private final Handle<RequestHandler> requestHandlerHandle;
-
- public BasicServerRequestConsumer(final Unmarshaller unmarshaller, final RequestHandler requestHandler, final BlockingQueue<FutureBasicReply> replyQueue, final StreamChannel streamChannel, final Handle<RequestHandler> requestHandlerHandle) {
- this.unmarshaller = unmarshaller;
- this.requestHandler = requestHandler;
- this.replyQueue = replyQueue;
- this.streamChannel = streamChannel;
- this.requestHandlerHandle = requestHandlerHandle;
- }
-
- public void run() {
- try {
- int requestSequence = 0;
- for (;;) {
- final int id = unmarshaller.read();
- switch (id) {
- case -1: {
- // done.
- return;
- }
- case 2: {
- // two-way request
- final int requestId = requestSequence++;
- final Object request = unmarshaller.readObject();
- final FutureBasicReply future = new FutureBasicReply(requestId);
- replyQueue.add(future);
- final RemoteRequestContext requestContext = requestHandler.receiveRequest(request, new ReplyHandler() {
-
- public void handleReply(final Object reply) {
- future.setResult(reply);
- }
-
- public void handleException(final IOException exception) {
- future.setException(exception);
- }
-
- public void handleCancellation() {
- future.finishCancel();
- }
- });
- future.requestContext = requestContext;
- break;
- }
- case 3: {
- // cancel request
- final int requestId = unmarshaller.readInt();
- // simply iterate over the outstanding requests until we match or are past it...
- for (FutureBasicReply future : replyQueue) {
- final int queuedId = future.id;
- if (queuedId == requestId) {
- future.cancel();
- break;
- } else if (queuedId > requestId) {
- break;
- }
- }
- break;
- }
- default: {
- // invalid byte
- throw new IOException("Read an invalid byte from the client");
- }
- }
- }
- } catch (Exception e) {
- log.error(e, "Connection failed");
- } finally {
- IoUtils.safeClose(streamChannel);
- IoUtils.safeClose(requestHandlerHandle);
- }
- }
-}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/FutureBasicReply.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/FutureBasicReply.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/protocol/basic/FutureBasicReply.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.protocol.basic;
-
-import org.jboss.xnio.AbstractIoFuture;
-import org.jboss.xnio.IoFuture;
-import org.jboss.remoting3.spi.RemoteRequestContext;
-import java.io.IOException;
-
-/**
- *
- */
-final class FutureBasicReply extends AbstractIoFuture<Object> {
-
- final int id;
- RemoteRequestContext requestContext;
-
- public FutureBasicReply(final int id) {
- this.id = id;
- }
-
- protected boolean setException(final IOException exception) {
- return super.setException(exception);
- }
-
- protected boolean setResult(final Object result) {
- return super.setResult(result);
- }
-
- protected boolean finishCancel() {
- return super.finishCancel();
- }
-
- public IoFuture<Object> cancel() {
- requestContext.cancel();
- return this;
- }
-}
Copied: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExample2Main.java (from rev 5492, remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExampleMain.java)
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExample2Main.java (rev 0)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/LocalBasicExample2Main.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3.samples.simple;
+
+import java.net.URI;
+import org.jboss.remoting3.Client;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.Remoting;
+import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.LocalServiceConfiguration;
+import org.jboss.remoting3.Registration;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.OptionMap;
+
+/**
+ *
+ */
+public final class LocalBasicExample2Main {
+
+ private LocalBasicExample2Main() {
+ }
+
+ public static void main(String[] args) throws Exception {
+ final Endpoint endpoint = Remoting.createEndpoint("simple");
+ try {
+ final LocalServiceConfiguration<String, String> config = LocalServiceConfiguration.create(new StringRot13ClientListener(), String.class, String.class);
+ config.setGroupName("main");
+ config.setServiceType("simple.rot13");
+ final Registration handle = endpoint.registerService(config);
+ try {
+ final Connection connection = endpoint.connect(new URI("local:///"), OptionMap.EMPTY).get();
+ try {
+ final Client<String, String> client = connection.openClient("simple.rot13", "*", String.class, String.class).get();
+ try {
+ final String original = "The Secret Message";
+ 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(connection);
+ }
+ } finally {
+ IoUtils.safeClose(handle);
+ }
+ } finally {
+ IoUtils.safeClose(endpoint);
+ }
+ }
+}
\ No newline at end of file
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexClientExample.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexClientExample.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexClientExample.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,75 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.simple;
-
-import org.jboss.remoting3.Endpoint;
-import org.jboss.remoting3.Remoting;
-import org.jboss.xnio.OptionMap;
-import org.jboss.remoting3.Connection;
-import org.jboss.remoting3.Client;
-import org.jboss.xnio.IoUtils;
-import java.io.IOException;
-import java.net.URI;
-
-import java.util.logging.Logger;
-import java.util.logging.Level;
-
-/**
- *
- */
-public final class MultiplexClientExample {
-
- static {
- final Logger l = Logger.getLogger("");
- l.getHandlers()[0].setLevel(Level.ALL);
- l.setLevel(Level.INFO);
- }
-
- private MultiplexClientExample() {
- }
-
- public static void main(String[] args) {
- try {
- final Endpoint endpoint = Remoting.createEndpoint("example-client-endpoint");
- try {
- final Connection connection = endpoint.connect(URI.create(args[0]), OptionMap.EMPTY).get();
- try {
- final Client<String,String> client = connection.openClient("samples.rot13", "*", String.class, String.class).get();
- 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(connection);
- }
- } finally {
- IoUtils.safeClose(endpoint);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
Deleted: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexServerExample.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexServerExample.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexServerExample.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,97 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.simple;
-
-import org.jboss.remoting3.Remoting;
-import org.jboss.remoting3.Endpoint;
-import org.jboss.remoting3.LocalServiceConfiguration;
-import org.jboss.remoting3.SimpleCloseable;
-import org.jboss.remoting3.spi.ConnectionProviderRegistration;
-import org.jboss.remoting3.multiplex.MultiplexConnectionProviderFactory;
-import org.jboss.remoting3.multiplex.MultiplexServerFactory;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.CloseableExecutor;
-import org.jboss.xnio.Xnio;
-import org.jboss.xnio.TcpServer;
-import org.jboss.xnio.OptionMap;
-import org.jboss.xnio.channels.Channels;
-import java.io.IOException;
-
-import java.util.logging.Logger;
-import java.util.logging.Level;
-
-/**
- *
- */
-public final class MultiplexServerExample {
-
- static {
- final Logger l = Logger.getLogger("");
- l.getHandlers()[0].setLevel(Level.ALL);
- l.setLevel(Level.INFO);
- }
-
- private MultiplexServerExample() {
- }
-
- public static void main(String[] args) throws InterruptedException, IOException {
- final CloseableExecutor executor = Remoting.createExecutor(10);
- try {
- Xnio xnio = Xnio.create();
- try {
- final Endpoint endpoint = Remoting.createEndpoint(executor, "example-endpoint");
- try {
- final LocalServiceConfiguration<String, String> config = LocalServiceConfiguration.create(new StringRot13ClientListener(), String.class, String.class);
- config.setGroupName("main");
- config.setServiceType("simple.rot13");
- final SimpleCloseable handle = endpoint.registerService(config);
- try {
- // now create the server...
- final MultiplexConnectionProviderFactory multiplexConnectionProviderFactory = new MultiplexConnectionProviderFactory(xnio.createTcpConnector(OptionMap.EMPTY));
- final ConnectionProviderRegistration<MultiplexServerFactory> cpHandle = endpoint.addConnectionProvider("multiplex", multiplexConnectionProviderFactory);
- try {
- final TcpServer tcpServer = xnio.createTcpServer(Channels.createAllocatedMessageChannel(cpHandle.getProviderInterface().getServerListener(), OptionMap.EMPTY)).create();
- try {
- // now just wait for 15 seconds, and then shut it all down
- Thread.sleep(15000L);
- } finally {
- IoUtils.safeClose(tcpServer);
- }
- } finally {
- IoUtils.safeClose(cpHandle);
- }
- } finally {
- IoUtils.safeClose(handle);
- }
- } finally {
- IoUtils.safeClose(endpoint);
- }
- } finally {
- IoUtils.safeClose(xnio);
- }
- } finally {
- IoUtils.safeClose(executor);
- }
- }
-
-}
Deleted: remoting3/trunk/samples/src/test/java/org/jboss/remoting3/samples/protocol/basic/BasicTestCase.java
===================================================================
--- remoting3/trunk/samples/src/test/java/org/jboss/remoting3/samples/protocol/basic/BasicTestCase.java 2009-10-23 19:34:47 UTC (rev 5567)
+++ remoting3/trunk/samples/src/test/java/org/jboss/remoting3/samples/protocol/basic/BasicTestCase.java 2009-10-23 21:19:18 UTC (rev 5568)
@@ -1,132 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.samples.protocol.basic;
-
-import junit.framework.TestCase;
-import org.jboss.xnio.Xnio;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.ChannelSource;
-import org.jboss.xnio.IoFuture;
-import org.jboss.xnio.nio.NioXnio;
-import org.jboss.xnio.channels.StreamChannel;
-import org.jboss.remoting3.Endpoint;
-import org.jboss.remoting3.Remoting;
-import org.jboss.remoting3.RequestContext;
-import org.jboss.remoting3.RemoteExecutionException;
-import org.jboss.remoting3.Client;
-import org.jboss.remoting3.spi.RequestHandler;
-import org.jboss.marshalling.MarshallingConfiguration;
-import org.jboss.marshalling.river.RiverMarshallerFactory;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ExecutorService;
-import java.io.IOException;
-
-/**
- *
- */
-public final class BasicTestCase extends TestCase {
-
- public static void testConnect() throws Throwable {
- ExecutorService executor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
- try {
- Xnio xnio = NioXnio.create(executor, 2, 2, 2);
- try {
- final BasicConfiguration configuration = new BasicConfiguration();
- configuration.setExecutor(executor);
- configuration.setMarshallerFactory(new RiverMarshallerFactory());
- final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
- configuration.setMarshallingConfiguration(marshallingConfiguration);
- final Endpoint endpoint = Remoting.createEndpoint(executor, "test");
- try {
- final Handle<RequestHandler> requestHandlerHandle = endpoint.createLocalRequestHandler(new AbstractRequestListener<Object, Object>() {
- public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
- System.out.println("Got a request! " + request.toString());
- try {
- context.sendReply("GOOMBA");
- } catch (IOException e) {
- try {
- context.sendFailure("Failed", e);
- } catch (IOException e1) {
- // buh
- }
- }
- }
- }, Object.class, Object.class);
- try {
- final ChannelSource<StreamChannel> channelSource = xnio.createPipeServer(executor, IoUtils.singletonHandlerFactory(new IoHandler<StreamChannel>() {
- public void handleOpened(final StreamChannel channel) {
- try {
- System.out.println("Opening channel");
- BasicProtocol.createServer(requestHandlerHandle, channel, configuration);
- } catch (IOException e) {
- e.printStackTrace();
- IoUtils.safeClose(channel);
- }
- }
-
- public void handleReadable(final StreamChannel channel) {
- }
-
- public void handleWritable(final StreamChannel channel) {
- }
-
- public void handleClosed(final StreamChannel channel) {
- System.out.println("Closing channel");
- }
- }));
- final IoFuture<StreamChannel> futureChannel = channelSource.open(IoUtils.nullHandler());
- assertEquals(IoFuture.Status.DONE, futureChannel.await(1L, TimeUnit.SECONDS));
- final StreamChannel channel = futureChannel.get();
- try {
- final Handle<RequestHandler> clientHandlerHandle = BasicProtocol.createClient(channel, configuration);
- try {
- final Client<Object,Object> client = endpoint.createClient(clientHandlerHandle.getResource(), Object.class, Object.class);
- try {
- final IoFuture<? extends Object> futureReply = client.send("GORBA!");
- assertEquals(IoFuture.Status.DONE, futureReply.await(500L, TimeUnit.MILLISECONDS));
- System.out.println("Reply is:" + futureReply.get());
- } finally {
- IoUtils.safeClose(client);
- }
- } finally {
- IoUtils.safeClose(clientHandlerHandle);
- }
- } finally {
- IoUtils.safeClose(channel);
- }
- } finally {
- IoUtils.safeClose(requestHandlerHandle);
- }
- } finally {
- IoUtils.safeClose(endpoint);
- }
- } finally {
- IoUtils.safeClose(xnio);
- }
- } finally {
- executor.shutdownNow();
- }
- }
-}
15 years, 1 month
JBoss Remoting SVN: r5567 - in remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3: spi and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-23 15:34:47 -0400 (Fri, 23 Oct 2009)
New Revision: 5567
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemotingServiceDescriptor.java
Removed:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderDescriptor.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocolDescriptor.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
Log:
Round out service location code with support for all registerable types
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-10-23 19:10:31 UTC (rev 5566)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-10-23 19:34:47 UTC (rev 5567)
@@ -31,13 +31,18 @@
import java.util.concurrent.TimeUnit;
import java.util.ServiceLoader;
import org.jboss.remoting3.spi.RequestHandler;
-import org.jboss.remoting3.spi.ConnectionProviderDescriptor;
-import org.jboss.remoting3.spi.MarshallingProtocolDescriptor;
+import org.jboss.remoting3.spi.RemotingServiceDescriptor;
+import org.jboss.remoting3.spi.MarshallingProtocol;
+import org.jboss.remoting3.spi.ConnectionProviderFactory;
import org.jboss.xnio.CloseableExecutor;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.OptionMap;
-import org.jboss.xnio.Option;
import org.jboss.xnio.log.Logger;
+import org.jboss.marshalling.ClassTable;
+import org.jboss.marshalling.ObjectTable;
+import org.jboss.marshalling.ClassResolver;
+import org.jboss.marshalling.ObjectResolver;
+import org.jboss.marshalling.ClassExternalizerFactory;
/**
* The standalone interface into Remoting. This class contains static methods that are useful to standalone programs
@@ -81,37 +86,50 @@
* <li>{@link Options#LOAD_PROVIDERS} - specify whether providers should be auto-loaded (default {@code true})</li>
* </ul>
*
- * @param name the endpoint name
+ * @param endpointName the endpoint name
* @param optionMap the endpoint options
* @return the endpoint
* @throws IOException if an error occurs
*/
- public static Endpoint createEndpoint(final String name, final OptionMap optionMap) throws IOException {
- if (name == null) {
- throw new NullPointerException("name is null");
+ public static Endpoint createEndpoint(final String endpointName, final OptionMap optionMap) throws IOException {
+ if (endpointName == null) {
+ throw new NullPointerException("endpointName is null");
}
if (optionMap == null) {
throw new NullPointerException("optionMap is null");
}
final CloseableExecutor executor = createExecutor(optionMap.get(Options.MAX_THREADS, 10));
- final Endpoint endpoint = createEndpoint(executor, name);
+ final Endpoint endpoint = createEndpoint(executor, endpointName);
endpoint.addCloseHandler(new CloseHandler<Endpoint>() {
public void handleClose(final Endpoint closed) {
IoUtils.safeClose(executor);
}
});
if (optionMap.get(Options.LOAD_PROVIDERS, true)) {
- for (ConnectionProviderDescriptor descriptor : ServiceLoader.load(ConnectionProviderDescriptor.class)) try {
- endpoint.addConnectionProvider(descriptor.getUriScheme(), descriptor.getConnectionProviderFactory());
- } catch (DuplicateRegistrationException e) {
- log.debug("Duplicate registration for URI scheme '" + descriptor.getUriScheme() + "'");
+ for (RemotingServiceDescriptor descriptor : ServiceLoader.load(RemotingServiceDescriptor.class)) {
+ final String name = descriptor.getName();
+ final Class serviceType = descriptor.getType();
+ final Object service = descriptor.getService();
+ try {
+ if (serviceType == ConnectionProviderFactory.class) {
+ endpoint.addConnectionProvider(name, (ConnectionProviderFactory<?>) service);
+ } else if (serviceType == MarshallingProtocol.class) {
+ endpoint.addMarshallingProtocol(name, (MarshallingProtocol) service);
+ } else if (serviceType == ClassTable.class) {
+ endpoint.addUserClassTable(name, (ClassTable) service);
+ } else if (serviceType == ObjectTable.class) {
+ endpoint.addUserObjectTable(name, (ObjectTable) service);
+ } else if (serviceType == ClassResolver.class) {
+ endpoint.addUserClassResolver(name, (ClassResolver) service);
+ } else if (serviceType == ObjectResolver.class) {
+ endpoint.addUserObjectResolver(name, (ObjectResolver) service);
+ } else if (serviceType == ClassExternalizerFactory.class) {
+ endpoint.addUserExternalizerFactory(name, (ClassExternalizerFactory) service);
+ }
+ } catch (DuplicateRegistrationException e) {
+ log.debug("Duplicate registration for '" + name + "' of type " + serviceType);
+ }
}
- for (MarshallingProtocolDescriptor descriptor : ServiceLoader.load(MarshallingProtocolDescriptor.class)) try {
- endpoint.addMarshallingProtocol(descriptor.getName(), descriptor.getMarshallingProtocol());
- } catch (DuplicateRegistrationException e) {
- log.debug("Duplicate registration for marshalling protocol '" + descriptor.getName() + "'");
- }
- // todo - marshallers and components thereof
}
return endpoint;
}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderDescriptor.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderDescriptor.java 2009-10-23 19:10:31 UTC (rev 5566)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderDescriptor.java 2009-10-23 19:34:47 UTC (rev 5567)
@@ -1,50 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3.spi;
-
-/**
- * A descriptor for automatically-discovered connection provider types. Since instances of this interface are
- * constructed automatically, implementing classes should have a no-arg constructor.
- * <p>
- * To add an automatically-discovered provider, create a file called {@code "META-INF/services/org.jboss.remoting3.spi.ConnectionProviderDescriptor"}
- * and populate it with the names of classes that implement this interface.
- *
- * @see java.util.ServiceLoader
- */
-public interface ConnectionProviderDescriptor {
-
- /**
- * Get the URI scheme for this provider. A provider factory may be registered more than one time with different
- * URI schemes.
- *
- * @return the URI scheme
- */
- String getUriScheme();
-
- /**
- * Get the connection provider factory to associate with the given URI scheme.
- *
- * @return the connection provider factory
- */
- ConnectionProviderFactory<?> getConnectionProviderFactory();
-}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocolDescriptor.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocolDescriptor.java 2009-10-23 19:10:31 UTC (rev 5566)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocolDescriptor.java 2009-10-23 19:34:47 UTC (rev 5567)
@@ -1,49 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3.spi;
-
-/**
- * A descriptor for automatically-discovered marshaller types. Since instances of this interface are
- * constructed automatically, implementing classes should have a no-arg constructor.
- * <p>
- * To add an automatically-discovered marshaller, create a file called {@code "META-INF/services/org.jboss.remoting3.spi.MarshallingProtocolDescriptor"}
- * and populate it with the names of classes that implement this interface.
- *
- * @see java.util.ServiceLoader
- */
-public interface MarshallingProtocolDescriptor {
-
- /**
- * Get the name of this marshalling protocol.
- *
- * @return the name
- */
- String getName();
-
- /**
- * Get the marshalling protocol to associate with the given name.
- *
- * @return the marshalling protocol
- */
- MarshallingProtocol getMarshallingProtocol();
-}
Copied: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemotingServiceDescriptor.java (from rev 5566, remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/MarshallingProtocolDescriptor.java)
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemotingServiceDescriptor.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemotingServiceDescriptor.java 2009-10-23 19:34:47 UTC (rev 5567)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3.spi;
+
+/**
+ * A descriptor for automatically-discovered remoting service types. Since instances of this interface are
+ * constructed automatically, implementing classes should have a no-arg constructor.
+ * <p>
+ * To add an automatically-discovered service, create a file called {@code "META-INF/services/org.jboss.remoting3.spi.RemotingServiceDescriptor"}
+ * and populate it with the names of classes that implement this interface.
+ *
+ * @see java.util.ServiceLoader
+ */
+public interface RemotingServiceDescriptor<T> {
+
+ /**
+ * Get the type of service provided by this descriptor. Only the following types are supported:
+ * <ul>
+ * <li><code>{@link MarshallingProtocol}.class</code> - named marshalling protocol</li>
+ * <li><code>{@link ConnectionProviderFactory}.class</code> - named connection provider URI scheme</li>
+ * <li><code>{@link org.jboss.marshalling.ClassTable ClassTable}.class</code> - named marshalling class table</li>
+ * <li><code>{@link org.jboss.marshalling.ObjectTable ObjectTable}.class</code> - named marshalling object table</li>
+ * <li><code>{@link org.jboss.marshalling.ClassExternalizerFactory ClassExternalizerFactory}.class</code> - named marshalling externalizer factory</li>
+ * <li><code>{@link org.jboss.marshalling.ClassResolver ClassResolver}.class</code> - named marshalling class resolver</li>
+ * <li><code>{@link org.jboss.marshalling.ObjectResolver ObjectResolver}.class</code> - named marshalling object resolver</li>
+ * </ul>
+ * Other types are ignored, allowing new types to be added in the future while maintaining compatibility with
+ * older versions.
+ *
+ * @return the type of remoting service
+ */
+ Class<T> getType();
+
+ /**
+ * Get the name of this service.
+ *
+ * @return the name
+ */
+ String getName();
+
+ /**
+ * Get the service to associate with the given name.
+ *
+ * @return the service
+ */
+ T getService();
+}
15 years, 1 month