[jboss-remoting-commits] JBoss Remoting SVN: r4643 - in remoting3/trunk: core/src/main/java/org/jboss/remoting/core and 4 other directories.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Mon Nov 3 22:15:22 EST 2008


Author: david.lloyd at jboss.com
Date: 2008-11-03 22:15:22 -0500 (Mon, 03 Nov 2008)
New Revision: 4643

Modified:
   remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/AbstractHandleableCloseable.java
   remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java
   remoting3/trunk/core/src/test/java/org/jboss/remoting/core/EndpointTestCase.java
   remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
   remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
   remoting3/trunk/testing-support/src/main/resources/testing.policy
Log:
Various test fixes

Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/AbstractHandleableCloseable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/AbstractHandleableCloseable.java	2008-11-04 02:34:36 UTC (rev 4642)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/AbstractHandleableCloseable.java	2008-11-04 03:15:22 UTC (rev 4643)
@@ -99,6 +99,7 @@
     /**
      * {@inheritDoc}
      */
+    @SuppressWarnings({ "unchecked" })
     public final void close() throws IOException {
         if (! closed.getAndSet(true)) {
             log.trace("Closed %s", this);
@@ -113,7 +114,7 @@
                                 }
                             });
                         } catch (RejectedExecutionException ree) {
-                            log.warn("Unable to execute close handler (execution rejected) for %s (%s)", this, ree.getMessage());
+                            SpiUtils.safeHandleClose(handler, (T) AbstractHandleableCloseable.this);
                         }
                     }
                     closeHandlers = null;
@@ -134,7 +135,12 @@
             closeHandlers.add(handler);
             return new Key() {
                 public void remove() {
-                    closeHandlers.remove(handler);
+                    synchronized (closeLock) {
+                        final Set<CloseHandler<? super T>> closeHandlers = AbstractHandleableCloseable.this.closeHandlers;
+                        if (closeHandlers != null) {
+                            closeHandlers.remove(handler);
+                        }
+                    }
                 }
             };
         }

Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java	2008-11-04 02:34:36 UTC (rev 4642)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java	2008-11-04 03:15:22 UTC (rev 4643)
@@ -11,7 +11,6 @@
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
-import java.security.AccessController;
 import org.jboss.remoting.Client;
 import org.jboss.remoting.ClientSource;
 import org.jboss.remoting.CloseHandler;
@@ -149,7 +148,10 @@
     }
 
     public <I, O> Handle<RequestHandler> createRequestHandler(final RequestListener<I, O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException {
-        AccessController.checkPermission(CREATE_REQUEST_HANDLER_PERM);
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(CREATE_REQUEST_HANDLER_PERM);
+        }
         LocalRequestHandler.Config<I, O> config = new LocalRequestHandler.Config<I,O>(requestClass, replyClass);
         config.setExecutor(executor);
         config.setRequestListener(requestListener);
@@ -161,7 +163,10 @@
     }
 
     public <I, O> Handle<RequestHandlerSource> registerService(final LocalServiceConfiguration<I, O> configuration) throws IOException {
-        AccessController.checkPermission(REGISTER_SERVICE_PERM);
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(REGISTER_SERVICE_PERM);
+        }
         final String serviceType = configuration.getServiceType();
         final String groupName = configuration.getGroupName();
         final int metric = configuration.getMetric();
@@ -214,7 +219,10 @@
     }
 
     public <I, O> Client<I, O> createClient(final RequestHandler requestHandler, final Class<I> requestType, final Class<O> replyType) throws IOException {
-        AccessController.checkPermission(CREATE_CLIENT_PERM);
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(CREATE_CLIENT_PERM);
+        }
         boolean ok = false;
         final Handle<RequestHandler> handle = requestHandler.getHandle();
         try {
@@ -234,7 +242,10 @@
     }
 
     public <I, O> ClientSource<I, O> createClientSource(final RequestHandlerSource requestHandlerSource, final Class<I> requestClass, final Class<O> replyClass) throws IOException {
-        AccessController.checkPermission(CREATE_CLIENT_SOURCE_PERM);
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(CREATE_CLIENT_SOURCE_PERM);
+        }
         boolean ok = false;
         final Handle<RequestHandlerSource> handle = requestHandlerSource.getHandle();
         try {
@@ -324,7 +335,10 @@
     }
 
     public SimpleCloseable registerRemoteService(final RemoteServiceConfiguration configuration) throws IllegalArgumentException, IOException {
-        AccessController.checkPermission(REGISTER_REMOTE_SERVICE_PERM);
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(REGISTER_REMOTE_SERVICE_PERM);
+        }
         final RequestHandlerSource handlerSource = configuration.getRequestHandlerSource();
         final String serviceType = configuration.getServiceType();
         final String groupName = configuration.getGroupName();
@@ -381,7 +395,10 @@
     }
 
     public SimpleCloseable addServiceListener(final ServiceListener serviceListener, final boolean onlyNew) {
-        AccessController.checkPermission(ADD_SERVICE_LISTENER_PERM);
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(ADD_SERVICE_LISTENER_PERM);
+        }
         final Object key = new Object();
         synchronized (serviceLock) {
             final ServiceListenerRegistration registration = new ServiceListenerRegistration(serviceListener);

Modified: remoting3/trunk/core/src/test/java/org/jboss/remoting/core/EndpointTestCase.java
===================================================================
--- remoting3/trunk/core/src/test/java/org/jboss/remoting/core/EndpointTestCase.java	2008-11-04 02:34:36 UTC (rev 4642)
+++ remoting3/trunk/core/src/test/java/org/jboss/remoting/core/EndpointTestCase.java	2008-11-04 03:15:22 UTC (rev 4643)
@@ -37,6 +37,7 @@
 import org.jboss.remoting.spi.RequestHandler;
 import org.jboss.remoting.spi.Handle;
 import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
 
 /**
  *
@@ -46,6 +47,8 @@
         LoggingHelper.init();
     }
 
+    private static final Logger log = Logger.getLogger(EndpointTestCase.class);
+
     private static void safeStop(EndpointImpl endpoint) {
         try {
             endpoint.stop();
@@ -92,7 +95,7 @@
                             }
                         }
                     }
-                }, INIT_ME, INIT_ME2);
+                }, Object.class, Object.class);
                 final RequestHandler requestHandler = handle.getResource();
                 try {
                     requestHandler.addCloseHandler(new CloseHandler<RequestHandler>() {
@@ -100,7 +103,7 @@
                             clientEndpointClosed.set(true);
                         }
                     });
-                    final Client<Object,Object> client = endpoint.createClient(requestHandler, requestType, replyType);
+                    final Client<Object,Object> client = endpoint.createClient(requestHandler, Object.class, Object.class);
                     try {
                         client.addCloseHandler(new CloseHandler<Client<Object, Object>>() {
                             public void handleClose(final Client<Object, Object> closed) {
@@ -144,14 +147,10 @@
                         try {
                             context.sendReply(replyObj);
                         } catch (IOException e) {
-                            try {
-                                context.sendFailure(e.getMessage(), e);
-                            } catch (IOException e1) {
-                                fail("double fault");
-                            }
+                            log.error(e, "Error sending reply!");
                         }
                     }
-                }, INIT_ME, INIT_ME2);
+                }, Object.class, Object.class);
                 final RequestHandler requestHandler = handle.getResource();
                 try {
                     requestHandler.addCloseHandler(new CloseHandler<RequestHandler>() {
@@ -159,7 +158,7 @@
                             clientEndpointClosed.set(true);
                         }
                     });
-                    final Client<Object,Object> client = endpoint.createClient(requestHandler, requestType, replyType);
+                    final Client<Object,Object> client = endpoint.createClient(requestHandler, Object.class, Object.class);
                     try {
                         client.addCloseHandler(new CloseHandler<Client<Object, Object>>() {
                             public void handleClose(final Client<Object, Object> closed) {

Modified: remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
===================================================================
--- remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java	2008-11-04 02:34:36 UTC (rev 4642)
+++ remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java	2008-11-04 03:15:22 UTC (rev 4643)
@@ -77,7 +77,7 @@
                     }
                 }
             }
-        }, INIT_ME, INIT_ME2);
+        }, Object.class, Object.class);
         final ChannelSource<StreamChannel> channelSource = xnio.createPipeServer(executor, IoUtils.singletonHandlerFactory(new IoHandler<StreamChannel>() {
             public void handleOpened(final StreamChannel channel) {
                 try {
@@ -101,7 +101,7 @@
         }));
         final IoFuture<StreamChannel> futureChannel = channelSource.open(IoUtils.nullHandler());
         final Handle<RequestHandler> clientHandlerHandle = BasicProtocol.createClient(futureChannel.get(), configuration);
-        final Client<Object,Object> client = endpoint.createClient(clientHandlerHandle.getResource(), requestType, replyType);
+        final Client<Object,Object> client = endpoint.createClient(clientHandlerHandle.getResource(), Object.class, Object.class);
         System.out.println("Reply is:" + client.invoke("GORBA!"));
 
     }

Modified: remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java	2008-11-04 02:34:36 UTC (rev 4642)
+++ remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java	2008-11-04 03:15:22 UTC (rev 4643)
@@ -48,7 +48,9 @@
     /**
      * Create a request server for the multiplex protocol.
      *
-     * @return a handler factory for passing to an XNIO server @param executor the executor to use for invocations @param configuration
+     * @param endpoint the endpoint
+     * @param configuration the configuration
+     * @return a handler factory for passing to an XNIO server
      */
     public static IoHandlerFactory<AllocatedMessageChannel> createServer(final Endpoint endpoint, final MultiplexConfiguration configuration) {
         return new IoHandlerFactory<AllocatedMessageChannel>() {
@@ -61,8 +63,11 @@
     /**
      * Create a request client for the multiplex protocol.
      *
+     * @param endpoint the endpoint
+     * @param configuration the configuration
+     * @param channelSource the XNIO channel source to use to establish the connection @param allocator the buffer allocator to use
      * @return a handle which may be used to close the connection
-     * @throws IOException if an error occurs @param executor the executor to use for invocations @param channelSource the XNIO channel source to use to establish the connection @param allocator the buffer allocator to use @param configuration
+     * @throws IOException if an error occurs
      */
     public static IoFuture<SimpleCloseable> connect(final Endpoint endpoint, final MultiplexConfiguration configuration, final ChannelSource<AllocatedMessageChannel> channelSource) throws IOException {
         final MultiplexHandler multiplexHandler = new MultiplexHandler(endpoint, configuration);
@@ -85,7 +90,7 @@
         }
 
         public String toString() {
-            return "connection <" + Integer.toString(hashCode()) + ">";
+            return "Remoting multiplex connection <" + Integer.toString(hashCode()) + ">";
         }
     }
 }

Modified: remoting3/trunk/testing-support/src/main/resources/testing.policy
===================================================================
--- remoting3/trunk/testing-support/src/main/resources/testing.policy	2008-11-04 02:34:36 UTC (rev 4642)
+++ remoting3/trunk/testing-support/src/main/resources/testing.policy	2008-11-04 03:15:22 UTC (rev 4643)
@@ -9,12 +9,16 @@
 grant codeBase "file:${build.home}/core/target/test/classes/-"
 {
     permission java.lang.RuntimePermission "modifyThread"; // for executor control
+    permission org.jboss.remoting.EndpointPermission "createRequestHandler";
+    permission org.jboss.remoting.EndpointPermission "createClient";
 };
 
 grant codeBase "file:${build.home}/protocol/basic/target/test/classes/-"
 {
     permission java.lang.RuntimePermission "modifyThread"; // for executor control
     permission java.net.SocketPermission "*:*", "accept, connect, resolve";
+    permission org.jboss.remoting.EndpointPermission "createRequestHandler";
+    permission org.jboss.remoting.EndpointPermission "createClient";
 };
 
 grant codeBase "file:${build.home}/protocol/multiplex/target/test/classes/-"
@@ -33,6 +37,7 @@
 grant codeBase "file:${build.home}/core/target/main/classes/-"
 {
     permission java.util.PropertyPermission "jboss.remoting.*", "read";
+    permission org.jboss.remoting.EndpointPermission "*";
 };
 
 grant codeBase "file:${build.home}/protocol/basic/target/main/classes/-"




More information about the jboss-remoting-commits mailing list