KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > IMAPServer


1 /***********************************************************************
2  * Copyright (c) 2000-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * may obtain a copy of the License at: *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17
18 package org.apache.james.imapserver;
19
20 import org.apache.avalon.cornerstone.services.connection.AbstractService;
21 import org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory;
22 import org.apache.avalon.cornerstone.services.connection.DefaultHandlerFactory;
23 import org.apache.avalon.framework.configuration.Configuration;
24 import org.apache.avalon.framework.configuration.ConfigurationException;
25 import org.apache.avalon.framework.context.Context;
26 import org.apache.avalon.framework.component.Component;
27
28 import java.net.InetAddress JavaDoc;
29 import java.net.UnknownHostException JavaDoc;
30
31 /**
32  * The Server listens on a specified port and passes connections to a
33  * ConnectionHandler. In this implementation, each ConnectionHandler runs in
34  * its own thread.
35  *
36  * @version 0.2 on 04 Aug 2002
37  */

38 public class IMAPServer
39     extends AbstractService implements Component {
40
41     private Context _context;
42
43     protected ConnectionHandlerFactory createFactory()
44     {
45         return new DefaultHandlerFactory( SingleThreadedConnectionHandler.class );
46     }
47
48     public void configure( final Configuration configuration )
49         throws ConfigurationException {
50
51         m_port = configuration.getChild( "port" ).getValueAsInteger( 143 );
52
53         try
54         {
55             final String JavaDoc bindAddress = configuration.getChild( "bind" ).getValue( null );
56             if( null != bindAddress )
57             {
58                 m_bindTo = InetAddress.getByName( bindAddress );
59             }
60         }
61         catch( final UnknownHostException JavaDoc unhe )
62         {
63             throw new ConfigurationException( "Malformed bind parameter", unhe );
64         }
65
66         final String JavaDoc useTLS = configuration.getChild("useTLS").getValue( "" );
67         if( useTLS.equals( "TRUE" ) ) m_serverSocketType = "ssl";
68
69         super.configure( configuration.getChild( "handler" ) );
70     }
71
72     public void initialize() throws Exception JavaDoc {
73
74         getLogger().info( "IMAPServer init..." );
75         getLogger().info( "IMAPListener using " + m_serverSocketType + " on port " + m_port );
76         super.initialize();
77         getLogger().info("IMAPServer ...init end");
78         System.out.println("Started IMAP Server "+m_connectionName);
79     }
80 }
81     
82
Popular Tags