]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/alistoragemanager/AliStorageClientThread.cxx
Client Thread of Storage Manager split into smaller classes. Preparation for moving...
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / AliStorageClientThread.cxx
CommitLineData
5eb34a26 1#include "AliStorageClientThread.h"
5eb34a26 2
eadbe6fa 3//#include <sstream>
5eb34a26 4#include <signal.h>
5#include <fstream>
6#include <iostream>
7
5eb34a26 8using namespace std;
5eb34a26 9
eadbe6fa 10bool gClientQuit = false;
5eb34a26 11void GotSignalClient(int){gClientQuit = true;}
12
13AliStorageClientThread::AliStorageClientThread() :
eadbe6fa 14fDIMListenerThread(0),
15fEventsCollectorThread(0),
16fCommunicationThread(0),
5eb34a26 17fConnectionStatus(STATUS_WAITING),
18fReceivingStatus(STATUS_WAITING),
19fSavingStatus(STATUS_WAITING),
5eb34a26 20fCurrentStorageSize(0),
21fMaximumStorageSize(0),
22fStoragePath(""),
23fNumberOfEventsInFile(0),
24fStorageOccupationLevel(0),
25fRemoveEventsPercentage(0)
5eb34a26 26{
eadbe6fa 27 // make sure that when program is closed destructor will be called
28 struct sigaction sa;
29 memset(&sa,0,sizeof(sa));
30 sa.sa_handler = GotSignalClient;
31 sigfillset(&sa.sa_mask);
32 sigaction(SIGINT,&sa,NULL);
33
34 ifstream configFile (GetConfigFilePath());
35 if (configFile.is_open())
36 {
37 string line;
38 int from,to;
39 while(configFile.good())
40 {
41 getline(configFile,line);
42 from = line.find("\"")+1;
43 to = line.find_last_of("\"");
44 if(line.find("STORAGE_PATH=")==0){
45 fStoragePath=line.substr(from,to-from);
46 }
47 else if(line.find("MAX_SIZE=")==0){
48 fMaximumStorageSize=atoi(line.substr(from,to-from).c_str());
49 }
50 else if(line.find("MAX_OCCUPATION=")==0){
51 fStorageOccupationLevel=atoi(line.substr(from,to-from).c_str());
52 }
53 else if(line.find("REMOVE_PERCENT=")==0){
54 fRemoveEventsPercentage=atoi(line.substr(from,to-from).c_str());
55 }
56 else if(line.find("EVENTS_IN_FILE=")==0){
57 fNumberOfEventsInFile=atoi(line.substr(from,to-from).c_str());
58 }
59 }
60 if(configFile.eof()){configFile.clear();}
61 configFile.close();
62 }
63 else{cout<<"CLIENT -- Unable to open config file"<<endl;}
64
65 //create directory for storage if it doesn't exist
66 gSystem->Exec(Form("mkdir -p %s",fStoragePath.c_str()));
67
68 fDIMListenerThread = new AliDIMListenerThread();
69 fEventsCollectorThread = new AliEventsCollectorThread(this);
70 fCommunicationThread = new AliCommunicationThread(this);
5eb34a26 71}
72
eadbe6fa 73AliStorageClientThread::~AliStorageClientThread()
5eb34a26 74{
eadbe6fa 75 while(!gClientQuit){sleep(1);}
76 fEventsCollectorThread->Kill();
77 fCommunicationThread->Kill();
78}