Client Thread of Storage Manager split into smaller classes. Preparation for moving...
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / AliStorageClientThread.cxx
1 #include "AliStorageClientThread.h"
2
3 //#include <sstream>
4 #include <signal.h>
5 #include <fstream>
6 #include <iostream>
7
8 using namespace std;
9
10 bool gClientQuit = false;
11 void GotSignalClient(int){gClientQuit = true;}
12
13 AliStorageClientThread::AliStorageClientThread() :
14 fDIMListenerThread(0),
15 fEventsCollectorThread(0),
16 fCommunicationThread(0),
17 fConnectionStatus(STATUS_WAITING),
18 fReceivingStatus(STATUS_WAITING),
19 fSavingStatus(STATUS_WAITING),
20 fCurrentStorageSize(0),
21 fMaximumStorageSize(0),
22 fStoragePath(""),
23 fNumberOfEventsInFile(0),
24 fStorageOccupationLevel(0),
25 fRemoveEventsPercentage(0)
26 {
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);
71 }
72
73 AliStorageClientThread::~AliStorageClientThread()
74 {
75     while(!gClientQuit){sleep(1);}
76     fEventsCollectorThread->Kill();
77     fCommunicationThread->Kill();
78 }