Scopira 20080306

scopira::agent::task_context Class Reference

#include <context.h>

List of all members.

Public Member Functions

 task_context (void)
 task_context (taskmsg_reactor_i *reac)
 task_context (int myindex, const scopira::basekit::narray< scopira::tool::uuid > &peers)
 ~task_context ()
 destructor
bool failed (void) const
int find_services (scopira::tool::uuid &serviceid, scopira::basekit::narray< scopira::tool::uuid > &out)
int universe_size (void)
scopira::tool::uuid get_agent_id (void)
template<class M >
scopira::tool::uuid launch_task (scopira::tool::uuid where=scopira::tool::uuid())
scopira::tool::uuid launch_task (const std::string &classname, scopira::tool::uuid where=scopira::tool::uuid())
 another variant
template<class M >
scopira::tool::uuid launch_group (int numps)
 the core variant
scopira::tool::uuid launch_group (int numps, const std::string &classname)
 another variant
template<class M >
void launch_slaves (int numps)
 the core variant
void launch_slaves (int numps, const std::string &classname)
void kill_task (scopira::tool::uuid ps)
bool wait_task (scopira::tool::uuid ps, int msec=0)
bool is_alive_task (scopira::tool::uuid ps)
bool is_killed_task (void)
bool wait_msg (scopira::tool::uuid src, int timeout=0)
bool wait_msg (int src=-1, int timeout=0)
bool wait_msg (const scopira::agent::uuid_query &Q, int timeout=0)
bool has_msg (scopira::tool::uuid src)
bool has_msg (int src=-1)
bool has_msg (const scopira::agent::uuid_query &Q)
scopira::tool::uuid get_source (void) const
int get_index (void) const
int get_index (scopira::tool::uuid id) const
int get_group_size (void) const
scopira::tool::uuid get_id (void) const
scopira::tool::uuid get_id (int idx) const
const scopira::basekit::narray
< scopira::tool::uuid > & 
get_group (void) const
void barrier_group (void)
void wait_group (void)

Friends

class scopira::agent::send_msg
class scopira::agent::recv_msg

Detailed Description

The simplest run constext.

Author:
Aleksander Demko

Constructor & Destructor Documentation

scopira::agent::task_context::task_context ( void  )

Constructor, for users.

Author:
Aleksander Demko
scopira::agent::task_context::task_context ( taskmsg_reactor_i reac)

A constrcutor, for users, that also registers a on-received-msg reactor. You would then do all your recv_msg stuff in that handler.

This is useful for gui programming and other places where you'd rather not pole or block for messages.

Note that your reactor will be called in one of the agent's threads. If you do any gui stuff, make sure to aquire any proper locks and such.

Author:
Aleksander Demko

Member Function Documentation

void scopira::agent::task_context::barrier_group ( void  )

A barrier for all the processes in this group (similar to MPI_Barrier)

Author:
Aleksander Demko
bool scopira::agent::task_context::failed ( void  ) const [inline]

Is the agent in a failed state?

Author:
Aleksander Demko

References scopira::agent::agent_i::failed(), and scopira::agent::agent_i::instance().

int scopira::agent::task_context::find_services ( scopira::tool::uuid serviceid,
scopira::basekit::narray< scopira::tool::uuid > &  out 
)

Search for service providers. This function will find all the (usually) tasks that support the given serviceid.

In the future, this function may also accept distance and arch-querty critieria to further refine the search.

It will return the number of tasks found, which may be 0. The output list will be put into out. The resulting array may have some rough sorting, and if it does it'll be from more prefered (by what metric? usually network distance) to least.

Author:
Aleksander Demko
scopira::tool::uuid scopira::agent::task_context::get_agent_id ( void  ) [inline]

Gets the UUID of current I'm running under agent.

Author:
Aleksander Demko

References scopira::agent::agent_i::instance().

const scopira::basekit::narray<scopira::tool::uuid>& scopira::agent::task_context::get_group ( void  ) const [inline]

Your whole peer group.

Author:
Aleksander Demko
int scopira::agent::task_context::get_group_size ( void  ) const [inline]

Gets the size of my group. This will always be atleast 1.

Author:
Aleksander Demko

References scopira::basekit::narray< T, DIM >::size().

scopira::tool::uuid scopira::agent::task_context::get_id ( int  idx) const [inline]

Gets the UUID of the given peer by index. the index must be valid.

Author:
Aleksander Demko
scopira::tool::uuid scopira::agent::task_context::get_id ( void  ) const [inline]

Gets my UUID

Author:
Aleksander Demko
int scopira::agent::task_context::get_index ( void  ) const [inline]

Gets my index within a group.

Author:
Aleksander Demko
int scopira::agent::task_context::get_index ( scopira::tool::uuid  id) const

Gets the index of the given process UUID in my group. Returns -1 for not found.

Author:
Aleksander Demko
scopira::tool::uuid scopira::agent::task_context::get_source ( void  ) const [inline]

Gets the source UUID of the last wait_msg trigger. This is not to be confused with the one in recv_msg::get_source: they're unrelated

Author:
Aleksander Demko
bool scopira::agent::task_context::has_msg ( scopira::tool::uuid  src)

Checks (polls) if there is a msg from the given peer in the event queue. A zero src is "from anyone". The actual source can be retrived with get_source().

Author:
Aleksander Demko
bool scopira::agent::task_context::has_msg ( int  src = -1)

Checks if there a message from the given group peer. -1 is anyone in the GROUP. The actual source can be retrived with get_source().

Author:
Aleksander Demko
bool scopira::agent::task_context::has_msg ( const scopira::agent::uuid_query Q)

Checks if there a message that satisfies the given query. The actual source can be retrived with get_source().

Author:
Aleksander Demko
bool scopira::agent::task_context::is_alive_task ( scopira::tool::uuid  ps) [inline]

Check if the given process exists.

Author:
Aleksander Demko

References scopira::agent::agent_i::instance().

bool scopira::agent::task_context::is_killed_task ( void  ) [inline]

Has this task been "killed"? A task may "kill" another task with the kill_task method. When a task is killed, is_kill will return true for that task. Also, when the victum task returns from its run method, it will be destroyed. Note, this will return true when a task has been scheduled to die, but has not yet completed its run method. is_alive_task() on the otherhand, will only return fall (dead) when the specified task no longer exists.

Author:
Aleksander Demko

References scopira::agent::agent_i::instance().

void scopira::agent::task_context::kill_task ( scopira::tool::uuid  ps) [inline]

Kills a given process. If the process doesnt exit, nothing happens. If it does, a kill signal is queued for the process. The process will then be terminated at its next checkpoint.

Author:
Aleksander Demko

References scopira::agent::agent_i::instance().

template<class M >
scopira::tool::uuid scopira::agent::task_context::launch_group ( int  numps) [inline]

the core variant

Spawn the given master process as a group.

The given process will be the master process. numps-1 additional processes will be spawned. If numps is 0, then it numps will be the number of free processes in the system.

numps must be greater than 0. Use universe_size() to get a good idea of a size of group to launch.

The t must be registered for serialization.

Author:
Aleksander Demko

References scopira::agent::agent_i::instance().

template<class M >
void scopira::agent::task_context::launch_slaves ( int  numps) [inline]

the core variant

Launch additional slave processes. The calling task/process will be the "master" (id 0) of this new group.

This is especially useful for master threads/ui threads/userland threads.

numps must be greater than 0. Use universe_size() to get a good idea of a size of group to launch. numps will include the already running caller/master, so the number of new slave tasks actually launched will be numps-1.

This cannot be called for processes that are already in process groups.

Author:
Aleksander Demko
template<class M >
scopira::tool::uuid scopira::agent::task_context::launch_task ( scopira::tool::uuid  where = scopira::tool::uuid()) [inline]

Spawn the given one task into the agent system. The UUID of the task is returned, useful for non-blocking spawns.

The UUID is your "handle" to the running task. You should "forgot" all your pointers to the given task object, as it will be absorbed into the agent system (and possibly moved between machines, etc).

The where parameter allows you to control where the new task is deployed. This can be:

  • zero-uuid for the default placement system
  • a specific agent-uuid for placement on that agent
  • a specific task-uuid for specific "load balancing" service agent (not yet implemented)
  • a constant uuid for a specific operation (see where_*_c in ids.h)
Author:
Aleksander Demko

References scopira::agent::agent_i::instance().

int scopira::agent::task_context::universe_size ( void  ) [inline]

Returns the recommended/maximum number of full CPU-bound tasks to launch in a group/at once. Will always return >0.

Author:
Aleksander Demko

References scopira::agent::agent_i::instance().

void scopira::agent::task_context::wait_group ( void  )

Waits until all the others in my group die (ie. wait_task on each of them)

Author:
Aleksander Demko
bool scopira::agent::task_context::wait_msg ( const scopira::agent::uuid_query Q,
int  timeout = 0 
)

Waits for a msg that satisfies the given query. Returns true if one came within the time out. Make timeout 0 for inifnity. The actual source can be retrived with get_source().

Use has_msg to do instantaneous polling.

Author:
Aleksander Demko
bool scopira::agent::task_context::wait_msg ( int  src = -1,
int  timeout = 0 
)

Waits for a msg from the given peer in my group. Make src -1 for "anyone in the GROUP" (and just the group). Returns true if one came within the time out. Make timeout 0 for inifnity. The actual source can be retrived with get_source().

Use has_msg to do instantaneous polling.

Author:
Aleksander Demko
bool scopira::agent::task_context::wait_msg ( scopira::tool::uuid  src,
int  timeout = 0 
)

Waits for a msg from the given src. Make src zero for "anyone in the universe". Returns true if one came within the time out. Make timeout 0 for inifnity. The actual source can be retrived with get_source().

Use has_msg to do instantaneous polling.

Author:
Aleksander Demko
bool scopira::agent::task_context::wait_task ( scopira::tool::uuid  ps,
int  msec = 0 
) [inline]

Wait for the given process to die. Returns true if the process died/is dead/doesnt exist. False if the process still lives after the given time out. (1000 msec=second). A timeout of 0 msec means to wait indefinatly.

Author:
Aleksander Demko

References scopira::agent::agent_i::instance().


The documentation for this class was generated from the following file: