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
SetIterator.h
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 SET_ITER_H
20 #define SET_ITER_H
21 
22 #include "OutputIterator.h"
23 #include "SetScan.h"
24 #include <snappy.h>
25 
26 namespace pdb {
27 
28 template <class OutType>
29 class SetIterator {
30 
31 public:
32  // constructor; this should only be used by the query client
34  int portIn,
35  std::string& serverNameIn,
36  std::string& dbNameIn,
37  std::string& setNameIn) {
38  myLogger = loggerIn;
39  port = portIn;
40  serverName = serverNameIn;
41  dbName = dbNameIn;
42  setName = setNameIn;
43  wasError = false;
44  }
45 
47  wasError = true;
48  }
49 
51 
52  // this basically sets up a connection to the server, and returns it
54 
55  // if there was an error, just get outta here
56  if (wasError) {
57  std::cout << "You are trying to create an iterator when there was an error.\n";
58  return OutputIterator<OutType>();
59  }
60 
61  // establish a connection
62  std::string errMsg;
63  PDBCommunicatorPtr temp = std::make_shared<PDBCommunicator>();
64  if (temp->connectToInternetServer(myLogger, port, serverName, errMsg)) {
65  myLogger->error(errMsg);
66  myLogger->error("output iterator: not able to connect to server.\n");
67  return OutputIterator<OutType>();
68  }
69 
70  // build the request
71  const UseTemporaryAllocationBlock tempBlock{1024};
72  Handle<SetScan> request = makeObject<SetScan>(dbName, setName);
73  if (!temp->sendObject(request, errMsg)) {
74  myLogger->error(errMsg);
75  myLogger->error("output iterator: not able to send request to server.\n");
76  return OutputIterator<OutType>();
77  }
78  PDB_COUT << "sent SetScan object to manager" << std::endl;
79  return OutputIterator<OutType>(temp);
80  }
81 
83  return OutputIterator<OutType>();
84  }
85 
86 private:
87  // these are used so that the output knows how to connect to the server for iteration
88  int port;
89  std::string serverName;
91 
92  // records the place where the input comes from
93  std::string dbName;
94  std::string setName;
95 
96  // true if there is an error
97  bool wasError;
98 
99  // allows creation of these objects
100  friend class QueryClient;
101 };
102 }
103 
104 #endif
OutputIterator< OutType > begin()
Definition: SetIterator.h:53
std::string serverName
Definition: SetIterator.h:89
std::shared_ptr< PDBCommunicator > PDBCommunicatorPtr
OutputIterator< OutType > end()
Definition: SetIterator.h:82
SetIterator(PDBLoggerPtr loggerIn, int portIn, std::string &serverNameIn, std::string &dbNameIn, std::string &setNameIn)
Definition: SetIterator.h:33
#define PDB_COUT
Definition: PDBDebug.h:31
std::string dbName
Definition: SetIterator.h:93
PDBLoggerPtr myLogger
Definition: SetIterator.h:90
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
std::string setName
Definition: SetIterator.h:94