Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

RWRunnableServer


RWRunnableServer RWThread

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Member Functions

Package

Threading

Header File

#include <rw/thread/RWRunnableServer.h>

Description

The runnable server may be used alone, or within a class for an active object class implementation. The runnable server object, when started, waits for other threads to enqueue runnable objects that they would like the server thread to execute for them. Each runnable object that the server finds in its internal queue is dequeued and started. The runnable server does not join with the runnables it starts. The runnable server continues to dequeue runnables and execute them until stopped, interrupted, or canceled.

Runnables may be enqueued with a guard functor, or a priority value, or both.

The server uses the guard functor to determine whether the associated runnable is currently eligible for retrieval and execution. A guarded runnable is not retrieved by the server until that runnable is the first runnable in the queue whose guard evaluates to TRUE. Using guards to block runnable execution is important when implementing active objects; guards can be used to insure that the active object maintains consistent state and preserves any necessary invariants.

The priority value is used during write operations to determine a runnable's insertion point within the server's input queue, such that the set of un-processed and eligible runnables will be retrieved in priority order by the server.

The RWRunnable::requestCancellation() function should be used if the server thread is to stop execution as soon as possible without dequeuing and dispatching any additional runnables.

The RWRunnable::requestInterrupt() function can be used to temporarily suspend execution of the server thread.

An active object implementation using this class defines a client interface with member functions that simply produce "runnable functor" objects (see RWRunnableFunction.h and RWTRunnableIOUFunction.h) which, when invoked, execute some corresponding private or local member function within the active object instance. The public members pass the runnable functors to the server thread by calling the enqueue() member, which stores the runnables in a queue. The client interface member function then returns to its caller.

Runnables that use IOUs can be used to represent a future return value or result of the asynchronous active object operation. In this situation, the client interface would create the appropriate IOU-capable runnable object, enqueue the runnable for execution, retrieve the runnable's IOU result, and return that IOU to the caller. The caller could then redeem that IOU at some point in the future.

Example

The following is a skeleton of an active object class implemented using an RWRunnableServer. For a complete active object example, refer to activobj.cpp in the threxam directory.

Public Constructors

RWRunnableServer(void);
RWRunnableServer(const RWRunnableServer& second);

Public Member Operator

RWRunnableServer&
operator=(const RWRunnableServer& second);

Public Member Functions

void
enqueue(const RWRunnable& runnable);
RWWaitStatus
enqueue(const RWRunnable& runnable,
unsigned long milliseconds);
void
enqueue(const RWRunnable& runnable, 
        const RWRunnableGuard& guard);
RWWaitStatus
enqueue(const RWRunnable& runnable,
const RWRunnableGuard& guard
unsigned long milliseconds);
void
enqueue(long priority,
const RWRunnable& runnable);
RWWaitStatus
enqueue(long priority,
const RWRunnable& runnable,
unsigned long milliseconds);
void
enqueue(long priority,
const RWRunnable& runnable, const RWRunnableGuard& guard);
RWWaitStatus
enqueue(long priority,
const RWRunnable& runnable,
const RWRunnableGuard& guard
unsigned long milliseconds);
size_t
getCapacity(void) const;
static RWRunnableServer
make(void);
static RWRunnableServer
make(size_t maxCapacity);
static RWRunnableServer
make(const RWThreadAttribute& serverThreadAttr);
static RWRunnableServer
make(const RWThreadAttribute& serverThreadAttr,
size_t maxCapacity);
size_t
setCapacity(size_t maxCapacity) const;
void
stop(void)

Protected Constructor

RWRunnableServer(RWRunnableServerImp* threadImpP)

See Also

RWGuardedRunnableQueue, RWRunnable, RWThread, RWServerPool



Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.