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
DispatcherClientTemplate.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 #ifndef OBJECTQUERYMODEL_DISPATCHERCLIENTTEMPLATE_CC
19 #define OBJECTQUERYMODEL_DISPATCHERCLIENTTEMPLATE_CC
20 
21 #include "DispatcherClient.h"
22 #include "DispatcherAddData.h"
23 #include "SimpleSendDataRequest.h"
24 #include "SimpleSendBytesRequest.h"
25 #include "SimpleRequestResult.h"
26 #include <snappy.h>
27 namespace pdb {
28 
29 template <class DataType>
30 bool DispatcherClient::sendData(std::pair<std::string, std::string> setAndDatabase,
31  Handle<Vector<Handle<DataType>>> dataToSend,
32  std::string& errMsg) {
33  return simpleSendDataRequest<DispatcherAddData, Handle<DataType>, SimpleRequestResult, bool>(
34  logger,
35  port,
36  address,
37  false,
38  1024,
39  [&](Handle<SimpleRequestResult> result) {
40  if (result != nullptr) {
41  if (!result->getRes().first) {
42  errMsg = "Error dispatching data: " + result->getRes().second;
43  logger->error(errMsg);
44  }
45  }
46  return true;
47  },
48  dataToSend,
49  setAndDatabase.second,
50  setAndDatabase.first,
51  getTypeName<DataType>());
52 }
53 
54 
55 template <class DataType>
56 bool DispatcherClient::sendBytes(std::pair<std::string, std::string> setAndDatabase,
57  char* bytes,
58  size_t numBytes,
59  std::string& errMsg) {
60 #ifdef ENABLE_COMPRESSION
61  char* compressedBytes = new char[snappy::MaxCompressedLength(numBytes)];
62  size_t compressedSize;
63  snappy::RawCompress((char*)bytes, numBytes, compressedBytes, &compressedSize);
64  std::cout << "size before compression is " << numBytes << " and size after compression is "
65  << compressedSize << std::endl;
66  return simpleSendBytesRequest<DispatcherAddData, SimpleRequestResult, bool>(
67  logger,
68  port,
69  address,
70  false,
71  1024,
72  [&](Handle<SimpleRequestResult> result) {
73  if (result != nullptr)
74  if (!result->getRes().first) {
75  logger->error("Error sending data: " + result->getRes().second);
76  errMsg = "Error sending data: " + result->getRes().second;
77  }
78  return true;
79  },
80  compressedBytes,
81  compressedSize,
82  setAndDatabase.second,
83  setAndDatabase.first,
84  getTypeName<DataType>(),
85  true);
86 #else
87  return simpleSendBytesRequest<DispatcherAddData, SimpleRequestResult, bool>(
88  logger,
89  port,
90  address,
91  false,
92  1024,
93  [&](Handle<SimpleRequestResult> result) {
94  if (result != nullptr)
95  if (!result->getRes().first) {
96  logger->error("Error sending data: " + result->getRes().second);
97  errMsg = "Error sending data: " + result->getRes().second;
98  }
99  return true;
100  },
101  bytes,
102  numBytes,
103  setAndDatabase.second,
104  setAndDatabase.first,
105  getTypeName<DataType>());
106 
107 
108 #endif
109 }
110 }
111 
112 #endif
bool sendBytes(std::pair< std::string, std::string > setAndDatabase, char *bytes, size_t numBytes, std::string &errMsg)
bool sendData(std::pair< std::string, std::string > setAndDatabase, Handle< Vector< Handle< DataType >>> dataToSend, std::string &errMsg)