singleton() public static method

Creates a new singleton application server instance.
public static singleton ( AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory, AppserverIo\Storage\GenericStackable $runlevels ) : AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface
$namingDirectory AppserverIo\Psr\Naming\NamingDirectoryInterface
$runlevels AppserverIo\Storage\GenericStackable The storage for the services
return AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface The singleton application instance
Esempio n. 1
0
$namingDirectory->createSubdirectory('php:env');
$namingDirectory->createSubdirectory('php:env/args');
$namingDirectory->createSubdirectory('php:global');
$namingDirectory->createSubdirectory('php:global/log');
$namingDirectory->createSubdirectory('php:services');
// create the default subdirectories
foreach (array_keys(ApplicationServer::$runlevels) as $runlevel) {
    $namingDirectory->createSubdirectory(sprintf('php:services/%s', $runlevel));
}
// bind the command line arguments to the naming directory
foreach ($arguments as $name => $value) {
    $namingDirectory->bind(sprintf('php:env/args/%s', $name), empty($value) ? true : $value);
}
// bind the current user to the naming directory
$namingDirectory->bind('php:env/currentUser', isset($_SERVER['SUDO_USER']) ? $_SERVER['SUDO_USER'] : get_current_user());
// bind the path to the default configuration and bootstrap filenames
$namingDirectory->bind('php:env/configurationFilename', DirectoryKeys::realpath($filename));
$namingDirectory->bind('php:env/bootstrapConfigurationFilename', DirectoryKeys::realpath($bootstrapFilename));
// add the storeage containers for the runlevels
$runlevels = new GenericStackable();
foreach (ApplicationServer::$runlevels as $runlevel) {
    $runlevels[$runlevel] = new GenericStackable();
}
// initialize and start the application server
$applicationServer = ApplicationServer::singleton($namingDirectory, $runlevels);
// we've to wait for shutdown
while ($applicationServer->keepRunning()) {
    sleep(1);
}
// wait until all threads have been stopped
$applicationServer->join();