You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ec...@apache.org on 2017/08/10 15:20:13 UTC
[05/27] geode-native git commit: GEODE-2729: Remove global variables
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/VersionedCacheableObjectPartList.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/VersionedCacheableObjectPartList.cpp b/src/cppcache/src/VersionedCacheableObjectPartList.cpp
index 94ec919..ecfc350 100644
--- a/src/cppcache/src/VersionedCacheableObjectPartList.cpp
+++ b/src/cppcache/src/VersionedCacheableObjectPartList.cpp
@@ -203,6 +203,8 @@ Serializable* VersionedCacheableObjectPartList::fromData(DataInput& input) {
len = versionTaglen;
m_versionTags.resize(versionTaglen);
std::vector<uint16_t> ids;
+ MemberListForVersionStamp& memberListForVersionStamp =
+ *(m_region->getCacheImpl()->getMemberListForVersionStamp());
for (int32_t index = 0; index < versionTaglen; index++) {
uint8_t entryType = 0;
input.read(&entryType);
@@ -213,9 +215,11 @@ Serializable* VersionedCacheableObjectPartList::fromData(DataInput& input) {
}
case FLAG_FULL_TAG: {
if (persistent) {
- versionTag = VersionTagPtr(new DiskVersionTag());
+ versionTag =
+ VersionTagPtr(new DiskVersionTag(memberListForVersionStamp));
} else {
- versionTag = VersionTagPtr(new VersionTag());
+ versionTag =
+ VersionTagPtr(new VersionTag(memberListForVersionStamp));
}
versionTag->fromData(input);
versionTag->replaceNullMemberId(getEndpointMemId());
@@ -224,9 +228,11 @@ Serializable* VersionedCacheableObjectPartList::fromData(DataInput& input) {
case FLAG_TAG_WITH_NEW_ID: {
if (persistent) {
- versionTag = VersionTagPtr(new DiskVersionTag());
+ versionTag =
+ VersionTagPtr(new DiskVersionTag(memberListForVersionStamp));
} else {
- versionTag = VersionTagPtr(new VersionTag());
+ versionTag =
+ VersionTagPtr(new VersionTag(memberListForVersionStamp));
}
versionTag->fromData(input);
ids.push_back(versionTag->getInternalMemID());
@@ -235,9 +241,11 @@ Serializable* VersionedCacheableObjectPartList::fromData(DataInput& input) {
case FLAG_TAG_WITH_NUMBER_ID: {
if (persistent) {
- versionTag = VersionTagPtr(new DiskVersionTag());
+ versionTag =
+ VersionTagPtr(new DiskVersionTag(memberListForVersionStamp));
} else {
- versionTag = VersionTagPtr(new VersionTag());
+ versionTag =
+ VersionTagPtr(new VersionTag(memberListForVersionStamp));
}
versionTag->fromData(input);
int32_t idNumber;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/VersionedCacheableObjectPartList.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/VersionedCacheableObjectPartList.hpp b/src/cppcache/src/VersionedCacheableObjectPartList.hpp
index 91b7f3c..9ebd6f4 100644
--- a/src/cppcache/src/VersionedCacheableObjectPartList.hpp
+++ b/src/cppcache/src/VersionedCacheableObjectPartList.hpp
@@ -126,6 +126,18 @@ class VersionedCacheableObjectPartList : public CacheableObjectPartList {
;
}
+ VersionedCacheableObjectPartList(ThinClientRegion* region, uint16_t dsmemId,
+ ACE_Recursive_Thread_Mutex& responseLock)
+ : CacheableObjectPartList(region),
+ m_responseLock(responseLock),
+ m_endpointMemId(dsmemId) {
+ m_regionIsVersioned = false;
+ m_serializeValues = false;
+ m_hasTags = false;
+ this->m_hasKeys = false;
+ ;
+ }
+
VersionedCacheableObjectPartList(VectorOfCacheableKey* keys,
ACE_Recursive_Thread_Mutex& responseLock)
: m_tempKeys(keys), m_responseLock(responseLock) {
@@ -136,8 +148,12 @@ class VersionedCacheableObjectPartList : public CacheableObjectPartList {
this->m_hasKeys = false;
}
- VersionedCacheableObjectPartList(ACE_Recursive_Thread_Mutex& responseLock)
- : m_responseLock(responseLock) {
+ VersionedCacheableObjectPartList(ThinClientRegion* region,
+ VectorOfCacheableKey* keys,
+ ACE_Recursive_Thread_Mutex& responseLock)
+ : CacheableObjectPartList(region),
+ m_tempKeys(keys),
+ m_responseLock(responseLock) {
m_regionIsVersioned = false;
m_serializeValues = false;
m_hasTags = false;
@@ -145,12 +161,15 @@ class VersionedCacheableObjectPartList : public CacheableObjectPartList {
this->m_hasKeys = false;
}
- /*inline VersionedCacheableObjectPartList(bool serializeValues)
- {
- m_serializeValues = serializeValues;
- GF_NEW(m_tempKeys, VectorOfCacheableKey);
-
- }*/
+ VersionedCacheableObjectPartList(ThinClientRegion* region,
+ ACE_Recursive_Thread_Mutex& responseLock)
+ : m_responseLock(responseLock), CacheableObjectPartList(region) {
+ m_regionIsVersioned = false;
+ m_serializeValues = false;
+ m_hasTags = false;
+ m_endpointMemId = 0;
+ this->m_hasKeys = false;
+ }
inline uint16_t getEndpointMemId() { return m_endpointMemId; }
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/GeodeStatisticsFactory.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/GeodeStatisticsFactory.cpp b/src/cppcache/src/statistics/GeodeStatisticsFactory.cpp
index ae5ec92..b3423e7 100644
--- a/src/cppcache/src/statistics/GeodeStatisticsFactory.cpp
+++ b/src/cppcache/src/statistics/GeodeStatisticsFactory.cpp
@@ -33,11 +33,6 @@
using namespace apache::geode::client;
using namespace apache::geode::statistics;
-/**
- * static member initialization
- */
-GeodeStatisticsFactory* GeodeStatisticsFactory::s_singleton = nullptr;
-
GeodeStatisticsFactory::GeodeStatisticsFactory(StatisticsManager* statMngr) {
m_name = "GeodeStatisticsFactory";
m_id = ACE_OS::getpid();
@@ -46,31 +41,6 @@ GeodeStatisticsFactory::GeodeStatisticsFactory(StatisticsManager* statMngr) {
m_statMngr = statMngr;
}
-GeodeStatisticsFactory* GeodeStatisticsFactory::initInstance(
- StatisticsManager* statMngr) {
- if (!s_singleton) {
- s_singleton = new GeodeStatisticsFactory(statMngr);
- }
-
- return s_singleton;
-}
-
-GeodeStatisticsFactory* GeodeStatisticsFactory::getExistingInstance() {
- GF_D_ASSERT(!!s_singleton);
-
- s_singleton->getId(); // should fault if !s_singleton
-
- return s_singleton;
-}
-
-/**************************Dtor*******************************************/
-void GeodeStatisticsFactory::clean() {
- if (s_singleton != nullptr) {
- delete s_singleton;
- s_singleton = nullptr;
- }
-}
-
GeodeStatisticsFactory::~GeodeStatisticsFactory() {
try {
m_statMngr = nullptr;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/GeodeStatisticsFactory.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/GeodeStatisticsFactory.hpp b/src/cppcache/src/statistics/GeodeStatisticsFactory.hpp
index ba9157c..33c3a32 100644
--- a/src/cppcache/src/statistics/GeodeStatisticsFactory.hpp
+++ b/src/cppcache/src/statistics/GeodeStatisticsFactory.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_STATISTICS_GEODESTATISTICSFACTORY_H_
-#define GEODE_STATISTICS_GEODESTATISTICSFACTORY_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -20,19 +15,22 @@
* limitations under the License.
*/
-#include <geode/geode_globals.hpp>
+#pragma once
+
+#ifndef GEODE_STATISTICS_GEODESTATISTICSFACTORY_H_
+#define GEODE_STATISTICS_GEODESTATISTICSFACTORY_H_
-#include <sys/types.h>
-#ifndef WIN32
-#include <unistd.h>
-#endif
#include <vector>
+
#include <ace/Recursive_Thread_Mutex.h>
#include <ace/Map_Manager.h>
-#include "StatisticsTypeImpl.hpp"
+
+#include <geode/geode_globals.hpp>
+#include <geode/ExceptionTypes.hpp>
#include <geode/statistics/StatisticsFactory.hpp>
+
+#include "StatisticsTypeImpl.hpp"
#include "StatisticsManager.hpp"
-#include <geode/ExceptionTypes.hpp>
using namespace apache::geode::client;
@@ -51,20 +49,12 @@ class StatisticsManager;
*/
class GeodeStatisticsFactory : public StatisticsFactory {
private:
- //--------------------Properties-------------------------------------------------
-
const char* m_name;
int64_t m_id;
StatisticsManager* m_statMngr;
- static GeodeStatisticsFactory* s_singleton;
-
- //------------------ methods ------------------------------
-
- GeodeStatisticsFactory(StatisticsManager* statMngr);
-
int64_t m_statsListUniqueId; // Creates a unique id for each stats object in
// the list
@@ -76,23 +66,14 @@ class GeodeStatisticsFactory : public StatisticsFactory {
StatisticsTypeImpl* addType(StatisticsTypeImpl* t);
- //////////////////////////public member functions///////////////////////////
-
public:
+ GeodeStatisticsFactory(StatisticsManager* statMngr);
~GeodeStatisticsFactory();
- static void clean();
-
const char* getName();
int64_t getId();
- static GeodeStatisticsFactory* initInstance(StatisticsManager* statMngr);
-
- static GeodeStatisticsFactory* getExistingInstance();
-
- //------------ StatisticsFactory methods: Statistics
- //------------------------------
Statistics* createStatistics(StatisticsType* type);
Statistics* createStatistics(StatisticsType* type, const char* textId);
@@ -110,15 +91,11 @@ class GeodeStatisticsFactory : public StatisticsFactory {
Statistics* createAtomicStatistics(StatisticsType* type, const char* textId,
int64_t numericId);
- //------------ StatisticsFactory methods: Statistics Type
- //------------------------------
StatisticsType* createType(const char* name, const char* description,
StatisticDescriptor** stats, int32_t statsLength);
StatisticsType* findType(const char* name);
- //------------ StatisticsFactory methods: Statistics Descriptor
- //---------------------
StatisticDescriptor* createIntCounter(const char* name,
const char* description,
const char* units, bool largerBetter);
@@ -145,8 +122,7 @@ class GeodeStatisticsFactory : public StatisticsFactory {
/** Return the first instance that matches the type, or nullptr */
Statistics* findFirstStatisticsByType(StatisticsType* type);
-
-}; // class
+};
} // namespace statistics
} // namespace geode
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/HostStatHelper.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatHelper.cpp b/src/cppcache/src/statistics/HostStatHelper.cpp
index d2a330f..040930d 100644
--- a/src/cppcache/src/statistics/HostStatHelper.cpp
+++ b/src/cppcache/src/statistics/HostStatHelper.cpp
@@ -83,20 +83,21 @@ void HostStatHelper::refresh() {
* Creates and returns a {@link Statistics} with
* the given pid and name.
*/
-void HostStatHelper::newProcessStats(int64_t pid, const char* name) {
+void HostStatHelper::newProcessStats(GeodeStatisticsFactory* statisticsFactory,
+ int64_t pid, const char* name) {
// Init OsCode
initOSCode();
// Create processStats , Internally they will create own stats
switch (osCode) {
case GFS_OSTYPE_SOLARIS:
- processStats = new SolarisProcessStats(pid, name);
+ processStats = new SolarisProcessStats(statisticsFactory, pid, name);
break;
case GFS_OSTYPE_LINUX:
- processStats = new LinuxProcessStats(pid, name);
+ processStats = new LinuxProcessStats(statisticsFactory, pid, name);
break;
case GFS_OSTYPE_WINDOWS:
- processStats = new WindowsProcessStats(pid, name);
+ processStats = new WindowsProcessStats(statisticsFactory, pid, name);
break;
case GFS_OSTYPE_MACOSX:
processStats = new NullProcessStats(pid, name);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/HostStatHelper.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatHelper.hpp b/src/cppcache/src/statistics/HostStatHelper.hpp
index eb63531..be26bb2 100644
--- a/src/cppcache/src/statistics/HostStatHelper.hpp
+++ b/src/cppcache/src/statistics/HostStatHelper.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_STATISTICS_HOSTSTATHELPER_H_
-#define GEODE_STATISTICS_HOSTSTATHELPER_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -20,6 +15,11 @@
* limitations under the License.
*/
+#pragma once
+
+#ifndef GEODE_STATISTICS_HOSTSTATHELPER_H_
+#define GEODE_STATISTICS_HOSTSTATHELPER_H_
+
#include <geode/geode_globals.hpp>
#include <string>
#include "StatisticDescriptorImpl.hpp"
@@ -42,7 +42,7 @@
// TODO refactor - conditionally include os specific impl headers.
/** @file
-*/
+ */
namespace apache {
namespace geode {
@@ -72,13 +72,14 @@ class CPPCACHE_EXPORT HostStatHelper {
static void refresh();
- static void newProcessStats(int64_t pid, const char* name);
+ static void newProcessStats(GeodeStatisticsFactory* statisticsFactory,
+ int64_t pid, const char* name);
static void close();
static void cleanup();
};
-} // namespace client
+} // namespace statistics
} // namespace geode
} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/HostStatSampler.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatSampler.cpp b/src/cppcache/src/statistics/HostStatSampler.cpp
index 7f8788f..777fed3 100644
--- a/src/cppcache/src/statistics/HostStatSampler.cpp
+++ b/src/cppcache/src/statistics/HostStatSampler.cpp
@@ -39,6 +39,9 @@
#include "GeodeStatisticsFactory.hpp"
#include <ClientHealthStats.hpp>
#include <ClientProxyMembershipID.hpp>
+#include "CacheImpl.hpp"
+using namespace apache::geode::statistics;
+using namespace apache::geode::client;
namespace apache {
namespace geode {
@@ -58,7 +61,9 @@ typedef std::vector<std::pair<std::string, int64_t> > g_fileInfo;
} // namespace geode
} // namespace apache
-extern "C" {
+using namespace apache::geode::statistics::globals;
+
+// extern "C" {
int selector(const dirent* d) {
std::string inputname(d->d_name);
@@ -110,7 +115,7 @@ int comparator(const dirent** d1, const dirent** d2) {
return 0;
}
}
-}
+//}
namespace apache {
namespace geode {
@@ -124,26 +129,27 @@ using std::chrono::nanoseconds;
const char* HostStatSampler::NC_HSS_Thread = "NC HSS Thread";
HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
- StatisticsManager* statMngr,
+ StatisticsManager* statMngr, Cache* cache,
+ const char* durableClientId,
+ const uint32_t durableTimeout,
int64_t statFileLimit,
- int64_t statDiskSpaceLimit) {
+ int64_t statDiskSpaceLimit)
+ : m_cache(cache) {
m_isStatDiskSpaceEnabled = false;
m_adminError = false;
m_running = false;
m_stopRequested = false;
m_archiver = nullptr;
- m_samplerStats = new StatSamplerStats();
-
+ m_samplerStats = new StatSamplerStats(statMngr->getStatisticsFactory());
m_startTime = system_clock::now();
-
m_pid = ACE_OS::getpid();
m_statMngr = statMngr;
m_archiveFileName = filePath;
- globals::g_statFile = filePath;
+ g_statFile = filePath;
m_sampleRate = sampleIntervalMs;
rollIndex = 0;
m_archiveDiskSpaceLimit = statDiskSpaceLimit;
- globals::g_spaceUsed = 0;
+ g_spaceUsed = 0;
if (statDiskSpaceLimit != 0) {
m_isStatDiskSpaceEnabled = true;
@@ -365,7 +371,7 @@ void HostStatSampler::changeArchive(std::string filename) {
}
filename = chkForGFSExt(filename);
if (m_archiver != nullptr) {
- globals::g_previoussamplesize = m_archiver->getSampleSize();
+ g_previoussamplesize = m_archiver->getSampleSize();
m_archiver->closeFile();
}
// create new file only when tis file has some data; otherwise reuse it
@@ -385,7 +391,7 @@ void HostStatSampler::changeArchive(std::string filename) {
m_archiver = nullptr;
}
- m_archiver = new StatArchiveWriter(filename, this);
+ m_archiver = new StatArchiveWriter(filename, this, m_cache);
}
std::string HostStatSampler::chkForGFSExt(std::string filename) {
@@ -500,7 +506,8 @@ int32_t HostStatSampler::rollArchive(std::string filename) {
void HostStatSampler::initSpecialStats() {
// After Special categories are decided initialize them here
- HostStatHelper::newProcessStats(m_pid, "ProcessStats");
+ HostStatHelper::newProcessStats(m_statMngr->getStatisticsFactory(), m_pid,
+ "ProcessStats");
}
void HostStatSampler::sampleSpecialStats() { HostStatHelper::refresh(); }
@@ -537,10 +544,13 @@ void HostStatSampler::putStatsInAdminRegion() {
static std::string clientId = "";
AdminRegionPtr adminRgn = m_statMngr->getAdminRegion();
if (adminRgn == nullptr) return;
+ auto conn_man = adminRgn->getConnectionManager();
+ if (conn_man->isNetDown()) {
+ return;
+ }
TryReadGuard _guard(adminRgn->getRWLock(), adminRgn->isDestroyed());
if (!adminRgn->isDestroyed()) {
- TcrConnectionManager* m_conn_man = adminRgn->getConnectionManager();
- if (m_conn_man->getNumEndPoints() > 0) {
+ if (conn_man->getNumEndPoints() > 0) {
if (!initDone) {
adminRgn->init();
initDone = true;
@@ -548,8 +558,7 @@ void HostStatSampler::putStatsInAdminRegion() {
int puts = 0, gets = 0, misses = 0, numListeners = 0, numThreads = 0,
creates = 0;
int64_t cpuTime = 0;
- GeodeStatisticsFactory* gf =
- GeodeStatisticsFactory::getExistingInstance();
+ auto gf = m_statMngr->getStatisticsFactory();
if (gf) {
StatisticsType* cacheStatType = gf->findType("CachePerfStats");
if (cacheStatType) {
@@ -577,15 +586,12 @@ void HostStatSampler::putStatsInAdminRegion() {
ACE_INET_Addr driver("", hostName, "tcp");
uint32_t hostAddr = driver.get_ip_address();
uint16_t hostPort = 0;
- SystemProperties* sysProp = DistributedSystem::getSystemProperties();
- const char* durableId =
- (sysProp != nullptr) ? sysProp->durableClientId() : nullptr;
- const uint32_t durableTimeOut =
- (sysProp != nullptr) ? sysProp->durableTimeout() : 0;
-
- ClientProxyMembershipID memId(hostName, hostAddr, hostPort, durableId,
- durableTimeOut);
- clientId = memId.getDSMemberIdForThinClientUse();
+
+ auto memId = conn_man->getCacheImpl()
+ ->getClientProxyMembershipIDFactory()
+ .create(hostName, hostAddr, hostPort,
+ m_durableClientId, m_durableTimeout);
+ clientId = memId->getDSMemberIdForThinClientUse();
}
CacheableKeyPtr keyPtr = CacheableString::create(clientId.c_str());
@@ -619,39 +625,40 @@ void HostStatSampler::doSample(std::string& archivefilename) {
checkListeners();
// Populate Admin Region for GFMon
- if (isSamplingEnabled() && !m_adminError &&
- !TcrConnectionManager::isNetDown) {
+ if (isSamplingEnabled() && !m_adminError) {
putStatsInAdminRegion();
}
- m_archiver->sample();
+ if (m_archiver) {
+ m_archiver->sample();
- if (m_archiveFileSizeLimit != 0) {
- int64_t size = m_archiver->getSampleSize();
- int64_t bytesWritten =
- m_archiver->bytesWritten(); // + globals::g_previoussamplesize;
- if (bytesWritten > (m_archiveFileSizeLimit - size)) {
- // roll the archive
- changeArchive(archivefilename);
+ if (m_archiveFileSizeLimit != 0) {
+ int64_t size = m_archiver->getSampleSize();
+ int64_t bytesWritten =
+ m_archiver->bytesWritten(); // + g_previoussamplesize;
+ if (bytesWritten > (m_archiveFileSizeLimit - size)) {
+ // roll the archive
+ changeArchive(archivefilename);
+ }
+ }
+ g_spaceUsed += m_archiver->bytesWritten();
+ // delete older stat files if disk limit is about to be exceeded.
+ if ((m_archiveDiskSpaceLimit != 0) &&
+ (g_spaceUsed >=
+ (m_archiveDiskSpaceLimit - m_archiver->getSampleSize()))) {
+ checkDiskLimit();
}
- }
- globals::g_spaceUsed += m_archiver->bytesWritten();
- // delete older stat files if disk limit is about to be exceeded.
- if ((m_archiveDiskSpaceLimit != 0) &&
- (globals::g_spaceUsed >=
- (m_archiveDiskSpaceLimit - m_archiver->getSampleSize()))) {
- checkDiskLimit();
- }
- // It will flush the contents to the archive file, in every
- // sample run.
+ // It will flush the contents to the archive file, in every
+ // sample run.
- m_archiver->flush();
+ m_archiver->flush();
+ }
}
void HostStatSampler::checkDiskLimit() {
- globals::g_fileInfo fileInfo;
- globals::g_spaceUsed = 0;
+ g_fileInfo fileInfo;
+ g_spaceUsed = 0;
char fullpath[512] = {0};
std::string dirname = ACE::dirname(globals::g_statFile.c_str());
// struct dirent **resultArray;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/HostStatSampler.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatSampler.hpp b/src/cppcache/src/statistics/HostStatSampler.hpp
index 7723799..67d2238 100644
--- a/src/cppcache/src/statistics/HostStatSampler.hpp
+++ b/src/cppcache/src/statistics/HostStatSampler.hpp
@@ -39,7 +39,7 @@
using namespace apache::geode::client;
/** @file
-*/
+ */
#ifndef GEMFIRE_MAX_STATS_FILE_LIMIT
#define GEMFIRE_MAX_STATS_FILE_LIMIT (1024 * 1024 * 1024)
#endif
@@ -82,8 +82,9 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
* Constructor:
*/
HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
- StatisticsManager* statMngr, int64_t statFileLimit = 0,
- int64_t statDiskSpaceLimit = 0);
+ StatisticsManager* statMngr, Cache* cache,
+ const char* durableClientId, const uint32_t durableTimeout,
+ int64_t statFileLimit = 0, int64_t statDiskSpaceLimit = 0);
/**
* Adds the pid to the archive file passed to it.
@@ -192,8 +193,8 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
int32_t svc(void);
/**
- * Method to know whether the sampling thread is running or not.
- */
+ * Method to know whether the sampling thread is running or not.
+ */
bool isRunning();
~HostStatSampler();
@@ -207,12 +208,15 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
volatile bool m_isStatDiskSpaceEnabled;
StatArchiveWriter* m_archiver;
StatSamplerStats* m_samplerStats;
+ const char* m_durableClientId;
+ uint32_t m_durableTimeout;
std::string m_archiveFileName;
int64_t m_archiveFileSizeLimit;
int64_t m_archiveDiskSpaceLimit;
int64_t m_sampleRate;
StatisticsManager* m_statMngr;
+ Cache* m_cache;
int64_t m_pid;
system_clock::time_point m_startTime;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/LinuxProcessStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/LinuxProcessStats.cpp b/src/cppcache/src/statistics/LinuxProcessStats.cpp
index ca77bba..f1e0a2b 100644
--- a/src/cppcache/src/statistics/LinuxProcessStats.cpp
+++ b/src/cppcache/src/statistics/LinuxProcessStats.cpp
@@ -18,8 +18,8 @@
#include <ace/Thread_Mutex.h>
#include <ace/Singleton.h>
#include "LinuxProcessStats.hpp"
-#include "GeodeStatisticsFactory.hpp"
#include "HostStatHelperLinux.hpp"
+
using namespace apache::geode::statistics;
/**
@@ -28,10 +28,8 @@ using namespace apache::geode::statistics;
*
*/
-LinuxProcessStats::LinuxProcessStats(int64_t pid, const char* name) {
- GeodeStatisticsFactory* statFactory =
- GeodeStatisticsFactory::getExistingInstance();
-
+LinuxProcessStats::LinuxProcessStats(GeodeStatisticsFactory* statFactory,
+ int64_t pid, const char* name) {
// Create Statistics Type
createType(statFactory);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/LinuxProcessStats.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/LinuxProcessStats.hpp b/src/cppcache/src/statistics/LinuxProcessStats.hpp
index 86eb745..19321ce 100644
--- a/src/cppcache/src/statistics/LinuxProcessStats.hpp
+++ b/src/cppcache/src/statistics/LinuxProcessStats.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_STATISTICS_LINUXPROCESSSTATS_H_
-#define GEODE_STATISTICS_LINUXPROCESSSTATS_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -20,17 +15,24 @@
* limitations under the License.
*/
+#pragma once
+
+#ifndef GEODE_STATISTICS_LINUXPROCESSSTATS_H_
+#define GEODE_STATISTICS_LINUXPROCESSSTATS_H_
+
#include <geode/geode_globals.hpp>
#include <geode/statistics/Statistics.hpp>
#include <geode/statistics/StatisticsType.hpp>
#include <geode/statistics/StatisticDescriptor.hpp>
+
#include "ProcessStats.hpp"
#include "HostStatHelper.hpp"
+#include "GeodeStatisticsFactory.hpp"
using namespace apache::geode::client;
/** @file
-*/
+ */
namespace apache {
namespace geode {
@@ -60,7 +62,8 @@ class CPPCACHE_EXPORT LinuxProcessStats : public ProcessStats {
void createType(StatisticsFactory* statFactory);
public:
- LinuxProcessStats(int64_t pid, const char* name);
+ LinuxProcessStats(GeodeStatisticsFactory* statFactory, int64_t pid,
+ const char* name);
~LinuxProcessStats();
int64_t getProcessSize();
@@ -79,7 +82,7 @@ class CPPCACHE_EXPORT LinuxProcessStats : public ProcessStats {
}; // Class LinuxProcessStats
-} // namespace client
+} // namespace statistics
} // namespace geode
} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/PoolStatsSampler.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/PoolStatsSampler.cpp b/src/cppcache/src/statistics/PoolStatsSampler.cpp
index 96e5d78..094b59f 100644
--- a/src/cppcache/src/statistics/PoolStatsSampler.cpp
+++ b/src/cppcache/src/statistics/PoolStatsSampler.cpp
@@ -38,7 +38,11 @@ const char* PoolStatsSampler::NC_PSS_Thread = "NC PSS Thread";
PoolStatsSampler::PoolStatsSampler(int64_t sampleRate, CacheImpl* cache,
ThinClientPoolDM* distMan)
- : m_sampleRate(sampleRate), m_distMan(distMan) {
+ : m_sampleRate(sampleRate),
+ m_distMan(distMan),
+ m_statisticsFactory(cache->getDistributedSystem()
+ .getStatisticsManager()
+ ->getStatisticsFactory()) {
m_running = false;
m_stopRequested = false;
m_adminRegion = AdminRegion::create(cache, distMan);
@@ -91,13 +95,12 @@ void PoolStatsSampler::putStatsInAdminRegion() {
int puts = 0, gets = 0, misses = 0, numListeners = 0, numThreads = 0,
creates = 0;
int64_t cpuTime = 0;
- GeodeStatisticsFactory* gf =
- GeodeStatisticsFactory::getExistingInstance();
- if (gf) {
- StatisticsType* cacheStatType = gf->findType("CachePerfStats");
+ if (m_statisticsFactory) {
+ StatisticsType* cacheStatType =
+ m_statisticsFactory->findType("CachePerfStats");
if (cacheStatType) {
Statistics* cachePerfStats =
- gf->findFirstStatisticsByType(cacheStatType);
+ m_statisticsFactory->findFirstStatisticsByType(cacheStatType);
if (cachePerfStats) {
puts = cachePerfStats->getInt((char*)"puts");
gets = cachePerfStats->getInt((char*)"gets");
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/PoolStatsSampler.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/PoolStatsSampler.hpp b/src/cppcache/src/statistics/PoolStatsSampler.hpp
index 2ccf809..d600312 100644
--- a/src/cppcache/src/statistics/PoolStatsSampler.hpp
+++ b/src/cppcache/src/statistics/PoolStatsSampler.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_STATISTICS_POOLSTATSSAMPLER_H_
-#define GEODE_STATISTICS_POOLSTATSSAMPLER_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -19,8 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#pragma once
+
+#ifndef GEODE_STATISTICS_POOLSTATSSAMPLER_H_
+#define GEODE_STATISTICS_POOLSTATSSAMPLER_H_
+
#include <ace/Task.h>
#include <geode/geode_globals.hpp>
+
+#include "statistics/GeodeStatisticsFactory.hpp"
+
namespace apache {
namespace geode {
namespace client {
@@ -60,6 +64,7 @@ class CPPCACHE_EXPORT PoolStatsSampler : public ACE_Task_Base {
ThinClientPoolDM* m_distMan;
ACE_Recursive_Thread_Mutex m_lock;
static const char* NC_PSS_Thread;
+ GeodeStatisticsFactory* m_statisticsFactory;
};
} // namespace statistics
} // namespace geode
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/SolarisProcessStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/SolarisProcessStats.cpp b/src/cppcache/src/statistics/SolarisProcessStats.cpp
index 27275b1..7aa3327 100644
--- a/src/cppcache/src/statistics/SolarisProcessStats.cpp
+++ b/src/cppcache/src/statistics/SolarisProcessStats.cpp
@@ -18,8 +18,8 @@
#include <ace/Thread_Mutex.h>
#include <ace/Singleton.h>
#include "SolarisProcessStats.hpp"
-#include "GeodeStatisticsFactory.hpp"
#include "HostStatHelperSolaris.hpp"
+
using namespace apache::geode::statistics;
/**
@@ -28,10 +28,8 @@ using namespace apache::geode::statistics;
*
*/
-SolarisProcessStats::SolarisProcessStats(int64_t pid, const char* name) {
- GeodeStatisticsFactory* statFactory =
- GeodeStatisticsFactory::getExistingInstance();
-
+SolarisProcessStats::SolarisProcessStats(GeodeStatisticsFactory* statFactory,
+ int64_t pid, const char* name) {
// Create Statistics Type
createType(statFactory);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/SolarisProcessStats.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/SolarisProcessStats.hpp b/src/cppcache/src/statistics/SolarisProcessStats.hpp
index 3233b13..5defe55 100644
--- a/src/cppcache/src/statistics/SolarisProcessStats.hpp
+++ b/src/cppcache/src/statistics/SolarisProcessStats.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_STATISTICS_SOLARISPROCESSSTATS_H_
-#define GEODE_STATISTICS_SOLARISPROCESSSTATS_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -19,17 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
+
+#ifndef GEODE_STATISTICS_SOLARISPROCESSSTATS_H_
+#define GEODE_STATISTICS_SOLARISPROCESSSTATS_H_
+
#include <geode/geode_globals.hpp>
#include <geode/statistics/Statistics.hpp>
#include <geode/statistics/StatisticsType.hpp>
#include <geode/statistics/StatisticDescriptor.hpp>
#include "ProcessStats.hpp"
#include "HostStatHelper.hpp"
+#include "GeodeStatisticsFactory.hpp"
using namespace apache::geode::client;
/** @file
-*/
+ */
namespace apache {
namespace geode {
@@ -60,7 +61,8 @@ class CPPCACHE_EXPORT SolarisProcessStats : public ProcessStats {
void createType(StatisticsFactory* statFactory);
public:
- SolarisProcessStats(int64_t pid, const char* name);
+ SolarisProcessStats(GeodeStatisticsFactory* statisticsFactory, int64_t pid,
+ const char* name);
~SolarisProcessStats();
int64_t getProcessSize();
@@ -80,7 +82,7 @@ class CPPCACHE_EXPORT SolarisProcessStats : public ProcessStats {
}; // Class SolarisProcessStats
-} // namespace client
+} // namespace statistics
} // namespace geode
} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/StatArchiveWriter.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatArchiveWriter.cpp b/src/cppcache/src/statistics/StatArchiveWriter.cpp
index 90e79f2..47f03ec 100644
--- a/src/cppcache/src/statistics/StatArchiveWriter.cpp
+++ b/src/cppcache/src/statistics/StatArchiveWriter.cpp
@@ -39,11 +39,14 @@ using std::chrono::nanoseconds;
// Constructor and Member functions of StatDataOutput class
-StatDataOutput::StatDataOutput(std::string filename) {
+StatDataOutput::StatDataOutput(std::string filename, Cache *cache) {
if (filename.length() == 0) {
std::string s("undefined archive file name");
throw IllegalArgumentException(s.c_str());
}
+
+ SerializationRegistry serializationRegistry;
+ dataBuffer = cache->createDataOutput();
outFile = filename;
closed = false;
bytesWritten = 0;
@@ -63,12 +66,12 @@ StatDataOutput::~StatDataOutput() {
int64_t StatDataOutput::getBytesWritten() { return this->bytesWritten; }
void StatDataOutput::flush() {
- const uint8_t *buffBegin = dataBuffer.getBuffer();
+ const uint8_t *buffBegin = dataBuffer->getBuffer();
if (buffBegin == nullptr) {
std::string s("undefined stat data buffer beginning");
throw NullPointerException(s.c_str());
}
- const uint8_t *buffEnd = dataBuffer.getCursor();
+ const uint8_t *buffEnd = dataBuffer->getCursor();
if (buffEnd == nullptr) {
std::string s("undefined stat data buffer end");
throw NullPointerException(s.c_str());
@@ -90,41 +93,41 @@ void StatDataOutput::flush() {
}
void StatDataOutput::resetBuffer() {
- dataBuffer.reset();
+ dataBuffer->reset();
bytesWritten = 0;
}
void StatDataOutput::writeByte(int8_t v) {
- dataBuffer.write((int8_t)v);
+ dataBuffer->write((int8_t)v);
bytesWritten += 1;
}
void StatDataOutput::writeBoolean(int8_t v) { writeByte(v); }
void StatDataOutput::writeShort(int16_t v) {
- dataBuffer.writeInt(v);
+ dataBuffer->writeInt(v);
bytesWritten += 2;
}
void StatDataOutput::writeInt(int32_t v) {
- dataBuffer.writeInt(v);
+ dataBuffer->writeInt(v);
bytesWritten += 4;
}
void StatDataOutput::writeLong(int64_t v) {
- dataBuffer.writeInt(v);
+ dataBuffer->writeInt(v);
bytesWritten += 8;
}
void StatDataOutput::writeString(std::string s) {
size_t len = s.length();
- dataBuffer.writeASCII(s.data(), static_cast<uint32_t>(len));
+ dataBuffer->writeASCII(s.data(), static_cast<uint32_t>(len));
bytesWritten += len;
}
void StatDataOutput::writeUTF(std::wstring s) {
size_t len = s.length();
- dataBuffer.writeUTF(s.data(), static_cast<uint32_t>(len));
+ dataBuffer->writeUTF(s.data(), static_cast<uint32_t>(len));
bytesWritten += len;
}
@@ -311,7 +314,8 @@ void ResourceInst::writeResourceInst(StatDataOutput *dataOutArg,
// Constructor and Member functions of StatArchiveWriter class
StatArchiveWriter::StatArchiveWriter(std::string outfile,
- HostStatSampler *samplerArg) {
+ HostStatSampler *samplerArg, Cache *cache)
+ : cache(cache) {
resourceTypeId = 0;
resourceInstId = 0;
statResourcesModCount = 0;
@@ -323,7 +327,7 @@ StatArchiveWriter::StatArchiveWriter(std::string outfile,
*/
m_samplesize = 0;
- dataBuffer = new StatDataOutput(archiveFile);
+ dataBuffer = new StatDataOutput(archiveFile, cache);
this->sampler = samplerArg;
// write the time, system property etc.
@@ -426,14 +430,14 @@ void StatArchiveWriter::closeFile() { this->dataBuffer->close(); }
void StatArchiveWriter::openFile(std::string filename) {
// this->dataBuffer->openFile(filename, m_samplesize);
- StatDataOutput *p_dataBuffer = new StatDataOutput(filename);
+ StatDataOutput *p_dataBuffer = new StatDataOutput(filename, cache);
- const uint8_t *buffBegin = dataBuffer->dataBuffer.getBuffer();
+ const uint8_t *buffBegin = dataBuffer->dataBuffer->getBuffer();
if (buffBegin == nullptr) {
std::string s("undefined stat data buffer beginning");
throw NullPointerException(s.c_str());
}
- const uint8_t *buffEnd = dataBuffer->dataBuffer.getCursor();
+ const uint8_t *buffEnd = dataBuffer->dataBuffer->getCursor();
if (buffEnd == nullptr) {
std::string s("undefined stat data buffer end");
throw NullPointerException(s.c_str());
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/StatArchiveWriter.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatArchiveWriter.hpp b/src/cppcache/src/statistics/StatArchiveWriter.hpp
index 55f30cb..d908ca9 100644
--- a/src/cppcache/src/statistics/StatArchiveWriter.hpp
+++ b/src/cppcache/src/statistics/StatArchiveWriter.hpp
@@ -24,6 +24,7 @@
#include <list>
#include <geode/geode_globals.hpp>
#include <geode/ExceptionTypes.hpp>
+#include <geode/Cache.hpp>
#include "StatsDef.hpp"
#include <geode/statistics/Statistics.hpp>
#include <geode/statistics/StatisticDescriptor.hpp>
@@ -34,9 +35,9 @@
#include <geode/DataOutput.hpp>
#include <NonCopyable.hpp>
#include <chrono>
+#include "SerializationRegistry.hpp"
using namespace apache::geode::client;
-
/**
* some constants to be used while archiving
*/
@@ -78,8 +79,10 @@ using std::chrono::steady_clock;
class CPPCACHE_EXPORT StatDataOutput {
public:
- StatDataOutput() : bytesWritten(0), m_fp(nullptr), closed(false) {}
- StatDataOutput(std::string);
+ StatDataOutput(Cache *cache) : bytesWritten(0), m_fp(nullptr), closed(false) {
+ dataBuffer = cache->createDataOutput();
+ }
+ StatDataOutput(std::string, Cache *cache);
~StatDataOutput();
/**
* Returns the number of bytes written into the buffer so far.
@@ -126,14 +129,14 @@ class CPPCACHE_EXPORT StatDataOutput {
/**
* This method is for the unit tests only for this class.
*/
- const uint8_t *getBuffer() { return dataBuffer.getBuffer(); }
+ const uint8_t *getBuffer() { return dataBuffer->getBuffer(); }
void close();
void openFile(std::string, int64_t);
private:
int64_t bytesWritten;
- DataOutput dataBuffer;
+ std::unique_ptr<DataOutput> dataBuffer;
std::string outFile;
FILE *m_fp;
bool closed;
@@ -204,6 +207,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
private:
HostStatSampler *sampler;
StatDataOutput *dataBuffer;
+ Cache *cache;
steady_clock::time_point previousTimeStamp;
int32_t resourceTypeId;
int32_t resourceInstId;
@@ -225,7 +229,8 @@ class CPPCACHE_EXPORT StatArchiveWriter {
bool resourceInstMapHas(Statistics *sp);
public:
- StatArchiveWriter(std::string archiveName, HostStatSampler *sampler);
+ StatArchiveWriter(std::string archiveName, HostStatSampler *sampler,
+ Cache *cache);
~StatArchiveWriter();
/**
* Returns the number of bytes written so far to this archive.
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/StatSamplerStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatSamplerStats.cpp b/src/cppcache/src/statistics/StatSamplerStats.cpp
index 10ea6b4..41240c3 100644
--- a/src/cppcache/src/statistics/StatSamplerStats.cpp
+++ b/src/cppcache/src/statistics/StatSamplerStats.cpp
@@ -16,14 +16,14 @@
*/
#include "StatSamplerStats.hpp"
+#include "statistics/StatisticsManager.hpp"
using namespace apache::geode::statistics;
/**
* Statistics related to the statistic sampler.
*/
-StatSamplerStats::StatSamplerStats() {
- StatisticsFactory* statFactory = StatisticsFactory::getExistingInstance();
+StatSamplerStats::StatSamplerStats(StatisticsFactory* statFactory) {
statDescriptorArr = new StatisticDescriptor*[2];
statDescriptorArr[0] = statFactory->createIntCounter(
"sampleCount", "Total number of samples taken by this sampler.",
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/StatSamplerStats.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatSamplerStats.hpp b/src/cppcache/src/statistics/StatSamplerStats.hpp
index 41c352f..aafc8ab 100644
--- a/src/cppcache/src/statistics/StatSamplerStats.hpp
+++ b/src/cppcache/src/statistics/StatSamplerStats.hpp
@@ -29,7 +29,7 @@
using namespace apache::geode::client;
/** @file
-*/
+ */
namespace apache {
namespace geode {
@@ -48,7 +48,7 @@ class CPPCACHE_EXPORT StatSamplerStats {
StatisticDescriptor** statDescriptorArr;
public:
- StatSamplerStats();
+ StatSamplerStats(StatisticsFactory* statFactory);
void tookSample(int64_t nanosSpentWorking);
void close();
void setInitialValues();
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/StatisticDescriptorImpl.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatisticDescriptorImpl.hpp b/src/cppcache/src/statistics/StatisticDescriptorImpl.hpp
index 25b8154..9e8f0cb 100644
--- a/src/cppcache/src/statistics/StatisticDescriptorImpl.hpp
+++ b/src/cppcache/src/statistics/StatisticDescriptorImpl.hpp
@@ -25,7 +25,7 @@
#include <geode/statistics/StatisticDescriptor.hpp>
/** @file
-*/
+ */
namespace apache {
namespace geode {
@@ -127,7 +127,8 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
* @throws IllegalArgumentException
* <code>code</code> is an unknown type
*/
- static int32_t getTypeCodeBits(FieldType code) throw(IllegalArgumentException);
+ static int32_t getTypeCodeBits(FieldType code) throw(
+ IllegalArgumentException);
///////////////////////////Create methods ////////////////////////////////////
@@ -138,7 +139,7 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
*/
static StatisticDescriptor* createIntCounter(
const char* name, const char* description, const char* units,
- bool isLargerBetter) throw(OutOfMemoryException);
+ bool isLargerBetter) throw(apache::geode::client::OutOfMemoryException);
/**
* Creates a descriptor of Long type
* whose value behaves like a counter
@@ -147,7 +148,7 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
static StatisticDescriptor* createLongCounter(
const char* name, const char* description, const char* units,
- bool isLargerBetter) throw(OutOfMemoryException);
+ bool isLargerBetter) throw(apache::geode::client::OutOfMemoryException);
/**
* Creates a descriptor of Double type
@@ -156,7 +157,7 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
*/
static StatisticDescriptor* createDoubleCounter(
const char* name, const char* description, const char* units,
- bool isLargerBetter) throw(OutOfMemoryException);
+ bool isLargerBetter) throw(apache::geode::client::OutOfMemoryException);
/**
* Creates a descriptor of Integer type
@@ -165,7 +166,7 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
*/
static StatisticDescriptor* createIntGauge(
const char* name, const char* description, const char* units,
- bool isLargerBetter) throw(OutOfMemoryException);
+ bool isLargerBetter) throw(apache::geode::client::OutOfMemoryException);
/**
* Creates a descriptor of Long type
@@ -174,7 +175,7 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
*/
static StatisticDescriptor* createLongGauge(
const char* name, const char* description, const char* units,
- bool isLargerBetter) throw(OutOfMemoryException);
+ bool isLargerBetter) throw(apache::geode::client::OutOfMemoryException);
/**
* Creates a descriptor of Double type
@@ -183,7 +184,7 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
*/
static StatisticDescriptor* createDoubleGauge(
const char* name, const char* description, const char* units,
- bool isLargerBetter) throw(OutOfMemoryException);
+ bool isLargerBetter) throw(apache::geode::client::OutOfMemoryException);
///////////////// StatisticDescriptor(Base class) Methods
///////////////////////
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/StatisticsFactory.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatisticsFactory.cpp b/src/cppcache/src/statistics/StatisticsFactory.cpp
deleted file mode 100644
index 0ca4502..0000000
--- a/src/cppcache/src/statistics/StatisticsFactory.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "GeodeStatisticsFactory.hpp"
-
-namespace apache {
-namespace geode {
-namespace statistics {
-
-StatisticsFactory* StatisticsFactory::getExistingInstance() {
- return GeodeStatisticsFactory::getExistingInstance();
-}
-} // namespace client
-} // namespace geode
-} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/StatisticsManager.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatisticsManager.cpp b/src/cppcache/src/statistics/StatisticsManager.cpp
index bc81a33..a4a4df0 100644
--- a/src/cppcache/src/statistics/StatisticsManager.cpp
+++ b/src/cppcache/src/statistics/StatisticsManager.cpp
@@ -36,21 +36,24 @@ using namespace apache::geode::statistics;
/**
* static member initialization
*/
-StatisticsManager* StatisticsManager::s_singleton = nullptr;
StatisticsManager::StatisticsManager(const char* filePath,
int64_t sampleInterval, bool enabled,
+ Cache* cache, const char* durableClientId,
+ const uint32_t durableTimeout,
int64_t statFileLimit,
int64_t statDiskSpaceLimit)
: m_sampler(nullptr), m_adminRegion(nullptr) {
m_sampleIntervalMs =
static_cast<int32_t>(sampleInterval) * 1000; /* convert to millis */
m_newlyAddedStatsList.reserve(16); // Allocate initial sizes
- GeodeStatisticsFactory::initInstance(this);
+ m_statisticsFactory =
+ std::unique_ptr<GeodeStatisticsFactory>(new GeodeStatisticsFactory(this));
try {
if (m_sampler == nullptr && enabled) {
- m_sampler = new HostStatSampler(filePath, m_sampleIntervalMs, this,
+ m_sampler = new HostStatSampler(filePath, m_sampleIntervalMs, this, cache,
+ durableClientId, durableTimeout,
statFileLimit, statDiskSpaceLimit);
m_sampler->start();
}
@@ -60,25 +63,6 @@ StatisticsManager::StatisticsManager(const char* filePath,
}
}
-StatisticsManager* StatisticsManager::initInstance(
- const char* filePath, int64_t sampleIntervalMs, bool enabled,
- int64_t statsFileLimit, int64_t statsDiskSpaceLimit) {
- if (!s_singleton) {
- s_singleton = new StatisticsManager(filePath, sampleIntervalMs, enabled,
- statsFileLimit, statsDiskSpaceLimit);
- }
-
- return s_singleton;
-}
-
-StatisticsManager* StatisticsManager::getExistingInstance() {
- if (s_singleton) {
- return s_singleton;
- }
-
- return nullptr;
-}
-
void StatisticsManager::forceSample() {
if (m_sampler) m_sampler->forceSample();
}
@@ -115,10 +99,6 @@ StatisticsManager::~StatisticsManager() {
}
m_statsList.erase(m_statsList.begin(), m_statsList.end());
}
-
- // Clean Factory: clean Type map etc.
- GeodeStatisticsFactory::clean();
-
} catch (const Exception& ex) {
Log::warningCatch("~StatisticsManager swallowing Geode exception", ex);
@@ -132,15 +112,6 @@ StatisticsManager::~StatisticsManager() {
}
}
-void StatisticsManager::clean() {
- if (s_singleton != nullptr) {
- delete s_singleton;
- s_singleton = nullptr;
- }
-}
-
-////////////////////// Mutex methods ///////////////////////////
-
ACE_Recursive_Thread_Mutex& StatisticsManager::getListMutex() {
return m_statsListLock;
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/StatisticsManager.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatisticsManager.hpp b/src/cppcache/src/statistics/StatisticsManager.hpp
index 0fa9ed2..0d48d0c 100644
--- a/src/cppcache/src/statistics/StatisticsManager.hpp
+++ b/src/cppcache/src/statistics/StatisticsManager.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_STATISTICS_STATISTICSMANAGER_H_
-#define GEODE_STATISTICS_STATISTICSMANAGER_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -20,72 +15,61 @@
* limitations under the License.
*/
-#include <geode/geode_globals.hpp>
+#pragma once
-#include <sys/types.h>
-#ifndef WIN32
-#include <unistd.h>
-#endif
+#ifndef GEODE_STATISTICS_STATISTICSMANAGER_H_
+#define GEODE_STATISTICS_STATISTICSMANAGER_H_
+
+#include <memory>
#include <vector>
-#include "HostStatSampler.hpp"
-#include <geode/ExceptionTypes.hpp>
-#include "StatisticsTypeImpl.hpp"
+
+#include <geode/geode_globals.hpp>
#include <geode/statistics/Statistics.hpp>
-#include <AdminRegion.hpp>
+#include <geode/ExceptionTypes.hpp>
-/** @file
- */
+#include "HostStatSampler.hpp"
+#include "StatisticsTypeImpl.hpp"
+#include "AdminRegion.hpp"
+#include "GeodeStatisticsFactory.hpp"
namespace apache {
namespace geode {
namespace statistics {
+class GeodeStatisticsFactory;
+
/**
* Head Application Manager for Statistics Module.
*
*/
class StatisticsManager {
private:
- //--------------------Properties-------------------------------------------------
-
// interval at which the sampler will take a sample of Stats
int32_t m_sampleIntervalMs;
- //----------------Sampler and Stat Lists-----------------------------------
-
- HostStatSampler* m_sampler; // Statistics sampler
+ // Statistics sampler
+ HostStatSampler* m_sampler;
- std::vector<Statistics*>
- m_statsList; // Vector containing all the Stats objects
+ // Vector containing all the Stats objects
+ std::vector<Statistics*> m_statsList;
// Vector containing stats pointers which are not yet sampled.
std::vector<Statistics*> m_newlyAddedStatsList;
- ACE_Recursive_Thread_Mutex m_statsListLock; // Mutex to lock the list of
- // Stats
+ // Mutex to lock the list of Stats
+ ACE_Recursive_Thread_Mutex m_statsListLock;
- //----------------Admin Region -----------------------------------
AdminRegionPtr m_adminRegion;
- //////////////////////////private member functions///////////////////////////
-
- static StatisticsManager* s_singleton;
-
- StatisticsManager(const char* filePath, int64_t sampleIntervalMs,
- bool enabled, int64_t statFileLimit = 0,
- int64_t statDiskSpaceLimit = 0);
+ std::unique_ptr<GeodeStatisticsFactory> m_statisticsFactory;
void closeSampler();
- //////////////////////////public member functions///////////////////////////
-
public:
- static StatisticsManager* initInstance(const char* filePath,
- int64_t sampleIntervalMs, bool enabled,
- int64_t statFileLimit = 0,
- int64_t statDiskSpaceLimit = 0);
-
- static StatisticsManager* getExistingInstance();
+ StatisticsManager(const char* filePath, int64_t sampleIntervalMs,
+ bool enabled, Cache* cache, const char* durableClientId,
+ const uint32_t durableTimeout, int64_t statFileLimit = 0,
+ int64_t statDiskSpaceLimit = 0);
void RegisterAdminRegion(AdminRegionPtr adminRegPtr) {
m_adminRegion = adminRegPtr;
@@ -101,18 +85,12 @@ class StatisticsManager {
void addStatisticsToList(Statistics* stat);
- static void clean();
-
- //--------------------Stat List
- // functions--------------------------------------
std::vector<Statistics*>& getStatsList();
std::vector<Statistics*>& getNewlyAddedStatsList();
ACE_Recursive_Thread_Mutex& getListMutex();
- //------------ Find Statistics ---------------------
-
/** Return the first instance that matches the type, or nullptr */
Statistics* findFirstStatisticsByType(StatisticsType* type);
@@ -126,6 +104,10 @@ class StatisticsManager {
static void deleteStatistics(Statistics*& stat);
+ GeodeStatisticsFactory* getStatisticsFactory() const {
+ return m_statisticsFactory.get();
+ }
+
}; // class
} // namespace statistics
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/WindowsProcessStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/WindowsProcessStats.cpp b/src/cppcache/src/statistics/WindowsProcessStats.cpp
index f9213ec..c9cc88e 100644
--- a/src/cppcache/src/statistics/WindowsProcessStats.cpp
+++ b/src/cppcache/src/statistics/WindowsProcessStats.cpp
@@ -19,20 +19,17 @@
#include <ace/Singleton.h>
#include "WindowsProcessStats.hpp"
#include "HostStatHelperWin.hpp"
-#include "GeodeStatisticsFactory.hpp"
#include "HostStatHelper.hpp"
using namespace apache::geode::statistics;
-WindowsProcessStats::WindowsProcessStats(int64_t pid, const char* name) {
- GeodeStatisticsFactory* statFactory =
- GeodeStatisticsFactory::getExistingInstance();
-
+WindowsProcessStats::WindowsProcessStats(
+ GeodeStatisticsFactory* statisticsFactory, int64_t pid, const char* name) {
// Create for Statistics Type
- createType(statFactory);
+ createType(statisticsFactory);
// Create Statistics
- this->stats = statFactory->createOsStatistics(m_statsType, name, pid);
+ this->stats = statisticsFactory->createOsStatistics(m_statsType, name, pid);
GF_D_ASSERT(this->stats != nullptr);
// Refresh Stats Values
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/src/statistics/WindowsProcessStats.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/WindowsProcessStats.hpp b/src/cppcache/src/statistics/WindowsProcessStats.hpp
index 8dae107..1f3ca48 100644
--- a/src/cppcache/src/statistics/WindowsProcessStats.hpp
+++ b/src/cppcache/src/statistics/WindowsProcessStats.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_STATISTICS_WINDOWSPROCESSSTATS_H_
-#define GEODE_STATISTICS_WINDOWSPROCESSSTATS_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -19,18 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#pragma once
+
+#ifndef GEODE_STATISTICS_WINDOWSPROCESSSTATS_H_
+#define GEODE_STATISTICS_WINDOWSPROCESSSTATS_H_
+
#include <geode/geode_globals.hpp>
#include <geode/statistics/Statistics.hpp>
#include <geode/statistics/StatisticsType.hpp>
#include <geode/statistics/StatisticDescriptor.hpp>
#include <geode/statistics/StatisticsFactory.hpp>
-#include "ProcessStats.hpp"
#include <geode/ExceptionTypes.hpp>
+#include "ProcessStats.hpp"
+#include "GeodeStatisticsFactory.hpp"
+
using namespace apache::geode::client;
/** @file
-*/
+ */
namespace apache {
namespace geode {
@@ -68,7 +71,8 @@ class CPPCACHE_EXPORT WindowsProcessStats : public ProcessStats {
void createType(StatisticsFactory* statFactory);
public:
- WindowsProcessStats(int64_t pid, const char* name);
+ WindowsProcessStats(GeodeStatisticsFactory* statisticsFactory, int64_t pid,
+ const char* name);
~WindowsProcessStats();
int64_t getProcessSize();
@@ -83,7 +87,7 @@ class CPPCACHE_EXPORT WindowsProcessStats : public ProcessStats {
friend class HostStatHelperWin;
};
-} // namespace client
+} // namespace statistics
} // namespace geode
} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/test/CacheXmlParserTest.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/test/CacheXmlParserTest.cpp b/src/cppcache/test/CacheXmlParserTest.cpp
index 6b5d9c8..b0d4404 100644
--- a/src/cppcache/test/CacheXmlParserTest.cpp
+++ b/src/cppcache/test/CacheXmlParserTest.cpp
@@ -105,13 +105,13 @@ std::string dtd_prefix = R"(<?xml version="1.0" encoding="UTF-8"?>
<client-cache>)";
TEST(CacheXmlParser, CanParseRegionConfigFromAValidXsdCacheConfig) {
- CacheXmlParser parser;
+ CacheXmlParser parser(nullptr);
std::string xml = xsd_prefix + valid_cache_config_body;
parser.parseMemory(xml.c_str(), static_cast<int>(xml.length()));
}
TEST(CacheXmlParser, CanParseRegionConfigFromAValidDtdCacheConfig) {
- CacheXmlParser parser;
+ CacheXmlParser parser(nullptr);
std::string xml = dtd_prefix + valid_cache_config_body;
parser.parseMemory(xml.c_str(), static_cast<int>(xml.length()));
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/test/ClientProxyMembershipIDFactoryTest.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/test/ClientProxyMembershipIDFactoryTest.cpp b/src/cppcache/test/ClientProxyMembershipIDFactoryTest.cpp
new file mode 100644
index 0000000..b9fec88
--- /dev/null
+++ b/src/cppcache/test/ClientProxyMembershipIDFactoryTest.cpp
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <regex>
+
+#include <gtest/gtest.h>
+
+#include <ClientProxyMembershipIDFactory.hpp>
+
+using namespace apache::geode::client;
+
+TEST(ClientProxyMembershipIDFactoryTest, testCreate) {
+ ClientProxyMembershipIDFactory factory("myDs");
+
+ auto id = factory.create("myHost", 1, 2, "myClientID", 3);
+ ASSERT_NE(nullptr, id);
+
+ EXPECT_EQ("myDs", id->getDSName());
+ EXPECT_EQ(1, static_cast<uint32_t>(*id->getHostAddr()));
+ EXPECT_EQ(4, id->getHostAddrLen());
+ EXPECT_EQ(2, id->getHostPort());
+
+ auto uniqueTag = id->getUniqueTag();
+ ASSERT_NE("", uniqueTag);
+ EXPECT_EQ(std::string(":1:0:0:0:2:myDs:").append(uniqueTag),
+ id->getHashKey());
+ EXPECT_TRUE(std::regex_search(
+ id->getDSMemberIdForThinClientUse(),
+ std::regex(
+ std::string("myHost(.*):2:").append(uniqueTag).append(":myDs"))));
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/da389793/src/cppcache/test/DataInputTest.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/test/DataInputTest.cpp b/src/cppcache/test/DataInputTest.cpp
index 90727fa..804e709 100644
--- a/src/cppcache/test/DataInputTest.cpp
+++ b/src/cppcache/test/DataInputTest.cpp
@@ -23,24 +23,42 @@
#include <gtest/gtest.h>
+#include <geode/CacheFactory.hpp>
#include <geode/DataInput.hpp>
-#include <geode/DataOutput.hpp>
#include <memory>
#include "ByteArrayFixture.hpp"
+#include "DataInputInternal.hpp"
+#include "DataOutputInternal.hpp"
+#include "SerializationRegistry.hpp"
+
+namespace {
using namespace apache::geode::client;
+class DataInputUnderTest : public DataInputInternal {
+ public:
+ using DataInputInternal::DataInputInternal;
+
+ virtual const SerializationRegistry &getSerializationRegistry()
+ const override {
+ return m_serializationRegistry;
+ }
+
+ private:
+ SerializationRegistry m_serializationRegistry;
+};
+
class TestDataInput {
public:
- explicit TestDataInput(const char *str)
+ explicit TestDataInput(const char *str, Cache *cache)
: m_byteArray(ByteArray::fromString(str)),
- m_dataInput(m_byteArray.get(), m_byteArray.size()) {
+ m_dataInput(m_byteArray.get(), m_byteArray.size(), cache) {
// NOP
}
- explicit TestDataInput(const wchar_t *str)
+ explicit TestDataInput(const wchar_t *str, Cache *cache)
: m_byteArray(ByteArray::fromString(str)),
- m_dataInput(m_byteArray.get(), m_byteArray.size()) {
+ m_dataInput(m_byteArray.get(), m_byteArray.size(), cache) {
// NOP
}
@@ -183,7 +201,7 @@ class TestDataInput {
private:
ByteArray m_byteArray;
- DataInput m_dataInput;
+ DataInputUnderTest m_dataInput;
};
class DataInputTest : public ::testing::Test, protected ByteArrayFixture {
@@ -194,7 +212,7 @@ class DataInputTest : public ::testing::Test, protected ByteArrayFixture {
};
TEST_F(DataInputTest, ThrowsWhenReadingInputWithSizeZero) {
- TestDataInput dataInput("");
+ TestDataInput dataInput("", nullptr);
uint8_t aByte = 0U;
ASSERT_THROW(dataInput.read(&aByte),
@@ -202,7 +220,7 @@ TEST_F(DataInputTest, ThrowsWhenReadingInputWithSizeZero) {
}
TEST_F(DataInputTest, ThrowsWhenReadingMoreBytesThanSizePassedToConstructor) {
- TestDataInput dataInput("01");
+ TestDataInput dataInput("01", nullptr);
uint8_t aByte = 0U;
dataInput.read(&aByte);
@@ -214,7 +232,7 @@ TEST_F(DataInputTest, ThrowsWhenReadingMoreBytesThanSizePassedToConstructor) {
}
TEST_F(DataInputTest, CanReadUnsignedBytesFromInput) {
- TestDataInput dataInput("FF00");
+ TestDataInput dataInput("FF00", nullptr);
uint8_t aByte = 0U;
dataInput.read(&aByte);
@@ -226,7 +244,7 @@ TEST_F(DataInputTest, CanReadUnsignedBytesFromInput) {
}
TEST_F(DataInputTest, CanReadSignedBytesFromInput) {
- TestDataInput dataInput("807F");
+ TestDataInput dataInput("807F", nullptr);
int8_t aByte = 0U;
dataInput.read(&aByte);
@@ -239,7 +257,7 @@ TEST_F(DataInputTest, CanReadSignedBytesFromInput) {
TEST_F(DataInputTest, CanReadABooleanFromInput) {
bool boolArray[2] = {true, false};
- DataInput dataInput(reinterpret_cast<uint8_t *>(boolArray), 2);
+ DataInputUnderTest dataInput(reinterpret_cast<uint8_t *>(boolArray), 2, nullptr);
bool aBool = false;
dataInput.readBoolean(&aBool);
@@ -251,7 +269,7 @@ TEST_F(DataInputTest, CanReadABooleanFromInput) {
}
TEST_F(DataInputTest, CanReadAnArrayOfBytesFromInput) {
- TestDataInput dataInput("010203");
+ TestDataInput dataInput("010203", nullptr);
uint8_t byteArrayCopy[4];
dataInput.readBytesOnly(byteArrayCopy, 3);
@@ -262,7 +280,7 @@ TEST_F(DataInputTest, CanReadAnArrayOfBytesFromInput) {
TEST_F(DataInputTest,
ThrowsWhenReadingMoreContinuousBytesThanSizePassedToConstructor) {
- TestDataInput dataInput("010203");
+ TestDataInput dataInput("010203", nullptr);
// fails to read 4 bytes from 3 byte buffer
uint8_t byteArrayCopy[4];
@@ -272,7 +290,8 @@ TEST_F(DataInputTest,
TEST_F(DataInputTest, CanReadIntWithAMaxSizeUnsigned64BitIntInput) {
uint64_t intArray[1] = {std::numeric_limits<uint64_t>::max()};
- DataInput dataInput(reinterpret_cast<uint8_t *>(intArray), sizeof(intArray));
+ DataInputUnderTest dataInput(reinterpret_cast<uint8_t *>(intArray), sizeof(intArray),
+ nullptr);
uint64_t aInt = 0UL;
dataInput.readInt(&aInt);
@@ -282,10 +301,12 @@ TEST_F(DataInputTest, CanReadIntWithAMaxSizeUnsigned64BitIntInput) {
TEST_F(DataInputTest, CanReadASCIIWithAnASCIIStringInput) {
char *actualString;
const char *expectedString = "foobar";
- DataOutput stream;
+ DataOutputInternal stream;
+
stream.writeASCII(expectedString);
- DataInput dataInput(stream.getBufferCopy(), stream.getBufferLength());
+ DataInputUnderTest dataInput(stream.getBufferCopy(), stream.getBufferLength(),
+ nullptr);
dataInput.readASCII(&actualString);
EXPECT_TRUE(std::string(expectedString) == std::string(actualString));
@@ -294,10 +315,11 @@ TEST_F(DataInputTest, CanReadASCIIWithAnASCIIStringInput) {
TEST_F(DataInputTest, ThrowsWhenCallingReadStringWithAnASCIIStringInput) {
char *actualString;
const char *expectedString = "foobar";
- DataOutput stream;
+ DataOutputInternal stream;
stream.writeASCII(expectedString);
- DataInput dataInput(stream.getBufferCopy(), stream.getBufferLength());
+ DataInputUnderTest dataInput(stream.getBufferCopy(), stream.getBufferLength(),
+ nullptr);
// ASCII and non-ASCII: consider matching exception string
ASSERT_THROW(dataInput.readString(&actualString),
@@ -307,10 +329,11 @@ TEST_F(DataInputTest, ThrowsWhenCallingReadStringWithAnASCIIStringInput) {
TEST_F(DataInputTest, CanReadASCIIWithAnUTFStringInput) {
char *actualString;
const char *expectedString = "foobar";
- DataOutput stream;
+ DataOutputInternal stream;
stream.writeUTF(expectedString);
- DataInput dataInput(stream.getBufferCopy(), stream.getBufferLength());
+ DataInputUnderTest dataInput(stream.getBufferCopy(), stream.getBufferLength(),
+ nullptr);
dataInput.readASCII(&actualString);
EXPECT_TRUE(std::string(expectedString) == std::string(actualString));
@@ -319,10 +342,11 @@ TEST_F(DataInputTest, CanReadASCIIWithAnUTFStringInput) {
TEST_F(DataInputTest, ThrowsWhenCallingReadStringWithAnUTFStringInput) {
char *actualString;
const char *expectedString = "foobar";
- DataOutput stream;
+ DataOutputInternal stream;
stream.writeUTF(expectedString);
- DataInput dataInput(stream.getBufferCopy(), stream.getBufferLength());
+ DataInputUnderTest dataInput(stream.getBufferCopy(), stream.getBufferLength(),
+ nullptr);
// UTF and non-UTF: consider matching exception string
ASSERT_THROW(dataInput.readString(&actualString),
@@ -332,10 +356,11 @@ TEST_F(DataInputTest, ThrowsWhenCallingReadStringWithAnUTFStringInput) {
TEST_F(DataInputTest, CanReadUTFWithAnUTFStringInput) {
char *actualString;
const char *expectedString = "foobar";
- DataOutput stream;
+ DataOutputInternal stream;
stream.writeUTF(expectedString);
- DataInput dataInput(stream.getBufferCopy(), stream.getBufferLength());
+ DataInputUnderTest dataInput(stream.getBufferCopy(), stream.getBufferLength(),
+ nullptr);
dataInput.readUTF(&actualString);
EXPECT_TRUE(std::string(expectedString) == std::string(actualString));
@@ -344,17 +369,18 @@ TEST_F(DataInputTest, CanReadUTFWithAnUTFStringInput) {
TEST_F(DataInputTest, CanReadUTFWithAnASCIIStringInput) {
char *actualString;
const char *expectedString = "foobar";
- DataOutput stream;
+ DataOutputInternal stream;
stream.writeASCII(expectedString);
- DataInput dataInput(stream.getBufferCopy(), stream.getBufferLength());
+ DataInputUnderTest dataInput(stream.getBufferCopy(), stream.getBufferLength(),
+ nullptr);
dataInput.readUTF(&actualString);
EXPECT_TRUE(std::string(expectedString) == std::string(actualString));
}
TEST_F(DataInputTest, InputResetCausesPristineRead) {
- TestDataInput dataInput("010203");
+ TestDataInput dataInput("010203", nullptr);
// 1) read byte off buffer
// 2) then reset buffer back
@@ -369,7 +395,7 @@ TEST_F(DataInputTest, InputResetCausesPristineRead) {
}
TEST_F(DataInputTest, InputRewindCausesReplayedRead) {
- TestDataInput dataInput("010203");
+ TestDataInput dataInput("010203", nullptr);
uint8_t aByte = 0U;
dataInput.read(&aByte);
@@ -383,28 +409,28 @@ TEST_F(DataInputTest, InputRewindCausesReplayedRead) {
}
TEST_F(DataInputTest, TestReadUint8) {
- TestDataInput dataInput("37");
+ TestDataInput dataInput("37", nullptr);
uint8_t value = 0U;
dataInput.read(&value);
EXPECT_EQ((uint8_t)55U, value) << "Correct uint8_t";
}
TEST_F(DataInputTest, TestReadInt8) {
- TestDataInput dataInput("37");
+ TestDataInput dataInput("37", nullptr);
int8_t value = 0;
dataInput.read(&value);
EXPECT_EQ((int8_t)55, value) << "Correct int8_t";
}
TEST_F(DataInputTest, TestReadBoolean) {
- TestDataInput dataInput("01");
+ TestDataInput dataInput("01", nullptr);
bool value = false;
dataInput.readBoolean(&value);
EXPECT_EQ(true, value) << "Correct bool";
}
TEST_F(DataInputTest, TestReadUint8_tBytesOnly) {
- TestDataInput dataInput("BABEFACE");
+ TestDataInput dataInput("BABEFACE", nullptr);
uint8_t buffer[4];
::memset(buffer, 0U, 4 * sizeof(uint8_t));
dataInput.readBytesOnly(buffer, 4);
@@ -415,7 +441,7 @@ TEST_F(DataInputTest, TestReadUint8_tBytesOnly) {
}
TEST_F(DataInputTest, TestReadInt8_tBytesOnly) {
- TestDataInput dataInput("DEADBEEF");
+ TestDataInput dataInput("DEADBEEF", nullptr);
int8_t buffer[4];
::memset(buffer, 0, 4 * sizeof(int8_t));
dataInput.readBytesOnly(buffer, 4);
@@ -426,7 +452,7 @@ TEST_F(DataInputTest, TestReadInt8_tBytesOnly) {
}
TEST_F(DataInputTest, TestReadUint8_tBytes) {
- TestDataInput dataInput("04BABEFACE");
+ TestDataInput dataInput("04BABEFACE", nullptr);
uint8_t *buffer = nullptr;
int32_t len = 0;
dataInput.readBytes(&buffer, &len);
@@ -440,7 +466,7 @@ TEST_F(DataInputTest, TestReadUint8_tBytes) {
}
TEST_F(DataInputTest, TestReadInt8_tBytes) {
- TestDataInput dataInput("04DEADBEEF");
+ TestDataInput dataInput("04DEADBEEF", nullptr);
int8_t *buffer = nullptr;
int32_t len = 0;
dataInput.readBytes(&buffer, &len);
@@ -454,42 +480,42 @@ TEST_F(DataInputTest, TestReadInt8_tBytes) {
}
TEST_F(DataInputTest, TestReadIntUint16) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
uint16_t value = 0U;
dataInput.readInt(&value);
EXPECT_EQ((uint16_t)4660U, value) << "Correct uint16_t";
}
TEST_F(DataInputTest, TestReadIntInt16) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
int16_t value = 0;
dataInput.readInt(&value);
EXPECT_EQ((int16_t)4660, value) << "Correct int16_t";
}
TEST_F(DataInputTest, TestReadIntUint32) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
uint32_t value = 0U;
dataInput.readInt(&value);
EXPECT_EQ((uint32_t)305419896U, value) << "Correct uint32_t";
}
TEST_F(DataInputTest, TestReadIntInt32) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
int32_t value = 0;
dataInput.readInt(&value);
EXPECT_EQ((int32_t)305419896, value) << "Correct int32_t";
}
TEST_F(DataInputTest, TestReadIntUint64) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
uint64_t value = 0U;
dataInput.readInt(&value);
EXPECT_EQ((uint64_t)1311768467463790320U, value) << "Correct uint64_t";
}
TEST_F(DataInputTest, TestReadIntInt64) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
int64_t value = 0;
dataInput.readInt(&value);
EXPECT_EQ((int64_t)1311768467463790320, value) << "Correct int64_t";
@@ -498,19 +524,19 @@ TEST_F(DataInputTest, TestReadIntInt64) {
TEST_F(DataInputTest, TestReadArrayLen) {
int32_t len = 0;
- TestDataInput dataInput0("FF12345678");
+ TestDataInput dataInput0("FF12345678", nullptr);
dataInput0.readArrayLen(&len);
EXPECT_EQ(-1, len) << "Correct length for 0xFF";
- TestDataInput dataInput1("FE12345678");
+ TestDataInput dataInput1("FE12345678", nullptr);
dataInput1.readArrayLen(&len);
EXPECT_EQ(4660, len) << "Correct length for 0xFE";
- TestDataInput dataInput2("FD12345678");
+ TestDataInput dataInput2("FD12345678", nullptr);
dataInput2.readArrayLen(&len);
EXPECT_EQ(305419896, len) << "Correct length for 0xFD";
- TestDataInput dataInput3("FC12345678");
+ TestDataInput dataInput3("FC12345678", nullptr);
dataInput3.readArrayLen(&len);
EXPECT_EQ(252, len) << "Correct length for 0xFC";
}
@@ -528,21 +554,22 @@ TEST_F(DataInputTest, TestReadUnsignedVL) {
// 1110000
// 00 12 1A 15 4F 09 55 73 3D 70
// 00 92 9A 95 CF 89 D5 F3 BD F0
- TestDataInput dataInput("F0BDF3D589CF959A9200");
+
+ TestDataInput dataInput("F0BDF3D589CF959A9200", nullptr);
int64_t value = 0;
dataInput.readUnsignedVL(&value);
EXPECT_EQ((int64_t)1311768467463790320, value) << "Correct int64_t";
}
TEST_F(DataInputTest, TestReadFloat) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
float value = 0.F;
dataInput.readFloat(&value);
EXPECT_FLOAT_EQ(5.6904566e-28F, value) << "Correct float";
}
TEST_F(DataInputTest, TestReadDouble) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
double value = 0.;
dataInput.readDouble(&value);
EXPECT_DOUBLE_EQ(5.626349274901198e-221, value) << "Correct double";
@@ -550,7 +577,7 @@ TEST_F(DataInputTest, TestReadDouble) {
TEST_F(DataInputTest, TestReadASCII) {
TestDataInput dataInput(
- "001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
char *value = nullptr;
uint16_t len = 0U;
dataInput.readASCII(&value, &len);
@@ -561,7 +588,8 @@ TEST_F(DataInputTest, TestReadASCII) {
TEST_F(DataInputTest, TestReadASCIIHuge) {
TestDataInput dataInput(
- "0000001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "0000001B596F7520686164206D65206174206D65617420746F726E61646F2E",
+ nullptr);
char *value = nullptr;
uint32_t len = 0U;
dataInput.readASCIIHuge(&value, &len);
@@ -572,7 +600,7 @@ TEST_F(DataInputTest, TestReadASCIIHuge) {
TEST_F(DataInputTest, TestReadUTFNarrow) {
TestDataInput dataInput(
- "001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
char *value = nullptr;
uint16_t len = 0U;
dataInput.readUTF(&value, &len);
@@ -584,7 +612,8 @@ TEST_F(DataInputTest, TestReadUTFNarrow) {
TEST_F(DataInputTest, TestReadUTFHugeNarrow) {
TestDataInput dataInput(
"0000001B0059006F007500200068006100640020006D00650020006100740020006D0065"
- "0061007400200074006F0072006E00610064006F002E");
+ "0061007400200074006F0072006E00610064006F002E",
+ nullptr);
char *value = nullptr;
uint32_t len = 0U;
dataInput.readUTFHuge(&value, &len);
@@ -595,7 +624,7 @@ TEST_F(DataInputTest, TestReadUTFHugeNarrow) {
TEST_F(DataInputTest, TestReadUTFNoLen) {
TestDataInput dataInput(
- "596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
wchar_t *value = nullptr;
dataInput.readUTFNoLen(&value, static_cast<uint16_t>(27U));
EXPECT_STREQ(L"You had me at meat tornado.", value) << "Correct wchar_t *";
@@ -604,7 +633,7 @@ TEST_F(DataInputTest, TestReadUTFNoLen) {
TEST_F(DataInputTest, TestReadUTFWide) {
TestDataInput dataInput(
- "001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
wchar_t *value = nullptr;
uint16_t len = 0U;
dataInput.readUTF(&value, &len);
@@ -616,7 +645,8 @@ TEST_F(DataInputTest, TestReadUTFWide) {
TEST_F(DataInputTest, TestReadUTFHugeWide) {
TestDataInput dataInput(
"0000001B0059006F007500200068006100640020006D00650020006100740020006D0065"
- "0061007400200074006F0072006E00610064006F002E");
+ "0061007400200074006F0072006E00610064006F002E",
+ nullptr);
wchar_t *value = nullptr;
uint32_t len = 0U;
dataInput.readUTFHuge(&value, &len);
@@ -627,7 +657,7 @@ TEST_F(DataInputTest, TestReadUTFHugeWide) {
TEST_F(DataInputTest, TestReadObjectSharedPtr) {
TestDataInput dataInput(
- "57001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "57001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
CacheableStringPtr objptr;
dataInput.readObject(objptr);
EXPECT_STREQ((const char *)"You had me at meat tornado.",
@@ -636,20 +666,20 @@ TEST_F(DataInputTest, TestReadObjectSharedPtr) {
}
TEST_F(DataInputTest, TestReadNativeBool) {
- TestDataInput dataInput("0001");
+ TestDataInput dataInput("0001", nullptr);
const bool value = dataInput.readNativeBool();
EXPECT_EQ(true, value) << "Correct bool";
}
TEST_F(DataInputTest, TestReadNativeInt32) {
- TestDataInput dataInput("0012345678");
+ TestDataInput dataInput("0012345678", nullptr);
const int32_t value = dataInput.readNativeInt32();
EXPECT_EQ((int32_t)305419896, value) << "Correct int32_t";
}
TEST_F(DataInputTest, TestReadNativeString) {
TestDataInput dataInput(
- "57001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "57001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
CacheableStringPtr objptr;
ASSERT_EQ(true, dataInput.readNativeString(objptr)) << "Successful read";
EXPECT_STREQ((const char *)"You had me at meat tornado.",
@@ -659,7 +689,7 @@ TEST_F(DataInputTest, TestReadNativeString) {
TEST_F(DataInputTest, TestReadDirectObject) {
TestDataInput dataInput(
- "57001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "57001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
SerializablePtr objptr;
dataInput.readDirectObject(objptr);
EXPECT_STREQ(
@@ -671,7 +701,7 @@ TEST_F(DataInputTest, TestReadDirectObject) {
TEST_F(DataInputTest, TestReadObjectSerializablePtr) {
TestDataInput dataInput(
- "57001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "57001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
SerializablePtr objptr;
dataInput.readObject(objptr);
EXPECT_STREQ(
@@ -684,7 +714,8 @@ TEST_F(DataInputTest, TestReadObjectSerializablePtr) {
TEST_F(DataInputTest, TestReadCharArray) {
TestDataInput dataInput(
"1C0059006F007500200068006100640020006D00650020006100740020006D0065006100"
- "7400200074006F0072006E00610064006F002E0000");
+ "7400200074006F0072006E00610064006F002E0000",
+ nullptr);
char *value = nullptr;
int32_t length = 0;
dataInput.readCharArray(&value, length);
@@ -695,7 +726,7 @@ TEST_F(DataInputTest, TestReadCharArray) {
TEST_F(DataInputTest, TestReadString) {
TestDataInput dataInput(
- "57001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "57001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
char *value = nullptr;
dataInput.readString(&value);
EXPECT_STREQ("You had me at meat tornado.", value) << "Correct char *";
@@ -704,7 +735,7 @@ TEST_F(DataInputTest, TestReadString) {
TEST_F(DataInputTest, TestReadWideString) {
TestDataInput dataInput(
- "57001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "57001B596F7520686164206D65206174206D65617420746F726E61646F2E", nullptr);
wchar_t *value = nullptr;
dataInput.readWideString(&value);
EXPECT_STREQ(L"You had me at meat tornado.", value) << "Correct wchar_t *";
@@ -713,7 +744,8 @@ TEST_F(DataInputTest, TestReadWideString) {
TEST_F(DataInputTest, TestReadStringArray) {
TestDataInput dataInput(
- "0157001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "0157001B596F7520686164206D65206174206D65617420746F726E61646F2E",
+ nullptr);
char **value = nullptr;
int32_t length = 0;
dataInput.readStringArray(&value, length);
@@ -725,7 +757,8 @@ TEST_F(DataInputTest, TestReadStringArray) {
TEST_F(DataInputTest, TestReadWideStringArray) {
TestDataInput dataInput(
- "0157001B596F7520686164206D65206174206D65617420746F726E61646F2E");
+ "0157001B596F7520686164206D65206174206D65617420746F726E61646F2E",
+ nullptr);
wchar_t **value = nullptr;
int32_t length = 0;
dataInput.readWideStringArray(&value, length);
@@ -736,7 +769,7 @@ TEST_F(DataInputTest, TestReadWideStringArray) {
}
TEST_F(DataInputTest, TestReadArrayOfByteArrays) {
- TestDataInput dataInput("0104DEADBEEF");
+ TestDataInput dataInput("0104DEADBEEF", nullptr);
int8_t **arrayOfByteArrays = nullptr;
int32_t arrayLength = 0;
int32_t *elementLength = nullptr;
@@ -757,7 +790,7 @@ TEST_F(DataInputTest, TestReadArrayOfByteArrays) {
}
TEST_F(DataInputTest, TestGetBytesRead) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
EXPECT_EQ((int32_t)0, dataInput.getBytesRead())
<< "Correct bytes read before any reads";
uint8_t value = 0U;
@@ -776,7 +809,7 @@ TEST_F(DataInputTest, TestGetBytesRead) {
}
TEST_F(DataInputTest, TestGetBytesRemaining) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
EXPECT_EQ((int32_t)8, dataInput.getBytesRemaining())
<< "Correct bytes remaining before any reads";
uint8_t value = 0U;
@@ -795,7 +828,7 @@ TEST_F(DataInputTest, TestGetBytesRemaining) {
}
TEST_F(DataInputTest, TestAdvanceCursor) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
EXPECT_EQ((int32_t)0, dataInput.getBytesRead())
<< "Correct bytes read before any advancement";
EXPECT_EQ((int32_t)8, dataInput.getBytesRemaining())
@@ -813,7 +846,7 @@ TEST_F(DataInputTest, TestAdvanceCursor) {
}
TEST_F(DataInputTest, TestRewindCursor) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
EXPECT_EQ((int32_t)0, dataInput.getBytesRead())
<< "Correct bytes read before any rewinding";
EXPECT_EQ((int32_t)8, dataInput.getBytesRemaining())
@@ -831,7 +864,7 @@ TEST_F(DataInputTest, TestRewindCursor) {
}
TEST_F(DataInputTest, TestReset) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
EXPECT_EQ((int32_t)0, dataInput.getBytesRead())
<< "Correct bytes read before any reads";
EXPECT_EQ((int32_t)8, dataInput.getBytesRemaining())
@@ -853,7 +886,7 @@ TEST_F(DataInputTest, TestReset) {
}
TEST_F(DataInputTest, TestSetBuffer) {
- TestDataInput dataInput("123456789ABCDEF0");
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
EXPECT_EQ((int32_t)0, dataInput.getBytesRead())
<< "Correct bytes read before any reads";
EXPECT_EQ((int32_t)8, dataInput.getBytesRemaining())
@@ -876,7 +909,8 @@ TEST_F(DataInputTest, TestSetBuffer) {
TEST_F(DataInputTest, TestSetPoolName) {
static const char *poolName = "Das Schwimmbad";
- TestDataInput dataInput("123456789ABCDEF0");
+
+ TestDataInput dataInput("123456789ABCDEF0", nullptr);
EXPECT_EQ((const char *)nullptr, dataInput.getPoolName())
<< "Null pool name before setting";
dataInput.setPoolName(poolName);
@@ -885,3 +919,5 @@ TEST_F(DataInputTest, TestSetPoolName) {
EXPECT_STREQ(poolName, dataInput.getPoolName())
<< "Correct pool name after setting";
}
+
+} // namespace