/**
  * Run the containers logic
  *
  * @return void
  */
 public function main()
 {
     // define webservers base dir
     define('SERVER_BASEDIR', $this->getInitialContext()->getSystemConfiguration()->getBaseDirectory()->getNodeValue()->__toString() . DIRECTORY_SEPARATOR);
     define('SERVER_AUTOLOADER', SERVER_BASEDIR . 'app' . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
     // deploy and initialize the applications for this container
     $this->getDeployment()->deploy($this);
     // deployment has been successful
     $this->containerState = ContainerStateKeys::get(ContainerStateKeys::DEPLOYMENT_SUCCESSFUL);
     // setup configurations
     $serverConfigurations = array();
     foreach ($this->getContainerNode()->getServers() as $serverNode) {
         $serverConfigurations[] = new ServerNodeConfiguration($serverNode);
     }
     // init server array
     $servers = array();
     // start servers by given configurations
     foreach ($serverConfigurations as $serverConfig) {
         // get type definitions
         $serverType = $serverConfig->getType();
         $serverContextType = $serverConfig->getServerContextType();
         // create a new instance server context
         /* @var \TechDivision\WebServer\Interfaces\ServerContextInterface $serverContext */
         $serverContext = new $serverContextType();
         // inject container to be available in specific mods etc. and initialize the module
         $serverContext->injectContainer($this);
         $serverContext->init($serverConfig);
         $serverContext->injectLoggers($this->getInitialContext()->getLoggers());
         // Create the server (which should start it automatically)
         $server = new $serverType($serverContext);
         // Collect the servers we started
         $servers[] = $server;
     }
     // wait for all servers to be started
     $waitForServers = true;
     while ($waitForServers) {
         // iterate over all servers to check the state
         foreach ($servers as $server) {
             if ($server->state === 0) {
                 // if the server has not been started
                 sleep(1);
                 continue 2;
             }
         }
         // if all servers has been started, stop waiting
         $waitForServers = false;
     }
     // the servers has been started and we wait for the servers to finish work now
     $this->containerState = ContainerStateKeys::get(ContainerStateKeys::SERVERS_STARTED_SUCCESSFUL);
     // wait for shutdown signal
     while ($this->containerState->equals(ContainerStateKeys::get(ContainerStateKeys::SERVERS_STARTED_SUCCESSFUL))) {
         sleep(1);
     }
     // wait till all servers has been shutdown
     foreach ($servers as $server) {
         $server->join();
     }
 }
 /**
  * Starts the registered container threads.
  *
  * @return void
  */
 public function startContainers()
 {
     // start the container threads
     foreach ($this->getContainers() as $container) {
         // start the container
         $container->start();
         // wait for the container to be started
         $waitForContainer = true;
         while ($waitForContainer) {
             sleep(1);
             if ($container->containerState->greaterOrEqualThan(ContainerStateKeys::get(ContainerStateKeys::SERVERS_STARTED_SUCCESSFUL))) {
                 $waitForContainer = false;
             }
         }
     }
 }