AceSmartSoft API Documentation
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
SmartACE::ServiceHandler Class Referenceabstract

#include <smartServiceHandler.hh>

Inheritance diagram for SmartACE::ServiceHandler:
SmartACE::EventClientServiceHandler SmartACE::EventServerServiceHandler SmartACE::NSProxy SmartACE::PushClientServiceHandler SmartACE::PushServerServiceHandler SmartACE::QueryClientServiceHandler SmartACE::QueryServerServiceHandler SmartACE::SendClientServiceHandler SmartACE::SendServerServiceHandler

Public Member Functions

 ServiceHandler (ACE_Reactor *reactor=ACE_Reactor::instance())
 Default constructor and destructor. More...
 
virtual ~ServiceHandler ()
 
virtual int open (void *handler=0)
 Initialization to create and activate an instance of this ACE_Svc_Handler class. More...
 
virtual int handle_input (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 This is the main input-handler function that is called by the reactor to handle incoming data streams. More...
 
virtual int handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask)
 Hook handler method to handle closing connection. More...
 
virtual int send_command_message (ACE_CDR::Long commandId, const ACE_Message_Block *further_comands=NULL, const ACE_Message_Block *message=NULL)
 This method encapsulates the message sending behavior. More...
 
void trigger_shutdown ()
 Trigger the shutdown procedure to be executed by the reactor. More...
 
bool is_disconnected () const
 This method returns true if reactor has closed the connection (due to e.g. More...
 

Protected Types

typedef ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH > super
 Definition for parent class. More...
 

Protected Member Functions

virtual int handle_incomming_message (ACE_CDR::Long command, ACE_InputCDR &cmd_is, ACE_InputCDR &msg_is)=0
 This handler should be implemented in derived classes. More...
 
virtual int handle_exception (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 This callback handler is indirectly triggered (using the reactor's notify mechanism) from the method trigger_shutdown() which can be used by external threads. More...
 
virtual void destroy (void)
 This class is overloaded from base class to change visibility (in order to prevent the destruction from external threads). More...
 

Protected Attributes

bool connectionClosedByUser
 This internal variable is used to distinguish whether a connection is closed actively by an external thread (using the method trigger_shutdown() ) or the connection is closed because the underlying socket is broken. More...
 
bool connectionResetByReactor
 This internal variable indicates that a connection was closed by reactor e.g. More...
 

Detailed Description

ACE ServiceHandler Abstract base class

This class implements a bidirectional communication mechanism that allows to communicate between two end-points in a network (using in this case the SOCK_STREAM). In SmartSoft this class is used in all Server communication ports together with the ACE_Acceptor class and in all Client communication ports together with the ACE_Connector class.

Since 2013, this class additionally implements a more robust error handling mechanism, which directly deals with the broken pipe error inside of the communication methods. It is important to know that therefore, on Unix systems the broken pipe error should be deactivated (redirected to a no-op handler), because the default handling results in closing down the whole process (which is not nice the smartsoft case).

Also an adjusted clean-up procedure is implemented which decouples the destruction called from an external thread to be executed by the reactor itself. This is needed since otherwise a thread could destroy this class while the reactor still uses it, which in some cases leads to unexpected behavior.

Member Typedef Documentation

◆ super

typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> SmartACE::ServiceHandler::super
protected

Definition for parent class.

This allows to use functions from parent class in a more readable way.

Constructor & Destructor Documentation

◆ ServiceHandler()

SmartACE::ServiceHandler::ServiceHandler ( ACE_Reactor *  reactor = ACE_Reactor::instance())

Default constructor and destructor.

◆ ~ServiceHandler()

virtual SmartACE::ServiceHandler::~ServiceHandler ( )
virtual

Member Function Documentation

◆ destroy()

virtual void SmartACE::ServiceHandler::destroy ( void  )
protectedvirtual

This class is overloaded from base class to change visibility (in order to prevent the destruction from external threads).

◆ handle_close()

virtual int SmartACE::ServiceHandler::handle_close ( ACE_HANDLE  handle,
ACE_Reactor_Mask  close_mask 
)
virtual

Hook handler method to handle closing connection.

This default behavior is changed here. This method should not destroy the object itself (as implemented by default). Instead, the destruction is explicitly triggered by the user method triggerShutdown().

◆ handle_exception()

virtual int SmartACE::ServiceHandler::handle_exception ( ACE_HANDLE  fd = ACE_INVALID_HANDLE)
protectedvirtual

This callback handler is indirectly triggered (using the reactor's notify mechanism) from the method trigger_shutdown() which can be used by external threads.

◆ handle_incomming_message()

virtual int SmartACE::ServiceHandler::handle_incomming_message ( ACE_CDR::Long  command,
ACE_InputCDR &  cmd_is,
ACE_InputCDR &  msg_is 
)
protectedpure virtual

This handler should be implemented in derived classes.

It should implement the dispatching of the incoming requests to the corresponding call-back methods (from the communication pattern).

Implemented in SmartACE::NSProxy.

◆ handle_input()

virtual int SmartACE::ServiceHandler::handle_input ( ACE_HANDLE  fd = ACE_INVALID_HANDLE)
virtual

This is the main input-handler function that is called by the reactor to handle incoming data streams.

Within this function the de-marshaling takes place.

◆ is_disconnected()

bool SmartACE::ServiceHandler::is_disconnected ( ) const
inline

This method returns true if reactor has closed the connection (due to e.g.

a broken pipe or remotely called shutdown)

◆ open()

virtual int SmartACE::ServiceHandler::open ( void *  handler = 0)
virtual

Initialization to create and activate an instance of this ACE_Svc_Handler class.

Here, memory allocation and ACE_Svc_Handler parameterization takes place. The default implementation just calls the same method from parent class.

Parameters
handlerA pointer to the parent controlling class (in this case ACE_Connector or ACE_Acceptor)
Returns
error-code
  • A "-1" determines an error
  • A "0" is returned if all goes right

Reimplemented in SmartACE::QueryServerServiceHandler, SmartACE::EventServerServiceHandler, SmartACE::SendServerServiceHandler, SmartACE::NSProxy, and SmartACE::PushServerServiceHandler.

◆ send_command_message()

virtual int SmartACE::ServiceHandler::send_command_message ( ACE_CDR::Long  commandId,
const ACE_Message_Block *  further_comands = NULL,
const ACE_Message_Block *  message = NULL 
)
virtual

This method encapsulates the message sending behavior.

Within this method the marshaling takes place. It is safe to call this method from a user thread, however, this method is not thread safe and can not be called by several threads in parallel. It returns 0 on success or -1 on communication error.

◆ trigger_shutdown()

void SmartACE::ServiceHandler::trigger_shutdown ( )

Trigger the shutdown procedure to be executed by the reactor.

The shutdown procedure should not be triggered by external threads directly. Instead the reactor should be notified to shutdown this service handler as soon as possible. This prevents the error, which can occur if a thread removes the service handler while it is still used by the reactor for still pending events.

Member Data Documentation

◆ connectionClosedByUser

bool SmartACE::ServiceHandler::connectionClosedByUser
protected

This internal variable is used to distinguish whether a connection is closed actively by an external thread (using the method trigger_shutdown() ) or the connection is closed because the underlying socket is broken.

◆ connectionResetByReactor

bool SmartACE::ServiceHandler::connectionResetByReactor
protected

This internal variable indicates that a connection was closed by reactor e.g.

due to broken pipe or if the remote end-point calls shutdown (this variable prevents the service handler to run into broken pipe error in regular cases, however, as broken pipe is also handled inside of the receive/send methods, this functionality is not critical, it just improves the overall performance)


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