Author: pferraro
Date: 2008-09-24 13:30:20 -0400 (Wed, 24 Sep 2008)
New Revision: 1898
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Add explicit closing of input/output socket stream.
Cache socket reader/writer until closed.
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-24
15:28:12 UTC (rev 1897)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-24
17:30:20 UTC (rev 1898)
@@ -372,6 +372,7 @@
}
return result.toString();
}
+
public InetAddress getLocalAddress() throws IOException
{
IOException firstException = null;
@@ -834,6 +835,10 @@
@GuardedBy("Proxy.this")
private Socket socket = null;
+ @GuardedBy("Proxy.this")
+ private BufferedReader reader = null;
+ @GuardedBy("Proxy.this")
+ private BufferedWriter writer = null;
Proxy(InetAddress address, int port, SocketFactory socketFactory,
MCMPHandlerConfiguration config)
{
@@ -944,17 +949,25 @@
/**
* Convenience method that returns a reader to the proxy.
*/
- BufferedReader getConnectionReader() throws IOException
+ synchronized BufferedReader getConnectionReader() throws IOException
{
- return new BufferedReader(new
InputStreamReader(this.getConnection().getInputStream()));
+ if (this.reader == null)
+ {
+ this.reader = new BufferedReader(new
InputStreamReader(this.getConnection().getInputStream()));
+ }
+ return this.reader;
}
/**
* Convenience method that returns a writer to the proxy.
*/
- BufferedWriter getConnectionWriter() throws IOException
+ synchronized BufferedWriter getConnectionWriter() throws IOException
{
- return new BufferedWriter(new
OutputStreamWriter(this.getConnection().getOutputStream()));
+ if (this.writer == null)
+ {
+ this.writer = new BufferedWriter(new
OutputStreamWriter(this.getConnection().getOutputStream()));
+ }
+ return this.writer;
}
/**
@@ -962,16 +975,43 @@
*/
synchronized void closeConnection()
{
- if ((this.socket != null) && !this.socket.isClosed())
+ if (this.reader != null)
{
try
{
- this.socket.close();
+ this.reader.close();
}
catch (IOException e)
{
// Ignore
}
+ this.reader = null;
+ }
+ if (this.writer != null)
+ {
+ try
+ {
+ this.writer.close();
+ }
+ catch (IOException e)
+ {
+ // Ignore
+ }
+ this.writer = null;
+ }
+ if (this.socket != null)
+ {
+ if (!this.socket.isClosed())
+ {
+ try
+ {
+ this.socket.close();
+ }
+ catch (IOException e)
+ {
+ // Ignore
+ }
+ }
this.socket = null;
}
}
@@ -986,7 +1026,7 @@
this.ioExceptionLogged = ioErrorLogged;
}
}
-
+
@Immutable
private static class MCMPServerStateImpl implements MCMPServerState, Serializable
{
Show replies by date