Author: david.lloyd(a)jboss.com
Date: 2008-07-03 14:37:32 -0400 (Thu, 03 Jul 2008)
New Revision: 4350
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
More cleanup, add general close-leak protection
Modified:
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-03
17:08:28 UTC (rev 4349)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java 2008-07-03
18:37:32 UTC (rev 4350)
@@ -38,7 +38,7 @@
private final AtomicInteger refcount = new AtomicInteger(1);
private final Executor executor;
- private static Logger log = Logger.getLogger(AbstractAutoCloseable.class);
+ private static final Logger log = Logger.getLogger(AbstractAutoCloseable.class);
protected AbstractAutoCloseable(final Executor executor) {
super(executor);
Modified:
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-03
17:08:28 UTC (rev 4349)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-03
18:37:32 UTC (rev 4350)
@@ -26,6 +26,8 @@
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;
@@ -36,6 +38,8 @@
*/
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();
@@ -82,4 +86,15 @@
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/EndpointImpl.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-03
17:08:28 UTC (rev 4349)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-03
18:37:32 UTC (rev 4350)
@@ -81,10 +81,6 @@
// Lifecycle
- public void create() {
- // todo security check
- }
-
public void start() {
// todo security check
if (executor == null) {
@@ -104,10 +100,6 @@
// todo
}
- public void destroy() {
- executor = null;
- }
-
// Endpoint implementation
public ConcurrentMap<Object, Object> getAttributes() {
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
---
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03
17:08:28 UTC (rev 4349)
+++
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03
18:37:32 UTC (rev 4350)
@@ -1,7 +1,6 @@
package org.jboss.cx.remoting;
import java.io.IOException;
-import java.util.concurrent.ConcurrentMap;
import org.jboss.cx.remoting.core.EndpointImpl;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
@@ -15,19 +14,10 @@
public static Endpoint createEndpoint(String name) throws IOException {
synchronized (lifecycle) {
- boolean ok = false;
final EndpointImpl endpointImpl = new EndpointImpl();
endpointImpl.setName(name);
- endpointImpl.create();
- try {
- endpointImpl.start();
- ok = true;
- return endpointImpl;
- } finally {
- if (! ok) {
- endpointImpl.destroy();
- }
- }
+ endpointImpl.start();
+ return endpointImpl;
}
}
@@ -35,9 +25,7 @@
synchronized (lifecycle) {
if (endpoint instanceof EndpointImpl) {
final EndpointImpl endpointImpl = (EndpointImpl) endpoint;
- final ConcurrentMap<Object, Object> attributes =
endpointImpl.getAttributes();
endpointImpl.stop();
- endpointImpl.destroy();
}
}
}
Show replies by date