mwomack 2003/10/19 22:27:15 Modified: src/java/org/apache/log4j/net XMLSocketReceiver.java SocketReceiver.java SocketHubReceiver.java JMSReceiver.java Log: Various cleanup. Changed equals() method to new Plugin method isEquivalent. This method is used by PluginRegistry when a new plugin is being started. If an equivalent plugin is already running, it is left running and the new plugin is not started. Revision Changes Path 1.3 +14 -13 jakarta-log4j/src/java/org/apache/log4j/net/XMLSocketReceiver.java Index: XMLSocketReceiver.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/XMLSocketReceiver.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XMLSocketReceiver.java 9 Jul 2003 06:10:01 -0000 1.2 +++ XMLSocketReceiver.java 20 Oct 2003 05:27:15 -0000 1.3 @@ -51,6 +51,7 @@ import org.apache.log4j.helpers.LogLog; import org.apache.log4j.plugins.Receiver; +import org.apache.log4j.plugins.Plugin; import org.apache.log4j.spi.LoggerRepository; import java.net.ServerSocket; @@ -114,19 +115,19 @@ } /** - Returns true if the receiver is the same class and they are - configured for the same port, logger repository, and name. - This is used when determining if the same receiver is being - configured. */ - public boolean equals(Object obj) { - if ((obj != null) && obj instanceof XMLSocketReceiver) { - XMLSocketReceiver sReceiver = (XMLSocketReceiver) obj; - String sName = sReceiver.getName(); - - return ((repository == sReceiver.getLoggerRepository()) - && (port == sReceiver.getPort()) - && (((sName != null) && sName.equals(sReceiver.getName())) - || ((sName == null) && (sReceiver.getName() == null)))); + * Returns true if the receiver is the same class and they are + * configured for the same properties, and super class also considers + * them to be equivalent. This is used by PluginRegistry when determining + * if the a similarly configured receiver is being started. + * + * @param testPlugin The plugin to test equivalency against. + * @return boolean True if the testPlugin is equivalent to this plugin. + */ + public boolean isEquivalent(Plugin testPlugin) { + if ((testPlugin != null) && testPlugin instanceof XMLSocketReceiver) { + XMLSocketReceiver sReceiver = (XMLSocketReceiver) testPlugin; + + return (port == sReceiver.getPort() && super.isEquivalent(testPlugin)); } return false; 1.6 +14 -13 jakarta-log4j/src/java/org/apache/log4j/net/SocketReceiver.java Index: SocketReceiver.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/SocketReceiver.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SocketReceiver.java 24 Jun 2003 08:21:52 -0000 1.5 +++ SocketReceiver.java 20 Oct 2003 05:27:15 -0000 1.6 @@ -52,6 +52,7 @@ import org.apache.log4j.helpers.LogLog; import org.apache.log4j.plugins.Pauseable; import org.apache.log4j.plugins.Receiver; +import org.apache.log4j.plugins.Plugin; import org.apache.log4j.spi.LoggerRepository; import org.apache.log4j.spi.LoggingEvent; @@ -119,19 +120,19 @@ } /** - Returns true if the receiver is the same class and they are - configured for the same port, logger repository, and name. - This is used when determining if the same receiver is being - configured. */ - public boolean equals(Object obj) { - if ((obj != null) && obj instanceof SocketReceiver) { - SocketReceiver sReceiver = (SocketReceiver) obj; - String sName = sReceiver.getName(); - - return ((repository == sReceiver.getLoggerRepository()) - && (port == sReceiver.getPort()) - && (((sName != null) && sName.equals(sReceiver.getName())) - || ((sName == null) && (sReceiver.getName() == null)))); + * Returns true if the receiver is the same class and they are + * configured for the same properties, and super class also considers + * them to be equivalent. This is used by PluginRegistry when determining + * if the a similarly configured receiver is being started. + * + * @param testPlugin The plugin to test equivalency against. + * @return boolean True if the testPlugin is equivalent to this plugin. + */ + public boolean isEquivalent(Plugin testPlugin) { + if ((testPlugin != null) && testPlugin instanceof SocketReceiver) { + SocketReceiver sReceiver = (SocketReceiver) testPlugin; + + return (port == sReceiver.getPort() && super.isEquivalent(testPlugin)); } return false; 1.8 +15 -12 jakarta-log4j/src/java/org/apache/log4j/net/SocketHubReceiver.java Index: SocketHubReceiver.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/SocketHubReceiver.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SocketHubReceiver.java 18 Sep 2003 03:05:31 -0000 1.7 +++ SocketHubReceiver.java 20 Oct 2003 05:27:15 -0000 1.8 @@ -14,6 +14,7 @@ import org.apache.log4j.spi.LoggerRepository; import org.apache.log4j.plugins.Receiver; +import org.apache.log4j.plugins.Plugin; import org.apache.log4j.helpers.LogLog; /** @@ -129,20 +130,22 @@ } /** - Returns true if the receiver is the same class and they are - configured for the same port, logger repository, and name. - This is used when determining if the same receiver is being - configured. */ - public boolean equals(Object obj) { - if (obj != null && obj instanceof SocketHubReceiver) { - SocketHubReceiver sReceiver = (SocketHubReceiver)obj; - String sName = sReceiver.getName(); - return (repository == sReceiver.getLoggerRepository() && - port == sReceiver.getPort() && + * Returns true if the receiver is the same class and they are + * configured for the same properties, and super class also considers + * them to be equivalent. This is used by PluginRegistry when determining + * if the a similarly configured receiver is being started. + * + * @param testPlugin The plugin to test equivalency against. + * @return boolean True if the testPlugin is equivalent to this plugin. + */ + public boolean isEquivalent(Plugin testPlugin) { + if (testPlugin != null && testPlugin instanceof SocketHubReceiver) { + SocketHubReceiver sReceiver = (SocketHubReceiver)testPlugin; + + return (port == sReceiver.getPort() && host.equals(sReceiver.getHost()) && reconnectionDelay == sReceiver.getReconnectionDelay() && - ((sName != null && sName.equals(sReceiver.getName()) || - (sName == null && sReceiver.getName() == null)))); + super.isEquivalent(testPlugin)); } return false; 1.5 +30 -19 jakarta-log4j/src/java/org/apache/log4j/net/JMSReceiver.java Index: JMSReceiver.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/JMSReceiver.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JMSReceiver.java 5 May 2003 20:42:56 -0000 1.4 +++ JMSReceiver.java 20 Oct 2003 05:27:15 -0000 1.5 @@ -24,6 +24,7 @@ import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; +import org.apache.log4j.plugins.Plugin; import org.apache.log4j.plugins.Receiver; /** @@ -80,14 +81,16 @@ } /** - Sets the JMS topic name to use when creating the - JMS connection. */ + * Sets the JMS topic name to use when creating the + * JMS connection. + */ public void setTopicName(String _topicName) { topicName = _topicName; } /** - Gets the curernt JMS topic name property. */ + * Gets the curernt JMS topic name property. + */ public String getTopicName() { return topicName; } @@ -100,37 +103,45 @@ } /** - Gets the curernt user id property. */ + * Gets the current user id property. + */ public String getUserId() { return userId; } /** - Sets the password to use when creating the - JMS connection. */ + * Sets the password to use when creating the + * JMS connection. + */ public void setPassword(String _password) { password = _password; } /** - Gets the curernt password property. */ + * Gets the curernt password property. + */ public String getPassword() { return password; } /** - Returns true if the receiver is the same class and they are - configured for the same topic info, logger repository, and name. - This is used when determining if the same receiver is being - configured. */ - public boolean equals(Object obj) { - if (obj != null && obj instanceof JMSReceiver) { - JMSReceiver receiver = (JMSReceiver)obj; - String rName = receiver.getName(); - return (repository == receiver.getLoggerRepository() && - topicFactoryName.equals(receiver.getTopicFactoryName()) && - ((rName != null && rName.equals(this.getName()) || - (rName == null && this.getName() == null)))); + * Returns true if the receiver is the same class and they are + * configured for the same properties, and super class also considers + * them to be equivalent. This is used by PluginRegistry when determining + * if the a similarly configured receiver is being started. + * + * @param testPlugin The plugin to test equivalency against. + * @return boolean True if the testPlugin is equivalent to this plugin. + */ + public boolean isEquivalent(Plugin testPlugin) { + // only do full check if an instance of this class + if (testPlugin instanceof JMSReceiver) { + + JMSReceiver receiver = (JMSReceiver)testPlugin; + + // check for same topic name and super class equivalency + return (topicFactoryName.equals(receiver.getTopicFactoryName()) && + super.isEquivalent(testPlugin)); } return false;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]