KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > phoenixdemo > block > DefaultPDKDemoServer


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package phoenixdemo.block;
9
10 import org.apache.avalon.framework.activity.Initializable;
11 import org.apache.avalon.framework.activity.Startable;
12 import org.apache.avalon.framework.configuration.Configurable;
13 import org.apache.avalon.framework.configuration.Configuration;
14 import org.apache.avalon.framework.configuration.ConfigurationException;
15 import org.apache.avalon.framework.logger.AbstractLogEnabled;
16 import phoenixdemo.api.PDKDemoServer;
17 import phoenixdemo.server.PDKDemoServerImpl;
18
19 /**
20  * @author Paul Hammant <Paul_Hammant@yahoo.com>
21  * @version 1.0
22  */

23 public class DefaultPDKDemoServer
24     extends AbstractLogEnabled
25     implements PDKDemoServer, Configurable, Startable, Initializable
26 {
27     private int m_port;
28     private PDKDemoServerImpl m_pdkServer;
29     private SocketThread m_socketThread;
30
31     public void configure( final Configuration configuration )
32         throws ConfigurationException
33     {
34         m_port = configuration.getChild( "port" ).getValueAsInteger( 7777 );
35     }
36
37     public void initialize()
38         throws Exception JavaDoc
39     {
40         m_pdkServer = new PDKDemoServerImpl();
41     }
42
43     public void message(String JavaDoc string)
44     {
45         System.out.println( "String passed = " + string );
46     }
47
48     public void start()
49         throws Exception JavaDoc
50     {
51         m_socketThread = new SocketThread( m_pdkServer, m_port );
52         m_socketThread.start();
53
54         System.out.println( "Server started on port " + m_port );
55     }
56
57     public void stop()
58         throws Exception JavaDoc
59     {
60         m_socketThread = new SocketThread( m_pdkServer, m_port );
61         m_socketThread.interrupt();
62         m_socketThread = null;
63
64         System.out.println( "Server stopped on port " + m_port );
65     }
66 }
67
Popular Tags