Fork me on GitHub
Follow @essenceworks

Documentation

Eldhelm::Server::Main - An application server called The Eldhelm Platform.

Class contents

  1. Class name and inheritance
  2. Synopsis
  3. Description
  4. Methods
  5. Author
  6. License

Class name and inheritance

Synopsis

use strict;
use Eldhelm::Server::Main;

# with a config.pl
Eldhelm::Server::Main->new->start;

# you can try this for a quick start
Eldhelm::Server::Main->new(
	configPath => 'quickstart-config.pl'
)->start;

# or with your custom configuration
Eldhelm::Server::Main->new(
	configPath => 'myCustomConfig.pl'
)->start;

Description

A flexible, production ready, application server which can do advanced stuff (WOW).

The server traps some signals:

HUP

When you kill -HUP the server, it reloads the configuration file.
Pelase note that the server will not recreate any threads or sockets.
For all changes to apply you need to restart the server!

INT

When you kill -INT the server will gracefully shut down.
It will attempt to save it's state (if configured to do so).

TERM

Same as INT.

PIPE

Will nag about a broken pipe and attempt to continue normal operation.

Methods

new(%args)

Constructs the server object.

%args Hash - Contructor argumets;

configPath - specifies a configuration file. Defaults to config.pl;

start()

Starts the server.

Inherited methods

access($message)

Prints a message in the access log.

config() Eldhelm::Server::BaseObject

Returns an interface object (Eldhelm::Server::BaseObject) to access the current server configuration. It is accessible for both read and write.

debug($message)

Prints a message in the debug log.

doAction($action, $data)

Appends and action to be executed by the server task queue.

$action String - Dotted notation of a controller action;
$data HashRef - Context data to be used when executing the controller;

error($message)

Prints a message in the error log.

filterPersist($filter, $ids) Array

Checks whether a persistant object exists.

$filter HashRef - Properties to be matched on the persistant objects;
$ids ArrayRef - optional; A ist of ids. If ommited all persistant objects are filtered;
$self->filterPersist({
	connected => 1
});

# or filter a specific set
$self->filterPersist({
	connected => 1
}, [1, 2, 3, 4])

findAndFilterPersist($var, $values, $filter) Array

Finds objects by property matching a list of values. The optionally filters them.

$var String - A property name;
$values ArrayRef - A list of property values;
$filter HashRef - Optional; Properties to be matched on the persistant objects;
$self->findAndFilterPersist(
	'playerId',
	[1, 2, 3],
	{
		connected => 1
	}
);

getConfig($property) Mixed

Returns a clone of a node in the configuration file descrubed by a dotted notaion.

$property String - dotted notation;
my $name = $self->getConfig('server.name');

getConfigList(@list) Mixed

Returns a list of nodes from the configuration file descrubed by a dotted notaions.

@List Array - a list of dotted notations;
my ($name, $host) = 
	$self->getConfigList('server.name', 'server.host');

getPersist($id) Eldhelm::Basic::Persist

Finds a persistant object by id.

$id String - the id of the persistant object;

getPersistsByType($type, $filter) Array

Gets all persistant objects by type and then optionally filters them.

$type String - The type of the objects as a package name;
$fitler $filter - Optional; Properties to be matched on the persistant objects;
$self->getPersistsByType(
	'Eldhelm::Server::Session',
	{
		connected => 1
	}
);

getPersistsByTypeList($type, $filter) Array

Gets all persistant objects from specified types and then optionally filters them.

$types ArrayRef - The types of the objects as a package names;
$fitler $filter - Optional; Properties to be matched on the persistant objects;
$self->getPersistsByType(
	['Eldhelm::Server::Session', 'Eldhelm::Applictaion::Persists::MySession'],
	{
		connected => 1
	}
);

getShedule($name) Eldhelm::Server::Shedule

Returns a Eldhelm::Server::Shedule object by name. This object coordinates the execution of a scheduled task;

$name String - The name of the scheduled task;

getShedule($name, $schedule, $action, $data) self

Registers a new scheduled task.

$name String - A string indicating the sheduled task;
$schedule String - A string indicating when the task should be executed;
$action String - The controller action to be called;
$data HashRef - The context data when the action is called;

hasPersist($id) 1 or undef

Checks whether a persistant object exists.

$id String - the id of the persistant object;

log($message, $logName)

Prints a message in a log specified by name. Defaults to general.

removeShedule($name) self

Removes a scheduled task by name;

$name String - The name of the scheduled task;

runExternalScript($name, $args) Mixed

Runs a task in an external script and captures the result.

$name String - The script name
$args HashRef or ArrayRef - The script arguments

Sometimes you have to run non-thread safe code or a non-thread safe library.
This can do this using this utility. It provides a easy to use interface to run external scripts.
Please, see Eldhelm::Util::ExternalScript for more information of how to write your scripts.

runExternalScriptAsync($name, $args) self

Same as $self->runExternalScript, but the worker does not wait the script to finish and the result is not captured.

$name String - The script name
$args HashRef or ArrayRef - The script arguments

stash() Eldhelm::Server::BaseObject

This is a general purpose storage. Something like a local storage or a static persistant storage.
It is accessed via Eldhelm::Server::BaseObject so it works like any other persistant object.

Author

Andrey Glavchev @ Essence Ltd. (http://essenceworks.com)

License

This software is Copyright (c) 2011-2015 of Essence Ltd.

Distributed undert the MIT license.

Contents | Top