Author: david.lloyd(a)jboss.com
Date: 2010-03-25 19:32:01 -0400 (Thu, 25 Mar 2010)
New Revision: 5838
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClosingCloseHandler.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/SpiUtils.java
Log:
Extract ClosingCloseHandler into its own class
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClosingCloseHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClosingCloseHandler.java
(rev 0)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClosingCloseHandler.java 2010-03-25
23:32:01 UTC (rev 5838)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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 java.io.Closeable;
+import org.jboss.xnio.IoUtils;
+
+/**
+ * A close handler which closes some resource.
+ */
+public final class ClosingCloseHandler<T> implements CloseHandler<T> {
+ private final Closeable c;
+
+ /**
+ * Construct a new instance.
+ *
+ * @param c the resource to close
+ */
+ public ClosingCloseHandler(final Closeable c) {
+ this.c = c;
+ }
+
+ /** {@inheritDoc} */
+ public void handleClose(final T closed) {
+ IoUtils.safeClose(c);
+ }
+}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionHandler.java 2010-03-25
23:25:26 UTC (rev 5837)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionHandler.java 2010-03-25
23:32:01 UTC (rev 5838)
@@ -32,6 +32,7 @@
import org.jboss.marshalling.MarshallingConfiguration;
import org.jboss.marshalling.util.IntKeyMap;
import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.ClosingCloseHandler;
import org.jboss.remoting3.IndeterminateOutcomeException;
import org.jboss.remoting3.ServiceOpenException;
import org.jboss.remoting3.spi.AbstractHandleableCloseable;
@@ -83,11 +84,7 @@
config.setStreamHeader(Marshalling.nullStreamHeader());
// fixed for now (v0)
config.setVersion(2);
- remoteConnection.addCloseHandler(new CloseHandler<RemoteConnection>() {
- public void handleClose(final RemoteConnection closed) {
- IoUtils.safeClose(RemoteConnectionHandler.this);
- }
- });
+ remoteConnection.addCloseHandler(new
ClosingCloseHandler<RemoteConnection>(this));
marshallingConfiguration = config;
}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/SpiUtils.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/SpiUtils.java 2010-03-25
23:25:26 UTC (rev 5837)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/SpiUtils.java 2010-03-25
23:32:01 UTC (rev 5838)
@@ -25,6 +25,7 @@
import java.io.Closeable;
import java.io.IOException;
import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.ClosingCloseHandler;
import org.jboss.remoting3.RequestCancelHandler;
import org.jboss.remoting3.RequestContext;
import org.jboss.xnio.IoUtils;
@@ -159,11 +160,7 @@
* @param c the resource to close
* @return the close handler
*/
- public static CloseHandler<Object> closingCloseHandler(final Closeable c) {
- return new CloseHandler<Object>() {
- public void handleClose(final Object closed) {
- IoUtils.safeClose(c);
- }
- };
+ public static <T> CloseHandler<T> closingCloseHandler(final Closeable c)
{
+ return new ClosingCloseHandler<T>(c);
}
}