AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliZMQManager Class Reference

ZMQ communication manager. More...

#include <AliZMQManager.h>

Public Member Functions

void CreateSocket (storageSockets socket)
 
void RecreateSocket (storageSockets socket)
 
bool Send (std::vector< serverListStruct > list, storageSockets socket)
 
bool Send (std::vector< string100 > list, storageSockets socket)
 
bool Send (struct serverRequestStruct *request, storageSockets socket)
 
bool Send (struct clientRequestStruct *request, storageSockets socket)
 
bool Send (AliESDEvent *event, storageSockets socket)
 
bool Send (long message, storageSockets socket)
 
bool Send (bool message, storageSockets socket)
 
bool SendAsXml (AliESDEvent *event, storageSockets socket)
 
bool Get (std::vector< serverListStruct > *&result, storageSockets socket)
 
bool Get (std::vector< string100 > *&result, storageSockets socket)
 
bool Get (AliESDEvent *&result, storageSockets socket)
 
bool Get (struct serverRequestStruct *&result, storageSockets socket)
 
bool Get (struct clientRequestStruct *&result, storageSockets socket)
 
bool Get (long *result, storageSockets socket)
 
bool Get (bool *result, storageSockets socket)
 

Static Public Member Functions

static AliZMQManagerGetInstance ()
 

Private Member Functions

 AliZMQManager ()
 
 ~AliZMQManager ()
 
bool zmqInit (zmq_msg_t *msg, size_t size=0)
 
bool zmqSend (zmq_msg_t *msg, void *socket, int flags)
 
bool zmqRecv (zmq_msg_t *msg, void *socket, int flags)
 
 AliZMQManager (const AliZMQManager &)
 
AliZMQManageroperator= (const AliZMQManager &)
 

Private Attributes

std::string fStorageServer
 hostname for Storage Manager More...
 
std::string fEventServer
 hostname for Online Reconstruction More...
 
int fStorageServerPort
 SM server thread's port. More...
 
int fStorageClientPort
 SM client thread's port. More...
 
int fEventServerPort
 Online Reconstruction port. More...
 
int fXmlServerPort
 port for xml publisher More...
 
void * fContexts [NUMBER_OF_SOCKETS]
 array of ZMQ contexts for all sockets More...
 
void * fSockets [NUMBER_OF_SOCKETS]
 array of all ZMQ sockets More...
 

Static Private Attributes

static AliZMQManagerfManagerInstance = 0
 single instance of AliZMQManager More...
 

Detailed Description

ZMQ communication manager.

This class handles communication based on ZMQ to provide easy to use interface. Manager is capable of sending and receiving different data types and can be extended for other types if needed.

Usage: 1) Get manager's instance: AliZMQManager *manager = AliZMQManager::GetInstance(); 2) Create a socket: manager->CreateSocket(NAME_OF_SOCKET);

Names of avaliable sockets are stored in AliStorageTypes.h 3) Use Send() and Get():

manager->Send(true,NAME_OF_SOCKET); manager->Get(&longResponse,NAME_OF_SOCKET);

Communication's logic: Every send and get call has a timeout of 5 seconds. Every Send(...) and Get(...) will return bool, which indicates status (1-success,0-failed). It is your responsibility to invent a communication logic that will handle all cases. Especially keep in mind, that REQ-REP communication is sensitive to the state of socket, so if you successfully sent massage on REQ socket and then you failed to receive a response, you cannot send new request, as socket is expecting you to try to receive message again.

If you are sure you want to send new message after receive failed, you can always recreate socket (it will be closed and created again in the default state). To do that, call:

manager->RecreateSocket(NAME_OF_SOCKET);

Adding new sockets: If you need to add new socket, you need to do two things: 1) Add name of socket in AliStorageTypes.h (enum storageSockets), 2) Extend CreateSocket(...) method by adding another case in the switch (to be consistent, copy one of existing cases and modify it).

Author
Jeremi Niedziela jerem.nosp@m.i.ni.nosp@m.edzie.nosp@m.la@c.nosp@m.ern.c.nosp@m.h, Warsaw University of Technology, CERN

Definition at line 57 of file AliZMQManager.h.

Constructor & Destructor Documentation

AliZMQManager::AliZMQManager ( )
private

Defaul counstructor of AliZMQManager

In constructor, config files with hostnames and port number are being read. Contexts for all sockets are being created.

Definition at line 32 of file AliZMQManager.cxx.

AliZMQManager::~AliZMQManager ( )
private

Default destructor of AliZMQManager.

All contexts and sockets will be closed/destroyed.

Definition at line 81 of file AliZMQManager.cxx.

AliZMQManager::AliZMQManager ( const AliZMQManager )
private

Member Function Documentation

void AliZMQManager::CreateSocket ( storageSockets  socket)

Method to create socket with given name.

Names of sockets are defined in AliStorageTypes.h This method should be extended in case of need for additional sockets.

Parameters
socketName of socket (of type storageSockets) to be created.

Definition at line 112 of file AliZMQManager.cxx.

Referenced by AliStorageAdministratorPanel::AliStorageAdministratorPanel(), AliStorageAdministratorPanelListEvents::AliStorageAdministratorPanelListEvents(), AliEventsCollectorThread::CollectorHandle(), AliCommunicationThread::CommunicationHandle(), AliOnlineReconstruction::ReconstructionLoop(), and AliStorageServerThread::StartCommunication().

bool AliZMQManager::Get ( std::vector< string100 > *&  result,
storageSockets  socket 
)
bool AliZMQManager::Get ( AliESDEvent *&  result,
storageSockets  socket 
)

Method to get AliESDEvent from given socket.

Usage:

AliESDEvent *event; manager->Get(event,socket);

Parameters
resultAdres of pointer to which resulting event should be written
socketName of socket from which message should be received
Returns
Returns true in case of success, false in case of failure

Definition at line 670 of file AliZMQManager.cxx.

bool AliZMQManager::Get ( struct serverRequestStruct *&  result,
storageSockets  socket 
)

Method to get serverRequestStruct from given socket.

Usage:

struct serverRequestStruct *request; manager->Get(request,socket);

Parameters
resultAdres of pointer to which resulting struct should be written
socketName of socket from which message should be received
Returns
Returns true in case of success, false in case of failure

Definition at line 720 of file AliZMQManager.cxx.

bool AliZMQManager::Get ( struct clientRequestStruct *&  result,
storageSockets  socket 
)

Method to get clientRequestStruct from given socket.

Usage:

struct clientRequestStruct *request; manager->Get(request,socket);

Parameters
resultAdres of pointer to which resulting struct should be written
socketName of socket from which message should be received
Returns
Returns true in case of success, false in case of failure

Definition at line 750 of file AliZMQManager.cxx.

bool AliZMQManager::Get ( long *  result,
storageSockets  socket 
)

Method to get message of type long from given socket.

Parameters
resultPointer to which resulting message should be written
socketName of socket from which message should be received
Returns
Returns true in case of success, false in case of failure

Definition at line 774 of file AliZMQManager.cxx.

bool AliZMQManager::Get ( bool *  result,
storageSockets  socket 
)

Method to get message of type bool from given socket.

Parameters
resultPointer to which resulting message should be written
socketName of socket from which message should be received
Returns
Returns true in case of success, false in case of failure

Definition at line 797 of file AliZMQManager.cxx.

AliZMQManager& AliZMQManager::operator= ( const AliZMQManager )
private
void AliZMQManager::RecreateSocket ( storageSockets  socket)

Method to close and create from scratch given socket.

This must be used if socket is expecting to receive a message, but you need to send one and vice versa. Use only when you are sure what you are doing, you should design communication pattern yourself depending on what you need.

Parameters
socketName of socket to be recreated

Definition at line 822 of file AliZMQManager.cxx.

Referenced by AliCommunicationThread::CommunicationHandle(), AliStorageAdministratorPanelListEvents::onGetListButton(), AliStorageAdministratorPanelListEvents::onLoadButton(), AliStorageAdministratorPanelListEvents::onMarkButton(), AliStorageServerThread::StartCommunication(), and AliStorageAdministratorPanelListEvents::TriggerClassesFromCDB().

bool AliZMQManager::Send ( std::vector< string100 >  list,
storageSockets  socket 
)
bool AliZMQManager::Send ( struct serverRequestStruct *  request,
storageSockets  socket 
)

Method sends structs of type serverRequestStruct to given socket.

Define your request as:

struct serverRequestStruct *request = new struct serverRequestStruct;

and call this method as:

manager->Send(request,socket);
Parameters
requestStruct to be sent
socketName of socket to which list shold be sent
Returns
Returns true in case of success, false in case of failure

Definition at line 328 of file AliZMQManager.cxx.

bool AliZMQManager::Send ( struct clientRequestStruct *  request,
storageSockets  socket 
)

Method sends structs of type clientRequestStruct to given socket.

Define your request as:

struct clientRequestStruct *request = new struct clientRequestStruct;

and call this method as:

manager->Send(request,socket);
Parameters
requestStruct to be sent
socketName of socket to which list shold be sent
Returns
Returns true in case of success, false in case of failure

Definition at line 358 of file AliZMQManager.cxx.

bool AliZMQManager::Send ( AliESDEvent *  event,
storageSockets  socket 
)

Method sends message of type AliESDEvent to given socket.

Parameters
eventPointer to AliESDEvent object which is to be sent
socketName of socket to which list shold be sent
Returns
Returns true in case of success, false in case of failure

Definition at line 424 of file AliZMQManager.cxx.

bool AliZMQManager::Send ( long  message,
storageSockets  socket 
)

Method sends message of type long to given socket.

Parameters
messageLong message to be sent
socketName of socket to which list shold be sent
Returns
Returns true in case of success, false in case of failure

Definition at line 383 of file AliZMQManager.cxx.

bool AliZMQManager::Send ( bool  message,
storageSockets  socket 
)

Method sends message of type bool to given socket.

Parameters
messageBool message to be sent
socketName of socket to which list shold be sent
Returns
Returns true in case of success, false in case of failure

Definition at line 404 of file AliZMQManager.cxx.

bool AliZMQManager::SendAsXml ( AliESDEvent *  event,
storageSockets  socket 
)

Method sends AliESDEvent as an xml to given socket.

This method extracts some information from AliESDEvent, puts it in a string formatted as an xml and sends it to a given socket.

Parameters
eventPointer to AliESDEvent object which is to be sent
socketName of socket to which list shold be sent
Returns
Returns true in case of success, false in case of failure

Definition at line 456 of file AliZMQManager.cxx.

bool AliZMQManager::zmqInit ( zmq_msg_t *  msg,
size_t  size = 0 
)
private

Definition at line 830 of file AliZMQManager.cxx.

bool AliZMQManager::zmqRecv ( zmq_msg_t *  msg,
void *  socket,
int  flags 
)
private

Definition at line 865 of file AliZMQManager.cxx.

bool AliZMQManager::zmqSend ( zmq_msg_t *  msg,
void *  socket,
int  flags 
)
private

Definition at line 851 of file AliZMQManager.cxx.

Member Data Documentation

void* AliZMQManager::fContexts[NUMBER_OF_SOCKETS]
private

array of ZMQ contexts for all sockets

Definition at line 102 of file AliZMQManager.h.

std::string AliZMQManager::fEventServer
private

hostname for Online Reconstruction

Definition at line 95 of file AliZMQManager.h.

int AliZMQManager::fEventServerPort
private

Online Reconstruction port.

Definition at line 98 of file AliZMQManager.h.

AliZMQManager * AliZMQManager::fManagerInstance = 0
staticprivate

single instance of AliZMQManager

Definition at line 86 of file AliZMQManager.h.

void* AliZMQManager::fSockets[NUMBER_OF_SOCKETS]
private

array of all ZMQ sockets

Definition at line 103 of file AliZMQManager.h.

int AliZMQManager::fStorageClientPort
private

SM client thread's port.

Definition at line 97 of file AliZMQManager.h.

std::string AliZMQManager::fStorageServer
private

hostname for Storage Manager

Definition at line 94 of file AliZMQManager.h.

int AliZMQManager::fStorageServerPort
private

SM server thread's port.

Definition at line 96 of file AliZMQManager.h.

int AliZMQManager::fXmlServerPort
private

port for xml publisher

Definition at line 99 of file AliZMQManager.h.


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