From: <tk...@hy...> - 2008-05-14 06:46:03
|
Author: tkeeney Date: 2008-05-13 23:45:56 -0700 (Tue, 13 May 2008) New Revision: 9520 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=9520 Modified: trunk/src/org/hyperic/hq/agent/AgentStreamPair.java trunk/src/org/hyperic/hq/agent/client/AgentConnection.java trunk/src/org/hyperic/hq/agent/client/SocketStreamPair.java Log: Make sure to clean up the stream pair correctly especially on agent file transfer. Modified: trunk/src/org/hyperic/hq/agent/AgentStreamPair.java =================================================================== --- trunk/src/org/hyperic/hq/agent/AgentStreamPair.java 2008-05-14 06:45:05 UTC (rev 9519) +++ trunk/src/org/hyperic/hq/agent/AgentStreamPair.java 2008-05-14 06:45:56 UTC (rev 9520) @@ -25,6 +25,7 @@ package org.hyperic.hq.agent; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -44,4 +45,18 @@ public OutputStream getOutputStream(){ return this.outStream; } + + public void close() throws IOException { + try { + getInputStream().close(); + } catch (Exception e) { + // swallow + } + + try { + getOutputStream().close(); + } catch (Exception e) { + // swallow + } + } } Modified: trunk/src/org/hyperic/hq/agent/client/AgentConnection.java =================================================================== --- trunk/src/org/hyperic/hq/agent/client/AgentConnection.java 2008-05-14 06:45:05 UTC (rev 9519) +++ trunk/src/org/hyperic/hq/agent/client/AgentConnection.java 2008-05-14 06:45:56 UTC (rev 9520) @@ -216,7 +216,7 @@ exc.getMessage()); } finally { try { - streamPair.getSocket().close(); + streamPair.close(); } catch(IOException ignoreexc){ } } Modified: trunk/src/org/hyperic/hq/agent/client/SocketStreamPair.java =================================================================== --- trunk/src/org/hyperic/hq/agent/client/SocketStreamPair.java 2008-05-14 06:45:05 UTC (rev 9519) +++ trunk/src/org/hyperic/hq/agent/client/SocketStreamPair.java 2008-05-14 06:45:56 UTC (rev 9520) @@ -27,12 +27,13 @@ import org.hyperic.hq.agent.AgentStreamPair; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; -class SocketStreamPair +public class SocketStreamPair extends AgentStreamPair { private Socket sock; @@ -42,7 +43,20 @@ this.sock = s; } - Socket getSocket(){ + public Socket getSocket(){ return this.sock; } + + public void close() throws IOException { + try { + super.close(); + } finally { + Socket socket = getSocket(); + + if (!socket.isClosed()) { + socket.close(); + } + } + } + } |