コード例 #1
0
 /**
  * Start's the server's worker as defined in configuration
  *
  * @return void
  *
  * @throws \AppserverIo\Server\Exceptions\ModuleNotFoundException
  * @throws \AppserverIo\Server\Exceptions\ConnectionHandlerNotFoundException
  */
 public function run()
 {
     // set current dir to base dir for relative dirs
     chdir(SERVER_BASEDIR);
     // setup autoloader
     require SERVER_AUTOLOADER;
     // init server context
     $serverContext = $this->getServerContext();
     // init config var for shorter calls
     $serverConfig = $serverContext->getServerConfig();
     // init server name
     $serverName = $serverConfig->getName();
     // init logger
     $logger = $serverContext->getLogger();
     $logger->debug(sprintf("starting %s (%s)", $serverName, __CLASS__));
     // initialization has been successful
     $this->serverState = ServerStateKeys::get(ServerStateKeys::INITIALIZATION_SUCCESSFUL);
     // initialize the connection handler
     $connectionHandler = null;
     // initiate server connection handlers
     $connectionHandlersTypes = $serverConfig->getConnectionHandlers();
     foreach ($connectionHandlersTypes as $connectionHandlerType) {
         // check if connection handler type exists
         if (!class_exists($connectionHandlerType)) {
             throw new ConnectionHandlerNotFoundException($connectionHandlerType);
         }
         // instantiate connection handler type
         $applications = $serverContext->getContainer()->getApplications();
         $connectionHandler = new $connectionHandlerType($applications);
         $logger->debug(sprintf("%s init connectionHandler (%s)", $serverName, $connectionHandlerType));
         // init connection handler with serverContext (this)
         $connectionHandler->init($serverContext);
         // inject modules
         $connectionHandler->injectModules(array());
         // stop, because we only support one connection handler
         break;
     }
     // get class names
     $socketType = $serverConfig->getSocketType();
     // setup server bound on local address
     $serverConnection = $socketType::getServerInstance($connectionHandler, $serverConfig->getPort(), $serverConfig->getAddress());
     $logger->debug(sprintf("%s started socket (%s)", $serverName, $socketType));
     // sockets has been started
     $this->serverState = ServerStateKeys::get(ServerStateKeys::SERVER_SOCKET_STARTED);
     $logger->info(sprintf("%s listing on %s:%s...", $serverName, $serverConfig->getAddress(), $serverConfig->getPort()));
     // start the server connection
     $serverConnection->run();
 }
コード例 #2
0
 /**
  * Factory method to create a new server state instance.
  *
  * @param integer $serverState The server state to create an instance for
  *
  * @return \AppserverIo\Server\Dictionaries\ServerStateKeys The server state key instance
  * @throws \AppserverIo\Server\Exceptions\InvalidServerStateException
  *      Is thrown if the server state is not available
  */
 public static function get($serverState)
 {
     // check if the requested server state is available and create a new instance
     if (in_array($serverState, ServerStateKeys::getServerStates())) {
         return new ServerStateKeys($serverState);
     }
     // throw a exception if the requested server state is not available
     throw new InvalidServerStateException(sprintf('Requested server state %s is not available (choose on of: %s)', $serverState, implode(',', ServerStateKeys::getServerStates())));
 }