A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ServerWork.cc
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #ifndef SERVER_WORK_CC
20 #define SERVER_WORK_CC
21 
22 #include "ServerWork.h"
23 
24 namespace pdb {
25 
26 ServerWork::ServerWork(PDBServer& workOnMeIn) : workOnMe(workOnMeIn) {
27  wasEnError = false;
28 }
29 
31  PDBCommWorkPtr returnVal{make_shared<ServerWork>(workOnMe)};
32  return returnVal;
33 }
34 
36  wasEnError = true;
37  getLogger()->error("ServerWork: got an error");
38 }
39 
41  return std::make_shared<PDBBuzzer>([&](PDBAlarm myAlarm) {});
42 }
43 
44 void ServerWork::execute(PDBBuzzerPtr callerBuzzer) {
45 
46  // while there is still something to do on this connection
47  getLogger()->trace("ServerWork: about to handle a request");
48  PDBBuzzerPtr myBuzzer{getLinkedBuzzer()};
49  while (!wasEnError && workOnMe.handleOneRequest(myBuzzer, getCommunicator())) {
50  getLogger()->trace("ServerWork: just handled another request");
51  myBuzzer = getLinkedBuzzer();
52  }
53 
54  getLogger()->trace("ServerWork: done with this server work");
55  callerBuzzer->buzz(PDBAlarm::WorkAllDone);
56 }
57 }
58 
59 #endif
PDBCommWorkPtr clone() override
Definition: ServerWork.cc:30
PDBCommunicatorPtr getCommunicator()
Definition: PDBCommWork.cc:28
void handleError()
Definition: ServerWork.cc:35
bool handleOneRequest(PDBBuzzerPtr buzzMeWhenDone, PDBCommunicatorPtr myCommunicator)
Definition: PDBServer.cc:246
PDBLoggerPtr getLogger()
Definition: PDBWork.cc:36
shared_ptr< PDBBuzzer > PDBBuzzerPtr
Definition: PDBBuzzer.h:32
void execute(PDBBuzzerPtr callerBuzzer) override
Definition: ServerWork.cc:44
PDBAlarm
Definition: PDBAlarm.h:28
PDBBuzzerPtr getLinkedBuzzer() override
Definition: ServerWork.cc:40
ServerWork(PDBServer &workOnMe)
Definition: ServerWork.cc:26
std::shared_ptr< PDBCommWork > PDBCommWorkPtr
Definition: PDBCommWork.h:37
PDBServer & workOnMe
Definition: ServerWork.h:63