1 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 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 39 { 40 m_pdkServer = new PDKDemoServerImpl(); 41 } 42 43 public void message(String string) 44 { 45 System.out.println( "String passed = " + string ); 46 } 47 48 public void start() 49 throws Exception 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 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 |