/***********************************************************************
* Copyright (c) 2000-2004 The Apache Software Foundation. *
* All rights reserved. *
* ------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); you *
* may not use this file except in compliance with the License. You *
* may obtain a copy of the License at: *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
* implied. See the License for the specific language governing *
* permissions and limitations under the License. *
***********************************************************************/
package org.apache.james.imapserver;
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.context.Context;
import org.apache.avalon.framework.component.Component;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* The Server listens on a specified port and passes connections to a
* ConnectionHandler. In this implementation, each ConnectionHandler runs in
* its own thread.
*
* @version 0.2 on 04 Aug 2002
*/
public class IMAPServer
extends AbstractService implements Component {
private Context _context;
protected ConnectionHandlerFactory createFactory()
{
return new DefaultHandlerFactory( SingleThreadedConnectionHandler.class );
}
public void configure( final Configuration configuration )
throws ConfigurationException {
m_port = configuration.getChild( "port" ).getValueAsInteger( 143 );
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 String useTLS = configuration.getChild("useTLS").getValue( "" );
if( useTLS.equals( "TRUE" ) ) m_serverSocketType = "ssl";
super.configure( configuration.getChild( "handler" ) );
}
public void initialize() throws Exception {
getLogger().info( "IMAPServer init..." );
getLogger().info( "IMAPListener using " + m_serverSocketType + " on port " + m_port );
super.initialize();
getLogger().info("IMAPServer ...init end");
System.out.println("Started IMAP Server "+m_connectionName);
}
}