From: <tk...@hy...> - 2008-07-02 22:33:09
|
Author: tkeeney Date: 2008-07-02 15:33:08 -0700 (Wed, 02 Jul 2008) New Revision: 9984 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=9984 Modified: trunk/src/org/hyperic/hq/agent/AgentStartupCallback.java Log: If the agent up callback port is not specified (such as when starting the agent through the AgentRunner) don't try the callback. Modified: trunk/src/org/hyperic/hq/agent/AgentStartupCallback.java =================================================================== --- trunk/src/org/hyperic/hq/agent/AgentStartupCallback.java 2008-07-02 22:32:06 UTC (rev 9983) +++ trunk/src/org/hyperic/hq/agent/AgentStartupCallback.java 2008-07-02 22:33:08 UTC (rev 9984) @@ -31,7 +31,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hyperic.hq.bizapp.agent.CommandsAPIInfo; /** * A callback class that notifies the starting entity (most likely the agent @@ -46,19 +45,15 @@ /** * Creates an instance. * - * @throws AgentConfigException if the "camUpPort" is not specified. + * @param config The agent configuration. * @throws IOException if the callback fails to establish a connection * to the starting entity. */ - public AgentStartupCallback() throws AgentConfigException, IOException { - String startupPort = System.getProperty(CommandsAPIInfo.PROP_UP_PORT); + public AgentStartupCallback(AgentConfig config) throws AgentConfigException, IOException { - if(startupPort == null){ - throw new AgentConfigException("Failure to find startup " + - "reporting port in sys properties"); - } else { - int sPort = Integer.parseInt(startupPort); - + int sPort = config.getNotifyUpPort(); + + if (sPort != -1) { try { _startupSock = new Socket("127.0.0.1", sPort); } catch(IOException exc){ @@ -67,8 +62,11 @@ throw new IOException("Failed to connect to startup " + "port (" + sPort + "): " + exc.getMessage()); - } - } + } + } else { + _log.debug("Agent startup callback is disabled"); + _startupSock = null; + } } /** @@ -89,13 +87,19 @@ * Clean up resources just in case! */ protected void finalize() throws Throwable { - try { - _startupSock.close(); - } catch (Exception e) { + if (_startupSock != null) { + try { + _startupSock.close(); + } catch (Exception e) { + } } } private void writeStartupState(int state) { + if (_startupSock == null) { + _log.debug("Agent startup callback is disabled"); + } + try { DataOutputStream dOs = new DataOutputStream(_startupSock.getOutputStream()); |