ServerComponent Class Reference

This class represents any object that can be added to a ReflectServer object in one way or another, to help define the ReflectServer's behaviour. More...

#include <ServerComponent.h>

Inheritance diagram for ServerComponent:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 ServerComponent ()
 Default Constructor.
virtual ~ServerComponent ()
 Destructor.
virtual status_t AttachedToServer ()
 This method is called when this object has been added to a ReflectServer object.
virtual void AboutToDetachFromServer ()
 This method is called just before we are removed from the ReflectServer object.
virtual void MessageReceivedFromSession (AbstractReflectSession &from, const MessageRef &msg, void *userData)
 Called when a message is sent to us by an AbstractReflectSession object.
virtual void MessageReceivedFromFactory (ReflectSessionFactory &from, const MessageRef &msg, void *userData)
 Called when a message is sent to us by a ReflectSessionFactory object.
bool IsAttachedToServer () const
 Returns true if we are attached to the ReflectServer object, false if we are not.
ReflectServerGetOwner () const
 Returns the ReflectServer we are currently attached to, or NULL if we aren't currently attached to a ReflectServer.
void SetOwner (ReflectServer *s)
 Sets the ReflectServer we are currently attached to.
void IncrementRefCount () const
 Increments the counter and returns true iff the new value is zero.
bool DecrementRefCount () const
 Decrements the counter and returns true iff the new value is zero.
void SetManager (AbstractObjectManager *manager)
 Sets the recycle-pointer for this object.
AbstractObjectManagerGetManager () const
 Returns this object's current recyler pointer.
uint32 GetRefCount () const
 Returns this object's current reference count.
virtual uint64 GetPulseTime (uint64 now, uint64 prevResult)
 This method can be overridden to tell the PulseNodeManager when we would like to have our Pulse() method called.
virtual void Pulse (uint64 now, uint64 scheduledTime)
 Will be called at the time specified previously by GetPulseTime().
status_t PutPulseChild (PulseNode *child)
 Adds the given child into our set of child PulseNodes.
status_t RemovePulseChild (PulseNode *child)
 Attempts to remove the given child from our set of child PulseNodes.
void ClearPulseChildren ()
 Removes all children from our set of child PulseNodes.
bool ContainsPulseChild (PulseNode *child) const
 Returns true iff the given child is in our set of child PulseNodes.
uint64 GetScheduledPulseTime () const
 Returns when this object wants its call to Pulse() scheduled next, or MUSCLE_TIME_NEVER if it has no call to Pulse() currently scheduled.
uint64 GetCycleStartTime () const
 Returns the run-time at which the PulseNodeManager started calling our callbacks.
void SetSuggestedMaximumTimeSlice (uint64 maxUsecs)
 Sets the maximum number of microseconds that this class should allow its callback methods to execute for (relative to the cycle start time, as shown above).
uint64 GetSuggestedMaximumTimeSlice () const
 Returns the current suggested maximum duration of our time slice, or MUSCLE_TIME_NEVER if there is no suggested limit.
bool IsSuggestedTimeSliceExpired () const
 Convenience method -- returns true iff the current value of the run-time clock (GetRunTime64()) indicates that our suggested time slice has expired.

Protected Member Functions

uint64 GetServerUptime () const
 Returns the number of milliseconds that the server has been running.
uint32 GetNumAvailableBytes () const
 Returns the number of bytes that are currently available to be allocated.
uint32 GetMaxNumBytes () const
 Returns the maximum number of bytes that may be allocated at any given time.
uint32 GetNumUsedBytes () const
 Returns the number of bytes that are currently allocated.
status_t PutAcceptFactory (uint16 port, const ReflectSessionFactoryRef &factoryRef, const ip_address &interfaceIP=invalidIP, uint16 *optRetPort=NULL)
 Passes through to ReflectServer::PutAcceptFactory().
status_t RemoveAcceptFactory (uint16 port, const ip_address &interfaceIP=invalidIP)
 Passes through to ReflectServer::RemoveAcceptFactory().
void EndServer ()
 Tells the whole server process to quit ASAP.
MessageGetCentralState () const
 Returns a reference to a Message that is shared by all objects in a single ReflectServer.
status_t AddNewSession (const AbstractReflectSessionRef &session, const SocketRef &socket=SocketRef())
 Adds the given AbstractReflectSession to the server's session list.
status_t AddNewConnectSession (const AbstractReflectSessionRef &session, const ip_address &targetIPAddress, uint16 port, uint64 autoReconnectDelay=MUSCLE_TIME_NEVER)
 Like AddNewSession(), only creates a session that connects asynchronously to the given IP address.
status_t AddNewDormantConnectSession (const AbstractReflectSessionRef &ref, const ip_address &targetIPAddress, uint16 port, uint64 autoReconnectDelay=MUSCLE_TIME_NEVER)
 Like AddNewConnectSession(), except that the added session will not initiate a TCP connection to the specified address immediately.
const Hashtable< const String *,
AbstractReflectSessionRef > & 
GetSessions () const
 Returns our server's table of attached sessions.
AbstractReflectSessionRef GetSession (uint32 id) const
 Looks up a session connected to our ReflectServer via its session ID string.
AbstractReflectSessionRef GetSession (const String &id) const
 Looks up a session connected to our ReflectServer via its session ID string.
const Hashtable< IPAddressAndPort,
ReflectSessionFactoryRef > & 
GetFactories () const
 Returns the table of session factories currently attached to the server.
ReflectSessionFactoryRef GetFactory (uint16) const
 Given a port number, returns a reference to the factory of that port, or a NULL reference if no such factory exists.
void InvalidatePulseTime (bool clearPrevResult=true)
 Sets a flag to indicate that GetPulseTime() should be called on this object.

Detailed Description

This class represents any object that can be added to a ReflectServer object in one way or another, to help define the ReflectServer's behaviour.

This class provides callback wrappers that let you operate on the server's state.

Definition at line 28 of file ServerComponent.h.


Member Function Documentation

virtual status_t ServerComponent::AttachedToServer (  )  [virtual]

This method is called when this object has been added to a ReflectServer object.

When this method is called, it is okay to call the other methods in the ServerComponent API. Should return B_NO_ERROR if everything is okay; something else if there is a problem and the attachment should be aborted. Default implementation does nothing and returns B_NO_ERROR. If you override this, be sure to call your superclass's implementation of this method as the first thing in your implementation, and if it doesn't return B_NO_ERROR, immediately return an error yourself.

Reimplemented in ProxySessionFactory, StorageReflectSession, ThreadWorkerSession, and ThreadWorkerSessionFactory.

virtual void ServerComponent::AboutToDetachFromServer (  )  [virtual]

This method is called just before we are removed from the ReflectServer object.

Methods in the ServerComponent API may still be called at this time (but not after this method returns). Default implementation does nothing. If you override this, be sure to call you superclass's implementation of this method as the last thing you do in your implementation.

Reimplemented in ProxySessionFactory, StorageReflectSession, ThreadWorkerSession, ThreadWorkerSessionFactory, and ThreadSupervisorSession.

virtual void ServerComponent::MessageReceivedFromSession ( AbstractReflectSession from,
const MessageRef msg,
void *  userData 
) [virtual]

Called when a message is sent to us by an AbstractReflectSession object.

Default implementation is a no-op.

Parameters:
from The session who is sending the Message to us.
msg A reference to the message that was sent.
userData Additional data whose semantics are determined by the sending subclass. (For StorageReflectSessions, this value, if non-NULL, is a pointer to the DataNode in this Session's node subtree that was matched by the paths in (msg))

Reimplemented in DumbReflectSession, FilterSessionFactory, ThreadWorkerSession, and ThreadSupervisorSession.

virtual void ServerComponent::MessageReceivedFromFactory ( ReflectSessionFactory from,
const MessageRef msg,
void *  userData 
) [virtual]

Called when a message is sent to us by a ReflectSessionFactory object.

Default implementation is a no-op.

Parameters:
from The session who is sending the Message to us.
msg A reference to the message that was sent.
userData Additional data whose semantics are determined by the sending subclass.

Reimplemented in ThreadSupervisorSession.

void ServerComponent::SetOwner ( ReflectServer s  )  [inline]

Sets the ReflectServer we are currently attached to.

Don't call this if you don't know what you are doing.

Definition at line 87 of file ServerComponent.h.

Message& ServerComponent::GetCentralState (  )  const [protected]

Returns a reference to a Message that is shared by all objects in a single ReflectServer.

This message can be used for whatever purpose the ServerComponents care to; it is not used by the server itself. (Note that StorageReflectSessions add data to this Message and expect it to remain there, so be careful not to remove or overwrite it if you are using StorageReflectSessions)

status_t ServerComponent::AddNewSession ( const AbstractReflectSessionRef session,
const SocketRef socket = SocketRef() 
) [protected]

Adds the given AbstractReflectSession to the server's session list.

If (socket) is less than zero, no TCP connection will be used, and the session will be a pure server-side entity.

Parameters:
session A reference to the new session to add to the server.
socket the socket descriptor associated with the new session, or a NULL reference. If the socket descriptor argument is a NULL reference, the session's CreateDefaultSocket() method will be called to supply the SocketRef. If that also returns a NULL reference, then the client will run without a connection to anything.
Returns:
B_NO_ERROR if the session was successfully added, or B_ERROR on error.

status_t ServerComponent::AddNewConnectSession ( const AbstractReflectSessionRef session,
const ip_address &  targetIPAddress,
uint16  port,
uint64  autoReconnectDelay = MUSCLE_TIME_NEVER 
) [protected]

Like AddNewSession(), only creates a session that connects asynchronously to the given IP address.

AttachedToServer() will be called immediately on the session, and then when the connection is complete, AsyncConnectCompleted() will be called. Other than that, however, (session) will behave like any other session, except any I/O messages for the client won't be transferred until the connection completes.

Parameters:
session A reference to the new session to add to the server.
targetIPAddress IP address to connect to
port port to connect to at that address
autoReconnectDelay If specified, this is the number of microseconds after the connection is broken that an automatic reconnect should be attempted. If not specified, an automatic reconnect will not be attempted, and the session will be removed when the connection breaks. Specifying this is equivalent to calling SetAutoReconnectDelay() on (session).
Returns:
B_NO_ERROR if the session was successfully added, or B_ERROR on error (out-of-memory or the connect attempt failed immediately).

status_t ServerComponent::AddNewDormantConnectSession ( const AbstractReflectSessionRef ref,
const ip_address &  targetIPAddress,
uint16  port,
uint64  autoReconnectDelay = MUSCLE_TIME_NEVER 
) [protected]

Like AddNewConnectSession(), except that the added session will not initiate a TCP connection to the specified address immediately.

Instead, it will just hang out and do nothing until you call Reconnect() on it. Only then will it create the TCP connection to the address specified here.

Parameters:
ref New session to add to the server.
targetIPAddress IP address to connect to
port Port to connect to at that IP address.
autoReconnectDelay If specified, this is the number of microseconds after the connection is broken that an automatic reconnect should be attempted. If not specified, an automatic reconnect will not be attempted, and the session will be removed when the connection breaks. Specifying this is equivalent to calling SetAutoReconnectDelay() on (ref).
Returns:
B_NO_ERROR if the session was successfully added, or B_ERROR on error (out-of-memory, or the connect attempt failed immediately)

AbstractReflectSessionRef ServerComponent::GetSession ( uint32  id  )  const [protected]

Looks up a session connected to our ReflectServer via its session ID string.

Parameters:
id The ID of the session you are looking for.
Returns:
A reference to the session with the given session ID, or a NULL reference on failure.

AbstractReflectSessionRef ServerComponent::GetSession ( const String id  )  const [protected]

Looks up a session connected to our ReflectServer via its session ID string.

Parameters:
id The ID string of the session you are looking for.
Returns:
A reference to the session with the given session ID, or a NULL reference on failure.

void RefCountable::IncrementRefCount (  )  const [inline, inherited]

Increments the counter and returns true iff the new value is zero.

Thread safe.

Definition at line 32 of file RefCount.h.

References AtomicCounter::AtomicIncrement().

bool RefCountable::DecrementRefCount (  )  const [inline, inherited]

Decrements the counter and returns true iff the new value is zero.

Thread safe.

Definition at line 35 of file RefCount.h.

References AtomicCounter::AtomicDecrement().

void RefCountable::SetManager ( AbstractObjectManager manager  )  [inline, inherited]

Sets the recycle-pointer for this object.

If set to non-NULL, this pointer is used by the ObjectPool class to recycle this object when it is no longer in use, so as to avoid the overhead of having to delete it and re-create it later on. The RefCountable class itself does nothing with this pointer. Default value is NULL.

Parameters:
manager Pointer to the new manager object to use, or NULL to use no manager.

Definition at line 44 of file RefCount.h.

uint32 RefCountable::GetRefCount (  )  const [inline, inherited]

Returns this object's current reference count.

Note that the value returned by this method is volatile in multithreaded environments, so it may already be wrong by the time it is returned. Be careful!

Definition at line 54 of file RefCount.h.

References AtomicCounter::GetCount().

virtual uint64 PulseNode::GetPulseTime ( uint64  now,
uint64  prevResult 
) [virtual, inherited]

This method can be overridden to tell the PulseNodeManager when we would like to have our Pulse() method called.

This method is guaranteed to be called only during the following times:

  1. When the PulseNode is first probed by the PulseNodeManager
  2. Immediately after our Pulse() method has returned
  3. Soon after InvalidatePulseTime() has been called one or more times (InvalidatePulseTime() calls are merged together for efficiency)
Parameters:
now The current wall-clock time in microseconds, for convenience.
prevResult The value that this method returned the last time it was called. The very first time this method is called, this value will be passed in as MUSCLE_TIME_NEVER.
Returns:
Return MUSCLE_TIME_NEVER if you don't wish to schedule a future call to Pulse(); or return the time at which you want Pulse() to be called. Returning values less than or equal to (now) will cause Pulse() to be called as soon as possible. The default implementation always returns MUSCLE_TIME_NEVER.

Reimplemented in AbstractReflectSession, and RateLimitSessionIOPolicy.

virtual void PulseNode::Pulse ( uint64  now,
uint64  scheduledTime 
) [virtual, inherited]

Will be called at the time specified previously by GetPulseTime().

GetPulseTime() will be called again immediately after this call, to check if you want to schedule another Pulse() call for later. Default implementation is a no-op.

Parameters:
now The current wall-clock time-value in microseconds, for convenience.
scheduledTime The time this Pulse() call was scheduled to occur at, in microseconds, as previously returned by GetPulseTime(). Note that unless your computer is infinitely fast, this time will always be at least a bit less than (now), since there is a delay between when the program gets woken up to service the next Pulse() call, and when the call actually happens. (you may be able to use this value to compensate for the slippage, if it bothers you)

Reimplemented in AbstractReflectSession, and RateLimitSessionIOPolicy.

status_t PulseNode::PutPulseChild ( PulseNode child  )  [inherited]

Adds the given child into our set of child PulseNodes.

Any PulseNode in our set of children will have its pulsing needs taken care of by us, but it is not considered "owned" by this PulseNode--it will not be deleted when we are.

Parameters:
child The child to place into our set of child PulseNodes.
Returns:
B_NO_ERROR on success, or B_ERROR on failure (out of memory).

status_t PulseNode::RemovePulseChild ( PulseNode child  )  [inherited]

Attempts to remove the given child from our set of child PulseNodes.

Parameters:
child The child to remove
Returns:
B_NO_ERROR on success, or B_ERROR on failure (child wasn't in our set)

bool PulseNode::ContainsPulseChild ( PulseNode child  )  const [inline, inherited]

Returns true iff the given child is in our set of child PulseNodes.

Parameters:
child the child to look for.

Definition at line 84 of file PulseNode.h.

References PulseNode::_parent.

uint64 PulseNode::GetCycleStartTime (  )  const [inline, inherited]

Returns the run-time at which the PulseNodeManager started calling our callbacks.

Useful for any object that wants to limit the maximum duration of its timeslice in the PulseNodeManager's event loop.

Definition at line 95 of file PulseNode.h.

void PulseNode::SetSuggestedMaximumTimeSlice ( uint64  maxUsecs  )  [inline, inherited]

Sets the maximum number of microseconds that this class should allow its callback methods to execute for (relative to the cycle start time, as shown above).

Note that this value is merely a suggestion; it remains up to the subclass's callback methods to ensure that the suggestion is actually followed.

Parameters:
maxUsecs Maximum number of microseconds that the time slice should last for. If set to MUSCLE_TIME_NEVER, that indicates that there is no suggested limit.

Definition at line 104 of file PulseNode.h.

uint64 PulseNode::GetSuggestedMaximumTimeSlice (  )  const [inline, inherited]

Returns the current suggested maximum duration of our time slice, or MUSCLE_TIME_NEVER if there is no suggested limit.

Default value is MUSCLE_TIME_NEVER.

Definition at line 109 of file PulseNode.h.

bool PulseNode::IsSuggestedTimeSliceExpired (  )  const [inline, inherited]

Convenience method -- returns true iff the current value of the run-time clock (GetRunTime64()) indicates that our suggested time slice has expired.

This method is cheap to call often.

Definition at line 115 of file PulseNode.h.

void PulseNode::InvalidatePulseTime ( bool  clearPrevResult = true  )  [protected, inherited]

Sets a flag to indicate that GetPulseTime() should be called on this object.

Call this whenever you've decided to reschedule your pulse time outside of a Pulse() event.

Parameters:
clearPrevResult if true, this call will also clear the stored prevResult value, so that the next time GetPulseTime() is called, prevResult is passed in as MUSCLE_TIME_NEVER. If false, the prevResult value will be left alone.

Referenced by AbstractReflectSession::SetAutoReconnectDelay().


The documentation for this class was generated from the following file:
Generated on Thu Jun 5 17:48:32 2008 for MUSCLE by  doxygen 1.5.1