1 87 package org.codehaus.loom.demos.distributed.block; 88 89 import org.apache.avalon.framework.activity.Initializable; 90 import org.apache.avalon.framework.activity.Startable; 91 import org.apache.avalon.framework.configuration.Configurable; 92 import org.apache.avalon.framework.configuration.Configuration; 93 import org.apache.avalon.framework.configuration.ConfigurationException; 94 import org.apache.avalon.framework.logger.AbstractLogEnabled; 95 import org.codehaus.loom.demos.distributed.api.Server; 96 97 108 public class DefaultServer 109 extends AbstractLogEnabled 110 implements Server, Configurable, Startable, Initializable 111 { 112 private int m_port; 113 private ServerImpl m_server; 114 private SocketThread m_socketThread; 115 116 public void configure( final Configuration configuration ) 117 throws ConfigurationException 118 { 119 m_port = configuration.getChild( "port" ).getValueAsInteger( 7777 ); 120 } 121 122 public void initialize() 123 throws Exception 124 { 125 m_server = new ServerImpl(); 126 } 127 128 public void start() 129 throws Exception 130 { 131 m_socketThread = new SocketThread( m_server, m_port ); 132 m_socketThread.start(); 133 134 System.out.println( "Server started on port " + m_port ); 135 } 136 137 public void stop() 138 throws Exception 139 { 140 m_socketThread.close(); 141 m_socketThread = null; 142 143 System.out.println( "Server stopped on port " + m_port ); 144 } 145 146 public void message( final String string ) 147 { 148 m_server.message( string ); 149 } 150 } 151 | Popular Tags |