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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu Jul 10 14:49:25 EDT 2008


Author: david.lloyd at jboss.com
Date: 2008-07-10 14:49:25 -0400 (Thu, 10 Jul 2008)
New Revision: 4370

Added:
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
Removed:
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
Modified:
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
   remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingSecurityManager.java
Log:
add more SPI support stuff

Copied: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java (from rev 4368, remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java)
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java	                        (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.spi;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.spi.remote.Handle;
+import org.jboss.xnio.log.Logger;
+
+/**
+ *
+ */
+public abstract class AbstractAutoCloseable<T> extends AbstractCloseable<T> {
+
+    private final AtomicBoolean autoClose = new AtomicBoolean();
+    private final AtomicInteger refcount = new AtomicInteger(1);
+    private final Executor executor;
+
+    private static final Logger log = Logger.getLogger(AbstractAutoCloseable.class);
+
+    protected AbstractAutoCloseable(final Executor executor) {
+        super(executor);
+        this.executor = executor;
+    }
+
+    protected void safeDec() {
+        try {
+            dec();
+        } catch (Throwable t) {
+            log.trace("Failed to decrement reference count: %s", t);
+        }
+    }
+
+    protected void dec() throws RemotingException {
+        final int v = refcount.decrementAndGet();
+        if (v == 0) {
+            // we dropped the refcount to zero
+            if (refcount.compareAndSet(0, -65536)) {
+                // we are closing
+                close();
+            }
+            // someone incremented it in the meantime... lucky them
+        } else if (v < 0) {
+            // was already closed; put the count back
+            refcount.incrementAndGet();
+        }
+        // otherwise, the resource remains open
+    }
+
+    protected void inc() throws RemotingException {
+        final int v = refcount.getAndIncrement();
+        if (v < 0) {
+            // was already closed
+            refcount.decrementAndGet();
+            throw new RemotingException("Resource is closed");
+        }
+    }
+
+    public void autoClose() throws RemotingException {
+        if (! autoClose.getAndSet(true)) {
+            dec();
+        }
+    }
+
+    public Handle<T> getHandle() throws RemotingException {
+        return new HandleImpl();
+    }
+
+    private final class HandleImpl extends AbstractCloseable<Handle<T>> implements Handle<T> {
+
+        private HandleImpl() throws RemotingException {
+            super(AbstractAutoCloseable.this.executor);
+            inc();
+        }
+
+        @SuppressWarnings({ "unchecked" })
+        public T getResource() {
+            return (T) AbstractAutoCloseable.this;
+        }
+    }
+}

Copied: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java (from rev 4368, remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java)
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java	                        (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.spi;
+
+import org.jboss.cx.remoting.Closeable;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.spi.SpiUtils;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ *
+ */
+public abstract class AbstractCloseable<T> implements Closeable<T> {
+
+    private static final Logger log = Logger.getLogger(AbstractCloseable.class);
+
+    protected final Executor executor;
+    private final Object closeLock = new Object();
+    private final AtomicBoolean closed = new AtomicBoolean();
+    private Set<CloseHandler<? super T>> closeHandlers;
+
+    protected AbstractCloseable(final Executor executor) {
+        if (executor == null) {
+            throw new NullPointerException("executor is null");
+        }
+        this.executor = executor;
+    }
+
+    protected boolean isOpen() {
+        return ! closed.get();
+    }
+
+    public void close() throws RemotingException {
+        if (! closed.getAndSet(true)) {
+            synchronized (closeLock) {
+                if (closeHandlers != null) {
+                    for (final CloseHandler<? super T> handler : closeHandlers) {
+                        executor.execute(new Runnable() {
+                            @SuppressWarnings({ "unchecked" })
+                            public void run() {
+                                SpiUtils.safeHandleClose(handler, (T) AbstractCloseable.this);
+                            }
+                        });
+                    }
+                    closeHandlers = null;
+                }
+            }
+        }
+    }
+
+    public void addCloseHandler(final CloseHandler<? super T> handler) {
+        synchronized (closeLock) {
+            if (closeHandlers == null) {
+                closeHandlers = new HashSet<CloseHandler<? super T>>();
+            }
+            closeHandlers.add(handler);
+        }
+    }
+
+    protected Executor getExecutor() {
+        return executor;
+    }
+
+    protected void finalize() throws Throwable {
+        try {
+            super.finalize();
+        } finally {
+            if (isOpen()) {
+                log.warn("Leaked a %s instance!", getClass().getName());
+                IoUtils.safeClose(this);
+            }
+        }
+    }
+}

Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -23,6 +23,7 @@
 package org.jboss.cx.remoting.spi;
 
 import org.jboss.cx.remoting.spi.remote.ReplyHandler;
+import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
 import org.jboss.cx.remoting.RequestCancelHandler;
 import org.jboss.cx.remoting.RequestContext;
 import org.jboss.cx.remoting.CloseHandler;
@@ -126,5 +127,16 @@
             log.error(t, "Request completion handler failed unexpectedly");
         }
     }
+
+    public static RemoteRequestContext getBlankRemoteRequestContext() {
+        return BLANK_REMOTE_REQUEST_CONTEXT;
+    }
+
+    private static final RemoteRequestContext BLANK_REMOTE_REQUEST_CONTEXT = new BlankRemoteRequestContext();
+
+    private static final class BlankRemoteRequestContext implements RemoteRequestContext {
+        public void cancel(final boolean mayInterrupt) {
+        }
+    }
 }
 

Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.cx.remoting.core;
-
-import java.util.concurrent.Executor;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.spi.remote.Handle;
-import org.jboss.xnio.log.Logger;
-
-/**
- *
- */
-public abstract class AbstractAutoCloseable<T> extends AbstractCloseable<T> {
-
-    private final AtomicBoolean autoClose = new AtomicBoolean();
-    private final AtomicInteger refcount = new AtomicInteger(1);
-    private final Executor executor;
-
-    private static final Logger log = Logger.getLogger(AbstractAutoCloseable.class);
-
-    protected AbstractAutoCloseable(final Executor executor) {
-        super(executor);
-        this.executor = executor;
-    }
-
-    protected void safeDec() {
-        try {
-            dec();
-        } catch (Throwable t) {
-            log.trace("Failed to decrement reference count: %s", t);
-        }
-    }
-
-    protected void dec() throws RemotingException {
-        final int v = refcount.decrementAndGet();
-        if (v == 0) {
-            // we dropped the refcount to zero
-            if (refcount.compareAndSet(0, -65536)) {
-                // we are closing
-                close();
-            }
-            // someone incremented it in the meantime... lucky them
-        } else if (v < 0) {
-            // was already closed; put the count back
-            refcount.incrementAndGet();
-        }
-        // otherwise, the resource remains open
-    }
-
-    protected void inc() throws RemotingException {
-        final int v = refcount.getAndIncrement();
-        if (v < 0) {
-            // was already closed
-            refcount.decrementAndGet();
-            throw new RemotingException("Resource is closed");
-        }
-    }
-
-    public void autoClose() throws RemotingException {
-        if (! autoClose.getAndSet(true)) {
-            dec();
-        }
-    }
-
-    public Handle<T> getHandle() throws RemotingException {
-        return new HandleImpl();
-    }
-
-    private final class HandleImpl extends AbstractCloseable<Handle<T>> implements Handle<T> {
-
-        private HandleImpl() throws RemotingException {
-            super(AbstractAutoCloseable.this.executor);
-            inc();
-        }
-
-        @SuppressWarnings({ "unchecked" })
-        public T getResource() {
-            return (T) AbstractAutoCloseable.this;
-        }
-    }
-}

Deleted: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -1,100 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.cx.remoting.core;
-
-import org.jboss.cx.remoting.Closeable;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.CloseHandler;
-import org.jboss.cx.remoting.spi.SpiUtils;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.log.Logger;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Executor;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- *
- */
-public abstract class AbstractCloseable<T> implements Closeable<T> {
-
-    private static final Logger log = Logger.getLogger(AbstractCloseable.class);
-
-    protected final Executor executor;
-    private final Object closeLock = new Object();
-    private final AtomicBoolean closed = new AtomicBoolean();
-    private Set<CloseHandler<? super T>> closeHandlers;
-
-    protected AbstractCloseable(final Executor executor) {
-        if (executor == null) {
-            throw new NullPointerException("executor is null");
-        }
-        this.executor = executor;
-    }
-
-    protected boolean isOpen() {
-        return ! closed.get();
-    }
-
-    public void close() throws RemotingException {
-        if (! closed.getAndSet(true)) {
-            synchronized (closeLock) {
-                if (closeHandlers != null) {
-                    for (final CloseHandler<? super T> handler : closeHandlers) {
-                        executor.execute(new Runnable() {
-                            @SuppressWarnings({ "unchecked" })
-                            public void run() {
-                                SpiUtils.safeHandleClose(handler, (T) AbstractCloseable.this);
-                            }
-                        });
-                    }
-                    closeHandlers = null;
-                }
-            }
-        }
-    }
-
-    public void addCloseHandler(final CloseHandler<? super T> handler) {
-        synchronized (closeLock) {
-            if (closeHandlers == null) {
-                closeHandlers = new HashSet<CloseHandler<? super T>>();
-            }
-            closeHandlers.add(handler);
-        }
-    }
-
-    protected Executor getExecutor() {
-        return executor;
-    }
-
-    protected void finalize() throws Throwable {
-        try {
-            super.finalize();
-        } finally {
-            if (isOpen()) {
-                log.warn("Leaked a %s instance!", getClass().getName());
-                IoUtils.safeClose(this);
-            }
-        }
-    }
-}

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractContextImpl.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -25,6 +25,7 @@
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.Executor;
 import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.cx.remoting.spi.AbstractCloseable;
 
 /**
  *
@@ -40,4 +41,12 @@
     public ConcurrentMap<Object, Object> getAttributes() {
         return attributes;
     }
+
+    protected Executor getExecutor() {
+        return super.getExecutor();
+    }
+
+    protected boolean isOpen() {
+        return super.isOpen();
+    }
 }

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -28,6 +28,7 @@
 import org.jboss.cx.remoting.Endpoint;
 import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
 import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
+import org.jboss.cx.remoting.spi.AbstractCloseable;
 
 /**
  *

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -158,7 +158,7 @@
         boolean ok = false;
         final Handle<RemoteServiceEndpoint<I,O>> handle = endpoint.getHandle();
         try {
-            final ClientSourceImpl<I, O> client = new ClientSourceImpl<I, O>(endpoint, executor);
+            final ClientSourceImpl<I, O> client = new ClientSourceImpl<I, O>(endpoint, this);
             client.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
                 public void handleClose(final ClientSource<I, O> closed) {
                     IoUtils.safeClose(handle);

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -26,6 +26,7 @@
 import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
 import org.jboss.cx.remoting.spi.remote.ReplyHandler;
 import org.jboss.cx.remoting.spi.SpiUtils;
+import org.jboss.cx.remoting.spi.AbstractAutoCloseable;
 import org.jboss.cx.remoting.RemotingException;
 import org.jboss.cx.remoting.RequestListener;
 import org.jboss.cx.remoting.RemoteExecutionException;

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -24,6 +24,7 @@
 
 import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
 import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.AbstractAutoCloseable;
 import org.jboss.cx.remoting.RequestListener;
 import org.jboss.cx.remoting.RemotingException;
 import org.jboss.cx.remoting.CloseHandler;

Modified: remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingSecurityManager.java
===================================================================
--- remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingSecurityManager.java	2008-07-10 14:56:19 UTC (rev 4369)
+++ remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingSecurityManager.java	2008-07-10 18:49:25 UTC (rev 4370)
@@ -169,7 +169,7 @@
         }
     }
 
-    /** @noinspection deprecation*/
+    @SuppressWarnings({"deprecation"})
     public void checkMulticast(final InetAddress maddr, final byte ttl) {
         try {
             super.checkMulticast(maddr, ttl);




More information about the jboss-remoting-commits mailing list