http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableString.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableString.cpp b/clicache/src/CacheableString.cpp new file mode 100644 index 0000000..ceea6d6 --- /dev/null +++ b/clicache/src/CacheableString.cpp @@ -0,0 +1,212 @@ +/* + * 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 "DataOutput.hpp" +#include "DataInput.hpp" + +//#include "geode_includes.hpp" +#include "CacheableString.hpp" +#include "ExceptionTypes.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + void CacheableString::ToData(DataOutput^ output) + { + if (m_type == GeodeClassIds::CacheableASCIIString || + m_type == GeodeClassIds::CacheableString) + { + output->WriteUTF(m_value); + } + else if (m_type == GeodeClassIds::CacheableASCIIStringHuge) + { + output->WriteASCIIHuge(m_value); + } + else + { + output->WriteUTFHuge(m_value); + } + } + + IGeodeSerializable^ CacheableString::FromData(DataInput^ input) + { + if (m_type == GeodeClassIds::CacheableASCIIString || + m_type == GeodeClassIds::CacheableString) + { + m_value = input->ReadUTF(); + } + else if (m_type == GeodeClassIds::CacheableASCIIStringHuge) + { + m_value = input->ReadASCIIHuge(); + } + else + { + m_value = input->ReadUTFHuge(); + } + + return this; + } + + + inline void CacheableString::GetCacheableString(String^ value, + apache::geode::client::CacheableStringPtr& cStr) + { + size_t len; + if (value != nullptr && (len = value->Length) > 0) { + pin_ptr<const wchar_t> pin_value = PtrToStringChars(value); + cStr = apache::geode::client::CacheableString::create(pin_value, (System::Int32)len); + } + else { + cStr.reset( + static_cast<apache::geode::client::CacheableString*>(apache::geode::client::CacheableString::createDeserializable())); + } + } + + inline void CacheableString::GetCacheableString(array<Char>^ value, + apache::geode::client::CacheableStringPtr& cStr) + { + size_t len; + if (value != nullptr && (len = value->Length) > 0) { + pin_ptr<const Char> pin_value = &value[0]; + cStr = apache::geode::client::CacheableString::create( + (const wchar_t*)pin_value, (System::Int32)len); + } + else { + cStr.reset( + static_cast<apache::geode::client::CacheableString*>(apache::geode::client::CacheableString::createDeserializable())); + } + } + + CacheableString::CacheableString(String^ value) + : CacheableKey() + { + if (value == nullptr) { + throw gcnew IllegalArgumentException("CacheableString: null or " + + "zero-length string provided to the constructor."); + } + m_value = value; + + this->SetStringType(); + } + + CacheableString::CacheableString(array<Char>^ value) + : CacheableKey() + { + if (value == nullptr) { + throw gcnew IllegalArgumentException("CacheableString: null or " + + "zero-length character array provided to the constructor."); + } + m_value = gcnew String(value); + + this->SetStringType(); + } + + CacheableString::CacheableString(String^ value, bool noParamCheck) + : CacheableKey() + { + m_value = value; + this->SetStringType(); + } + + CacheableString::CacheableString(array<Char>^ value, bool noParamCheck) + : CacheableKey() + { + m_value = gcnew String(value); + this->SetStringType(); + } + + System::UInt32 CacheableString::ObjectSize::get() + { + return (m_value->Length * sizeof(char)); + } + + bool CacheableString::Equals(Apache::Geode::Client::ICacheableKey^ other) + { + if (other == nullptr || other->ClassId != ClassId) { + return false; + } + + CacheableString^ otherStr = + dynamic_cast<CacheableString^>(other); + + if (otherStr == nullptr) + return false; + + return m_value->Equals(otherStr->Value);//TODO:: + } + + bool CacheableString::Equals(Object^ obj) + { + CacheableString^ otherStr = + dynamic_cast<CacheableString^>(obj); + + if (otherStr != nullptr) { + return m_value->Equals(otherStr->Value); + } + return false; + } + + System::Int32 CacheableString::GetHashCode() + { + if (String::IsNullOrEmpty(m_value)) { + return 0; + } + //TODO: need to need java hashcode + //return m_value->GetHashCode(); + if (m_hashcode == 0) + { + System::Int32 prime = 31; + System::Int32 localHash = 0; + for (System::Int32 i = 0; i < m_value->Length; i++) + localHash = prime*localHash + m_value[i]; + m_hashcode = localHash; + } + return m_hashcode; + } + + void CacheableString::SetStringType() + { + int len = DataOutput::getEncodedLength(m_value); + + if (len == m_value->Length)//ASCII string + { + if (len > 0xFFFF) + m_type = GeodeClassIds::CacheableASCIIStringHuge; + else + m_type = GeodeClassIds::CacheableASCIIString; + } + else + { + if (len > 0xFFFF) + m_type = GeodeClassIds::CacheableStringHuge; + else + m_type = GeodeClassIds::CacheableString; + } // namespace Client + } // namespace Geode + } // namespace Apache + + } +} //namespace +
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableString.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableString.hpp b/clicache/src/CacheableString.hpp new file mode 100644 index 0000000..d24adc5 --- /dev/null +++ b/clicache/src/CacheableString.hpp @@ -0,0 +1,326 @@ +/* + * 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/CacheableString.hpp> +#include "end_native.hpp" + +#include "impl/ManagedString.hpp" +#include "CacheableKey.hpp" +#include "GeodeClassIds.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// An immutable string wrapper that can serve as a distributable + /// key object for caching as well as being a string value. + /// </summary> + ref class CacheableString + : public CacheableKey + { + public: + /// <summary> + /// Allocates a new instance copying from the given string. + /// </summary> + /// <param name="value">the string value of the new instance</param> + /// <exception cref="IllegalArgumentException"> + /// if the provided string is null or has zero length + /// </exception> + CacheableString(String^ value); + + /// <summary> + /// Allocates a new instance copying from the given character array. + /// </summary> + /// <param name="value"> + /// the character array value of the new instance + /// </param> + /// <exception cref="IllegalArgumentException"> + /// if the provided array is null or has zero length + /// </exception> + CacheableString(array<Char>^ value); + + /// <summary> + /// Static function to create a new instance copying from + /// the given string. + /// </summary> + /// <remarks> + /// Providing a null or zero size string will return a null + /// <c>CacheableString</c> object. + /// </remarks> + /// <param name="value">the string value of the new instance</param> + inline static CacheableString^ Create(String^ value) + { + return (value != nullptr ? + gcnew CacheableString(value, true) : nullptr); + } + + /// <summary> + /// Serializes this managed object. + /// </summary> + /// <param name="output"> + /// the DataOutput object to use for serializing the object + /// </param> + virtual void ToData(DataOutput^ output) override; + + /// <summary> + /// Deserializes the managed object -- returns an instance of the + /// <c>IGeodeSerializable</c> class. + /// </summary> + /// <param name="input"> + /// the DataInput stream to use for reading the object data + /// </param> + /// <returns>the deserialized object</returns> + virtual IGeodeSerializable^ FromData(DataInput^ input) override; + + // <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + virtual System::UInt32 get() override + { + return m_type; + } + } + + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual property System::UInt32 ObjectSize + { + virtual System::UInt32 get() override; + } + + /// <summary> + /// Static function to create a new instance copying from + /// the given character array. + /// </summary> + /// <remarks> + /// Providing a null or zero size character array will return a null + /// <c>CacheableString</c> object. + /// </remarks> + /// <param name="value"> + /// the character array value of the new instance + /// </param> + inline static CacheableString^ Create(array<Char>^ value) + { + return (value != nullptr && value->Length > 0 ? + gcnew CacheableString(value, true) : nullptr); + } + + /// <summary> + /// Return a string representation of the object. + /// This returns the same string as <c>Value</c> property. + /// </summary> + virtual String^ ToString() override + { + return m_value; + } + + /// <summary> + /// Return true if this key matches other object. + /// It invokes the '==' operator of the underlying + /// <c>apache::geode::client::CacheableString</c> object. + /// </summary> + virtual bool Equals(Apache::Geode::Client::ICacheableKey^ other) override; + + /// <summary> + /// Return true if this key matches other object. + /// It invokes the '==' operator of the underlying + /// <c>apache::geode::client::CacheableString</c> object. + /// </summary> + virtual bool Equals(Object^ obj) override; + + /// <summary> + /// Return the hashcode for this key. + /// </summary> + virtual System::Int32 GetHashCode() override; + + /// <summary> + /// Gets the string value. + /// </summary> + property String^ Value + { + inline String^ get() + { + return m_value; + } + } + + /// <summary> + /// Static function to check whether IsNullOrEmpty. + /// </summary> + /// <remarks> + /// This is similar to the C# string.IsNullOrEmpty method. + /// </remarks> + /// <param name="value">the CacheableString value to check</param> + inline static bool IsNullOrEmpty(CacheableString^ value) + { + return (value == nullptr || value->Length == 0); + } + + /// <summary> + /// Implicit conversion operator to underlying <c>System.String</c>. + /// </summary> + inline static operator String ^ (CacheableString^ str) + { + return (str != nullptr ? CacheableString::GetString(str) : nullptr); + } + + /// <summary> + /// Gets the length of the underlying C string. + /// </summary> + property System::UInt32 Length + { + inline System::UInt32 get() + { + return m_value->Length; + } + } + + /// <summary> + /// True when the underlying C string is a wide-character string. + /// </summary> + property bool IsWideString + { + inline bool get() + { + return true;//TODO: + } + } + + internal: + static IGeodeSerializable^ CreateDeserializable() + { + return gcnew CacheableString(GeodeClassIds::CacheableASCIIString); + } + + static IGeodeSerializable^ createDeserializableHuge() + { + return gcnew CacheableString(GeodeClassIds::CacheableASCIIStringHuge); + } + + static IGeodeSerializable^ createUTFDeserializable() + { + return gcnew CacheableString(GeodeClassIds::CacheableString); + } + + static IGeodeSerializable^ createUTFDeserializableHuge() + { + return gcnew CacheableString(GeodeClassIds::CacheableStringHuge); + } + /// <summary> + /// Factory function to register wrapper + /// </summary> + static IGeodeSerializable^ Create(apache::geode::client::SerializablePtr obj) + { + return (obj != nullptr ? + gcnew CacheableString(obj) : nullptr); + } + + /// <summary> + /// Internal function to create a <c>apache::geode::client::CacheableString</c> + /// from the given managed string. + /// </summary> + static void GetCacheableString(String^ value, + apache::geode::client::CacheableStringPtr& cStr); + + /// <summary> + /// Internal function to create a <c>apache::geode::client::CacheableString</c> + /// from the given managed array of characters. + /// </summary> + static void GetCacheableString(array<Char>^ value, + apache::geode::client::CacheableStringPtr& cStr); + + /// <summary> + /// Get the <c>System.String</c> from the given + /// <c>apache::geode::client::CacheableString</c> + /// </summary> + inline static String^ GetString(apache::geode::client::CacheableString * cStr) + { + if (cStr == NULL) { + return nullptr; + } + else if (cStr->isWideString()) { + return ManagedString::Get(cStr->asWChar()); + } + else { + return ManagedString::Get(cStr->asChar()); + } + } + + inline static String^ GetString(CacheableString^ cStr) + { + return cStr->Value; + } + + CacheableString(System::UInt32 type) : CacheableKey() + { + m_type = type; + } + + private: + String^ m_value; + System::UInt32 m_type; + int m_hashcode; + + CacheableString() : CacheableKey() + { + m_type = GeodeClassIds::CacheableASCIIString; + } + + void SetStringType(); + /// <summary> + /// Private constructor to create a CacheableString without checking + /// for arguments. + /// </summary> + CacheableString(String^ value, bool noParamCheck); + + /// <summary> + /// Private constructor to create a CacheableString without checking + /// for arguments. + /// </summary> + CacheableString(array<Char>^ value, bool noParamCheck); + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CacheableString(apache::geode::client::SerializablePtr nativeptr) + : CacheableKey(nativeptr) { } + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableStringArray.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableStringArray.cpp b/clicache/src/CacheableStringArray.cpp new file mode 100644 index 0000000..34c27ae --- /dev/null +++ b/clicache/src/CacheableStringArray.cpp @@ -0,0 +1,96 @@ +/* + * 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 "CacheableStringArray.hpp" +#include "CacheableString.hpp" +#include "DataInput.hpp" +#include "DataOutput.hpp" +#include "ExceptionTypes.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + CacheableStringArray::CacheableStringArray(array<String^>^ strings) + : Serializable() + { + m_value = strings; + } + + + array<String^>^ CacheableStringArray::GetValues() + { + return m_value; + } + + String^ CacheableStringArray::default::get(System::Int32 index) + { + return m_value[index]; + } + + void CacheableStringArray::ToData(DataOutput^ output) + { + if (m_value == nullptr) + { + output->WriteArrayLen(-1); + } + else + { + output->WriteArrayLen(m_value->Length); + if (m_value->Length > 0) + { + for(int i = 0; i < m_value->Length; i++) + { + output->WriteObject(m_value[i]); + } + GC::KeepAlive(this); + } + } + } + + + IGeodeSerializable^ CacheableStringArray::FromData(DataInput^ input) + { + int len = input->ReadArrayLen(); + if ( len == -1) + { + m_value = nullptr; + return nullptr; + } + else + { + m_value = gcnew array<String^>(len); + if (len > 0) + { + for( int i = 0; i < len; i++) + { + m_value[i] = dynamic_cast<String^>(input->ReadObject()); + } + } + return this; + } // namespace Client + } // namespace Geode +} // namespace Apache + +} + } //namespace http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableStringArray.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableStringArray.hpp b/clicache/src/CacheableStringArray.hpp new file mode 100644 index 0000000..e8c66f6 --- /dev/null +++ b/clicache/src/CacheableStringArray.hpp @@ -0,0 +1,193 @@ +/* + * 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/CacheableBuiltins.hpp> +#include "end_native.hpp" + +#include "Serializable.hpp" +#include "GeodeClassIds.hpp" +#include "CacheableString.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + ref class CacheableString; + + /// <summary> + /// An immutable wrapper for array of strings that can serve as + /// a distributable object for caching. + /// </summary> + ref class CacheableStringArray + : public Serializable + { + public: + /// <summary> + /// Static function to create a new instance copying from the given + /// string array. + /// </summary> + /// <remarks> + /// If the given array of strings is null or of zero-length then + /// this method returns null. + /// </remarks> + /// <exception cref="IllegalArgumentException"> + /// If the array contains a string greater than or equal 64K in length. + /// </exception> + inline static CacheableStringArray^ Create(array<String^>^ strings) + { + return (strings != nullptr && strings->Length > 0 ? + gcnew CacheableStringArray(strings) : nullptr); + } + + /// <summary> + /// Serializes this managed object. + /// </summary> + /// <param name="output"> + /// the DataOutput object to use for serializing the object + /// </param> + virtual void ToData(DataOutput^ output) override; + + /// <summary> + /// Deserializes the managed object -- returns an instance of the + /// <c>IGeodeSerializable</c> class. + /// </summary> + /// <param name="input"> + /// the DataInput stream to use for reading the object data + /// </param> + /// <returns>the deserialized object</returns> + virtual IGeodeSerializable^ FromData(DataInput^ input) override; + + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + virtual System::UInt32 get() override + { + return GeodeClassIds::CacheableStringArray; + } + } + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual property System::UInt32 ObjectSize + { + virtual System::UInt32 get() override + { + int size = 0; + for (int i = 0; i < m_value->Length; i++) + { + size += m_value[i]->Length; + } + return (System::UInt32)(size + sizeof(this)); + } + + } + + /// <summary> + /// Returns a copy of the underlying array of strings. + /// </summary> + array<String^>^ GetValues(); + + /// <summary> + /// Returns a copy of the underlying string at the given index. + /// </summary> + property String^ GFINDEXER(System::Int32) + { + String^ get(System::Int32 index); + } + + /// <summary> + /// Gets the length of the array. + /// </summary> + property System::Int32 Length + { + inline System::Int32 get() + { + return m_value->Length; + } + } + + virtual String^ ToString() override + { + return m_value->ToString(); + } + + /// <summary> + /// Factory function to register this class. + /// </summary> + static IGeodeSerializable^ CreateDeserializable() + { + return gcnew CacheableStringArray(); + } + + internal: + /// <summary> + /// Factory function to register wrapper + /// </summary> + static IGeodeSerializable^ Create(apache::geode::client::SerializablePtr obj) + { + return (obj != nullptr ? + gcnew CacheableStringArray(obj) : nullptr); + } + + private: + array<String^>^ m_value; + /// <summary> + /// Allocates a new instance copying from the given string array. + /// </summary> + /// <exception cref="IllegalArgumentException"> + /// If the array contains a string greater than or equal 64K in length. + /// </exception> + CacheableStringArray(array<String^>^ strings); + + + inline CacheableStringArray() + : Serializable() + { + //apache::geode::client::Serializable* sp = apache::geode::client::CacheableStringArray::createDeserializable(); + //SetSP(sp); + } + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CacheableStringArray(apache::geode::client::SerializablePtr nativeptr) + : Serializable(nativeptr) { } + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableUndefined.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableUndefined.cpp b/clicache/src/CacheableUndefined.cpp new file mode 100644 index 0000000..c6545c8 --- /dev/null +++ b/clicache/src/CacheableUndefined.cpp @@ -0,0 +1,53 @@ +/* + * 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 "CacheableUndefined.hpp" +#include "DataOutput.hpp" +#include "DataInput.hpp" + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + // Region: IGeodeSerializable Members + + void CacheableUndefined::ToData(DataOutput^ output) + { + } + + IGeodeSerializable^ CacheableUndefined::FromData(DataInput^ input) + { + return this; + } + + System::UInt32 CacheableUndefined::ObjectSize::get() + { + return static_cast<System::UInt32> (sizeof(CacheableUndefined^)); + } // namespace Client + } // namespace Geode +} // namespace Apache + + } //namespace http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableUndefined.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableUndefined.hpp b/clicache/src/CacheableUndefined.hpp new file mode 100644 index 0000000..83b40ff --- /dev/null +++ b/clicache/src/CacheableUndefined.hpp @@ -0,0 +1,109 @@ +/* + * 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 "IGeodeSerializable.hpp" +#include "GeodeClassIds.hpp" +#include "Log.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// Encapsulate an undefined result. + /// </summary> + public ref class CacheableUndefined + : public IGeodeSerializable + { + public: + /// <summary> + /// Allocates a new empty instance. + /// </summary> + inline CacheableUndefined() { } + + /// <summary> + /// Static function to create a new empty instance. + /// </summary> + inline static CacheableUndefined^ Create() + { + return gcnew CacheableUndefined(); + } + + // Region: IGeodeSerializable Members + + /// <summary> + /// Serializes this object. + /// </summary> + /// <param name="output"> + /// the DataOutput object to use for serializing the object + /// </param> + virtual void ToData(DataOutput^ output); + + /// <summary> + /// Deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + /// <param name="input"> + /// the DataInput stream to use for reading the object data + /// </param> + /// <returns>the deserialized object</returns> + virtual IGeodeSerializable^ FromData(DataInput^ input); + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual property System::UInt32 ObjectSize + { + virtual System::UInt32 get(); + } + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + inline virtual System::UInt32 get() + { + return GeodeClassIds::CacheableUndefined; + } + } + + // End Region: IGeodeSerializable Members + + /// <summary> + /// Factory function to register this class. + /// </summary> + static IGeodeSerializable^ CreateDeserializable() + { + return gcnew CacheableUndefined(); + } + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableVector.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableVector.cpp b/clicache/src/CacheableVector.cpp new file mode 100644 index 0000000..36f0e3a --- /dev/null +++ b/clicache/src/CacheableVector.cpp @@ -0,0 +1,78 @@ +/* + * 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 "CacheableVector.hpp" +#include "DataOutput.hpp" +#include "DataInput.hpp" +#include "ExceptionTypes.hpp" +#include "impl/SafeConvert.hpp" + +using namespace System; +using namespace System::Collections::Generic; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + // Region: IGeodeSerializable Members + + void CacheableVector::ToData(DataOutput^ output) + { + if(m_arrayList != nullptr) + { + output->WriteArrayLen(m_arrayList->Count); + for each (Object^ obj in m_arrayList) { + //TODO::split + output->WriteObject(obj); + } + } + else + output->WriteByte(0xFF); + } + + IGeodeSerializable^ CacheableVector::FromData(DataInput^ input) + { + int len = input->ReadArrayLen(); + for( int i = 0; i < len; i++) + { + m_arrayList->Add(input->ReadObject()); + } + return this; + } + + System::UInt32 CacheableVector::ObjectSize::get() + { + //TODO:: + /*System::UInt32 size = static_cast<System::UInt32> (sizeof(CacheableVector^)); + for each (IGeodeSerializable^ val in this) { + if (val != nullptr) { + size += val->ObjectSize; + } + }*/ + return m_arrayList->Count; + } // namespace Client + } // namespace Geode +} // namespace Apache + + } //namespace + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableVector.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableVector.hpp b/clicache/src/CacheableVector.hpp new file mode 100644 index 0000000..886f6a0 --- /dev/null +++ b/clicache/src/CacheableVector.hpp @@ -0,0 +1,136 @@ +/* + * 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 "IGeodeSerializable.hpp" +#include "GeodeClassIds.hpp" + + +using namespace System; +using namespace System::Collections::Generic; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// A mutable <c>IGeodeSerializable</c> vector wrapper that can serve as + /// a distributable object for caching. This class extends .NET generic + /// <c>List</c> class. + /// </summary> + ref class CacheableVector + : public IGeodeSerializable + { + public: + /// <summary> + /// Allocates a new empty instance. + /// </summary> + inline CacheableVector(System::Collections::IList^ arrayList) + { + m_arrayList = arrayList; + } + + + /// <summary> + /// Static function to create a new empty instance. + /// </summary> + inline static CacheableVector^ Create() + { + return gcnew CacheableVector(gcnew System::Collections::ArrayList()); + } + + /// <summary> + /// Static function to create a new empty instance. + /// </summary> + inline static CacheableVector^ Create(System::Collections::IList^ list) + { + return gcnew CacheableVector(list); + } + + + // Region: IGeodeSerializable Members + + /// <summary> + /// Serializes this object. + /// </summary> + /// <param name="output"> + /// the DataOutput object to use for serializing the object + /// </param> + virtual void ToData(DataOutput^ output); + + /// <summary> + /// Deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + /// <param name="input"> + /// the DataInput stream to use for reading the object data + /// </param> + /// <returns>the deserialized object</returns> + virtual IGeodeSerializable^ FromData(DataInput^ input); + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual property System::UInt32 ObjectSize + { + virtual System::UInt32 get(); + } + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + virtual System::UInt32 get() + { + return GeodeClassIds::CacheableVector; + } + } + + virtual property System::Collections::IList^ Value + { + virtual System::Collections::IList^ get() + { + return m_arrayList; + } + } + + // End Region: IGeodeSerializable Members + + /// <summary> + /// Factory function to register this class. + /// </summary> + static IGeodeSerializable^ CreateDeserializable() + { + return gcnew CacheableVector(gcnew System::Collections::ArrayList()); + } + + private: + System::Collections::IList^ m_arrayList; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqAttributes.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqAttributes.cpp b/clicache/src/CqAttributes.cpp new file mode 100644 index 0000000..ef10045 --- /dev/null +++ b/clicache/src/CqAttributes.cpp @@ -0,0 +1,74 @@ +/* + * 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 "CqAttributes.hpp" +#include "impl/ManagedCqListener.hpp" +#include "ICqListener.hpp" +#include "impl/ManagedCqStatusListener.hpp" +#include "ICqStatusListener.hpp" + +#include "begin_native.hpp" +#include <geode/CqAttributes.hpp> +#include "end_native.hpp" + +namespace Apache +{ + namespace Geode + { + namespace Client + { + using namespace System; + + namespace native = apache::geode::client; + + generic<class TKey, class TResult> + array<ICqListener<TKey, TResult>^>^ CqAttributes<TKey, TResult>::getCqListeners( ) + { + native::CqAttributes::listener_container_type vrr; + try + { + m_nativeptr->get()->getCqListeners(vrr); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + auto listners = gcnew array<ICqListener<TKey, TResult>^>(vrr.size()); + + for (System::Int32 index = 0; index < vrr.size(); index++) + { + auto nativeptr = vrr[index]; + if (auto mg_listener = std::dynamic_pointer_cast<native::ManagedCqListenerGeneric>(nativeptr)) + { + listners[index] = (ICqListener<TKey, TResult>^) mg_listener->userptr(); + } + else if (auto mg_statuslistener = std::dynamic_pointer_cast<native::ManagedCqStatusListenerGeneric>(nativeptr)) + { + listners[index] = (ICqStatusListener<TKey, TResult>^) mg_statuslistener->userptr(); + } + else + { + listners[index] = nullptr; + } + } + return listners; + } + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqAttributes.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqAttributes.hpp b/clicache/src/CqAttributes.hpp new file mode 100644 index 0000000..cf3fb56 --- /dev/null +++ b/clicache/src/CqAttributes.hpp @@ -0,0 +1,91 @@ +/* + * 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/CqAttributes.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> + interface class ICqListener; + + /// <summary> + /// Defines attributes for configuring a cq. + /// </summary> + generic<class TKey, class TResult> + public ref class CqAttributes sealed + { + public: + + /// <summary> + /// get all listeners in this attributes + /// </summary> + virtual array<Client::ICqListener<TKey, TResult>^>^ getCqListeners(); + + 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 CqAttributes<TKey, TResult>^ Create( native::CqAttributesPtr nativeptr ) + { + return __nullptr == nativeptr ? nullptr : + gcnew CqAttributes( nativeptr ); + } + + std::shared_ptr<native::CqAttributes> 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 CqAttributes( native::CqAttributesPtr nativeptr ) + { + m_nativeptr = gcnew native_shared_ptr<native::CqAttributes>(nativeptr); + } + + native_shared_ptr<native::CqAttributes>^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqAttributesFactory.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqAttributesFactory.cpp b/clicache/src/CqAttributesFactory.cpp new file mode 100644 index 0000000..45dcbb7 --- /dev/null +++ b/clicache/src/CqAttributesFactory.cpp @@ -0,0 +1,160 @@ +/* + * 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 "begin_native.hpp" +#include <geode/QueryService.hpp> +#include "end_native.hpp" + +//#include "geode_includes.hpp" +#include "CqAttributesFactory.hpp" +#include "impl/ManagedCqListener.hpp" +#include "ICqListener.hpp" +#include "impl/ManagedCqStatusListener.hpp" +#include "ICqStatusListener.hpp" +#include "CqAttributesMutator.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + generic<class TKey, class TResult> + void CqAttributesFactory<TKey, TResult>::AddCqListener( Client::ICqListener<TKey, TResult>^ cqListener ) + { + native_shared_ptr<native::CqListener>^ listenerptr; + if ( cqListener != nullptr ) { + if (auto cqStatusListener = dynamic_cast<ICqStatusListener<TKey, TResult>^>(cqListener)) { + auto sLstr = gcnew CqStatusListenerGeneric<TKey, TResult>(); + sLstr->AddCqListener(cqListener); + listenerptr = gcnew native_shared_ptr<native::CqListener>(std::shared_ptr<native::ManagedCqStatusListenerGeneric>(new native::ManagedCqStatusListenerGeneric(cqListener))); + try { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->ContainsKey(cqListener) ) { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict[cqListener] = listenerptr; + } + else { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->Add(cqListener, listenerptr); + } + } + finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + ((native::ManagedCqStatusListenerGeneric*)listenerptr->get())->setptr(sLstr); + } + else { + //TODO::split + auto cqlg = gcnew CqListenerGeneric<TKey, TResult>(); + cqlg->AddCqListener(cqListener); + listenerptr = gcnew native_shared_ptr<native::CqListener>(std::shared_ptr<native::ManagedCqListenerGeneric>(new native::ManagedCqListenerGeneric(cqListener))); + try { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->ContainsKey(cqListener) ) { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict[cqListener] = listenerptr; + } + else { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->Add(cqListener, listenerptr); + } + } finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + ((native::ManagedCqListenerGeneric*)listenerptr->get())->setptr(cqlg); + } + } + try + { + m_nativeptr->get()->addCqListener( listenerptr->get_shared_ptr() ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + void CqAttributesFactory<TKey, TResult>::InitCqListeners(array<Client::ICqListener<TKey, TResult>^>^ newListeners) + { + native::CqAttributes::listener_container_type vrr; + for( int i = 0; i < newListeners->Length; i++ ) + { + if (auto lister = dynamic_cast<Client::ICqStatusListener<TKey, TResult>^>(newListeners[i])) { + auto cptr = gcnew native_shared_ptr<native::CqListener>(std::shared_ptr<native::ManagedCqStatusListenerGeneric>(new native::ManagedCqStatusListenerGeneric(lister))); + vrr.push_back(cptr->get_shared_ptr()); + auto cqlg = gcnew CqStatusListenerGeneric<TKey, TResult>(); + cqlg->AddCqListener(newListeners[i]); + try { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->ContainsKey( newListeners[i]) ) { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict[newListeners[i]] = cptr; + } + else { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->Add(newListeners[i], cptr); + } + } finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + ((native::ManagedCqStatusListenerGeneric*)cptr->get())->setptr(cqlg); + } + else { + auto cptr = gcnew native_shared_ptr<native::CqListener>(std::shared_ptr<native::ManagedCqListenerGeneric>(new native::ManagedCqListenerGeneric(newListeners[i]))); + vrr.push_back(cptr->get_shared_ptr()); + auto cqlg = gcnew CqListenerGeneric<TKey, TResult>(); + cqlg->AddCqListener(newListeners[i]); + try { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->ContainsKey( newListeners[i]) ) { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict[newListeners[i]] = cptr; + } + else { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->Add(newListeners[i], cptr); + } + } finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + ((native::ManagedCqListenerGeneric*)cptr->get())->setptr(cqlg); + } + } + + try + { + m_nativeptr->get()->initCqListeners( vrr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + Client::CqAttributes<TKey, TResult>^ CqAttributesFactory<TKey, TResult>::Create( ) + { + try + { + return Client::CqAttributes<TKey, TResult>::Create(m_nativeptr->get()->create()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqAttributesFactory.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqAttributesFactory.hpp b/clicache/src/CqAttributesFactory.hpp new file mode 100644 index 0000000..6fa5ab0 --- /dev/null +++ b/clicache/src/CqAttributesFactory.hpp @@ -0,0 +1,92 @@ +/* + * 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/CqAttributesFactory.hpp> +#include "end_native.hpp" + +#include "impl/SafeConvert.hpp" +#include "CqAttributes.hpp" +#include "native_unique_ptr.hpp" + +using namespace System; +using namespace System::Collections::Generic; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + generic<class TKey, class TResult> + interface class ICqListener; + + /// <summary> + /// Creates instances of <c>CqAttributes</c>. + /// </summary> + /// <seealso cref="CqAttributes" /> + generic<class TKey, class TResult> + public ref class CqAttributesFactory sealed + { + public: + + /// <summary> + /// Creates a new instance of <c>CqAttributesFactory</c> ready + /// to create a <c>CqAttributes</c> with default settings. + /// </summary> + inline CqAttributesFactory( ) + { + m_nativeptr = gcnew native_unique_ptr<native::CqAttributesFactory>(std::make_unique<native::CqAttributesFactory>()); + } + + inline CqAttributesFactory(Client::CqAttributes<TKey, TResult>^ cqAttributes ) + { + m_nativeptr = gcnew native_unique_ptr<native::CqAttributesFactory>(std::make_unique<native::CqAttributesFactory>(cqAttributes->GetNative())); + } + + // ATTRIBUTES + + /// <summary> + /// add a cqListener + /// </summary> + void AddCqListener(Client::ICqListener<TKey, TResult>^ cqListener); + + /// <summary> + /// Initialize with an array of listeners + /// </summary> + void InitCqListeners( array<Client::ICqListener<TKey, TResult>^>^ cqListeners ); + + // FACTORY METHOD + + /// <summary> + /// Creates a <c>CqAttributes</c> with the current settings. + /// </summary> + Client::CqAttributes<TKey, TResult>^ Create( ); + + private: + + native_unique_ptr<native::CqAttributesFactory>^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqAttributesMutator.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqAttributesMutator.cpp b/clicache/src/CqAttributesMutator.cpp new file mode 100644 index 0000000..d728746 --- /dev/null +++ b/clicache/src/CqAttributesMutator.cpp @@ -0,0 +1,196 @@ +/* + * 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 "begin_native.hpp" +#include <memory> +#include <geode/QueryService.hpp> +#include "end_native.hpp" + +#include "CqAttributesMutator.hpp" +#include "impl/ManagedCqListener.hpp" +#include "impl/ManagedCqStatusListener.hpp" + +using namespace System; + + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + generic<class TKey, class TResult> + void CqAttributesMutator<TKey, TResult>::AddCqListener( Client::ICqListener<TKey, TResult>^ cqListener ) + { + native_shared_ptr<native::CqListener>^ listenerptr; + if ( cqListener != nullptr ) { + if (auto cqStatusListener = dynamic_cast<ICqStatusListener<TKey, TResult>^>(cqListener)) { + auto sLstr = gcnew CqStatusListenerGeneric<TKey, TResult>(); + sLstr->AddCqListener(cqListener); + listenerptr = gcnew native_shared_ptr<native::CqListener>(std::shared_ptr<native::ManagedCqStatusListenerGeneric>(new native::ManagedCqStatusListenerGeneric(cqListener))); + try { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->ContainsKey(cqListener) ) { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict[cqListener] = listenerptr; + } + else { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->Add(cqListener, listenerptr); + } + } + finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + ((native::ManagedCqStatusListenerGeneric*)listenerptr->get())->setptr(sLstr); + } + else { + //TODO::split + auto cqlg = gcnew CqListenerGeneric<TKey, TResult>(); + cqlg->AddCqListener(cqListener); + listenerptr = gcnew native_shared_ptr<native::CqListener>(std::shared_ptr<native::ManagedCqListenerGeneric>(new native::ManagedCqListenerGeneric(cqListener))); + try { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->ContainsKey(cqListener) ) { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict[cqListener] = listenerptr; + } + else { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->Add(cqListener, listenerptr); + } + } finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + ((native::ManagedCqListenerGeneric*)listenerptr->get())->setptr(cqlg); + } + } + try + { + m_nativeptr->get()->addCqListener( listenerptr->get_shared_ptr() ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + void CqAttributesMutator<TKey, TResult>::RemoveCqListener( Client::ICqListener<TKey, TResult>^ cqListener ) + { + if (auto lister = dynamic_cast<Client::ICqStatusListener<TKey, TResult>^>(cqListener)) { + auto cqlg = gcnew CqStatusListenerGeneric<TKey, TResult>(); + cqlg->AddCqListener(cqListener); + native::CqStatusListenerPtr lptr = std::shared_ptr<native::ManagedCqStatusListenerGeneric>( + new native::ManagedCqStatusListenerGeneric(lister)); + ((native::ManagedCqStatusListenerGeneric*)lptr.get())->setptr(cqlg); + try { + native_shared_ptr<native::CqListener>^ value; + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->TryGetValue(cqListener, value) ) { + try + { + m_nativeptr->get()->removeCqListener(value->get_shared_ptr()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + } finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + } + else { + auto cqlg = gcnew CqListenerGeneric<TKey, TResult>(); + cqlg->AddCqListener(cqListener); + native::CqListenerPtr lptr = std::shared_ptr<native::ManagedCqListenerGeneric>( + new native::ManagedCqListenerGeneric(cqListener)); + ((native::ManagedCqListenerGeneric*)lptr.get())->setptr(cqlg); + try { + native_shared_ptr<native::CqListener>^ value; + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->TryGetValue(cqListener, value) ) { + try + { + m_nativeptr->get()->removeCqListener(value->get_shared_ptr()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + } finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + } + } + + generic<class TKey, class TResult> + void CqAttributesMutator<TKey, TResult>::SetCqListeners(array<Client::ICqListener<TKey, TResult>^>^ newListeners) + { + native::CqAttributes::listener_container_type vrr; + for( int i = 0; i < newListeners->Length; i++ ) + { + if (auto lister = dynamic_cast<Client::ICqStatusListener<TKey, TResult>^>(newListeners[i])) { + auto cptr = gcnew native_shared_ptr<native::CqListener>(std::shared_ptr<native::ManagedCqStatusListenerGeneric>(new native::ManagedCqStatusListenerGeneric(lister))); + vrr.push_back(cptr->get_shared_ptr()); + auto cqlg = gcnew CqStatusListenerGeneric<TKey, TResult>(); + cqlg->AddCqListener(newListeners[i]); + try { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->ContainsKey( newListeners[i]) ) { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict[newListeners[i]] = cptr; + } + else { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->Add(newListeners[i], cptr); + } + } finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + ((native::ManagedCqStatusListenerGeneric*)cptr->get())->setptr(cqlg); + } + else { + auto cptr = gcnew native_shared_ptr<native::CqListener>(std::shared_ptr<native::ManagedCqListenerGeneric>(new native::ManagedCqListenerGeneric(newListeners[i]))); + vrr.push_back(cptr->get_shared_ptr()); + auto cqlg = gcnew CqListenerGeneric<TKey, TResult>(); + cqlg->AddCqListener(newListeners[i]); + try { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->AcquireWriterLock(-1); + if ( CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->ContainsKey( newListeners[i]) ) { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict[newListeners[i]] = cptr; + } + else { + CqListenerHelper<TKey, TResult>::m_ManagedVsUnManagedCqLstrDict->Add(newListeners[i], cptr); + } + } finally { + CqListenerHelper<TKey, TResult>::g_readerWriterLock->ReleaseWriterLock(); + } + ((native::ManagedCqListenerGeneric*)cptr->get())->setptr(cqlg); + } + } + + try + { + m_nativeptr->get()->setCqListeners( vrr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqAttributesMutator.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqAttributesMutator.hpp b/clicache/src/CqAttributesMutator.hpp new file mode 100644 index 0000000..7e04b65 --- /dev/null +++ b/clicache/src/CqAttributesMutator.hpp @@ -0,0 +1,117 @@ +/* + * 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/CqAttributesMutator.hpp> +#include "end_native.hpp" + + +#include "native_shared_ptr.hpp" + + +using namespace System; +using namespace System::Collections::Generic; +using namespace System::Threading; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + generic<class TKey, class TResult> + interface class ICqListener; + + generic<class TKey, class TResult> + private ref class CqListenerHelper sealed{ + public: + static Dictionary<Client::ICqListener<TKey, TResult>^, native_shared_ptr<native::CqListener>^>^ + m_ManagedVsUnManagedCqLstrDict = gcnew + Dictionary<Client::ICqListener<TKey, TResult>^, native_shared_ptr<native::CqListener>^>(); + + static ReaderWriterLock^ g_readerWriterLock = gcnew ReaderWriterLock(); + }; + + /// <summary> + /// Supports modification of certain cq attributes after the cq + /// has been created. + /// </summary> + generic<class TKey, class TResult> + public ref class CqAttributesMutator sealed + { + public: + + /// <summary> + /// Adds the CqListener for the cq. + /// </summary> + /// <param name="cqListener"> + /// user-defined cq listener, or null for no cache listener + /// </param> + void AddCqListener( Client::ICqListener<TKey, TResult>^ cqListener ); + + /// <summary> + /// Remove a CqListener for the cq. + /// </summary> + + void RemoveCqListener(Client::ICqListener<TKey, TResult>^ aListener); + + + /// <summary> + /// Initialize with an array of listeners + /// </summary> + + void SetCqListeners(array<Client::ICqListener<TKey, TResult>^>^ newListeners); + + + 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 Client::CqAttributesMutator<TKey, TResult>^ Create( native::CqAttributesMutatorPtr nativeptr ) + { + return __nullptr == nativeptr ? nullptr : + gcnew Client::CqAttributesMutator<TKey, TResult>( nativeptr ); + } + + + private: + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CqAttributesMutator<TKey, TResult>( native::CqAttributesMutatorPtr nativeptr ) + { + m_nativeptr = gcnew native_shared_ptr<native::CqAttributesMutator>(nativeptr); + } + + native_shared_ptr<native::CqAttributesMutator>^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqEvent.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqEvent.cpp b/clicache/src/CqEvent.cpp new file mode 100644 index 0000000..ae1c668 --- /dev/null +++ b/clicache/src/CqEvent.cpp @@ -0,0 +1,75 @@ +/* + * 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 "CqEvent.hpp" +#include "Log.hpp" +#include "impl/SafeConvert.hpp" +#include "CacheableBuiltins.hpp" +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + generic<class TKey, class TResult> + CqQuery<TKey, TResult>^ CqEvent<TKey, TResult>::getCq( ) + { + native::CqQueryPtr& cQueryptr( m_nativeptr->getCq( ) ); + return CqQuery<TKey, TResult>::Create( cQueryptr); + } + + generic<class TKey, class TResult> + CqOperationType CqEvent<TKey, TResult>::getBaseOperation( ) + { + return CqOperation::ConvertFromNative(m_nativeptr->getBaseOperation()); + } + + generic<class TKey, class TResult> + CqOperationType CqEvent<TKey, TResult>::getQueryOperation( ) + { + return CqOperation::ConvertFromNative(m_nativeptr->getQueryOperation()); + } + + generic<class TKey, class TResult> + TKey CqEvent<TKey, TResult>::getKey( ) + { + native::CacheableKeyPtr& keyptr( m_nativeptr->getKey( ) ); + return Serializable::GetManagedValueGeneric<TKey>(keyptr); + } + + generic<class TKey, class TResult> + TResult CqEvent<TKey, TResult>::getNewValue( ) + { + native::CacheablePtr& valptr( m_nativeptr->getNewValue( ) ); + return Serializable::GetManagedValueGeneric<TResult>(valptr); + } + + generic<class TKey, class TResult> + array< Byte >^ CqEvent<TKey, TResult>::getDeltaValue( ) + { + auto deltaBytes = m_nativeptr->getDeltaValue( ); + auto managedDeltaBytes = ( CacheableBytes^ ) CacheableBytes::Create( deltaBytes ); + return ( array< Byte >^ ) managedDeltaBytes; + } + } // namespace Client + } // namespace Geode +} //namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqEvent.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqEvent.hpp b/clicache/src/CqEvent.hpp new file mode 100644 index 0000000..d0ddcc1 --- /dev/null +++ b/clicache/src/CqEvent.hpp @@ -0,0 +1,105 @@ +/* + * 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 "native_shared_ptr.hpp" +#include "geode_defs.hpp" +#include "begin_native.hpp" +#include <geode/CqEvent.hpp> +#include "end_native.hpp" + +#include "CqQuery.hpp" +#include "CqOperation.hpp" + +#include "ICqEvent.hpp" +#include "ICacheableKey.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + interface class IGeodeSerializable; + + /// <summary> + /// This class encapsulates events that occur for cq. + /// </summary> + generic<class TKey, class TResult> + public ref class CqEvent sealed + { + public: + + + /// <summary> + /// Return the cqquery this event occurred in. + /// </summary> + CqQuery<TKey, TResult>^ getCq(); + + /// <summary> + /// Get the operation on the base operation that triggered this event. + /// </summary> + CqOperationType getBaseOperation(); + + /// <summary> + /// Get the operation on the query operation that triggered this event. + /// </summary> + CqOperationType getQueryOperation(); + + /// <summary> + /// Get the key relating to the event. + /// In case of REGION_CLEAR and REGION_INVALIDATE operation, the key will be null. + /// </summary> + TKey /*Generic::ICacheableKey^*/ getKey( ); + + /// <summary> + /// Get the new value of the modification. + /// If there is no new value returns null, this will happen during delete + /// operation. + /// </summary> + /*Object^*/ TResult getNewValue( ); + + array< Byte >^ getDeltaValue( ); + + internal: + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CqEvent( const native::CqEvent* nativeptr ) + : m_nativeptr(nativeptr) + { + } + + const native::CqEvent* GetNative() + { + return m_nativeptr; + } + + private: + const native::CqEvent* m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqOperation.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqOperation.hpp b/clicache/src/CqOperation.hpp new file mode 100644 index 0000000..e6292c9 --- /dev/null +++ b/clicache/src/CqOperation.hpp @@ -0,0 +1,96 @@ +/* + * 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/CqOperation.hpp> +#include "end_native.hpp" + + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + /// <summary> + /// Enumerated type for CqOperationType + /// </summary> + public enum class CqOperationType + { + OP_TYPE_INVALID = -1, + OP_TYPE_CREATE = 0, + OP_TYPE_UPDATE = 2, + OP_TYPE_INVALIDATE = 4, + OP_TYPE_REGION_CLEAR = 8, + OP_TYPE_DESTROY = 16, + OP_TYPE_MARKER = 32 + }; + + public ref class CqOperation sealed + { + public: + + /// <summary> + /// conenience function for convertin from c++ + /// native::CqOperation::CqOperationType to + /// CqOperationType here. + /// </summary> + inline static CqOperationType ConvertFromNative(native::CqOperation::CqOperationType tp) + { + if(tp==native::CqOperation::OP_TYPE_CREATE) + return CqOperationType::OP_TYPE_CREATE; + if(tp==native::CqOperation::OP_TYPE_UPDATE) + return CqOperationType::OP_TYPE_UPDATE; + if(tp==native::CqOperation::OP_TYPE_INVALIDATE) + return CqOperationType::OP_TYPE_INVALIDATE; + if(tp==native::CqOperation::OP_TYPE_REGION_CLEAR) + return CqOperationType::OP_TYPE_REGION_CLEAR; + if(tp==native::CqOperation::OP_TYPE_DESTROY) + return CqOperationType::OP_TYPE_DESTROY; + if(tp==native::CqOperation::OP_TYPE_MARKER) + return CqOperationType::OP_TYPE_MARKER; + return CqOperationType::OP_TYPE_INVALID; + } + internal: + + /// <summary> + /// Internal constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CqOperation( native::CqOperation* nativeptr ) + : m_nativeptr(nativeptr) + { + } + + private: + const native::CqOperation* m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CqQuery.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CqQuery.cpp b/clicache/src/CqQuery.cpp new file mode 100644 index 0000000..25c93d9 --- /dev/null +++ b/clicache/src/CqQuery.cpp @@ -0,0 +1,286 @@ +/* + * 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 "CqQuery.hpp" +#include "Query.hpp" +#include "CqAttributes.hpp" +#include "CqAttributesMutator.hpp" +#include "CqStatistics.hpp" +#include "ISelectResults.hpp" +#include "ResultSet.hpp" +#include "StructSet.hpp" +#include "ExceptionTypes.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + generic<class TKey, class TResult> + ICqResults<TResult>^ CqQuery<TKey, TResult>::ExecuteWithInitialResults() + { + return ExecuteWithInitialResults(DEFAULT_QUERY_RESPONSE_TIMEOUT); + } + + generic<class TKey, class TResult> + ICqResults<TResult>^ CqQuery<TKey, TResult>::ExecuteWithInitialResults(System::UInt32 timeout) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + try + { + auto nativeptr = m_nativeptr->get()->executeWithInitialResults(timeout); + + if (auto structptr = std::dynamic_pointer_cast<native::StructSet>(nativeptr)) + { + return StructSet<TResult>::Create(structptr); + } + + return nullptr; + } + finally + { + GC::KeepAlive(m_nativeptr); + } + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + + generic<class TKey, class TResult> + void CqQuery<TKey, TResult>::Execute() + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->execute(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + + generic<class TKey, class TResult> + String^ CqQuery<TKey, TResult>::QueryString::get( ) + { + try + { + return ManagedString::Get( m_nativeptr->get()->getQueryString( ) ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + String^ CqQuery<TKey, TResult>::Name::get( ) + { + try + { + return ManagedString::Get( m_nativeptr->get()->getName( ) ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + Query<TResult>^ CqQuery<TKey, TResult>::GetQuery( ) + { + try + { + return Query<TResult>::Create(m_nativeptr->get()->getQuery()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + CqAttributes<TKey, TResult>^ CqQuery<TKey, TResult>::GetCqAttributes( ) + { + try + { + return CqAttributes<TKey, TResult>::Create(m_nativeptr->get()->getCqAttributes( )); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + CqAttributesMutator<TKey, TResult>^ CqQuery<TKey, TResult>::GetCqAttributesMutator( ) + { + try + { + return CqAttributesMutator<TKey, TResult>::Create(m_nativeptr->get()->getCqAttributesMutator()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + CqStatistics^ CqQuery<TKey, TResult>::GetStatistics( ) + { + try + { + return CqStatistics::Create(m_nativeptr->get()->getStatistics()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + CqStateType CqQuery<TKey, TResult>::GetState( ) + { + try + { + auto st = m_nativeptr->get()->getState(); + CqStateType state; + switch (st) + { + case native::CqState::STOPPED: { + state = CqStateType::STOPPED; + break; + } + case native::CqState::RUNNING: { + state = CqStateType::RUNNING; + break; + } + case native::CqState::CLOSED: { + state = CqStateType::CLOSED; + break; + } + case native::CqState::CLOSING: { + state = CqStateType::CLOSING; + break; + } + default: { + state = CqStateType::INVALID; + break; + } + } + return state; + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic<class TKey, class TResult> + void CqQuery<TKey, TResult>::Stop( ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->stop( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + + generic<class TKey, class TResult> + void CqQuery<TKey, TResult>::Close( ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + m_nativeptr->get()->close( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + + generic<class TKey, class TResult> + bool CqQuery<TKey, TResult>::IsRunning( ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + return m_nativeptr->get()->isRunning( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + + generic<class TKey, class TResult> + bool CqQuery<TKey, TResult>::IsStopped( ) + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + return m_nativeptr->get()->isStopped( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + + generic<class TKey, class TResult> + bool CqQuery<TKey, TResult>::IsClosed() + { + _GF_MG_EXCEPTION_TRY2/* due to auto replace */ + + try + { + return m_nativeptr->get()->isClosed(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ + } + } // namespace Client + } // namespace Geode +} // namespace Apache