http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/LocalRegion.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/LocalRegion.hpp b/clicache/src/LocalRegion.hpp new file mode 100644 index 0000000..aa9679d --- /dev/null +++ b/clicache/src/LocalRegion.hpp @@ -0,0 +1,263 @@ +/* + * 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. + */ + +#pragma once + +#include "geode_defs.hpp" +#include "begin_native.hpp" +#include <geode/Cache.hpp> +#include "end_native.hpp" + +#include "native_shared_ptr.hpp" +#include "IRegion.hpp" +#include "Log.hpp" +#include "ExceptionTypes.hpp" +#include "RegionAttributes.hpp" + +using namespace System; +using namespace System::Collections::Generic; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + namespace native = apache::geode::client; + + generic<class TKey, class TValue> + ref class RegionEntry; + + generic<class TKey, class TValue> + ref class AttributesMutator; + + generic<class TKey, class TValue> + public ref class LocalRegion : public IRegion<TKey, TValue> + { + public: + + virtual property TValue default[TKey] + { + TValue get(TKey key); + void set(TKey key, TValue value); + } + + virtual System::Collections::Generic::IEnumerator<KeyValuePair<TKey,TValue>>^ GetEnumerator(); + + virtual System::Collections::IEnumerator^ GetEnumeratorOld() = + System::Collections::IEnumerable::GetEnumerator; + + virtual bool ContainsKey(TKey key); + + virtual void Add(TKey key, TValue val); + + virtual void Add(KeyValuePair<TKey, TValue> keyValuePair); + + virtual void Add(TKey key, TValue value, Object^ callbackArg); + + virtual bool Remove(TKey key); + + virtual bool Remove( TKey key, Object^ callbackArg ); + + virtual bool Remove(KeyValuePair<TKey,TValue> keyValuePair); + + virtual bool Remove(TKey key, TValue value, Object^ callbackArg ); + + virtual bool Contains(KeyValuePair<TKey,TValue> keyValuePair); + + virtual void Clear(); + + virtual void Clear(Object^ callbackArg); + + virtual void CopyTo(array<KeyValuePair<TKey,TValue>>^ toArray, int startIdx); + + virtual bool TryGetValue(TKey key, TValue %val); + + virtual property int Count + { + int get(); + } + + virtual property bool IsReadOnly + { + bool get() {throw gcnew System::NotImplementedException;/*return false;*/} + } + + virtual property System::Collections::Generic::ICollection<TKey>^ Keys + { + System::Collections::Generic::ICollection<TKey>^ get(); + } + + virtual property System::Collections::Generic::ICollection<TValue>^ Values + { + System::Collections::Generic::ICollection<TValue>^ get(); + } + + virtual void Put(TKey key, TValue value, Object^ callbackArg); + + virtual TValue Get(TKey key, Object^ callbackArg); + + virtual void InvalidateRegion(); + + virtual void InvalidateRegion(Object^ callbackArg); + + virtual void DestroyRegion(); + + virtual void DestroyRegion(Object^ callbackArg); + + virtual void Invalidate(TKey key); + + virtual void Invalidate(TKey key, Object^ callbackArg); + + virtual void PutAll(System::Collections::Generic::IDictionary<TKey, TValue>^ map); + + virtual void PutAll(System::Collections::Generic::IDictionary<TKey, TValue>^ map, int timeout); + + virtual void PutAll(System::Collections::Generic::IDictionary<TKey, TValue>^ map, int timeout, Object^ callbackArg); + + virtual void GetAll(System::Collections::Generic::ICollection<TKey>^ keys, + System::Collections::Generic::IDictionary<TKey, TValue>^ values, + System::Collections::Generic::IDictionary<TKey, System::Exception^>^ exceptions); + + virtual void GetAll(System::Collections::Generic::ICollection<TKey>^ keys, + System::Collections::Generic::IDictionary<TKey, TValue>^ values, + System::Collections::Generic::IDictionary<TKey, System::Exception^>^ exceptions, + bool addToLocalCache); + + virtual void GetAll(System::Collections::Generic::ICollection<TKey>^ keys, + System::Collections::Generic::IDictionary<TKey, TValue>^ values, + System::Collections::Generic::IDictionary<TKey, System::Exception^>^ exceptions, + bool addToLocalCache, Object^ callbackArg); + + virtual void RemoveAll(System::Collections::Generic::ICollection<TKey>^ keys); + virtual void RemoveAll(System::Collections::Generic::ICollection<TKey>^ keys, + Object^ callbackArg); + + virtual property String^ Name + { + String^ get(); + } + + virtual property String^ FullPath + { + String^ get(); + } + + virtual property IRegion<TKey, TValue>^ ParentRegion + { + IRegion<TKey, TValue>^ get( ); + } + + virtual property RegionAttributes<TKey, TValue>^ Attributes + { + RegionAttributes<TKey, TValue>^ get(); + } + + virtual property AttributesMutator<TKey, TValue>^ AttributesMutator + { + Apache::Geode::Client::AttributesMutator<TKey, TValue>^ get(); + } + + virtual property Apache::Geode::Client::CacheStatistics^ Statistics + { + Apache::Geode::Client::CacheStatistics^ get(); + } + + virtual IRegion<TKey, TValue>^ GetSubRegion( String^ path ); + + virtual IRegion<TKey, TValue>^ CreateSubRegion( String^ subRegionName, + RegionAttributes<TKey,TValue>^ attributes ); + + virtual System::Collections::Generic::ICollection<IRegion<TKey, TValue>^>^ SubRegions( bool recursive ); + + virtual RegionEntry<TKey, TValue>^ GetEntry( TKey key ); + + virtual System::Collections::Generic::ICollection<RegionEntry<TKey,TValue>^>^ GetEntries(bool recursive); + + virtual property Apache::Geode::Client::IRegionService^ RegionService + { + Apache::Geode::Client::IRegionService^ get( ); + } + + virtual bool ContainsValueForKey( TKey key ); + + //Additional Region properties and methods + virtual property bool IsDestroyed + { + bool get(); + } + + generic<class TResult> + virtual ISelectResults<TResult>^ Query( String^ predicate ); + + generic<class TResult> + virtual ISelectResults<TResult>^ Query( String^ predicate, System::UInt32 timeout ); + + virtual bool ExistsValue( String^ predicate ); + + virtual bool ExistsValue( String^ predicate, System::UInt32 timeout ); + + virtual Object^ SelectValue( String^ predicate ); + + virtual Object^ SelectValue( String^ predicate, System::UInt32 timeout ); + + virtual ISubscriptionService<TKey>^ GetSubscriptionService(); + + virtual IRegion<TKey, TValue>^ GetLocalView(); + + + internal: + /// <summary> + /// Internal factory function to wrap a native object pointer inside + /// this managed class with null pointer check. + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + /// <returns> + /// The managed wrapper object; null if the native pointer is null. + /// </returns> + //generic<class TKey, class TValue> + inline static IRegion<TKey, TValue>^ Create( native::RegionPtr nativeptr ) + { + return __nullptr == nativeptr ? nullptr : + gcnew LocalRegion<TKey, TValue>( nativeptr ); + } + + std::shared_ptr<native::Region> GetNative() + { + return m_nativeptr->get_shared_ptr(); + } + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline LocalRegion( native::RegionPtr nativeptr ) + { + m_nativeptr = gcnew native_shared_ptr<native::Region>(nativeptr); + } + + private: + inline apache::geode::client::SerializablePtr getRegionEntryValue(apache::geode::client::CacheableKeyPtr& key); + bool AreValuesEqual(apache::geode::client::CacheablePtr& val1, apache::geode::client::CacheablePtr& val2); + + native_shared_ptr<native::Region>^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache +
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/Log.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/Log.cpp b/clicache/src/Log.cpp new file mode 100644 index 0000000..2a1f6ab --- /dev/null +++ b/clicache/src/Log.cpp @@ -0,0 +1,124 @@ +/* + * 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 "geode_includes.hpp" +#include "Log.hpp" +#include "impl/ManagedString.hpp" +#include "impl/SafeConvert.hpp" +#include "ExceptionTypes.hpp" + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + void Log::Init(LogLevel level, String^ logFileName) + { + _GF_MG_EXCEPTION_TRY2 + + ManagedString mg_lfname(logFileName); + apache::geode::client::Log::init(static_cast<apache::geode::client::Log::LogLevel>(level), + mg_lfname.CharPtr); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + void Log::Init(LogLevel level, String^ logFileName, System::Int32 logFileLimit) + { + _GF_MG_EXCEPTION_TRY2 + + ManagedString mg_lfname(logFileName); + apache::geode::client::Log::init(static_cast<apache::geode::client::Log::LogLevel>(level), + mg_lfname.CharPtr, logFileLimit); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + void Log::Close() + { + apache::geode::client::Log::close(); + } + + LogLevel Log::Level() + { + return static_cast<LogLevel>(apache::geode::client::Log::logLevel()); + } + + void Log::SetLevel(LogLevel level) + { + apache::geode::client::Log::setLogLevel( + static_cast<apache::geode::client::Log::LogLevel>(level)); + } + + String^ Log::LogFileName() + { + _GF_MG_EXCEPTION_TRY2 + + return ManagedString::Get(apache::geode::client::Log::logFileName()); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + bool Log::Enabled(LogLevel level) + { + return apache::geode::client::Log::enabled( + static_cast<apache::geode::client::Log::LogLevel>(level)); + } + + void Log::Write(LogLevel level, String^ msg) + { + _GF_MG_EXCEPTION_TRY2 + + ManagedString mg_msg(msg); + apache::geode::client::Log::log(static_cast<apache::geode::client::Log::LogLevel>(level), + mg_msg.CharPtr); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + void Log::LogThrow(LogLevel level, String^ msg, System::Exception^ ex) + { + if (ex != nullptr) + { + String^ logMsg = String::Format( + System::Globalization::CultureInfo::CurrentCulture, + "Geode exception {0} thrown: {1}{2}{3}", ex->GetType(), + ex->Message, Environment::NewLine, msg); + Log::Write(level, logMsg); + } + } + + void Log::LogCatch(LogLevel level, String^ msg, System::Exception^ ex) + { + if (ex != nullptr) + { + String^ logMsg = String::Format( + System::Globalization::CultureInfo::CurrentCulture, + "Geode exception {0} caught: {1}{2}{3}", ex->GetType(), + ex->Message, Environment::NewLine, msg); + Log::Write(level, logMsg); + } // namespace Client + } // namespace Geode + } // namespace Apache + + } +} http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/Log.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/Log.hpp b/clicache/src/Log.hpp new file mode 100644 index 0000000..ed5dd28 --- /dev/null +++ b/clicache/src/Log.hpp @@ -0,0 +1,330 @@ +/* + * 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. + */ + +#pragma once + +#include "geode_defs.hpp" +#include "begin_native.hpp" +#include <geode/Log.hpp> +#include "end_native.hpp" + + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// Logging levels. + /// </summary> + public enum class LogLevel + { + /// <summary> + /// No log. + /// </summary> + Null = 0, + + /// <summary> + /// Indicates serious failure. + /// </summary> + Error, + /// <summary> + /// Indicates potential problem. + /// </summary> + Warning, + /// <summary> + /// For informational purpose. + /// </summary> + Info, + + /// <summary> + /// The default logging level. + /// </summary> + Default, + + /// <summary> + /// For Static configuration messages. + /// </summary> + Config, + + /// <summary> + /// For tracing information. + /// </summary> + Fine, + /// <summary> + /// For moderately detailed tracing information. + /// </summary> + Finer, + /// <summary> + /// For very detailed tracing information. + /// </summary> + Finest, + + /// <summary> + /// For highly detailed tracing information. + /// </summary> + Debug, + + /// <summary> + /// All the log messages. + /// </summary> + All, + }; + + + /// <summary> + /// Defines methods available to clients that want to write a log message + /// to their Geode system's shared log file. + /// </summary> + /// <remarks> + /// Any attempt to use an instance after its connection is disconnected + /// will throw a <c>NotConnectedException</c>. + /// <para> + /// For any logged message the log file will contain: + /// <ul> + /// <li> The message's log level.</li> + /// <li> The time the message was logged.</li> + /// <li> The ID of the connection and thread that logged the message.</li> + /// <li> The message itself, perhaps with + /// an exception including the exception's stack trace.</li> + /// </ul> + /// </para><para> + /// A message always has a level. + /// Logging levels are ordered. Enabling logging at a given level also + /// enables logging at higher levels. The higher the level the more + /// important and urgent the message. + /// </para><para> + /// The levels, in descending order of severity, are: + /// <ul> + /// + /// <li> <c>Error</c> (highest severity) is a message level + /// indicating a serious failure. In general <c>error</c> + /// messages should describe events that are of considerable + /// importance and which will prevent normal program execution. They + /// should be reasonably intelligible to end users and to system + /// administrators.</li> + /// + /// <li> <c>Warning</c> is a message level indicating a + /// potential problem. In general <c>warning</c> messages + /// should describe events that will be of interest to end users or + /// system managers, or which indicate potential problems.</li> + /// + /// <li> <c>Info</c> is a message level for informational + /// messages. Typically <c>info</c> messages should be + /// reasonably significant and should make sense to end users and + /// system administrators.</li> + /// + /// <li> <c>Config</c> is a message level for static + /// configuration messages. <c>config</c> messages are intended + /// to provide a variety of static configuration information, to + /// assist in debugging problems that may be associated with + /// particular configurations.</li> + /// + /// <li> <c>Fine</c> is a message level providing tracing + /// information. In general the <c>fine</c> level should be + /// used for information that will be broadly interesting to + /// developers. This level is for the lowest volume, and most + /// important, tracing messages.</li> + /// + /// <li> <c>Finer</c> indicates a moderately detailed tracing + /// message. This is an intermediate level between <c>fine</c> + /// and <c>finest</c>.</li> + /// + /// <li> <c>Finest</c> indicates a very detailed tracing + /// message. Logging calls for entering, returning, or throwing an + /// exception are traced at the <c>finest</c> level.</li> + /// + /// <li> <c>Debug</c> (lowest severity) indicates a highly + /// detailed tracing message. In general the <c>debug</c> level + /// should be used for the most voluminous detailed tracing messages.</li> + /// </ul> + /// + /// </para> + /// </remarks> + public ref class Log STATICCLASS + { + public: + + + + /// <summary> + /// Initializes the logging facility with the given level and filename. + /// </summary> + /// <param name="level">the logging level</param> + /// <param name="logFileName">the log file name</param> + static void Init(LogLevel level, String^ logFileName); + + /// <summary> + /// Initializes logging facility with given level, filename, and file size limit. + /// </summary> + /// <param name="level">the logging level</param> + /// <param name="logFileName">the log file name</param> + /// <param name="logFileLimit">maximum allowable size of the log file, in bytes, + /// or 0 for the default (1 Gbyte)</param> + static void Init(LogLevel level, String^ logFileName, System::Int32 logFileLimit); + + /// <summary> + /// Closes logging facility (until next init). + /// </summary> + static void Close(); + + /// <summary> + /// Returns the current log level. + /// </summary> + static LogLevel Level(); + + /// <summary> + /// Sets the current log level. + /// </summary> + static void SetLevel(LogLevel level); + + /// <summary> + /// Returns the name of the current log file. + /// NOTE: This function is for debugging only, as it is not completely + /// thread-safe! + /// </summary> + static String^ LogFileName(); + + /// <summary> + /// True if log messages at the given level are enabled. + /// </summary> + static bool Enabled(LogLevel level); + + /// <summary> + /// Logs a message at the given level. + /// </summary> + static void Write(LogLevel level, String^ msg); + + /// <summary> + /// Logs both a message and a thrown exception. + /// </summary> + static void LogThrow(LogLevel level, String^ msg, System::Exception^ ex); + + /// <summary> + /// Logs both a message and a caught exception. + /// </summary> + static void LogCatch(LogLevel level, String^ msg, System::Exception^ ex); + + // Convenience functions with variable number of arguments + // as in String.Format + + /// <summary> + /// Error level logging with variable number of arguments using + /// format as in <c>System.String.Format</c>. + /// </summary> + inline static void Error(String^ format, ... array<Object^>^ args) + { + if (staticLogLevel >= LogLevel::Error) + Log::Write(LogLevel::Error, String::Format( + System::Globalization::CultureInfo::CurrentCulture, format, args)); + } + + /// <summary> + /// Warning level logging with variable number of arguments using + /// format as in <c>System.String.Format</c>. + /// </summary> + inline static void Warning(String^ format, ... array<Object^>^ args) + { + if (staticLogLevel >= LogLevel::Warning) + Log::Write(LogLevel::Warning, String::Format( + System::Globalization::CultureInfo::CurrentCulture, format, args)); + } + + /// <summary> + /// Info level logging with variable number of arguments using + /// format as in <c>System.String.Format</c>. + /// </summary> + inline static void Info(String^ format, ... array<Object^>^ args) + { + if (staticLogLevel >= LogLevel::Info) + Log::Write(LogLevel::Info, String::Format( + System::Globalization::CultureInfo::CurrentCulture, format, args)); + } + + /// <summary> + /// Config level logging with variable number of arguments using + /// format as in <c>System.String.Format</c>. + /// </summary> + inline static void Config(String^ format, ... array<Object^>^ args) + { + if (staticLogLevel >= LogLevel::Config) + Log::Write(LogLevel::Config, String::Format( + System::Globalization::CultureInfo::CurrentCulture, format, args)); + } + + /// <summary> + /// Fine level logging with variable number of arguments using + /// format as in <c>System.String.Format</c>. + /// </summary> + inline static void Fine(String^ format, ... array<Object^>^ args) + { + if (staticLogLevel >= LogLevel::Fine) + Log::Write(LogLevel::Fine, String::Format( + System::Globalization::CultureInfo::CurrentCulture, format, args)); + } + + /// <summary> + /// Finer level logging with variable number of arguments using + /// format as in <c>System.String.Format</c>. + /// </summary> + inline static void Finer(String^ format, ... array<Object^>^ args) + { + if (staticLogLevel >= LogLevel::Finer) + Log::Write(LogLevel::Finer, String::Format( + System::Globalization::CultureInfo::CurrentCulture, format, args)); + } + + /// <summary> + /// Finest level logging with variable number of arguments using + /// format as in <c>System.String.Format</c>. + /// </summary> + inline static void Finest(String^ format, ... array<Object^>^ args) + { + if (staticLogLevel >= LogLevel::Finest) + Log::Write(LogLevel::Finest, String::Format( + System::Globalization::CultureInfo::CurrentCulture, format, args)); + } + + /// <summary> + /// Debug level logging with variable number of arguments using + /// format as in <c>System.String.Format</c>. + /// </summary> + inline static void Debug(String^ format, ... array<Object^>^ args) + { + if (staticLogLevel >= LogLevel::Debug) + Log::Write(LogLevel::Debug, String::Format( + System::Globalization::CultureInfo::CurrentCulture, format, args)); + } + internal: + + static void SetLogLevel(LogLevel level) + { + staticLogLevel = level; + } + + private: + static LogLevel staticLogLevel = LogLevel::Null; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/PdxIdentityFieldAttribute.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/PdxIdentityFieldAttribute.hpp b/clicache/src/PdxIdentityFieldAttribute.hpp new file mode 100755 index 0000000..0c43f84 --- /dev/null +++ b/clicache/src/PdxIdentityFieldAttribute.hpp @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#pragma once + +#include "geode_defs.hpp" +using namespace System; +using namespace System::Reflection; + + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + ///<summary> + /// PdxIdentityField attribute one can specify on member fields. + /// This attribute is used by <see cref="ReflectionBasedAutoSerializer">, + /// When it serializes the fields in Pdx <see cref="IPdxSerializable"> format. + /// This fields will be treated as identity fields for hashcode and equals methods. + ///<summary> + + [AttributeUsage(AttributeTargets::Field)] + public ref class PdxIdentityFieldAttribute : Attribute + { + public: + + PdxIdentityFieldAttribute() + { + } + }; + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/Pool.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/Pool.cpp b/clicache/src/Pool.cpp new file mode 100644 index 0000000..6bb1f91 --- /dev/null +++ b/clicache/src/Pool.cpp @@ -0,0 +1,463 @@ +/* + * 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 "geode_includes.hpp" +#include "Pool.hpp" +#include "QueryService.hpp" +#include "CacheableString.hpp" +#include "Cache.hpp" +//#include "Properties.hpp" +#include "impl/ManagedString.hpp" +#include "ExceptionTypes.hpp" +#include "impl/SafeConvert.hpp" + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + + String^ Pool::Name::get( ) + { + try + { + return ManagedString::Get( m_nativeptr->get()->getName( ) ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::FreeConnectionTimeout::get() + { + try + { + return m_nativeptr->get()->getFreeConnectionTimeout(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::LoadConditioningInterval::get() + { + try + { + return m_nativeptr->get()->getLoadConditioningInterval(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::SocketBufferSize::get() + { + try + { + return m_nativeptr->get()->getSocketBufferSize(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::ReadTimeout::get() + { + try + { + return m_nativeptr->get()->getReadTimeout(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::MinConnections::get() + { + try + { + return m_nativeptr->get()->getMinConnections(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::MaxConnections::get() + { + try + { + return m_nativeptr->get()->getMaxConnections(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::IdleTimeout::get() + { + try + { + return m_nativeptr->get()->getIdleTimeout(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::PingInterval::get() + { + try + { + return m_nativeptr->get()->getPingInterval(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::UpdateLocatorListInterval::get() + { + try + { + return m_nativeptr->get()->getUpdateLocatorListInterval(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::StatisticInterval::get() + { + try + { + return m_nativeptr->get()->getStatisticInterval(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::RetryAttempts::get() + { + try + { + return m_nativeptr->get()->getRetryAttempts(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Boolean Pool::SubscriptionEnabled::get() + { + try + { + return m_nativeptr->get()->getSubscriptionEnabled(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Boolean Pool::PRSingleHopEnabled::get() + { + try + { + return m_nativeptr->get()->getPRSingleHopEnabled(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::SubscriptionRedundancy::get() + { + try + { + return m_nativeptr->get()->getSubscriptionRedundancy(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::SubscriptionMessageTrackingTimeout::get() + { + try + { + return m_nativeptr->get()->getSubscriptionMessageTrackingTimeout(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Int32 Pool::SubscriptionAckInterval::get() + { + try + { + return m_nativeptr->get()->getSubscriptionAckInterval(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + String^ Pool::ServerGroup::get( ) + { + try + { + return ManagedString::Get( m_nativeptr->get()->getServerGroup( ) ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + array<String^>^ Pool::Locators::get() + { + try + { + auto locators = m_nativeptr->get()->getLocators(); + int length = locators->length(); + if (length > 0) + { + array<String^>^ result = gcnew array<String^>(length); + for (int item = 0; item < length; item++) + { + result[item] = CacheableString::GetString((*locators)[item].get()); + } + return result; + } + else + { + return nullptr; + } + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + + array<String^>^ Pool::Servers::get() + { + try + { + auto servers = m_nativeptr->get()->getServers(); + int length = servers->length(); + if (length > 0) + { + array<String^>^ result = gcnew array<String^>(length); + for (int item = 0; item < length; item++) + { + result[item] = CacheableString::GetString((*servers)[item].get()); + } + return result; + } + else + { + return nullptr; + } + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + //generic<class TKey, class TValue> + Boolean Pool::ThreadLocalConnections::get() + { + try + { + return m_nativeptr->get()->getThreadLocalConnections(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + bool Pool::MultiuserAuthentication::get() + { + try + { + return m_nativeptr->get()->getMultiuserAuthentication(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + void Pool::Destroy(Boolean KeepAlive) + { + try + { + m_nativeptr->get()->destroy(KeepAlive); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + void Pool::ReleaseThreadLocalConnection() + { + try + { + m_nativeptr->get()->releaseThreadLocalConnection(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + void Pool::Destroy() + { + try + { + m_nativeptr->get()->destroy(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + + Boolean Pool::Destroyed::get() + { + try + { + return m_nativeptr->get()->isDestroyed(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + generic<class TKey, class TResult> + QueryService<TKey, TResult>^ Pool::GetQueryService() + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + return QueryService<TKey, TResult>::Create(m_nativeptr->get()->getQueryService()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + + Int32 Pool::PendingEventCount::get() + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return m_nativeptr->get()->getPendingEventCount(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/Pool.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/Pool.hpp b/clicache/src/Pool.hpp new file mode 100644 index 0000000..5be1cd3 --- /dev/null +++ b/clicache/src/Pool.hpp @@ -0,0 +1,353 @@ +/* + * 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. + */ + +#pragma once + +#include "geode_defs.hpp" +#include "begin_native.hpp" +#include <geode/Pool.hpp> +#include "end_native.hpp" + +#include "native_shared_ptr.hpp" + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + generic<class TKey, class TResult> + ref class QueryService; + + ref class Cache; + + /// <summary> + /// A pool of connections. + /// </summary> + /// <remarks> + /// A pool of connections from a Geode client to a set of Geode servers. + /// </remarks> + // generic<class TKey, class TValue> + public ref class Pool sealed + { + public: + + /// <summary> + /// Get the name of the pool + /// </summary> + property String^ Name + { + String^ get(); + } + + /// <summary> + /// Returns the connection timeout of this pool. + /// </summary> + property Int32 FreeConnectionTimeout + { + Int32 get(); + } + + /// <summary> + /// Returns the load conditioning interval of this pool. + /// </summary> + property Int32 LoadConditioningInterval + { + Int32 get(); + } + + /// <summary> + /// Returns the socket buffer size of this pool. + /// </summary> + property Int32 SocketBufferSize + { + Int32 get(); + } + + /// <summary> + /// Returns the read timeout of this pool. + /// </summary> + property Int32 ReadTimeout + { + Int32 get(); + } + + /// <summary> + /// Get the minimum connections for this pool. + /// </summary> + property Int32 MinConnections + { + Int32 get(); + } + + /// <summary> + /// Get the maximum connections for this pool. + /// </summary> + property Int32 MaxConnections + { + Int32 get(); + } + + /// <summary> + /// Get the Idle connection timeout for this pool. + /// </summary> + property Int32 IdleTimeout + { + Int32 get(); + } + + /// <summary> + /// Get the ping interval for this pool. + /// </summary> + property Int32 PingInterval + { + Int32 get(); + } + + /// <summary> + /// Get the update locator list interval for this pool. + /// </summary> + property Int32 UpdateLocatorListInterval + { + Int32 get(); + } + + /// <summary> + /// Get the statistic interval for this pool. + /// </summary> + property Int32 StatisticInterval + { + Int32 get(); + } + + /// <summary> + /// Get the retry attempts for this pool. + /// </summary> + property Int32 RetryAttempts + { + Int32 get(); + } + + /// <summary> + /// Returns the true if a server-to-client subscriptions are enabled on this pool. + /// </summary> + property Boolean SubscriptionEnabled + { + Boolean get(); + } + + /// <summary> + /// Returns the true if a pr-single-hop is set to true on this pool. + /// </summary> + property Boolean PRSingleHopEnabled + { + Boolean get(); + } + + /// <summary> + /// Returns the subscription redundancy level of this pool. + /// </summary> + property Int32 SubscriptionRedundancy + { + Int32 get(); + } + + /// <summary> + /// Returns the subscription message tracking timeout of this pool. + /// </summary> + property Int32 SubscriptionMessageTrackingTimeout + { + Int32 get(); + } + + /// <summary> + /// Returns the subscription ack interval of this pool. + /// </summary> + property Int32 SubscriptionAckInterval + { + Int32 get(); + } + + /// <summary> + /// Returns the server group of this pool. + /// </summary> + property String^ ServerGroup + { + String^ get(); + } + + /// <summary> + /// Returns an unmodifiable list of locators + /// this pool is using. Each locator is either one + /// added explicitly when the pool was created or + /// were discovered using the explicit locators. + /// </summary> + /// <remarks> + /// If a pool has no locators then it can not discover servers or locators at runtime. + /// </remarks> + property array< String^ >^ Locators + { + array< String^ >^ get(); + } + + /// <summary> + /// Returns an unmodifiable list of + /// servers this pool is using. These servers were added + /// explicitly when the pool was created. + property array< String^ >^ Servers + { + array< String^ >^ get(); + } + + /// <summary> + /// Returns the true if ThreadLocalConnections are enabled on this pool. + /// </summary> + property Boolean ThreadLocalConnections + { + Boolean get(); + } + + /// <summary> + /// Returns <code>true</code> if multiuser authentication is enabled on this pool. + /// <summary> + property bool MultiuserAuthentication + { + bool get(); + } + /// <summary> + /// Destroys this pool closing any connections it produced. + /// </summary> + /// <param name="keepAlive"> + /// whether the server should keep the durable client's + /// subscriptions alive for the timeout period + /// </param> + /// <exception cref="IllegalStateException"> + /// if the pool is still in use + /// </exception> + void Destroy(Boolean keepAlive); + + /// <summary> + /// Destroys this pool closing any connections it produced. + /// </summary> + /// <exception cref="IllegalStateException"> + /// if the pool is still in use + /// </exception> + void Destroy(); + + /// <summary> + /// Indicates whether this Pool has been + /// destroyed. + /// </summary> + property Boolean Destroyed + { + Boolean get(); + } + + /// <summary> + /// Returns the QueryService for this Pool. + /// </summary> + /// <remarks> + /// The query operations performed using this QueryService will be executed + /// on the servers that are associated with this pool. + /// To perform Query operation on the local cache obtain the QueryService + /// instance from the Cache. + /// </remarks> + generic<class TKey, class TResult> + QueryService<TKey, TResult>^ GetQueryService(); + + void ReleaseThreadLocalConnection(); + + /// <summary> + /// Returns the approximate number of pending subscription events maintained at + /// server for this durable client pool at the time it (re)connected to the + /// server. Server would start dispatching these events to this durable client + /// pool when it receives {@link Cache#readyForEvents()} from it. + /// <p> + /// Durable clients can call this method on reconnect to assess the amount of + /// 'stale' data i.e. events accumulated at server while this client was away + /// and, importantly, before calling {@link Cache#readyForEvents()}. + /// <p> + /// Any number of invocations of this method during a single session will + /// return the same value. + /// <p> + /// It may return a zero value if there are no events pending at server for + /// this client pool. A negative value returned tells us that no queue was + /// available at server for this client pool. + /// <p> + /// A value -1 indicates that this client pool reconnected to server after its + /// 'durable-client-timeout' period elapsed and hence its subscription queue at + /// server was removed, possibly causing data loss. + /// <p> + /// A value -2 indicates that this client pool connected to server for the + /// first time. + /// + /// @return int The number of subscription events maintained at server for this + /// durable client pool at the time this pool (re)connected. A negative + /// value indicates no queue was found for this client pool. + /// @throws IllegalStateException + /// If called by a non-durable client or if invoked any time after + /// invocation of {@link Cache#readyForEvents()}. + /// @since 8.1 + /// + /// </summary> + property Int32 PendingEventCount + { + Int32 get(); + } + + internal: + /// <summary> + /// Internal factory function to wrap a native object pointer inside + /// this managed class with null pointer check. + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + /// <returns> + /// The managed wrapper object; null if the native pointer is null. + /// </returns> + inline static Pool^ Create(native::PoolPtr nativeptr) + { + return __nullptr == nativeptr ? nullptr : + gcnew Pool( nativeptr ); + } + + std::shared_ptr<native::Pool> GetNative() + { + return m_nativeptr->get_shared_ptr(); + } + + private: + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline Pool(native::PoolPtr nativeptr) + { + m_nativeptr = gcnew native_shared_ptr<native::Pool>(nativeptr); + } + + native_shared_ptr<native::Pool>^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/PoolFactory.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/PoolFactory.cpp b/clicache/src/PoolFactory.cpp new file mode 100644 index 0000000..bf3c0b1 --- /dev/null +++ b/clicache/src/PoolFactory.cpp @@ -0,0 +1,452 @@ +/* + * 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. + */ + +#pragma once + +#include "Pool.hpp" +#include "PoolFactory.hpp" + +#include "impl/ManagedString.hpp" +#include "ExceptionTypes.hpp" + +#include "Cache.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + + PoolFactory^ PoolFactory::SetFreeConnectionTimeout( Int32 connectionTimeout ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setFreeConnectionTimeout( connectionTimeout ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetLoadConditioningInterval( Int32 loadConditioningInterval ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setLoadConditioningInterval( loadConditioningInterval ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetSocketBufferSize( Int32 bufferSize ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setSocketBufferSize( bufferSize ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetReadTimeout( Int32 timeout ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setReadTimeout( timeout ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetMinConnections( Int32 minConnections ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setMinConnections( minConnections ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetMaxConnections( Int32 maxConnections ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setMaxConnections( maxConnections ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetIdleTimeout( Int32 idleTimeout ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setIdleTimeout( idleTimeout ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetRetryAttempts( Int32 retryAttempts ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setRetryAttempts( retryAttempts ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetPingInterval( Int32 pingInterval ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setPingInterval( pingInterval ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetUpdateLocatorListInterval( Int32 updateLocatorListInterval ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setUpdateLocatorListInterval( updateLocatorListInterval ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetStatisticInterval( Int32 statisticInterval ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setStatisticInterval( statisticInterval ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetServerGroup( String^ group ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + ManagedString mg_servergroup( group ); + try + { + m_nativeptr->get()->setServerGroup( mg_servergroup.CharPtr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::AddLocator( String^ host, Int32 port ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + ManagedString mg_host( host ); + try + { + m_nativeptr->get()->addLocator( mg_host.CharPtr, port ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::AddServer( String^ host, Int32 port ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + ManagedString mg_host( host ); + try + { + m_nativeptr->get()->addServer( mg_host.CharPtr, port ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetSubscriptionEnabled( Boolean enabled ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setSubscriptionEnabled( enabled ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetPRSingleHopEnabled( Boolean enabled ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setPRSingleHopEnabled(enabled); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetSubscriptionRedundancy( Int32 redundancy ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setSubscriptionRedundancy( redundancy ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetSubscriptionMessageTrackingTimeout( Int32 messageTrackingTimeout ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setSubscriptionMessageTrackingTimeout( messageTrackingTimeout ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::SetSubscriptionAckInterval( Int32 ackInterval ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setSubscriptionAckInterval( ackInterval ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + PoolFactory^ PoolFactory::SetThreadLocalConnections( Boolean enabled ) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + m_nativeptr->get()->setThreadLocalConnections( enabled ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + return this; + } + + PoolFactory^ PoolFactory::SetMultiuserAuthentication( bool multiuserAuthentication ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->setMultiuserAuthentication( multiuserAuthentication ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + PoolFactory^ PoolFactory::Reset() + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->reset( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + return this; + } + + + Pool^ PoolFactory::Create(String^ name, Cache^ cache) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + ManagedString mg_name(name); + try + { + return Pool::Create(m_nativeptr->get()->create(mg_name.CharPtr)); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/PoolFactory.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/PoolFactory.hpp b/clicache/src/PoolFactory.hpp new file mode 100644 index 0000000..cf16906 --- /dev/null +++ b/clicache/src/PoolFactory.hpp @@ -0,0 +1,427 @@ +/* + * 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. + */ + +#pragma once + +#include "geode_defs.hpp" +#include "begin_native.hpp" +#include <geode/PoolFactory.hpp> +#include "end_native.hpp" + +#include "native_shared_ptr.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + + ref class Pool; + + /// <summary> + /// This interface provides for the configuration and creation of instances of Pool. + /// </summary> + + public ref class PoolFactory sealed + { + public: + + /// <summary> + /// Sets the free connection timeout for this pool. + /// </summary> + /// <remarks> + /// If the pool has a max connections setting, operations will block + /// if all of the connections are in use. The free connection timeout + /// specifies how long those operations will block waiting for + /// a free connection before receiving an AllConnectionsInUseException. + /// If max connections is not set this setting has no effect. + /// </remarks> + /// <param> + /// connectionTimeout the connection timeout in milliseconds + /// </param> + /// <exception> + /// IllegalArgumentException if connectionTimeout + /// is less than or equal to 0. + /// </exception> + PoolFactory^ SetFreeConnectionTimeout(Int32 connectionTimeout); + + /// <summary> + /// Sets the load conditioning interval for this pool. + /// </summary> + /// <remarks> + /// This interval controls how frequently the pool will check to see if + /// a connection to a given server should be moved to a different + /// server to improve the load balance. + /// </remarks> + /// <param> + /// loadConditioningInterval the connection lifetime in milliseconds + /// A value of -1 disables load conditioning. + /// </param> + /// <exception> + /// throws IllegalArgumentException if connectionLifetime + /// is less than -1. + /// </exception> + PoolFactory^ SetLoadConditioningInterval(Int32 loadConditioningInterval); + + /// <summary> + /// Sets the socket buffer size for each connection made in this pool. + /// </summary> + /// <remarks> + /// Large messages can be received and sent faster when this buffer is larger. + /// Larger buffers also optimize the rate at which servers can send events + /// for client subscriptions. + /// </remarks> + /// <param> + /// bufferSize the size of the socket buffers used for reading and + /// writing on each connection in this pool. + /// </param> + /// <exception> + /// throws IllegalArgumentException if bufferSize + /// is less than or equal to 0. + /// </exception> + PoolFactory^ SetSocketBufferSize(Int32 bufferSize); + + /// <summary> + /// Sets the number of milliseconds to wait for a response from a server before + /// timing out the operation and trying another server (if any are available). + /// </summary> + /// <param> + /// timeout number of milliseconds to wait for a response from a server + /// </param> + /// <exception> + /// throws IllegalArgumentException if timeout + /// is less than or equal to 0. + /// </exception> + PoolFactory^ SetReadTimeout(Int32 timeout); + + /// <summary> + /// Set the minimum number of connections to keep available at all times. + /// </summary> + /// <remarks> + /// When the pool is created, it will create this many connections. + /// If 0 then connections will not be made until an actual operation + /// is done that requires client-to-server communication. + /// </remarks> + /// <param> + /// minConnections the initial number of connections this pool will create. + /// </param> + /// <exception> + /// throws IllegalArgumentException if minConnections is less than 0. + /// </exception> + PoolFactory^ SetMinConnections(Int32 minConnections); + + /// <summary> + /// Set the max number of client to server connections that the pool will create. + /// </summary> + /// <remarks> + /// If all of the connections are in use, an operation requiring a client to + /// server connection will block until a connection is available. + /// see setFreeConnectionTimeout(int) + /// </remarks> + /// <param> + /// maxConnections the maximum number of connections in the pool. + /// -1 indicates that there is no maximum number of connections. + /// </param> + /// <exception> + /// throws IllegalArgumentException if maxConnections is less than minConnections. + /// </exception> + PoolFactory^ SetMaxConnections(Int32 maxConnections); + + /// <summary> + /// Set the amount of time a connection can be idle before expiring the connection. + /// </summary> + /// <remarks> + /// If the pool size is greater than the minimum specified, connections which have + /// been idle for longer than the idleTimeout will be closed. + /// </remarks> + /// <param> + /// idleTimeout The amount of time in milliseconds that an idle connection + /// should live before expiring. -1 indicates that connections should never expire. + /// </param> + /// <exception> + /// throws IllegalArgumentException if idleTimout is less than 0. + /// </exception> + PoolFactory^ SetIdleTimeout(Int32 idleTimeout); + + /// <summary> + /// Set the number of times to retry a request after timeout/exception. + /// </summary> + /// <param> + /// retryAttempts The number of times to retry a request + /// after timeout/exception. -1 indicates that a request should be + /// tried against every available server before failing. + /// </param> + /// <exception> + /// throws IllegalArgumentException if idleTimout is less than 0. + /// </exception> + PoolFactory^ SetRetryAttempts(Int32 retryAttempts); + + /// <summary> + /// Set how often to ping servers to verify that they are still alive. + /// </summary> + /// <remarks> + /// Each server will be sent a ping every pingInterval if there has not + /// been any other communication with the server. + /// These pings are used by the server to monitor the health of + /// the client. Make sure that the pingInterval is less than the + /// maximum time between pings allowed by the bridge server. + /// see in CacheServer: setMaximumTimeBetweenPings(int) + /// </remarks> + /// <param> + /// pingInterval The amount of time in milliseconds between pings. + /// </param> + /// <exception> + /// throws IllegalArgumentException if pingInterval is less than 0. + /// </exception> + PoolFactory^ SetPingInterval(Int32 pingInterval); + + /// <summary> + /// Set how often to update locator list from locator + /// </summary> + /// <param> + /// updateLocatorListInterval The amount of time in milliseconds between + /// updating locator list. If its set to 0 then client will not update + /// the locator list. + /// </param> + /// <returns> + /// a instance of <c>CacheFactory</c> + /// </returns> + PoolFactory^ SetUpdateLocatorListInterval(Int32 updateLocatorListInterval); + + /// <summary> + /// Set how often to send client statistics to the server. + /// </summary> + /// <remarks> + /// Doing this allows gfmon to monitor clients. + /// A value of -1 disables the sending of client statistics + /// to the server. + /// </remarks> + /// <param> + /// statisticInterval The amount of time in milliseconds between + /// sends of client statistics to the server. + /// </param> + /// <exception> + /// throws IllegalArgumentException if statisticInterval + /// is less than -1. + /// </exception> + PoolFactory^ SetStatisticInterval(Int32 statisticInterval); + + /// <summary> + /// Configures the group that all servers this pool connects to must belong to. + /// </summary> + /// <param> + /// group the server group that this pool will connect to. + /// If null or "" then all servers will be connected to. + /// </param> + PoolFactory^ SetServerGroup(String^ group); + + /// <summary> + /// Add a locator, given its host and port, to this factory. + /// </summary> + /// <remarks> + /// The locator must be a server locator and will be used to discover other running + /// bridge servers and locators. + /// </remarks> + /// <param> + /// host the host name or ip address that the locator is listening on. + /// </param> + /// <param> + /// port the port that the locator is listening on + /// </param> + /// <exception> + /// throws IllegalArgumentException if host is an unknown host + /// or if port is outside the valid range of [1..65535] inclusive. + /// </exception> + /// <exception> + /// throws IllegalStateException if a locator has already been added to this factory. + /// </exception> + PoolFactory^ AddLocator(String^ host, Int32 port); + + /// <summary> + /// Add a server, given its host and port, to this factory. + /// </summary> + /// <remarks> + /// The server must be a bridge server and this client will + /// directly connect to without consulting a server locator. + /// </remarks> + /// <param> + /// host the host name or ip address that the server is listening on. + /// </param> + /// <param> + /// port the port that the server is listening on + /// </param> + /// <exception> + /// throws IllegalArgumentException if host is an unknown host + /// or if port is outside the valid range of [1..65535] inclusive. + /// </exception> + /// <exception> + /// throws IllegalStateException if a server has already been added to this factory. + /// </exception> + PoolFactory^ AddServer(String^ host, Int32 port); + + /// <summary> + /// Enable subscriptions. + /// </summary> + /// <remarks> + /// If set to true then the created pool will have server-to-client + /// subscriptions enabled. If set to false then all Subscription* + /// attributes are ignored at create time. + /// </remarks> + PoolFactory^ SetSubscriptionEnabled(Boolean enabled); + + /// <summary> + /// By default SetPRSingleHopEnabled is true. + /// </summary> + /// <remarks> + /// The client is aware of location of partitions on servers hosting + /// Using this information, the client routes the client cache operations + /// directly to the server which is hosting the required partition for the + /// cache operation. + /// If SetPRSingleHopEnabled is false the client can do an extra hop on servers + /// to go to the required partition for that cache operation. + /// The SetPRSingleHopEnabled avoids extra hops only for following cache operations : + /// put, get & destroy operations. + /// </remarks> + PoolFactory^ SetPRSingleHopEnabled(Boolean enabled); + + /// <summary> + /// Sets the redundancy level for this pools server-to-client subscriptions. + /// </summary> + /// <remarks> + /// If 0 then no redundant copies will be kept on the servers. + /// Otherwise an effort will be made to maintain the requested number of + /// copies of the server-to-client subscriptions. At most one copy per server will + /// be made up to the requested level. + /// </remarks> + /// <param> + /// redundancy the number of redundant servers for this client's subscriptions. + /// </param> + /// <exception> + /// throws IllegalArgumentException if redundancyLevel is less than -1. + /// </exception> + PoolFactory^ SetSubscriptionRedundancy(Int32 redundancy); + + /// <summary> + /// Sets the messageTrackingTimeout attribute which is the time-to-live period, + /// in milliseconds, for subscription events the client has received from the server. + /// </summary> + /// <remarks> + /// It's used to minimize duplicate events. Entries that have not been modified + /// for this amount of time are expired from the list. + /// </remarks> + /// <param> + /// messageTrackingTimeout number of milliseconds to set the timeout to. + /// </param> + /// <exception> + /// throws IllegalArgumentException if messageTrackingTimeout is less than or equal to 0. + /// </exception> + PoolFactory^ SetSubscriptionMessageTrackingTimeout(Int32 messageTrackingTimeout); + + /// <summary> + /// Sets the is the interval in milliseconds to wait before sending + /// acknowledgements to the bridge server for events received from the server subscriptions. + /// </summary> + /// <param> + /// ackInterval number of milliseconds to wait before sending event acknowledgements. + /// </param> + /// <exception> + /// throws IllegalArgumentException if ackInterval is less than or equal to 0. + /// </exception> + PoolFactory^ SetSubscriptionAckInterval(Int32 ackInterval); + + /// <summary> + /// Enable ThreadLocalConnection. + /// </summary> + /// <remarks> + /// Sets the thread local connections policy for this pool. + /// If true then any time a thread goes to use a connection + /// from this pool it will check a thread local cache and see if it already + /// has a connection in it. If so it will use it. If not it will get one from + /// this pool and cache it in the thread local. This gets rid of thread contention + /// for the connections but increases the number of connections the servers see. + /// If false then connections are returned to the pool as soon + /// as the operation being done with the connection completes. This allows + /// connections to be shared amonst multiple threads keeping the number of + /// connections down. + /// </remarks> + PoolFactory^ SetThreadLocalConnections(Boolean enabled); + + /// <summary> + /// Sets whether pool is in multiuser mode + /// If its in multiuser mode then app needs to get instance of cache from pool.getCache("creds"), to do the operations on cache. + /// </summary> + /// <param> + /// multiuserAuthentication should be true/false. Default value is false; + /// </param> + PoolFactory^ SetMultiuserAuthentication(bool multiuserAuthentication); + + /// <summary> + /// Resets the configuration of this factory to its defaults. + /// </summary> + PoolFactory^ Reset(); + + /// <summary> + /// Create a new Pool for connecting a client to a set of Geode Cache Servers. + /// using this factory's settings for attributes. + /// </summary> + /// <param> + /// name the name of the pool, used when connecting regions to it + /// </param> + /// <exception> + /// throws IllegalStateException if a pool with name already exists + /// throws IllegalStateException if a locator or server has not been added. + /// </exception> + Pool^ Create(String^ name, Cache^ cache); + + internal: + + /// <summary> + /// Internal factory function to wrap a native object pointer inside + /// this managed class with null pointer check. + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + /// <returns> + /// The managed wrapper object; null if the native pointer is null. + /// </returns> + inline static PoolFactory^ Create(native::PoolFactoryPtr nativeptr) + { + return __nullptr == nativeptr ? nullptr : + gcnew PoolFactory( nativeptr ); + } + + private: + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline PoolFactory(native::PoolFactoryPtr nativeptr) + { + m_nativeptr = gcnew native_shared_ptr<native::PoolFactory>(nativeptr); + } + + native_shared_ptr<native::PoolFactory>^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/PoolManager.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/PoolManager.cpp b/clicache/src/PoolManager.cpp new file mode 100644 index 0000000..3f641a7 --- /dev/null +++ b/clicache/src/PoolManager.cpp @@ -0,0 +1,77 @@ +/* + * 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. + */ + +#pragma once + +#include "Region.hpp" +#include "Pool.hpp" +#include "PoolManager.hpp" +#include "PoolFactory.hpp" +#include "CacheableString.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + PoolFactory^ PoolManager::CreateFactory() + { + return PoolFactory::Create(m_nativeref.createFactory()); + } + + const Dictionary<String^, Pool^>^ PoolManager::GetAll() + { + auto pools = m_nativeref.getAll(); + auto result = gcnew Dictionary<String^, Pool^>(); + for (const auto& iter : pools) + { + auto key = gcnew String(iter.first.c_str()); + auto val = Pool::Create(iter.second); + result->Add(key, val); + } + return result; + } + + Pool^ PoolManager::Find(String^ name) + { + ManagedString mg_name( name ); + auto pool = m_nativeref.find(mg_name.CharPtr); + return Pool::Create(pool); + } + + Pool^ PoolManager::Find(Client::Region<Object^, Object^>^ region) + { + return Pool::Create(m_nativeref.find(region->GetNative())); + } + + void PoolManager::Close(Boolean KeepAlive) + { + m_nativeref.close(KeepAlive); + } + + void PoolManager::Close() + { + m_nativeref.close(); + } + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/PoolManager.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/PoolManager.hpp b/clicache/src/PoolManager.hpp new file mode 100644 index 0000000..0ea139d --- /dev/null +++ b/clicache/src/PoolManager.hpp @@ -0,0 +1,102 @@ +/* + * 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. + */ + +#pragma once + +#include "geode_defs.hpp" +#include "begin_native.hpp" +#include <geode/PoolManager.hpp> +#include "end_native.hpp" + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + //generic<class TKey, class TValue> + ref class Pool; + // generic<class TKey, class TValue> + ref class PoolFactory; + + namespace native = apache::geode::client; + + /// <summary> + /// This interface provides for the configuration and creation of instances of PoolFactory. + /// </summary> + // generic<class TKey, class TValue> + public ref class PoolManager + { + public: + + /// <summary> + /// Creates a new PoolFactory which is used to configure and create Pools. + /// </summary> + PoolFactory/*<TKey, TValue>*/^ CreateFactory(); + + /// <summary> + /// Returns a map containing all the pools in this manager. + /// The keys are pool names and the values are Pool instances. + /// </summary> + const Dictionary<String^, Pool/*<TKey, TValue>*/^>^ GetAll(); + + /// <summary> + /// Find by name an existing connection pool. + /// </summary> + Pool/*<TKey, TValue>*/^ Find(String^ name); + + /// <summary> + /// Find the pool used by the given region. + /// </summary> + Pool/*<TKey, TValue>*/^ Find(Client::Region<Object^, Object^>^ region); + + /// <summary> + /// Destroys all created pools. + /// </summary> + void Close(Boolean KeepAlive); + + /// <summary> + /// Destroys all created pools. + /// </summary> + void Close(); + + internal: + + native::PoolManager& GetNative() + { + return m_nativeref; + } + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline PoolManager(native::PoolManager& nativeref) + : m_nativeref(nativeref) + { + } + + native::PoolManager& m_nativeref; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache +