![]() |
AliRoot Core
v5-06-30 (35d6c57)
|
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 AliZMQManager * | GetInstance () |
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 &) | |
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 * | 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 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.
|
private |
Default destructor of AliZMQManager.
All contexts and sockets will be closed/destroyed.
Definition at line 81 of file AliZMQManager.cxx.
|
private |
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 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< 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(), AliStorageServerThread::StartCommunication(), and AliStorageAdministratorPanelListEvents::TriggerClassesFromCDB().
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);
result | Adres of pointer to which resulting event should be written |
socket | Name of socket from which message should be received |
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);
result | Adres of pointer to which resulting struct should be written |
socket | Name of socket from which message should be received |
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);
result | Adres of pointer to which resulting struct should be written |
socket | Name of socket from which message should be received |
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.
result | Pointer to which resulting message should be written |
socket | Name of socket from which message should be received |
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.
result | Pointer to which resulting message should be written |
socket | Name of socket from which message should be received |
Definition at line 797 of file AliZMQManager.cxx.
|
static |
Method to get instance of AliZMQManager.
Only one instance of AliZMQManager will be created (thread-safe).
Definition at line 94 of file AliZMQManager.cxx.
Referenced by AliStorageAdministratorPanel::AliStorageAdministratorPanel(), AliStorageAdministratorPanelListEvents::AliStorageAdministratorPanelListEvents(), AliStorageAdministratorPanelMarkEvent::AliStorageAdministratorPanelMarkEvent(), AliStorageAdministratorPanelSetStorageParams::AliStorageAdministratorPanelSetStorageParams(), AliEventsCollectorThread::CollectorHandle(), AliCommunicationThread::CommunicationHandle(), AliOnlineReconstruction::ReconstructionLoop(), and AliStorageServerThread::StartCommunication().
|
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 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< serverListStruct > | list, |
storageSockets | socket | ||
) |
Referenced by AliStorageAdministratorPanel::CheckClientState(), AliCommunicationThread::CommunicationHandle(), 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().
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);
request | Struct to be sent |
socket | Name of socket to which list shold be sent |
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);
request | Struct to be sent |
socket | Name of socket to which list shold be sent |
Definition at line 358 of file AliZMQManager.cxx.
bool 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 424 of file AliZMQManager.cxx.
bool 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 383 of file AliZMQManager.cxx.
bool 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 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.
event | Pointer to AliESDEvent object which is to be sent |
socket | Name of socket to which list shold be sent |
Definition at line 456 of file AliZMQManager.cxx.
|
private |
Definition at line 830 of file AliZMQManager.cxx.
|
private |
Definition at line 865 of file AliZMQManager.cxx.
|
private |
Definition at line 851 of file AliZMQManager.cxx.
|
private |
array of ZMQ contexts for all sockets
Definition at line 102 of file AliZMQManager.h.
|
private |
hostname for Online Reconstruction
Definition at line 95 of file AliZMQManager.h.
|
private |
Online Reconstruction port.
Definition at line 98 of file AliZMQManager.h.
|
staticprivate |
single instance of AliZMQManager
Definition at line 86 of file AliZMQManager.h.
|
private |
array of all ZMQ sockets
Definition at line 103 of file AliZMQManager.h.
|
private |
SM client thread's port.
Definition at line 97 of file AliZMQManager.h.
|
private |
hostname for Storage Manager
Definition at line 94 of file AliZMQManager.h.
|
private |
SM server thread's port.
Definition at line 96 of file AliZMQManager.h.
|
private |
port for xml publisher
Definition at line 99 of file AliZMQManager.h.