![]() |
AliRoot Core
ee782a0 (ee782a0)
|
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 AliZMQManager * | GetInstance () |
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 &) | |
AliZMQManager & | operator= (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 AliZMQManager * | fManagerInstance = 0 |
single instance of AliZMQManager More... | |
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).
Definition at line 57 of file AliZMQManager.h.
|
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().
|
private |
Default destructor of AliZMQManager.
All contexts and sockets will be closed/destroyed.
Definition at line 87 of file AliZMQManager.cxx.
|
private |
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.
socket | Name 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< serverListStruct > *& | result, |
storageSockets | socket | ||
) |
Referenced by AliStorageAdministratorPanel::CheckClientState(), AliEventsCollectorThread::CollectorHandle(), AliCommunicationThread::CommunicationHandle(), AliStorageAdministratorPanelListEvents::onGetListButton(), AliStorageAdministratorPanelListEvents::onLoadButton(), AliStorageAdministratorPanelMarkEvent::onMarkButton(), AliStorageAdministratorPanelListEvents::onMarkButton(), AliStorageAdministratorPanel::onServerGetEvent(), AliStorageAdministratorPanel::onServerGetLastEvent(), AliStorageAdministratorPanel::onServerGetNextEvent(), AliStorageAdministratorPanel::onServerMarkAllEvents(), AliStorageAdministratorPanelSetStorageParams::onSetParamsButton(), SendAsXml(), AliStorageServerThread::StartCommunication(), and AliStorageAdministratorPanelListEvents::TriggerClassesFromCDB().
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);
result | Adres of pointer to which resulting event should be written |
socket | Name of socket from which message should be received |
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);
result | Adres of pointer to which resulting struct should be written |
socket | Name of socket from which message should be received |
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);
result | Adres of pointer to which resulting struct should be written |
socket | Name of socket from which message should be received |
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.
result | Pointer to which resulting message should be written |
socket | Name of socket from which message should be received |
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.
result | Pointer to which resulting message should be written |
socket | Name of socket from which message should be received |
Definition at line 809 of file AliZMQManager.cxx.
|
static |
Method to get instance of AliZMQManager.
Only one instance of AliZMQManager will be created (thread-safe).
Definition at line 101 of file AliZMQManager.cxx.
Referenced by AliStorageAdministratorPanel::AliStorageAdministratorPanel(), AliStorageAdministratorPanelListEvents::AliStorageAdministratorPanelListEvents(), AliStorageAdministratorPanelMarkEvent::AliStorageAdministratorPanelMarkEvent(), AliStorageAdministratorPanelSetStorageParams::AliStorageAdministratorPanelSetStorageParams(), AliEventsCollectorThread::CollectorHandle(), AliCommunicationThread::CommunicationHandle(), AliOnlineReconstruction::ReconstructionLoop(), AliStorageServerThread::StartCommunication(), and AliStorageClientThread::~AliStorageClientThread().
|
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.
socket | Name 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< serverListStruct > | list, |
storageSockets | socket | ||
) |
Referenced by AliStorageAdministratorPanel::CheckClientState(), AliCommunicationThread::CommunicationHandle(), CreateSocket(), AliStorageAdministratorPanelListEvents::onGetListButton(), AliStorageAdministratorPanelListEvents::onLoadButton(), AliStorageAdministratorPanelMarkEvent::onMarkButton(), AliStorageAdministratorPanelListEvents::onMarkButton(), AliStorageAdministratorPanel::onServerGetEvent(), AliStorageAdministratorPanel::onServerGetLastEvent(), AliStorageAdministratorPanel::onServerGetNextEvent(), AliStorageAdministratorPanel::onServerMarkAllEvents(), AliStorageAdministratorPanelSetStorageParams::onSetParamsButton(), AliOnlineReconstruction::ReconstructionLoop(), 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);
request | Struct to be sent |
socket | Name of socket to which list shold be sent |
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);
request | Struct to be sent |
socket | Name of socket to which list shold be sent |
Definition at line 370 of file AliZMQManager.cxx.
int AliZMQManager::Send | ( | AliESDEvent * | event, |
storageSockets | socket | ||
) |
Method sends message of type AliESDEvent to given socket.
event | Pointer to AliESDEvent object which is to be sent |
socket | Name of socket to which list shold be sent |
Definition at line 439 of file AliZMQManager.cxx.
int AliZMQManager::Send | ( | long | message, |
storageSockets | socket | ||
) |
Method sends message of type long to given socket.
message | Long message to be sent |
socket | Name of socket to which list shold be sent |
Definition at line 396 of file AliZMQManager.cxx.
int AliZMQManager::Send | ( | bool | message, |
storageSockets | socket | ||
) |
Method sends message of type bool to given socket.
message | Bool message to be sent |
socket | Name of socket to which list shold be sent |
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.
event | Pointer to AliESDEvent object which is to be sent |
socket | Name of socket to which list shold be sent |
Definition at line 472 of file AliZMQManager.cxx.
|
private |
Definition at line 838 of file AliZMQManager.cxx.
Referenced by CreateSocket(), Get(), Send(), and SendAsXml().
|
private |
Definition at line 877 of file AliZMQManager.cxx.
Referenced by CreateSocket(), Get(), and SendAsXml().
|
private |
Definition at line 859 of file AliZMQManager.cxx.
Referenced by CreateSocket(), Send(), and SendAsXml().
|
private |
single ZMQ context for all sockets
Definition at line 103 of file AliZMQManager.h.
Referenced by AliZMQManager(), Close(), and CreateSocket().
|
private |
hostname for Online Reconstruction
Definition at line 96 of file AliZMQManager.h.
Referenced by AliZMQManager(), and CreateSocket().
|
private |
Online Reconstruction port.
Definition at line 99 of file AliZMQManager.h.
Referenced by AliZMQManager(), and CreateSocket().
|
staticprivate |
single instance of AliZMQManager
Definition at line 87 of file AliZMQManager.h.
Referenced by GetInstance().
|
private |
array of all ZMQ sockets
Definition at line 104 of file AliZMQManager.h.
Referenced by CreateSocket(), Get(), RecreateSocket(), Send(), and SendAsXml().
|
private |
SM client thread's port.
Definition at line 98 of file AliZMQManager.h.
Referenced by AliZMQManager(), and CreateSocket().
|
private |
hostname for Storage Manager
Definition at line 95 of file AliZMQManager.h.
Referenced by AliZMQManager(), and CreateSocket().
|
private |
SM server thread's port.
Definition at line 97 of file AliZMQManager.h.
Referenced by AliZMQManager(), and CreateSocket().
|
private |
port for xml publisher
Definition at line 100 of file AliZMQManager.h.
Referenced by AliZMQManager(), and CreateSocket().