danny 2002/09/24 08:33:49
Modified: src/java/org/apache/james/smtpserver SMTPServer.java
src/java/org/apache/james/pop3server POP3Server.java
src/java/org/apache/james/nntpserver NNTPServer.java
Log:
Added an enabled="true|false" attribute to block conf for these blocks to easily
turn listening on and off without having to fully remove the block.
Revision Changes Path
1.11 +65 -80
jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java
Index: SMTPServer.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SMTPServer.java 14 Sep 2002 07:25:00 -0000 1.10
+++ SMTPServer.java 24 Sep 2002 15:33:48 -0000 1.11
@@ -6,7 +6,6 @@
* the LICENSE file.
*/
package org.apache.james.smtpserver;
-
import org.apache.avalon.cornerstone.services.connection.AbstractService;
import org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory;
import org.apache.avalon.cornerstone.services.connection.DefaultHandlerFactory;
@@ -15,13 +14,10 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.Component;
-
import org.apache.mailet.MailetContext;
import org.apache.james.Constants;
-
import java.net.InetAddress;
import java.net.UnknownHostException;
-
/**
* <p>Accepts SMTP connections on a server socket and dispatches them to
SMTPHandlers.</p>
*
@@ -31,76 +27,63 @@
* @author Federico Barbieri <[EMAIL PROTECTED]>
* @author Matthew Pangaro <[EMAIL PROTECTED]>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Danny Angus</a>
*/
-
/*
* IMPORTANT: SMTPServer extends AbstractService. If you implement ANY
* lifecycle methods, you MUST call super.<method> as well.
*/
-
-public class SMTPServer
- extends AbstractService implements Component {
-
+public class SMTPServer extends AbstractService implements Component {
/**
* The mailet context - we access it here to set the hello name for the Mailet
API
*/
MailetContext mailetcontext;
-
- protected ConnectionHandlerFactory createFactory()
- {
- return new DefaultHandlerFactory( SMTPHandler.class );
+ private boolean enabled = true;
+ protected ConnectionHandlerFactory createFactory() {
+ return new DefaultHandlerFactory(SMTPHandler.class);
+ }
+ /**
+ * Pass the <code>ComponentManager</code> to the <code>composer</code>.
+ * The instance uses the specified <code>ComponentManager</code> to
+ * acquire the components it needs for execution.
+ *
+ * @param componentManager The <code>ComponentManager</code> which this
+ * <code>Composable</code> uses.
+ * @throws ComponentException if an error occurs
+ */
+ public void compose(final ComponentManager componentManager) throws
ComponentException {
+ super.compose(componentManager);
+ mailetcontext = (MailetContext)
componentManager.lookup("org.apache.mailet.MailetContext");
}
-
- /**
- * Pass the <code>ComponentManager</code> to the <code>composer</code>.
- * The instance uses the specified <code>ComponentManager</code> to
- * acquire the components it needs for execution.
- *
- * @param componentManager The <code>ComponentManager</code> which this
- * <code>Composable</code> uses.
- * @throws ComponentException if an error occurs
- */
- public void compose(final ComponentManager componentManager) throws
ComponentException {
- super.compose(componentManager);
- mailetcontext = (MailetContext)
componentManager.lookup("org.apache.mailet.MailetContext");
- }
-
/**
* Pass the <code>Configuration</code> to the instance.
*
* @param configuration the class configurations.
* @throws ConfigurationException if an error occurs
*/
- public void configure( final Configuration configuration )
- throws ConfigurationException {
-
- m_port = configuration.getChild( "port" ).getValueAsInteger( 25 );
-
- try
- {
- final String bindAddress = configuration.getChild( "bind" ).getValue(
null );
- if( null != bindAddress )
- {
- m_bindTo = InetAddress.getByName( bindAddress );
+ public void configure(final Configuration configuration) throws
ConfigurationException {
+ m_port = configuration.getChild("port").getValueAsInteger(25);
+ if (configuration.getAttribute("enabled").equalsIgnoreCase("false")) {
+ enabled = false;
+ } else {
+ try {
+ final String bindAddress =
configuration.getChild("bind").getValue(null);
+ if (null != bindAddress) {
+ m_bindTo = InetAddress.getByName(bindAddress);
+ }
+ } catch (final UnknownHostException unhe) {
+ throw new ConfigurationException("Malformed bind parameter", unhe);
}
+ final boolean useTLS =
configuration.getChild("useTLS").getValueAsBoolean(false);
+ if (useTLS) {
+ m_serverSocketType = "ssl";
+ }
+ super.configure(configuration.getChild("handler"));
+ // make our "helloName" available through the MailetContext
+ String helloName =
SMTPHandler.configHelloName(configuration.getChild("handler"));
+ mailetcontext.setAttribute(Constants.HELLO_NAME, helloName);
}
- catch( final UnknownHostException unhe )
- {
- throw new ConfigurationException( "Malformed bind parameter", unhe );
- }
-
- final boolean useTLS = configuration.getChild("useTLS").getValueAsBoolean(
false );
- if( useTLS ) {
- m_serverSocketType = "ssl";
- }
-
- super.configure( configuration.getChild( "handler" ) );
-
- // make our "helloName" available through the MailetContext
- String helloName = SMTPHandler.configHelloName(configuration.getChild(
"handler" ));
- mailetcontext.setAttribute(Constants.HELLO_NAME, helloName);
}
-
/**
* Initialize the component. Initialization includes
* allocating any resources required throughout the
@@ -109,21 +92,25 @@
* @throws Exception if an error occurs
*/
public void initialize() throws Exception {
- getLogger().info("SMTPServer init...");
- super.initialize();
- StringBuffer logBuffer =
- new StringBuffer(128)
- .append("SMTPServer using ")
- .append(m_serverSocketType)
- .append(" on port ")
- .append(m_port)
- .append(" at ")
- .append(m_bindTo);
- getLogger().info( logBuffer.toString() );
- getLogger().info("SMTPServer ...init end");
- System.out.println("Started SMTP Server "+m_connectionName);
+ if (enabled) {
+ getLogger().info("SMTPServer init...");
+ super.initialize();
+ StringBuffer logBuffer =
+ new StringBuffer(128)
+ .append("SMTPServer using ")
+ .append(m_serverSocketType)
+ .append(" on port ")
+ .append(m_port)
+ .append(" at ")
+ .append(m_bindTo);
+ getLogger().info(logBuffer.toString());
+ getLogger().info("SMTPServer ...init end");
+ System.out.println("SMTP Server Started " + m_connectionName);
+ } else {
+ getLogger().info("SMTP Server Disabled");
+ System.out.println("SMTP Server Disabled");
+ }
}
-
/**
* The dispose operation is called at the end of a components lifecycle.
* Instances of this class use this method to release and destroy any
@@ -131,16 +118,14 @@
*
* @throws Exception if an error is encountered during shutdown
*/
- public void dispose()
- {
- getLogger().info( "SMTPServer dispose..." );
- getLogger().info( "SMTPServer dispose..." + m_connectionName);
- super.dispose();
-
- // This is needed to make sure sockets are promptly closed on Windows 2000
- System.gc();
-
- getLogger().info( "SMTPServer ...dispose end" );
+ public void dispose() {
+ if (enabled) {
+ getLogger().info("SMTPServer dispose...");
+ getLogger().info("SMTPServer dispose..." + m_connectionName);
+ super.dispose();
+ // This is needed to make sure sockets are promptly closed on Windows
2000
+ System.gc();
+ getLogger().info("SMTPServer ...dispose end");
+ }
}
}
-
1.9 +48 -57
jakarta-james/src/java/org/apache/james/pop3server/POP3Server.java
Index: POP3Server.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/pop3server/POP3Server.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- POP3Server.java 23 Aug 2002 08:00:28 -0000 1.8
+++ POP3Server.java 24 Sep 2002 15:33:48 -0000 1.9
@@ -6,17 +6,14 @@
* the LICENSE file.
*/
package org.apache.james.pop3server;
-
import org.apache.avalon.cornerstone.services.connection.AbstractService;
import org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory;
import org.apache.avalon.cornerstone.services.connection.DefaultHandlerFactory;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.Component;
-
import java.net.InetAddress;
import java.net.UnknownHostException;
-
/**
* <p>Accepts POP3 connections on a server socket and dispatches them to
POP3Handlers.</p>
*
@@ -24,52 +21,44 @@
*
* @version 1.0.0, 24/04/1999
* @author Federico Barbieri <[EMAIL PROTECTED]>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Danny Angus</a>
*/
-public class POP3Server
- extends AbstractService implements Component {
-
+public class POP3Server extends AbstractService implements Component {
+ private boolean enabled = true;
/**
* Creates a subclass specific handler factory for use by the superclass.
*
* @return a ConnectionHandlerFactory that produces POP3Handlers
*/
- protected ConnectionHandlerFactory createFactory()
- {
- return new DefaultHandlerFactory( POP3Handler.class );
+ protected ConnectionHandlerFactory createFactory() {
+ return new DefaultHandlerFactory(POP3Handler.class);
}
-
/**
* Pass the <code>Configuration</code> to the instance.
*
* @param configuration the class configurations.
* @throws ConfigurationException if an error occurs
*/
- public void configure( final Configuration configuration )
- throws ConfigurationException {
-
- m_port = configuration.getChild( "port" ).getValueAsInteger( 25 );
-
- try
- {
- final String bindAddress = configuration.getChild( "bind" ).getValue(
null );
- if( null != bindAddress )
- {
- m_bindTo = InetAddress.getByName( bindAddress );
+ public void configure(final Configuration configuration) throws
ConfigurationException {
+ if (configuration.getAttribute("enabled").equalsIgnoreCase("false")) {
+ enabled = false;
+ } else {
+ m_port = configuration.getChild("port").getValueAsInteger(25);
+ try {
+ final String bindAddress =
configuration.getChild("bind").getValue(null);
+ if (null != bindAddress) {
+ m_bindTo = InetAddress.getByName(bindAddress);
+ }
+ } catch (final UnknownHostException unhe) {
+ throw new ConfigurationException("Malformed bind parameter", unhe);
}
+ final boolean useTLS =
configuration.getChild("useTLS").getValueAsBoolean(false);
+ if (useTLS) {
+ m_serverSocketType = "ssl";
+ }
+ super.configure(configuration.getChild("handler"));
}
- catch( final UnknownHostException unhe )
- {
- throw new ConfigurationException( "Malformed bind parameter", unhe );
- }
-
- final boolean useTLS = configuration.getChild("useTLS").getValueAsBoolean(
false );
- if( useTLS ) {
- m_serverSocketType = "ssl";
- }
-
- super.configure( configuration.getChild( "handler" ) );
}
-
/**
* Initialize the component. Initialization includes
* allocating any resources required throughout the
@@ -78,21 +67,25 @@
* @throws Exception if an error occurs
*/
public void initialize() throws Exception {
- getLogger().info( "POP3Server init..." );
- StringBuffer logBuffer =
- new StringBuffer(128)
- .append("POP3Listener using ")
- .append(m_serverSocketType)
- .append(" on port ")
- .append(m_port)
- .append(" at ")
- .append(m_bindTo);
- getLogger().info( logBuffer.toString() );
- super.initialize();
- getLogger().info( "POP3Server ...init end" );
- System.out.println("Started POP3 Server " + m_connectionName);
+ if (enabled) {
+ getLogger().info("POP3Server init...");
+ StringBuffer logBuffer =
+ new StringBuffer(128)
+ .append("POP3Listener using ")
+ .append(m_serverSocketType)
+ .append(" on port ")
+ .append(m_port)
+ .append(" at ")
+ .append(m_bindTo);
+ getLogger().info(logBuffer.toString());
+ super.initialize();
+ getLogger().info("POP3Server ...init end");
+ System.out.println("POP3 Server Started " + m_connectionName);
+ } else {
+ getLogger().info("POP3Server Disabled");
+ System.out.println("POP3 Server Disabled");
+ }
}
-
/**
* The dispose operation is called at the end of a components lifecycle.
* Instances of this class use this method to release and destroy any
@@ -101,15 +94,13 @@
* @throws Exception if an error is encountered during shutdown
*/
public void dispose() {
- getLogger().info( "POP3Server dispose..." );
- getLogger().info( "POP3Server dispose..." + m_connectionName);
- super.dispose();
-
- // This is needed to make sure sockets are promptly closed on Windows 2000
- System.gc();
-
- getLogger().info( "POP3Server ...dispose end" );
+ if (enabled) {
+ getLogger().info("POP3Server dispose...");
+ getLogger().info("POP3Server dispose..." + m_connectionName);
+ super.dispose();
+ // This is needed to make sure sockets are promptly closed on Windows
2000
+ System.gc();
+ getLogger().info("POP3Server ...dispose end");
+ }
}
-
}
-
1.9 +35 -33
jakarta-james/src/java/org/apache/james/nntpserver/NNTPServer.java
Index: NNTPServer.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/NNTPServer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- NNTPServer.java 18 Aug 2002 07:30:17 -0000 1.8
+++ NNTPServer.java 24 Sep 2002 15:33:49 -0000 1.9
@@ -6,60 +6,53 @@
* the LICENSE file.
*/
package org.apache.james.nntpserver;
-
import org.apache.avalon.cornerstone.services.connection.AbstractService;
import org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory;
import org.apache.avalon.cornerstone.services.connection.DefaultHandlerFactory;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.Component;
-
import java.net.InetAddress;
import java.net.UnknownHostException;
-
/**
* NNTP Server Protocol Handler
*
* @author Harmeet Bedi <[EMAIL PROTECTED]>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Danny Angus</a>
*/
public class NNTPServer extends AbstractService implements Component {
-
+ private boolean enabled = true;
protected ConnectionHandlerFactory createFactory() {
- return new DefaultHandlerFactory( NNTPHandler.class );
+ return new DefaultHandlerFactory(NNTPHandler.class);
}
-
/**
* Pass the <code>Configuration</code> to the instance.
*
* @param configuration the class configurations.
* @throws ConfigurationException if an error occurs
*/
- public void configure( final Configuration configuration )
- throws ConfigurationException
- {
- //System.out.println(getClass().getName() + ": configure");
- m_port = configuration.getChild( "port" ).getValueAsInteger( 119 );
-
- try {
- String bindAddress = configuration.getChild( "bind" ).getValue( null );
- if( null != bindAddress )
- m_bindTo = InetAddress.getByName( bindAddress );
- } catch( final UnknownHostException unhe ) {
- throw new ConfigurationException( "Malformed bind parameter", unhe );
- }
-
- final boolean useTLS = configuration.getChild("userTLS").getValueAsBoolean(
false );
- if ( useTLS )
- {
- m_serverSocketType = "ssl";
- }
-
- super.configure( configuration.getChild( "handler" ) );
- if (getLogger().isInfoEnabled()) {
- getLogger().info("configured NNTPServer to run at : " + m_port);
+ public void configure(final Configuration configuration) throws
ConfigurationException {
+ if (configuration.getAttribute("enabled").equalsIgnoreCase("false")) {
+ enabled = false;
+ } else {
+ m_port = configuration.getChild("port").getValueAsInteger(119);
+ try {
+ String bindAddress = configuration.getChild("bind").getValue(null);
+ if (null != bindAddress)
+ m_bindTo = InetAddress.getByName(bindAddress);
+ } catch (final UnknownHostException unhe) {
+ throw new ConfigurationException("Malformed bind parameter", unhe);
+ }
+ final boolean useTLS =
configuration.getChild("userTLS").getValueAsBoolean(false);
+ if (useTLS) {
+ m_serverSocketType = "ssl";
+ }
+ super.configure(configuration.getChild("handler"));
+ if (getLogger().isInfoEnabled()) {
+ getLogger().info("configured NNTPServer to run at : " + m_port);
+ }
}
}
-
/**
* Initialize the component. Initialization includes
* allocating any resources required throughout the
@@ -68,8 +61,17 @@
* @throws Exception if an error occurs
*/
public void initialize() throws Exception {
- //System.out.println(getClass().getName() + ": init");
- super.initialize();
- System.out.println("Started NNTP Server "+m_connectionName);
+ if (enabled) {
+ super.initialize();
+ System.out.println("NNTP Server Started " + m_connectionName);
+ } else {
+ getLogger().info("NNTP Server Disabled");
+ System.out.println("NNTP Server Disabled");
+ }
}
+ public void dispose() {
+ if (enabled) {
+ super.dispose();
+ }
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>