#include <AbstractReflectSession.h>
Inheritance diagram for ReflectSessionFactory:

Public Member Functions | |
| ReflectSessionFactory () | |
| Constructor. | |
| virtual | ~ReflectSessionFactory () |
| Destructor. | |
| virtual AbstractReflectSessionRef | CreateSession (const String &clientAddress, const IPAddressAndPort &factoryInfo)=0 |
| Should be overriden to return a new ReflectSession object, or NULL on failure. | |
| virtual bool | IsReadyToAcceptSessions () const |
| Should return true iff this factory is currently ready to accept connections. | |
| uint32 | GetFactoryID () const |
| Returns an auto-assigned ID value that represents this factory. | |
| 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. | |
| ReflectServer * | GetOwner () 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. | |
| AbstractObjectManager * | GetManager () 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 | |
| void | BroadcastToAllSessions (const MessageRef &msgRef, void *userData=NULL) |
| Convenience method: Calls MessageReceivedFromFactory() on all session objects. | |
| void | BroadcastToAllFactories (const MessageRef &msgRef, void *userData=NULL, bool includeSelf=true) |
| Convenience method: Calls MessageReceivedFromFactory() on all session-factory objects. | |
| 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. | |
| Message & | GetCentralState () 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. | |
It is used by the ReflectServer classes to generate sessions when connections are received.
Definition at line 18 of file AbstractReflectSession.h.
| ReflectSessionFactory::ReflectSessionFactory | ( | ) |
Constructor.
Our globally unique factory ID is assigned here.
| virtual AbstractReflectSessionRef ReflectSessionFactory::CreateSession | ( | const String & | clientAddress, | |
| const IPAddressAndPort & | factoryInfo | |||
| ) | [pure virtual] |
Should be overriden to return a new ReflectSession object, or NULL on failure.
| clientAddress | A string representing the connecting client's host (typically an IP address, e.g. "192.168.1.102") | |
| factoryInfo | The IP address and port number of the local network interface on which this connection was received. |
Implemented in DumbReflectSessionFactory, FilterSessionFactory, StorageReflectSessionFactory, ThreadWorkerSessionFactory, and SharedFilterSessionFactory.
| virtual bool ReflectSessionFactory::IsReadyToAcceptSessions | ( | ) | const [inline, virtual] |
Should return true iff this factory is currently ready to accept connections.
This method is called each time through the event loop, and if this method is overridden to return false, then this factory will not be included in the select() set and any incoming TCP connections on this factory's port will not be acted upon (i.e. they will be forced to wait). Default implementation always returns true.
Definition at line 42 of file AbstractReflectSession.h.
| uint32 ReflectSessionFactory::GetFactoryID | ( | ) | const [inline] |
Returns an auto-assigned ID value that represents this factory.
The returned value is guaranteed to be unique across all factory in the server.
Definition at line 48 of file AbstractReflectSession.h.
| void ReflectSessionFactory::BroadcastToAllSessions | ( | const MessageRef & | msgRef, | |
| void * | userData = NULL | |||
| ) | [protected] |
Convenience method: Calls MessageReceivedFromFactory() on all session objects.
Saves you from having to do your own iteration every time you want to broadcast something.
| msgRef | a reference to the Message you wish to broadcast | |
| userData | any userData value you care to include. Defaults to NULL. |
| void ReflectSessionFactory::BroadcastToAllFactories | ( | const MessageRef & | msgRef, | |
| void * | userData = NULL, |
|||
| bool | includeSelf = true | |||
| ) | [protected] |
Convenience method: Calls MessageReceivedFromFactory() on all session-factory objects.
Saves you from having to do your own iteration every time you want to broadcast something to the factories.
| msgRef | a reference to the Message you wish to broadcast | |
| userData | any userData value you care to include. Defaults to NULL. | |
| includeSelf | Whether or not MessageReceivedFromFactory() should be called on 'this' factory. Defaults to true. |
| virtual status_t ServerComponent::AttachedToServer | ( | ) | [virtual, inherited] |
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, inherited] |
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, inherited] |
Called when a message is sent to us by an AbstractReflectSession object.
Default implementation is a no-op.
| 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, inherited] |
Called when a message is sent to us by a ReflectSessionFactory object.
Default implementation is a no-op.
| 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, inherited] |
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, inherited] |
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, inherited] |
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.
| 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. |
| status_t ServerComponent::AddNewConnectSession | ( | const AbstractReflectSessionRef & | session, | |
| const ip_address & | targetIPAddress, | |||
| uint16 | port, | |||
| uint64 | autoReconnectDelay = MUSCLE_TIME_NEVER | |||
| ) | [protected, inherited] |
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.
| 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). |
| status_t ServerComponent::AddNewDormantConnectSession | ( | const AbstractReflectSessionRef & | ref, | |
| const ip_address & | targetIPAddress, | |||
| uint16 | port, | |||
| uint64 | autoReconnectDelay = MUSCLE_TIME_NEVER | |||
| ) | [protected, inherited] |
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.
| 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). |
| AbstractReflectSessionRef ServerComponent::GetSession | ( | uint32 | id | ) | const [protected, inherited] |
Looks up a session connected to our ReflectServer via its session ID string.
| id | The ID of the session you are looking for. |
| AbstractReflectSessionRef ServerComponent::GetSession | ( | const String & | id | ) | const [protected, inherited] |
Looks up a session connected to our ReflectServer via its session ID string.
| id | The ID string of the session you are looking for. |
| 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.
| 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:
| 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. |
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.
| 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.
| child | The child to place into our set of child PulseNodes. |
| status_t PulseNode::RemovePulseChild | ( | PulseNode * | child | ) | [inherited] |
Attempts to remove the given child from our set of child PulseNodes.
| child | The child to remove |
| bool PulseNode::ContainsPulseChild | ( | PulseNode * | child | ) | const [inline, inherited] |
Returns true iff the given child is in our set of child PulseNodes.
| 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.
| 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.
| 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().
1.5.1