AliRoot Core  ee782a0 (ee782a0)
AliZMQManager Class Reference

ZMQ communication manager. More...

#include <AliZMQManager.h>

Public Member Functions

void Close ()
 
void CreateSocket (storageSockets socket)
 
void RecreateSocket (storageSockets socket)
 
int Send (std::vector< serverListStruct > list, storageSockets socket)
 
int Send (std::vector< string100 > list, storageSockets socket)
 
int Send (struct serverRequestStruct *request, storageSockets socket)
 
int Send (struct clientRequestStruct *request, storageSockets socket)
 
int Send (AliESDEvent *event, storageSockets socket)
 
int Send (long message, storageSockets socket)
 
int Send (bool message, storageSockets socket)
 
int SendAsXml (AliESDEvent *event, storageSockets socket)
 
int Get (std::vector< serverListStruct > *&result, storageSockets socket)
 
int Get (std::vector< string100 > *&result, storageSockets socket)
 
int Get (AliESDEvent *&result, storageSockets socket)
 
int Get (struct serverRequestStruct *&result, storageSockets socket)
 
int Get (struct clientRequestStruct *&result, storageSockets socket)
 
int Get (long *result, storageSockets socket)
 
int 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)
 
int zmqSend (zmq_msg_t *msg, void *socket, int flags)
 
int 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 * fContext
 single ZMQ context 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.

Referenced by GetInstance().

AliZMQManager::~AliZMQManager ( )
private

Default destructor of AliZMQManager.

All contexts and sockets will be closed/destroyed.

Definition at line 87 of file AliZMQManager.cxx.

AliZMQManager::AliZMQManager ( const AliZMQManager )
private

Member Function Documentation

void AliZMQManager::Close ( )

Definition at line 91 of file AliZMQManager.cxx.

Referenced by AliStorageClientThread::~AliStorageClientThread().

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 119 of file AliZMQManager.cxx.

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

int AliZMQManager::Get ( std::vector< string100 > *&  result,
storageSockets  socket 
)
int 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 692 of file AliZMQManager.cxx.

int 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 743 of file AliZMQManager.cxx.

int 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 769 of file AliZMQManager.cxx.

int 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 789 of file AliZMQManager.cxx.

int 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 809 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 830 of file AliZMQManager.cxx.

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

int AliZMQManager::Send ( std::vector< string100 >  list,
storageSockets  socket 
)
int 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 339 of file AliZMQManager.cxx.

int 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 370 of file AliZMQManager.cxx.

int 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 439 of file AliZMQManager.cxx.

int 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 396 of file AliZMQManager.cxx.

int 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 418 of file AliZMQManager.cxx.

int 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 472 of file AliZMQManager.cxx.

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

Definition at line 838 of file AliZMQManager.cxx.

Referenced by CreateSocket(), Get(), Send(), and SendAsXml().

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

Definition at line 877 of file AliZMQManager.cxx.

Referenced by CreateSocket(), Get(), and SendAsXml().

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

Definition at line 859 of file AliZMQManager.cxx.

Referenced by CreateSocket(), Send(), and SendAsXml().

Member Data Documentation

void* AliZMQManager::fContext
private

single ZMQ context for all sockets

Definition at line 103 of file AliZMQManager.h.

Referenced by AliZMQManager(), Close(), and CreateSocket().

std::string AliZMQManager::fEventServer
private

hostname for Online Reconstruction

Definition at line 96 of file AliZMQManager.h.

Referenced by AliZMQManager(), and CreateSocket().

int AliZMQManager::fEventServerPort
private

Online Reconstruction port.

Definition at line 99 of file AliZMQManager.h.

Referenced by AliZMQManager(), and CreateSocket().

AliZMQManager * AliZMQManager::fManagerInstance = 0
staticprivate

single instance of AliZMQManager

Definition at line 87 of file AliZMQManager.h.

Referenced by GetInstance().

void* AliZMQManager::fSockets[NUMBER_OF_SOCKETS]
private

array of all ZMQ sockets

Definition at line 104 of file AliZMQManager.h.

Referenced by CreateSocket(), Get(), RecreateSocket(), Send(), and SendAsXml().

int AliZMQManager::fStorageClientPort
private

SM client thread's port.

Definition at line 98 of file AliZMQManager.h.

Referenced by AliZMQManager(), and CreateSocket().

std::string AliZMQManager::fStorageServer
private

hostname for Storage Manager

Definition at line 95 of file AliZMQManager.h.

Referenced by AliZMQManager(), and CreateSocket().

int AliZMQManager::fStorageServerPort
private

SM server thread's port.

Definition at line 97 of file AliZMQManager.h.

Referenced by AliZMQManager(), and CreateSocket().

int AliZMQManager::fXmlServerPort
private

port for xml publisher

Definition at line 100 of file AliZMQManager.h.

Referenced by AliZMQManager(), and CreateSocket().


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