BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
DimRpcWriter.cxx
Go to the documentation of this file.
1#include "NetDataWriter/DimRpcWriter.h"
2#include "ClientErrHandler/ClientErrHandler.h"
3#include "DistBossUtil/DistBossCode.h"
4#include "IRawFile/RawFileExceptions.h"
5#include "dic.hxx"
6#include <iostream>
7
8pthread_mutex_t DimRpcWriter::m_rpcLock = PTHREAD_MUTEX_INITIALIZER;
9
11 : m_inCode(0)
12{
13 if ( name.empty() ) {
14 throw RawExMessage("[NetDataWriter] The name of DistBoss Server was not set!");
15 }
16
18
19 m_rpc = new DimRpcInfo(name.c_str(), 5, DistBossCode::ServerTimeout);
20}
21
23{
24 delete m_rpc;
25}
26
27int DimRpcWriter::writeEvent(void *pevt, int size)
28{
29 static int nn = 0;
30 ++nn;
31
32 for ( int i = 1; i < 7; ++i ) {
33 pthread_mutex_lock( &m_rpcLock );
34
35 m_rpc->setData(pevt, size);
36 int inCode = m_rpc->getInt();
37
38 pthread_mutex_unlock( &m_rpcLock );
39
40
41 if ( inCode != DistBossCode::StatusSuccess) {
42 if ( inCode == DistBossCode::ServerTimeout) {
43 if ( i < 6 ) {
44 int sec = i;
45 std::cout << "[NetDataWriter] Event " << nn << " timeout. Sleep " << sec << "s before retry." << std::endl;
46 sleep(sec);
47 std::cout << "[NetDataWriter] Event " << nn << " now retry time " << i << " ..." << std::endl;
48 continue;
49 }
50 else {
51 m_inCode = inCode;
52 throw RawExMessage("[NetDataWriter] Failed to retry server. Stop this client!");
53 }
54 }
55 else if ( inCode == DistBossCode::ServerError) {
56 m_inCode = inCode;
57 throw RawExMessage("[NetDataWriter] Received server ERROR code!");
58 }
59 else {
60 m_inCode = inCode;
61 throw RawExMessage("[NetDataWriter] Unknown server code!");
62 }
63 }
64
65 if ( size == 4 && *((int*)pevt) == DistBossCode::StatusFinalize) {
66 throw ReachEndOfFileList();
67 }
68
69 break;
70 }
71
72 return 0;
73}
74
76{
77 return 0;
78}
79
81{
82 return m_inCode;
83}
static void registerInstance()
DimRpcWriter(WriterArgType &name)
virtual ~DimRpcWriter()
int writeEvent(void *pevt, int size)