protected function worker(Handler $handler, array $app_definition)
 {
     // Make sure, that we have the needed class
     if (!class_exists($app_definition['class'])) {
         if (empty($app_definition['file'])) {
             throw new \LogicException('Class ' . $app_definition['class'] . ' can not be loaded');
         }
         $path = $this->cwd . '/' . $app_definition['file'];
         if (!file_exists($path)) {
             throw new \LogicException('File ' . $path . ' is not found');
         }
         require $path;
         if (!class_exists($app_definition['class'])) {
             throw new \LogicException('Class ' . $app_definition['class'] . ' is not found');
         }
     }
     // Instantiate the object
     if (isset($app_definition['parameters']) and count($app_definition['parameters']) > 0) {
         $reflect = new \ReflectionClass($app_definition['class']);
         $app = $reflect->newInstanceArgs($app_definition['parameters']);
     } else {
         $app = new $app_definition['class']();
     }
     // Instantiate the middlewares chain
     foreach (array_reverse($app_definition['middlewares']) as $middleware) {
         if (is_array($middleware)) {
             $mw_class = $middleware['class'];
             $mw_params = array_merge(array($app), $middleware['parameters']);
             $reflect = new \ReflectionClass($mw_class);
             $app = $reflect->newInstanceArgs($mw_params);
         } else {
             $mw_class = 'AiP\\Middleware\\' . $middleware;
             $app = new $mw_class($app);
         }
     }
     // Serve the app
     try {
         pcntl_signal(SIGUSR1, array($handler, 'graceful'), false);
         $handler->serve($app);
         pcntl_signal(SIGUSR1, SIG_DFL);
     } catch (\Exception $e) {
     }
 }