Author: david.lloyd(a)jboss.com
Date: 2009-09-16 16:31:34 -0400 (Wed, 16 Sep 2009)
New Revision: 5505
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractConnectionProviderRegistration.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/spi/ConnectionProviderRegistration.java
Log:
Make it possible for network servers to connect in to Remoting with the new API (part 2)
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-09-16
20:20:26 UTC (rev 5504)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-09-16
20:31:34 UTC (rev 5505)
@@ -5,6 +5,7 @@
import java.util.Set;
import org.jboss.remoting3.spi.ConnectionProviderFactory;
import org.jboss.remoting3.spi.RequestHandler;
+import org.jboss.remoting3.spi.ConnectionProviderRegistration;
import org.jboss.xnio.IoFuture;
/**
@@ -92,7 +93,7 @@
* @param providerFactory the provider factory
* @return a handle which may be used to remove the registration
*/
- SimpleCloseable addConnectionProvider(String uriScheme, ConnectionProviderFactory
providerFactory);
+ <T> ConnectionProviderRegistration<T> addConnectionProvider(String
uriScheme, ConnectionProviderFactory<T> providerFactory);
/**
* Flags which can be passed in to listener registration methods.
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-09-16
20:20:26 UTC (rev 5504)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-09-16
20:31:34 UTC (rev 5505)
@@ -50,6 +50,8 @@
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.AbstractConnectionProviderRegistration;
import org.jboss.xnio.IoFuture;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.WeakCloseable;
@@ -98,7 +100,7 @@
private final Set<Registration<ServiceRegistrationListener>>
serviceListenerRegistrations = hashSet();
private final Map<String, ServiceRegistration> registeredLocalServices =
hashMap();
- private final ConcurrentMap<String, ConnectionProvider> connectionProviders =
concurrentHashMap();
+ private final ConcurrentMap<String, ConnectionProvider<?>>
connectionProviders = concurrentHashMap();
private static final EndpointPermission CREATE_ENDPOINT_PERM = new
EndpointPermission("createEndpoint");
private static final EndpointPermission CREATE_REQUEST_HANDLER_PERM = new
EndpointPermission("createRequestHandler");
@@ -343,7 +345,7 @@
sm.checkPermission(CONNECT_PERM);
}
final String scheme = destination.getScheme();
- final ConnectionProvider connectionProvider = connectionProviders.get(scheme);
+ final ConnectionProvider<?> connectionProvider =
connectionProviders.get(scheme);
if (connectionProvider == null) {
throw new UnknownURISchemeException("No connection provider for URI
scheme \"" + scheme + "\" is installed");
}
@@ -356,13 +358,13 @@
return futureResult;
}
- public SimpleCloseable addConnectionProvider(final String uriScheme, final
ConnectionProviderFactory providerFactory) {
+ public <T> ConnectionProviderRegistration<T> addConnectionProvider(final
String uriScheme, final ConnectionProviderFactory<T> providerFactory) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(ADD_CONNECTION_PROVIDER_PERM);
}
final ConnectionProviderContextImpl context = new
ConnectionProviderContextImpl(executor, loopbackConnectionHandler);
- final ConnectionProvider provider = providerFactory.createInstance(context);
+ final ConnectionProvider<T> provider =
providerFactory.createInstance(context);
if (connectionProviders.putIfAbsent(uriScheme, provider) != null) {
IoUtils.safeClose(context);
throw new IllegalArgumentException("URI scheme '" + uriScheme +
"' is already registered to a provider");
@@ -372,10 +374,14 @@
connectionProviders.remove(uriScheme, provider);
}
});
- final AbstractSimpleCloseable handle = new AbstractSimpleCloseable(executor) {
+ final AbstractConnectionProviderRegistration<T> handle = new
AbstractConnectionProviderRegistration<T>(executor) {
protected void closeAction() throws IOException {
context.close();
}
+
+ public T getProviderInterface() {
+ return provider.getUserData();
+ }
};
context.addCloseHandler(new CloseHandler<ConnectionProviderContext>() {
public void handleClose(final ConnectionProviderContext closed) {
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractConnectionProviderRegistration.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractConnectionProviderRegistration.java
(rev 0)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractConnectionProviderRegistration.java 2009-09-16
20:31:34 UTC (rev 5505)
@@ -0,0 +1,42 @@
+/*
+ * 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.util.concurrent.Executor;
+
+/**
+ * An abstract implementation of {@code ConnectionProviderRegistration}.
+ *
+ * @param <T> the provider interface type
+ */
+public abstract class AbstractConnectionProviderRegistration<T> extends
AbstractHandleableCloseable<ConnectionProviderRegistration<T>> implements
ConnectionProviderRegistration<T> {
+
+ /**
+ * Basic constructor.
+ *
+ * @param executor the executor used to execute the close notification handlers
+ */
+ protected AbstractConnectionProviderRegistration(final Executor executor) {
+ super(executor);
+ }
+}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderRegistration.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderRegistration.java 2009-09-16
20:20:26 UTC (rev 5504)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderRegistration.java 2009-09-16
20:31:34 UTC (rev 5505)
@@ -25,7 +25,9 @@
import org.jboss.remoting3.HandleableCloseable;
/**
+ * A handle representing the registration of a connection provider.
*
+ * @param <T> the provider interface type
*/
public interface ConnectionProviderRegistration<T> extends
HandleableCloseable<ConnectionProviderRegistration<T>> {