http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCacheableKey.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCacheableKey.hpp b/src/clicache/src/impl/ManagedCacheableKey.hpp index f9c35f0..33ea461 100644 --- a/src/clicache/src/impl/ManagedCacheableKey.hpp +++ b/src/clicache/src/impl/ManagedCacheableKey.hpp @@ -37,135 +37,141 @@ using namespace System; //} //} -namespace gemfire +namespace apache { - - /// <summary> - /// Wraps the managed <see cref="GemStone.GemFire.Cache.IGFSerializable" /> - /// object and implements the native <c>gemfire::CacheableKey</c> interface. - /// </summary> - class ManagedCacheableKeyGeneric - : public gemfire::CacheableKey + namespace geode { - private : - int m_hashcode; - int m_classId; - int m_objectSize; - public: - - inline ManagedCacheableKeyGeneric( - GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr, int hashcode, int classId ) - : m_managedptr( managedptr ) { - m_hashcode = hashcode; - m_classId = classId; - m_objectSize = 0; - } - /// <summary> - /// Constructor to initialize with the provided managed object. - /// </summary> - /// <param name="managedptr"> - /// The managed object. - /// </param> - inline ManagedCacheableKeyGeneric( GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr ) - : m_managedptr( managedptr ) { - // m_hashcode = managedptr->GetHashCode(); - m_hashcode = 0; - m_classId = managedptr->ClassId; - m_objectSize = 0; - } - - /// <summary> - /// serialize this object - /// </summary> - virtual void toData( gemfire::DataOutput& output ) const; - - /// <summary> - /// deserialize this object, typical implementation should return - /// the 'this' pointer. - /// </summary> - virtual gemfire::Serializable* fromData( gemfire::DataInput& input ); - - - /// <summary> - /// return the size of this object in bytes - /// </summary> - virtual uint32_t objectSize() const; - - /// <summary> - /// return the classId of the instance being serialized. - /// This is used by deserialization to determine what instance - /// type to create and deserialize into. - /// </summary> - virtual int32_t classId( ) const; - - /// <summary> - /// return the typeId of the instance being serialized. - /// This is used by deserialization to determine what instance - /// type to create and deserialize into. - /// </summary> - virtual int8_t typeId( ) const; - - /// <summary> - /// return the Data Serialization Fixed ID type. - /// This is used to determine what instance type to create - /// and deserialize into. - /// - /// Note that this should not be overridden by custom implementations - /// and is reserved only for builtin types. - /// </summary> - virtual int8_t DSFID() const; - - /// <summary> - /// Display this object as 'string', which depends on the implementation in - /// the managed class - /// </summary> - virtual gemfire::CacheableStringPtr toString( ) const; - - /// <summary> - /// return true if this key matches other CacheableKey - /// </summary> - virtual bool operator == ( const CacheableKey& other ) const; - /// <summary> - /// return true if this key matches other ManagedCacheableKey - /// </summary> - virtual bool operator == ( const ManagedCacheableKeyGeneric& other ) const; - - /// <summary> - /// return the hashcode for this key. - /// </summary> - virtual uint32_t hashcode( ) const; - - /// <summary> - /// Copy the string form of a key into a char* buffer for logging purposes. - /// implementations should only generate a string as long as maxLength chars, - /// and return the number of chars written. buffer is expected to be large - /// enough to hold at least maxLength chars. - /// The default implementation renders the classname and instance address. - /// </summary> - virtual size_t logString( char* buffer, size_t maxLength ) const; - - /// <summary> - /// Returns the wrapped managed object reference. - /// </summary> - inline GemStone::GemFire::Cache::Generic::IGFSerializable^ ptr( ) const + namespace client { - return m_managedptr; - } - - - private: - - /// <summary> - /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). - /// Note: not using auto_gcroot since it will result in 'Dispose' of the IGFSerializable - /// to be called which is not what is desired when this object is destroyed. Normally this - /// managed object may be created by the user and will be handled automatically by the GC. - /// </summary> - gcroot<GemStone::GemFire::Cache::Generic::IGFSerializable^> m_managedptr; - - // Disable the copy and assignment constructors - ManagedCacheableKeyGeneric( const ManagedCacheableKeyGeneric& ); - ManagedCacheableKeyGeneric& operator = ( const ManagedCacheableKeyGeneric& ); - }; -} + /// <summary> + /// Wraps the managed <see cref="GemStone.GemFire.Cache.IGFSerializable" /> + /// object and implements the native <c>apache::geode::client::CacheableKey</c> interface. + /// </summary> + class ManagedCacheableKeyGeneric + : public apache::geode::client::CacheableKey + { + private: + int m_hashcode; + int m_classId; + int m_objectSize; + public: + + inline ManagedCacheableKeyGeneric( + GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr, int hashcode, int classId) + : m_managedptr(managedptr) { + m_hashcode = hashcode; + m_classId = classId; + m_objectSize = 0; + } + /// <summary> + /// Constructor to initialize with the provided managed object. + /// </summary> + /// <param name="managedptr"> + /// The managed object. + /// </param> + inline ManagedCacheableKeyGeneric(GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr) + : m_managedptr(managedptr) { + // m_hashcode = managedptr->GetHashCode(); + m_hashcode = 0; + m_classId = managedptr->ClassId; + m_objectSize = 0; + } + + /// <summary> + /// serialize this object + /// </summary> + virtual void toData(apache::geode::client::DataOutput& output) const; + + /// <summary> + /// deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + virtual apache::geode::client::Serializable* fromData(apache::geode::client::DataInput& input); + + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual uint32_t objectSize() const; + + /// <summary> + /// return the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + virtual int32_t classId() const; + + /// <summary> + /// return the typeId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + virtual int8_t typeId() const; + + /// <summary> + /// return the Data Serialization Fixed ID type. + /// This is used to determine what instance type to create + /// and deserialize into. + /// + /// Note that this should not be overridden by custom implementations + /// and is reserved only for builtin types. + /// </summary> + virtual int8_t DSFID() const; + + /// <summary> + /// Display this object as 'string', which depends on the implementation in + /// the managed class + /// </summary> + virtual apache::geode::client::CacheableStringPtr toString() const; + + /// <summary> + /// return true if this key matches other CacheableKey + /// </summary> + virtual bool operator == (const CacheableKey& other) const; + /// <summary> + /// return true if this key matches other ManagedCacheableKey + /// </summary> + virtual bool operator == (const ManagedCacheableKeyGeneric& other) const; + + /// <summary> + /// return the hashcode for this key. + /// </summary> + virtual uint32_t hashcode() const; + + /// <summary> + /// Copy the string form of a key into a char* buffer for logging purposes. + /// implementations should only generate a string as long as maxLength chars, + /// and return the number of chars written. buffer is expected to be large + /// enough to hold at least maxLength chars. + /// The default implementation renders the classname and instance address. + /// </summary> + virtual size_t logString(char* buffer, size_t maxLength) const; + + /// <summary> + /// Returns the wrapped managed object reference. + /// </summary> + inline GemStone::GemFire::Cache::Generic::IGFSerializable^ ptr() const + { + return m_managedptr; + } + + + private: + + /// <summary> + /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). + /// Note: not using auto_gcroot since it will result in 'Dispose' of the IGFSerializable + /// to be called which is not what is desired when this object is destroyed. Normally this + /// managed object may be created by the user and will be handled automatically by the GC. + /// </summary> + gcroot<GemStone::GemFire::Cache::Generic::IGFSerializable^> m_managedptr; + + // Disable the copy and assignment constructors + ManagedCacheableKeyGeneric(const ManagedCacheableKeyGeneric&); + ManagedCacheableKeyGeneric& operator = (const ManagedCacheableKeyGeneric&); + }; + + } // namespace client + } // namespace geode +} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCacheableKeyBytes.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCacheableKeyBytes.cpp b/src/clicache/src/impl/ManagedCacheableKeyBytes.cpp index 4d58eff..3343b7b 100644 --- a/src/clicache/src/impl/ManagedCacheableKeyBytes.cpp +++ b/src/clicache/src/impl/ManagedCacheableKeyBytes.cpp @@ -28,251 +28,257 @@ using namespace System; -namespace gemfire +namespace apache { - void ManagedCacheableKeyBytesGeneric::toData( gemfire::DataOutput& output ) const + namespace geode { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::toData: current domain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its domain ID: " + m_domainId ); - try { - //TODO: I think this should work as it is - output.writeBytesOnly(m_bytes, m_size); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - } + namespace client + { + void ManagedCacheableKeyBytesGeneric::toData(apache::geode::client::DataOutput& output) const + { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::toData: current domain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its domain ID: " + m_domainId); + try { + //TODO: I think this should work as it is + output.writeBytesOnly(m_bytes, m_size); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + } - gemfire::Serializable* ManagedCacheableKeyBytesGeneric::fromData( gemfire::DataInput& input ) - { - try { - - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::fromData: classid " + m_classId + "aid = " + + System::Threading::Thread::GetDomainID() ); - GemStone::GemFire::Cache::Generic::DataInput mg_input( &input, true ); - const uint8_t* objStartPos = input.currentBufferPosition(); - - GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); - obj->FromData(%mg_input); - - input.advanceCursor(mg_input.BytesReadInternally); + apache::geode::client::Serializable* ManagedCacheableKeyBytesGeneric::fromData(apache::geode::client::DataInput& input) + { + try { - m_hashCode = obj->GetHashCode(); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::fromData: classid " + m_classId + "aid = " + +System::Threading::Thread::GetDomainID()); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&input, true); + const uint8_t* objStartPos = input.currentBufferPosition(); - const uint8_t* objEndPos = input.currentBufferPosition(); - - //m_size = mg_input.BytesRead; - m_size = (uint32_t)(objEndPos - objStartPos); - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::fromData: objectSize = " + m_size + " m_hashCode = " + m_hashCode); - m_bytes = input.getBufferCopyFrom(objStartPos, m_size); - - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return this; - } + GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); + obj->FromData(%mg_input); - uint32_t ManagedCacheableKeyBytesGeneric::objectSize( ) const - { - try { - //return m_managedptr->ObjectSize; - return m_size; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } + input.advanceCursor(mg_input.BytesReadInternally); - int32_t ManagedCacheableKeyBytesGeneric::classId() const - { - uint32_t classId; - try { - //classId = m_managedptr->ClassId; - classId = m_classId; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return (classId >= 0x80000000 ? 0 : classId); - } + m_hashCode = obj->GetHashCode(); - int8_t ManagedCacheableKeyBytesGeneric::typeId() const - { - try { - //uint32_t classId = m_managedptr->ClassId; - uint32_t classId = m_classId; - if (classId >= 0x80000000) { - return (int8_t)((classId - 0x80000000) % 0x20000000); + const uint8_t* objEndPos = input.currentBufferPosition(); + + //m_size = mg_input.BytesRead; + m_size = (uint32_t)(objEndPos - objStartPos); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::fromData: objectSize = " + m_size + " m_hashCode = " + m_hashCode); + m_bytes = input.getBufferCopyFrom(objStartPos, m_size); + + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return this; } - else if (classId <= 0x7F) { - return (int8_t)gemfire::GemfireTypeIdsImpl::CacheableUserData; + + uint32_t ManagedCacheableKeyBytesGeneric::objectSize() const + { + try { + //return m_managedptr->ObjectSize; + return m_size; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; } - else if (classId <= 0x7FFF) { - return (int8_t)gemfire::GemfireTypeIdsImpl::CacheableUserData2; + + int32_t ManagedCacheableKeyBytesGeneric::classId() const + { + uint32_t classId; + try { + //classId = m_managedptr->ClassId; + classId = m_classId; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return (classId >= 0x80000000 ? 0 : classId); } - else { - return (int8_t)gemfire::GemfireTypeIdsImpl::CacheableUserData4; + + int8_t ManagedCacheableKeyBytesGeneric::typeId() const + { + try { + //uint32_t classId = m_managedptr->ClassId; + uint32_t classId = m_classId; + if (classId >= 0x80000000) { + return (int8_t)((classId - 0x80000000) % 0x20000000); + } + else if (classId <= 0x7F) { + return (int8_t)apache::geode::client::GemfireTypeIdsImpl::CacheableUserData; + } + else if (classId <= 0x7FFF) { + return (int8_t)apache::geode::client::GemfireTypeIdsImpl::CacheableUserData2; + } + else { + return (int8_t)apache::geode::client::GemfireTypeIdsImpl::CacheableUserData4; + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } - int8_t ManagedCacheableKeyBytesGeneric::DSFID() const - { - // convention that [0x8000000, 0xa0000000) is for FixedIDDefault, - // [0xa000000, 0xc0000000) is for FixedIDByte, - // [0xc0000000, 0xe0000000) is for FixedIDShort - // and [0xe0000000, 0xffffffff] is for FixedIDInt - // Note: depends on fact that FixedIDByte is 1, FixedIDShort is 2 - // and FixedIDInt is 3; if this changes then correct this accordingly - //uint32_t classId = m_managedptr->ClassId; - uint32_t classId = m_classId; - if (classId >= 0x80000000) { - return (int8_t)((classId - 0x80000000) / 0x20000000); - } - return 0; - } + int8_t ManagedCacheableKeyBytesGeneric::DSFID() const + { + // convention that [0x8000000, 0xa0000000) is for FixedIDDefault, + // [0xa000000, 0xc0000000) is for FixedIDByte, + // [0xc0000000, 0xe0000000) is for FixedIDShort + // and [0xe0000000, 0xffffffff] is for FixedIDInt + // Note: depends on fact that FixedIDByte is 1, FixedIDShort is 2 + // and FixedIDInt is 3; if this changes then correct this accordingly + //uint32_t classId = m_managedptr->ClassId; + uint32_t classId = m_classId; + if (classId >= 0x80000000) { + return (int8_t)((classId - 0x80000000) / 0x20000000); + } + return 0; + } - gemfire::CacheableStringPtr ManagedCacheableKeyBytesGeneric::toString( ) const - { - try { - GemStone::GemFire::Cache::Generic::IGFSerializable^ manageObject = getManagedObject(); - if(manageObject != nullptr) + apache::geode::client::CacheableStringPtr ManagedCacheableKeyBytesGeneric::toString() const { - gemfire::CacheableStringPtr cStr; - GemStone::GemFire::Cache::Generic::CacheableString::GetCacheableString( - manageObject->ToString(), cStr ); - return cStr; + try { + GemStone::GemFire::Cache::Generic::IGFSerializable^ manageObject = getManagedObject(); + if (manageObject != nullptr) + { + apache::geode::client::CacheableStringPtr cStr; + GemStone::GemFire::Cache::Generic::CacheableString::GetCacheableString( + manageObject->ToString(), cStr); + return cStr; + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return NULLPTR; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return NULLPTR; - } - bool ManagedCacheableKeyBytesGeneric::operator ==(const gemfire::CacheableKey& other) const - { - try { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal"); - // now checking classId(), typeId(), DSFID() etc. will be much more - // expensive than just a dynamic_cast - const ManagedCacheableKeyBytesGeneric* p_other = - dynamic_cast<const ManagedCacheableKeyBytesGeneric*>(&other); - if (p_other != NULL) { - gemfire::DataInput di(m_bytes, m_size); - GemStone::GemFire::Cache::Generic::DataInput mg_input(&di, true); - GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = - GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); - obj->FromData(%mg_input); - bool ret = obj->Equals(p_other->ptr()); - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal return VAL = " + ret); - return ret; + bool ManagedCacheableKeyBytesGeneric::operator ==(const apache::geode::client::CacheableKey& other) const + { + try { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal"); + // now checking classId(), typeId(), DSFID() etc. will be much more + // expensive than just a dynamic_cast + const ManagedCacheableKeyBytesGeneric* p_other = + dynamic_cast<const ManagedCacheableKeyBytesGeneric*>(&other); + if (p_other != NULL) { + apache::geode::client::DataInput di(m_bytes, m_size); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&di, true); + GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = + GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); + obj->FromData(%mg_input); + bool ret = obj->Equals(p_other->ptr()); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal return VAL = " + ret); + return ret; + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal returns false"); + return false; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal returns false"); - return false; - } - bool ManagedCacheableKeyBytesGeneric::operator ==(const ManagedCacheableKeyBytesGeneric& other) const - { - try { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal. "); - gemfire::DataInput di(m_bytes, m_size); - GemStone::GemFire::Cache::Generic::DataInput mg_input(&di, true); - GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = - GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); - obj->FromData(%mg_input); - bool ret = obj->Equals(other.ptr()); - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal return VAL = " + ret); - return ret; - //return obj->Equals(other.ptr()); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal return false"); - return false; - } + bool ManagedCacheableKeyBytesGeneric::operator ==(const ManagedCacheableKeyBytesGeneric& other) const + { + try { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal. "); + apache::geode::client::DataInput di(m_bytes, m_size); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&di, true); + GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = + GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); + obj->FromData(%mg_input); + bool ret = obj->Equals(other.ptr()); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal return VAL = " + ret); + return ret; + //return obj->Equals(other.ptr()); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::equal return false"); + return false; + } - uint32_t ManagedCacheableKeyBytesGeneric::hashcode( ) const - { - return m_hashCode; - } + uint32_t ManagedCacheableKeyBytesGeneric::hashcode() const + { + return m_hashCode; + } - size_t ManagedCacheableKeyBytesGeneric::logString( char* buffer, size_t maxLength ) const - { - try { - GemStone::GemFire::Cache::Generic::IGFSerializable^ manageObject = getManagedObject(); - if(manageObject != nullptr) + size_t ManagedCacheableKeyBytesGeneric::logString(char* buffer, size_t maxLength) const { - if ( maxLength > 0 ) { - String^ logstr = manageObject->GetType( )->Name + '(' + - manageObject->ToString( ) + ')'; - GemStone::GemFire::Cache::Generic::ManagedString mg_str( logstr ); - return snprintf( buffer, maxLength, "%s", mg_str.CharPtr ); + try { + GemStone::GemFire::Cache::Generic::IGFSerializable^ manageObject = getManagedObject(); + if (manageObject != nullptr) + { + if (maxLength > 0) { + String^ logstr = manageObject->GetType()->Name + '(' + + manageObject->ToString() + ')'; + GemStone::GemFire::Cache::Generic::ManagedString mg_str(logstr); + return snprintf(buffer, maxLength, "%s", mg_str.CharPtr); + } + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); } + return 0; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } - GemStone::GemFire::Cache::Generic::IGFSerializable^ - ManagedCacheableKeyBytesGeneric::getManagedObject() const - { + GemStone::GemFire::Cache::Generic::IGFSerializable^ + ManagedCacheableKeyBytesGeneric::getManagedObject() const + { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::getManagedObject " + m_size); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::getManagedObject " + m_size); - //System::Text::StringBuilder^ sb = gcnew System::Text::StringBuilder(2000); - //for(uint32_t i = 0; i<m_size; i++) - //{ - // if(m_bytes[i] != 0) - // sb->Append(System::Convert::ToChar( m_bytes[i])); - // //sb->Append(' '); - //} + //System::Text::StringBuilder^ sb = gcnew System::Text::StringBuilder(2000); + //for(uint32_t i = 0; i<m_size; i++) + //{ + // if(m_bytes[i] != 0) + // sb->Append(System::Convert::ToChar( m_bytes[i])); + // //sb->Append(' '); + //} - // GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::getManagedObject " + sb); - gemfire::DataInput dinp(m_bytes, m_size); - GemStone::GemFire::Cache::Generic::DataInput mg_dinp(&dinp, true); - GemStone::GemFire::Cache::Generic::TypeFactoryMethodGeneric^ creationMethod = - GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId); - GemStone::GemFire::Cache::Generic::IGFSerializable^ newObj = creationMethod(); - return newObj->FromData(%mg_dinp); - } -} + // GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyBytesGeneric::getManagedObject " + sb); + apache::geode::client::DataInput dinp(m_bytes, m_size); + GemStone::GemFire::Cache::Generic::DataInput mg_dinp(&dinp, true); + GemStone::GemFire::Cache::Generic::TypeFactoryMethodGeneric^ creationMethod = + GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId); + GemStone::GemFire::Cache::Generic::IGFSerializable^ newObj = creationMethod(); + return newObj->FromData(%mg_dinp); + } + } // namespace client + } // namespace geode +} // namespace apache http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCacheableKeyBytes.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCacheableKeyBytes.hpp b/src/clicache/src/impl/ManagedCacheableKeyBytes.hpp index 2333b10..9ef60cb 100644 --- a/src/clicache/src/impl/ManagedCacheableKeyBytes.hpp +++ b/src/clicache/src/impl/ManagedCacheableKeyBytes.hpp @@ -38,160 +38,166 @@ namespace GemStone } } -namespace gemfire +namespace apache { - - /// <summary> - /// Wraps the managed <see cref="GemStone.GemFire.Cache.IGFSerializable" /> - /// object and implements the native <c>gemfire::CacheableKey</c> interface. - /// </summary> - class ManagedCacheableKeyBytesGeneric - : public gemfire::CacheableKey + namespace geode { - public: - - /// <summary> - /// Constructor to initialize with the provided managed object. - /// </summary> - /// <param name="managedptr"> - /// The managed object. - /// </param> - inline ManagedCacheableKeyBytesGeneric( - GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr, bool storeBytes ) - : m_domainId(System::Threading::Thread::GetDomainID()), - m_classId(managedptr->ClassId), - m_bytes(NULL), - m_size(0), - m_hashCode(0) + namespace client { - if(managedptr != nullptr) + + /// <summary> + /// Wraps the managed <see cref="GemStone.GemFire.Cache.IGFSerializable" /> + /// object and implements the native <c>apache::geode::client::CacheableKey</c> interface. + /// </summary> + class ManagedCacheableKeyBytesGeneric + : public apache::geode::client::CacheableKey { - if(storeBytes)//if value is from app + public: + + /// <summary> + /// Constructor to initialize with the provided managed object. + /// </summary> + /// <param name="managedptr"> + /// The managed object. + /// </param> + inline ManagedCacheableKeyBytesGeneric( + GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr, bool storeBytes) + : m_domainId(System::Threading::Thread::GetDomainID()), + m_classId(managedptr->ClassId), + m_bytes(NULL), + m_size(0), + m_hashCode(0) { - gemfire::DataOutput dataOut; - GemStone::GemFire::Cache::Generic::DataOutput mg_output( &dataOut, true); - managedptr->ToData( %mg_output ); - - //move cursor - //dataOut.advanceCursor(mg_output.BufferLength); - mg_output.WriteBytesToUMDataOutput(); - - m_bytes = dataOut.getBufferCopy(); - m_size = dataOut.getBufferLength(); - - m_hashCode = managedptr->GetHashCode(); - GemStone::GemFire::Cache::Generic::Log::Fine( - "ManagedCacheableKeyBytes::Constructor objectSize = " + m_size + " m_hashCode = " + m_hashCode); + if (managedptr != nullptr) + { + if (storeBytes)//if value is from app + { + apache::geode::client::DataOutput dataOut; + GemStone::GemFire::Cache::Generic::DataOutput mg_output(&dataOut, true); + managedptr->ToData(%mg_output); + + //move cursor + //dataOut.advanceCursor(mg_output.BufferLength); + mg_output.WriteBytesToUMDataOutput(); + + m_bytes = dataOut.getBufferCopy(); + m_size = dataOut.getBufferLength(); + + m_hashCode = managedptr->GetHashCode(); + GemStone::GemFire::Cache::Generic::Log::Fine( + "ManagedCacheableKeyBytes::Constructor objectSize = " + m_size + " m_hashCode = " + m_hashCode); + } + } } - } - } - /// <summary> - /// serialize this object - /// </summary> - virtual void toData( gemfire::DataOutput& output ) const; - - /// <summary> - /// deserialize this object, typical implementation should return - /// the 'this' pointer. - /// </summary> - virtual gemfire::Serializable* fromData( gemfire::DataInput& input ); - - - /// <summary> - /// return the size of this object in bytes - /// </summary> - virtual uint32_t objectSize() const; - - /// <summary> - /// return the classId of the instance being serialized. - /// This is used by deserialization to determine what instance - /// type to create and deserialize into. - /// </summary> - virtual int32_t classId( ) const; - - /// <summary> - /// return the typeId of the instance being serialized. - /// This is used by deserialization to determine what instance - /// type to create and deserialize into. - /// </summary> - virtual int8_t typeId( ) const; - - /// <summary> - /// return the Data Serialization Fixed ID type. - /// This is used to determine what instance type to create - /// and deserialize into. - /// - /// Note that this should not be overridden by custom implementations - /// and is reserved only for builtin types. - /// </summary> - virtual int8_t DSFID() const; - - /// <summary> - /// Display this object as 'string', which depends on the implementation in - /// the managed class - /// </summary> - virtual gemfire::CacheableStringPtr toString( ) const; - - /// <summary> - /// return true if this key matches other CacheableKey - /// </summary> - virtual bool operator == ( const gemfire::CacheableKey& other ) const; - /// <summary> - /// return true if this key matches other ManagedCacheableKeyBytes - /// </summary> - virtual bool operator == ( const ManagedCacheableKeyBytesGeneric& other ) const; - - /// <summary> - /// return the hashcode for this key. - /// </summary> - virtual uint32_t hashcode( ) const; - - /// <summary> - /// Copy the string form of a key into a char* buffer for logging purposes. - /// implementations should only generate a string as long as maxLength chars, - /// and return the number of chars written. buffer is expected to be large - /// enough to hold at least maxLength chars. - /// The default implementation renders the classname and instance address. - /// </summary> - virtual size_t logString( char* buffer, size_t maxLength ) const; - - /// <summary> - /// Returns the wrapped managed object reference. - /// </summary> - inline GemStone::GemFire::Cache::Generic::IGFSerializable^ ptr( ) const - { - return getManagedObject(); - } - - inline ~ManagedCacheableKeyBytesGeneric() - { - GemStone::GemFire::Cache::Generic::Log::Fine( - "ManagedCacheableKeyBytes::Destructor current AppDomain ID: " + - System::Threading::Thread::GetDomainID() + " for object: " + - System::Convert::ToString((int)this) + " with its AppDomain ID: " + m_domainId); - GF_SAFE_DELETE(m_bytes); - } + /// <summary> + /// serialize this object + /// </summary> + virtual void toData(apache::geode::client::DataOutput& output) const; + + /// <summary> + /// deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + virtual apache::geode::client::Serializable* fromData(apache::geode::client::DataInput& input); + + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual uint32_t objectSize() const; + + /// <summary> + /// return the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + virtual int32_t classId() const; + + /// <summary> + /// return the typeId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + virtual int8_t typeId() const; + + /// <summary> + /// return the Data Serialization Fixed ID type. + /// This is used to determine what instance type to create + /// and deserialize into. + /// + /// Note that this should not be overridden by custom implementations + /// and is reserved only for builtin types. + /// </summary> + virtual int8_t DSFID() const; + + /// <summary> + /// Display this object as 'string', which depends on the implementation in + /// the managed class + /// </summary> + virtual apache::geode::client::CacheableStringPtr toString() const; + + /// <summary> + /// return true if this key matches other CacheableKey + /// </summary> + virtual bool operator == (const apache::geode::client::CacheableKey& other) const; + /// <summary> + /// return true if this key matches other ManagedCacheableKeyBytes + /// </summary> + virtual bool operator == (const ManagedCacheableKeyBytesGeneric& other) const; + + /// <summary> + /// return the hashcode for this key. + /// </summary> + virtual uint32_t hashcode() const; + + /// <summary> + /// Copy the string form of a key into a char* buffer for logging purposes. + /// implementations should only generate a string as long as maxLength chars, + /// and return the number of chars written. buffer is expected to be large + /// enough to hold at least maxLength chars. + /// The default implementation renders the classname and instance address. + /// </summary> + virtual size_t logString(char* buffer, size_t maxLength) const; + + /// <summary> + /// Returns the wrapped managed object reference. + /// </summary> + inline GemStone::GemFire::Cache::Generic::IGFSerializable^ ptr() const + { + return getManagedObject(); + } - private: - - GemStone::GemFire::Cache::Generic::IGFSerializable^ getManagedObject() const; - - /// <summary> - /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). - /// Note: not using auto_gcroot since it will result in 'Dispose' of the IGFSerializable - /// to be called which is not what is desired when this object is destroyed. Normally this - /// managed object may be created by the user and will be handled automatically by the GC. - /// </summary> -// gcroot<IGFSerializable^> m_managedptr; - int m_domainId; - UInt32 m_classId; - uint8_t * m_bytes; - uint32_t m_size; - uint32_t m_hashCode; - // Disable the copy and assignment constructors - ManagedCacheableKeyBytesGeneric( const ManagedCacheableKeyBytesGeneric& ); - ManagedCacheableKeyBytesGeneric& operator = ( const ManagedCacheableKeyBytesGeneric& ); - }; + inline ~ManagedCacheableKeyBytesGeneric() + { + GemStone::GemFire::Cache::Generic::Log::Fine( + "ManagedCacheableKeyBytes::Destructor current AppDomain ID: " + + System::Threading::Thread::GetDomainID() + " for object: " + + System::Convert::ToString((int)this) + " with its AppDomain ID: " + m_domainId); + GF_SAFE_DELETE(m_bytes); + } -} + private: + + GemStone::GemFire::Cache::Generic::IGFSerializable^ getManagedObject() const; + + /// <summary> + /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). + /// Note: not using auto_gcroot since it will result in 'Dispose' of the IGFSerializable + /// to be called which is not what is desired when this object is destroyed. Normally this + /// managed object may be created by the user and will be handled automatically by the GC. + /// </summary> + // gcroot<IGFSerializable^> m_managedptr; + int m_domainId; + UInt32 m_classId; + uint8_t * m_bytes; + uint32_t m_size; + uint32_t m_hashCode; + // Disable the copy and assignment constructors + ManagedCacheableKeyBytesGeneric(const ManagedCacheableKeyBytesGeneric&); + ManagedCacheableKeyBytesGeneric& operator = (const ManagedCacheableKeyBytesGeneric&); + }; + + } // namespace client + } // namespace geode +} // namespace apache http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCqListener.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCqListener.cpp b/src/clicache/src/impl/ManagedCqListener.cpp index 27604b2..4131e10 100644 --- a/src/clicache/src/impl/ManagedCqListener.cpp +++ b/src/clicache/src/impl/ManagedCqListener.cpp @@ -31,152 +31,159 @@ using namespace System::Text; using namespace System::Reflection; -//using namespace gemfire; -namespace gemfire +//using namespace apache::geode::client; +namespace apache { - - gemfire::CqListener* ManagedCqListenerGeneric::create( const char* assemblyPath, - const char* factoryFunctionName ) + namespace geode { - try + namespace client { - String^ mg_assemblyPath = - GemStone::GemFire::Cache::Generic::ManagedString::Get(assemblyPath); - String^ mg_factoryFunctionName = - GemStone::GemFire::Cache::Generic::ManagedString::Get(factoryFunctionName); - String^ mg_typeName = nullptr; - int32_t dotIndx = -1; - - if (mg_factoryFunctionName == nullptr || - ( dotIndx = mg_factoryFunctionName->LastIndexOf( '.' ) ) < 0 ) - { - std::string ex_str = "ManagedCqListener: Factory function name '"; - ex_str += factoryFunctionName; - ex_str += "' does not contain type name"; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - mg_typeName = mg_factoryFunctionName->Substring( 0, dotIndx ); - mg_factoryFunctionName = mg_factoryFunctionName->Substring( dotIndx + 1 ); - - Assembly^ assmb = nullptr; - try - { - assmb = Assembly::Load( mg_assemblyPath ); - } - catch (System::Exception^) + apache::geode::client::CqListener* ManagedCqListenerGeneric::create(const char* assemblyPath, + const char* factoryFunctionName) { - assmb = nullptr; - } - if (assmb == nullptr) - { - std::string ex_str = "ManagedCqListener: Could not load assembly: "; - ex_str += assemblyPath; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - Object^ typeInst = assmb->CreateInstance( mg_typeName, true ); - if (typeInst != nullptr) - { - MethodInfo^ mInfo = typeInst->GetType( )->GetMethod( mg_factoryFunctionName, - BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase ); - if (mInfo != nullptr) + try { - GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^ managedptr = nullptr; + String^ mg_assemblyPath = + GemStone::GemFire::Cache::Generic::ManagedString::Get(assemblyPath); + String^ mg_factoryFunctionName = + GemStone::GemFire::Cache::Generic::ManagedString::Get(factoryFunctionName); + String^ mg_typeName = nullptr; + int32_t dotIndx = -1; + + if (mg_factoryFunctionName == nullptr || + (dotIndx = mg_factoryFunctionName->LastIndexOf('.')) < 0) + { + std::string ex_str = "ManagedCqListener: Factory function name '"; + ex_str += factoryFunctionName; + ex_str += "' does not contain type name"; + throw IllegalArgumentException(ex_str.c_str()); + } + + mg_typeName = mg_factoryFunctionName->Substring(0, dotIndx); + mg_factoryFunctionName = mg_factoryFunctionName->Substring(dotIndx + 1); + + Assembly^ assmb = nullptr; try { - managedptr = dynamic_cast<GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^>( - mInfo->Invoke( typeInst, nullptr ) ); + assmb = Assembly::Load(mg_assemblyPath); } catch (System::Exception^) { - managedptr = nullptr; + assmb = nullptr; } - if (managedptr == nullptr) + if (assmb == nullptr) { - std::string ex_str = "ManagedCqListener: Could not create " - "object on invoking factory function ["; - ex_str += factoryFunctionName; + std::string ex_str = "ManagedCqListener: Could not load assembly: "; + ex_str += assemblyPath; + throw IllegalArgumentException(ex_str.c_str()); + } + Object^ typeInst = assmb->CreateInstance(mg_typeName, true); + if (typeInst != nullptr) + { + MethodInfo^ mInfo = typeInst->GetType()->GetMethod(mg_factoryFunctionName, + BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase); + if (mInfo != nullptr) + { + GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^ managedptr = nullptr; + try + { + managedptr = dynamic_cast<GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^>( + mInfo->Invoke(typeInst, nullptr)); + } + catch (System::Exception^) + { + managedptr = nullptr; + } + if (managedptr == nullptr) + { + std::string ex_str = "ManagedCqListener: Could not create " + "object on invoking factory function ["; + ex_str += factoryFunctionName; + ex_str += "] in assembly: "; + ex_str += assemblyPath; + throw IllegalArgumentException(ex_str.c_str()); + } + return new ManagedCqListenerGeneric((GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^)managedptr); + } + else + { + std::string ex_str = "ManagedCqListener: Could not load " + "function with name ["; + ex_str += factoryFunctionName; + ex_str += "] in assembly: "; + ex_str += assemblyPath; + throw IllegalArgumentException(ex_str.c_str()); + } + } + else + { + GemStone::GemFire::Cache::Generic::ManagedString typeName(mg_typeName); + std::string ex_str = "ManagedCqListener: Could not load type ["; + ex_str += typeName.CharPtr; ex_str += "] in assembly: "; ex_str += assemblyPath; - throw IllegalArgumentException( ex_str.c_str( ) ); + throw IllegalArgumentException(ex_str.c_str()); } - return new ManagedCqListenerGeneric( (GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^)managedptr ); } - else + catch (const apache::geode::client::Exception&) { - std::string ex_str = "ManagedCqListener: Could not load " - "function with name ["; - ex_str += factoryFunctionName; - ex_str += "] in assembly: "; - ex_str += assemblyPath; - throw IllegalArgumentException( ex_str.c_str( ) ); + throw; } + catch (System::Exception^ ex) + { + GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); + std::string ex_str = "ManagedCqListener: Got an exception while " + "loading managed library: "; + ex_str += mg_exStr.CharPtr; + throw IllegalArgumentException(ex_str.c_str()); + } + return NULL; } - else + + void ManagedCqListenerGeneric::onEvent(const CqEvent& ev) { - GemStone::GemFire::Cache::Generic::ManagedString typeName(mg_typeName); - std::string ex_str = "ManagedCqListener: Could not load type ["; - ex_str += typeName.CharPtr; - ex_str += "] in assembly: "; - ex_str += assemblyPath; - throw IllegalArgumentException( ex_str.c_str( ) ); + try { + + GemStone::GemFire::Cache::Generic::CqEvent<Object^, Object^> mevent(&ev); + m_managedptr->OnEvent(%mevent); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); + std::string ex_str = "ManagedCqListener: Got an exception in" + "onEvent: "; + ex_str += mg_exStr.CharPtr; + throw IllegalArgumentException(ex_str.c_str()); + } } - } - catch (const gemfire::Exception&) - { - throw; - } - catch (System::Exception^ ex) - { - GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); - std::string ex_str = "ManagedCqListener: Got an exception while " - "loading managed library: "; - ex_str += mg_exStr.CharPtr; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - return NULL; - } - - void ManagedCqListenerGeneric::onEvent( const CqEvent& ev ) - { - try { - - GemStone::GemFire::Cache::Generic::CqEvent<Object^, Object^> mevent( &ev ); - m_managedptr->OnEvent( %mevent ); - } - catch ( GemStone::GemFire::Cache::Generic::GemFireException^ ex ) { - ex->ThrowNative( ); - } - catch ( System::Exception^ ex ) { - GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); - std::string ex_str = "ManagedCqListener: Got an exception in" - "onEvent: "; - ex_str += mg_exStr.CharPtr; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - } - - void ManagedCqListenerGeneric::onError( const CqEvent& ev ) - { - GemStone::GemFire::Cache::Generic::CqEvent<Object^, Object^> mevent( &ev ); - m_managedptr->OnError( %mevent ); - } - void ManagedCqListenerGeneric::close() - { - try { - m_managedptr->Close(); - } - catch ( GemStone::GemFire::Cache::Generic::GemFireException^ ex ) { - ex->ThrowNative( ); - } - catch ( System::Exception^ ex ) { - GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); - std::string ex_str = "ManagedCqListener: Got an exception in" - "close: "; - ex_str += mg_exStr.CharPtr; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - } - -} + void ManagedCqListenerGeneric::onError(const CqEvent& ev) + { + GemStone::GemFire::Cache::Generic::CqEvent<Object^, Object^> mevent(&ev); + m_managedptr->OnError(%mevent); + } + + void ManagedCqListenerGeneric::close() + { + try { + m_managedptr->Close(); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); + std::string ex_str = "ManagedCqListener: Got an exception in" + "close: "; + ex_str += mg_exStr.CharPtr; + throw IllegalArgumentException(ex_str.c_str()); + } + } + + } // namespace client + } // namespace geode +} // namespace apache + http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCqListener.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCqListener.hpp b/src/clicache/src/impl/ManagedCqListener.hpp index 56087d1..f44085b 100644 --- a/src/clicache/src/impl/ManagedCqListener.hpp +++ b/src/clicache/src/impl/ManagedCqListener.hpp @@ -23,118 +23,122 @@ #include "../ICqListener.hpp" #include "CqListenerProxy.hpp" -//using namespace gemfire; -namespace gemfire { +//using namespace apache::geode::client; +namespace apache { + namespace geode { + namespace client { - /// <summary> - /// Wraps the managed <see cref="GemStone.GemFire.Cache.ICacheListener" /> - /// object and implements the native <c>gemfire::CacheListener</c> interface. - /// </summary> - class ManagedCqListenerGeneric - : public gemfire::CqListener - { - public: + /// <summary> + /// Wraps the managed <see cref="GemStone.GemFire.Cache.ICacheListener" /> + /// object and implements the native <c>apache::geode::client::CacheListener</c> interface. + /// </summary> + class ManagedCqListenerGeneric + : public apache::geode::client::CqListener + { + public: - /// <summary> - /// Constructor to initialize with the provided managed object. - /// </summary> - /// <param name="userptr"> - /// The user object. - /// </param> - inline ManagedCqListenerGeneric( /*Generic::ICqListener<Object^, Object^>^ managedptr*/Object^ userptr ) - : /*m_managedptr( managedptr )*/m_userptr( userptr ) { } + /// <summary> + /// Constructor to initialize with the provided managed object. + /// </summary> + /// <param name="userptr"> + /// The user object. + /// </param> + inline ManagedCqListenerGeneric( /*Generic::ICqListener<Object^, Object^>^ managedptr*/Object^ userptr) + : /*m_managedptr( managedptr )*/m_userptr(userptr) { } - /// <summary> - /// Static function to create a <c>ManagedCacheListener</c> using given - /// managed assembly path and given factory function. - /// </summary> - /// <param name="assemblyPath"> - /// The path of the managed assembly that contains the <c>ICacheListener</c> - /// factory function. - /// </param> - /// <param name="factoryFunctionName"> - /// The name of the factory function of the managed class for creating - /// an object that implements <c>ICacheListener</c>. - /// This should be a static function of the format - /// {Namespace}.{Class Name}.{Method Name}. - /// </param> - /// <exception cref="IllegalArgumentException"> - /// If the managed library cannot be loaded or the factory function fails. - /// </exception> - static CqListener* create( const char* assemblyPath, - const char* factoryFunctionName ); + /// <summary> + /// Static function to create a <c>ManagedCacheListener</c> using given + /// managed assembly path and given factory function. + /// </summary> + /// <param name="assemblyPath"> + /// The path of the managed assembly that contains the <c>ICacheListener</c> + /// factory function. + /// </param> + /// <param name="factoryFunctionName"> + /// The name of the factory function of the managed class for creating + /// an object that implements <c>ICacheListener</c>. + /// This should be a static function of the format + /// {Namespace}.{Class Name}.{Method Name}. + /// </param> + /// <exception cref="IllegalArgumentException"> + /// If the managed library cannot be loaded or the factory function fails. + /// </exception> + static CqListener* create(const char* assemblyPath, + const char* factoryFunctionName); - /// <summary> - /// Destructor -- does nothing. - /// </summary> - virtual ~ManagedCqListenerGeneric( ) { } + /// <summary> + /// Destructor -- does nothing. + /// </summary> + virtual ~ManagedCqListenerGeneric() { } - /// <summary> - /// Handles the event of a new key being added to a region. - /// </summary> - /// <remarks> - /// The entry did not previously exist in this region in the local cache - /// (even with a null value). - /// <para> - /// This function does not throw any exception. - /// </para> - /// </remarks> - /// <param name="ev"> - /// Denotes the event object associated with the entry creation. - /// </param> - /// <seealso cref="GemStone.GemFire.Cache.Region.Create" /> - /// <seealso cref="GemStone.GemFire.Cache.Region.Put" /> - /// <seealso cref="GemStone.GemFire.Cache.Region.Get" /> - virtual void onEvent( const gemfire::CqEvent& ev ); + /// <summary> + /// Handles the event of a new key being added to a region. + /// </summary> + /// <remarks> + /// The entry did not previously exist in this region in the local cache + /// (even with a null value). + /// <para> + /// This function does not throw any exception. + /// </para> + /// </remarks> + /// <param name="ev"> + /// Denotes the event object associated with the entry creation. + /// </param> + /// <seealso cref="GemStone.GemFire.Cache.Region.Create" /> + /// <seealso cref="GemStone.GemFire.Cache.Region.Put" /> + /// <seealso cref="GemStone.GemFire.Cache.Region.Get" /> + virtual void onEvent(const apache::geode::client::CqEvent& ev); - /// <summary> - /// Handles the event of an entry's value being modified in a region. - /// </summary> - /// <remarks> - /// This entry previously existed in this region in the local cache, - /// but its previous value may have been null. - /// </remarks> - /// <param name="ev"> - /// EntryEvent denotes the event object associated with updating the entry. - /// </param> - /// <seealso cref="GemStone.GemFire.Cache.Region.Put" /> - virtual void onError( const gemfire::CqEvent& ev ); + /// <summary> + /// Handles the event of an entry's value being modified in a region. + /// </summary> + /// <remarks> + /// This entry previously existed in this region in the local cache, + /// but its previous value may have been null. + /// </remarks> + /// <param name="ev"> + /// EntryEvent denotes the event object associated with updating the entry. + /// </param> + /// <seealso cref="GemStone.GemFire.Cache.Region.Put" /> + virtual void onError(const apache::geode::client::CqEvent& ev); - /// <summary> - /// Handles the event of an entry's value being invalidated. - /// </summary> - /// EntryEvent denotes the event object associated with the entry invalidation. - /// </param> - virtual void close(); - /// <summary> - /// Returns the wrapped managed object reference. - /// </summary> - inline GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^ ptr( ) const - { - return m_managedptr; - } + /// <summary> + /// Handles the event of an entry's value being invalidated. + /// </summary> + /// EntryEvent denotes the event object associated with the entry invalidation. + /// </param> + virtual void close(); + /// <summary> + /// Returns the wrapped managed object reference. + /// </summary> + inline GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^ ptr() const + { + return m_managedptr; + } - inline void setptr( GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^ managedptr ) - { - m_managedptr = managedptr; - } + inline void setptr(GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^ managedptr) + { + m_managedptr = managedptr; + } - inline Object^ userptr( ) const - { - return m_userptr; - } - private: + inline Object^ userptr() const + { + return m_userptr; + } + private: - /// <summary> - /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). - /// Note: not using auto_gcroot since it will result in 'Dispose' of the ICacheListener - /// to be called which is not what is desired when this object is destroyed. Normally this - /// managed object may be created by the user and will be handled automatically by the GC. - /// </summary> - gcroot<GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^> m_managedptr; - - gcroot<Object^> m_userptr; - }; + /// <summary> + /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). + /// Note: not using auto_gcroot since it will result in 'Dispose' of the ICacheListener + /// to be called which is not what is desired when this object is destroyed. Normally this + /// managed object may be created by the user and will be handled automatically by the GC. + /// </summary> + gcroot<GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^> m_managedptr; -} + gcroot<Object^> m_userptr; + }; + + } // namespace client + } // namespace geode +} // namespace apache http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCqStatusListener.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCqStatusListener.cpp b/src/clicache/src/impl/ManagedCqStatusListener.cpp index 3b559a1..e6a2924 100644 --- a/src/clicache/src/impl/ManagedCqStatusListener.cpp +++ b/src/clicache/src/impl/ManagedCqStatusListener.cpp @@ -30,185 +30,191 @@ using namespace System::Text; using namespace System::Reflection; -namespace gemfire +namespace apache { - - gemfire::CqListener* ManagedCqStatusListenerGeneric::create( const char* assemblyPath, - const char* factoryFunctionName ) + namespace geode { - try + namespace client { - String^ mg_assemblyPath = - GemStone::GemFire::Cache::Generic::ManagedString::Get(assemblyPath); - String^ mg_factoryFunctionName = - GemStone::GemFire::Cache::Generic::ManagedString::Get(factoryFunctionName); - String^ mg_typeName = nullptr; - int32_t dotIndx = -1; - - if (mg_factoryFunctionName == nullptr || - ( dotIndx = mg_factoryFunctionName->LastIndexOf( '.' ) ) < 0 ) - { - std::string ex_str = "ManagedCqStatusListenerGeneric: Factory function name '"; - ex_str += factoryFunctionName; - ex_str += "' does not contain type name"; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - - mg_typeName = mg_factoryFunctionName->Substring( 0, dotIndx ); - mg_factoryFunctionName = mg_factoryFunctionName->Substring( dotIndx + 1 ); - Assembly^ assmb = nullptr; - try - { - assmb = Assembly::Load( mg_assemblyPath ); - } - catch (System::Exception^) - { - assmb = nullptr; - } - if (assmb == nullptr) - { - std::string ex_str = "ManagedCqStatusListenerGeneric: Could not load assembly: "; - ex_str += assemblyPath; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - Object^ typeInst = assmb->CreateInstance( mg_typeName, true ); - if (typeInst != nullptr) + apache::geode::client::CqListener* ManagedCqStatusListenerGeneric::create(const char* assemblyPath, + const char* factoryFunctionName) { - MethodInfo^ mInfo = typeInst->GetType( )->GetMethod( mg_factoryFunctionName, - BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase ); - if (mInfo != nullptr) + try { - GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^ managedptr = nullptr; + String^ mg_assemblyPath = + GemStone::GemFire::Cache::Generic::ManagedString::Get(assemblyPath); + String^ mg_factoryFunctionName = + GemStone::GemFire::Cache::Generic::ManagedString::Get(factoryFunctionName); + String^ mg_typeName = nullptr; + int32_t dotIndx = -1; + + if (mg_factoryFunctionName == nullptr || + (dotIndx = mg_factoryFunctionName->LastIndexOf('.')) < 0) + { + std::string ex_str = "ManagedCqStatusListenerGeneric: Factory function name '"; + ex_str += factoryFunctionName; + ex_str += "' does not contain type name"; + throw IllegalArgumentException(ex_str.c_str()); + } + + mg_typeName = mg_factoryFunctionName->Substring(0, dotIndx); + mg_factoryFunctionName = mg_factoryFunctionName->Substring(dotIndx + 1); + + Assembly^ assmb = nullptr; try { - managedptr = dynamic_cast<GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^>( - mInfo->Invoke( typeInst, nullptr ) ); + assmb = Assembly::Load(mg_assemblyPath); } catch (System::Exception^) { - managedptr = nullptr; + assmb = nullptr; } - if (managedptr == nullptr) + if (assmb == nullptr) { - std::string ex_str = "ManagedCqStatusListenerGeneric: Could not create " - "object on invoking factory function ["; - ex_str += factoryFunctionName; + std::string ex_str = "ManagedCqStatusListenerGeneric: Could not load assembly: "; + ex_str += assemblyPath; + throw IllegalArgumentException(ex_str.c_str()); + } + Object^ typeInst = assmb->CreateInstance(mg_typeName, true); + if (typeInst != nullptr) + { + MethodInfo^ mInfo = typeInst->GetType()->GetMethod(mg_factoryFunctionName, + BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase); + if (mInfo != nullptr) + { + GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^ managedptr = nullptr; + try + { + managedptr = dynamic_cast<GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^>( + mInfo->Invoke(typeInst, nullptr)); + } + catch (System::Exception^) + { + managedptr = nullptr; + } + if (managedptr == nullptr) + { + std::string ex_str = "ManagedCqStatusListenerGeneric: Could not create " + "object on invoking factory function ["; + ex_str += factoryFunctionName; + ex_str += "] in assembly: "; + ex_str += assemblyPath; + throw IllegalArgumentException(ex_str.c_str()); + } + return new ManagedCqStatusListenerGeneric((GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^)managedptr); + } + else + { + std::string ex_str = "ManagedCqStatusListenerGeneric: Could not load " + "function with name ["; + ex_str += factoryFunctionName; + ex_str += "] in assembly: "; + ex_str += assemblyPath; + throw IllegalArgumentException(ex_str.c_str()); + } + } + else + { + GemStone::GemFire::Cache::Generic::ManagedString typeName(mg_typeName); + std::string ex_str = "ManagedCqStatusListenerGeneric: Could not load type ["; + ex_str += typeName.CharPtr; ex_str += "] in assembly: "; ex_str += assemblyPath; - throw IllegalArgumentException( ex_str.c_str( ) ); + throw IllegalArgumentException(ex_str.c_str()); } - return new ManagedCqStatusListenerGeneric( (GemStone::GemFire::Cache::Generic::ICqListener<Object^, Object^>^)managedptr ); } - else + catch (const apache::geode::client::Exception&) { - std::string ex_str = "ManagedCqStatusListenerGeneric: Could not load " - "function with name ["; - ex_str += factoryFunctionName; - ex_str += "] in assembly: "; - ex_str += assemblyPath; - throw IllegalArgumentException( ex_str.c_str( ) ); + throw; + } + catch (System::Exception^ ex) + { + GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); + std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception while " + "loading managed library: "; + ex_str += mg_exStr.CharPtr; + throw IllegalArgumentException(ex_str.c_str()); + } + return NULL; + } + + void ManagedCqStatusListenerGeneric::onEvent(const CqEvent& ev) + { + try { + + GemStone::GemFire::Cache::Generic::CqEvent<Object^, Object^> mevent(&ev); + m_managedptr->OnEvent(%mevent); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); + std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception in" + "onEvent: "; + ex_str += mg_exStr.CharPtr; + throw IllegalArgumentException(ex_str.c_str()); } } - else + + void ManagedCqStatusListenerGeneric::onError(const CqEvent& ev) { - GemStone::GemFire::Cache::Generic::ManagedString typeName(mg_typeName); - std::string ex_str = "ManagedCqStatusListenerGeneric: Could not load type ["; - ex_str += typeName.CharPtr; - ex_str += "] in assembly: "; - ex_str += assemblyPath; - throw IllegalArgumentException( ex_str.c_str( ) ); + GemStone::GemFire::Cache::Generic::CqEvent<Object^, Object^> mevent(&ev); + m_managedptr->OnError(%mevent); } - } - catch (const gemfire::Exception&) - { - throw; - } - catch (System::Exception^ ex) - { - GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); - std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception while " - "loading managed library: "; - ex_str += mg_exStr.CharPtr; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - return NULL; - } - - void ManagedCqStatusListenerGeneric::onEvent( const CqEvent& ev ) - { - try { - - GemStone::GemFire::Cache::Generic::CqEvent<Object^, Object^> mevent( &ev ); - m_managedptr->OnEvent( %mevent ); - } - catch ( GemStone::GemFire::Cache::Generic::GemFireException^ ex ) { - ex->ThrowNative( ); - } - catch ( System::Exception^ ex ) { - GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); - std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception in" - "onEvent: "; - ex_str += mg_exStr.CharPtr; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - } - - void ManagedCqStatusListenerGeneric::onError( const CqEvent& ev ) - { - GemStone::GemFire::Cache::Generic::CqEvent<Object^, Object^> mevent( &ev ); - m_managedptr->OnError( %mevent ); - } - void ManagedCqStatusListenerGeneric::close() - { - try { - m_managedptr->Close(); - } - catch ( GemStone::GemFire::Cache::Generic::GemFireException^ ex ) { - ex->ThrowNative( ); - } - catch ( System::Exception^ ex ) { - GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); - std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception in" - "close: "; - ex_str += mg_exStr.CharPtr; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - } - - void ManagedCqStatusListenerGeneric::onCqDisconnected() - { - try { - m_managedptr->OnCqDisconnected(); - } - catch ( GemStone::GemFire::Cache::Generic::GemFireException^ ex ) { - ex->ThrowNative( ); - } - catch ( System::Exception^ ex ) { - GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); - std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception in" - "onCqDisconnected: "; - ex_str += mg_exStr.CharPtr; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - } - - void ManagedCqStatusListenerGeneric::onCqConnected() - { - try { - m_managedptr->OnCqConnected(); - } - catch ( GemStone::GemFire::Cache::Generic::GemFireException^ ex ) { - ex->ThrowNative( ); - } - catch ( System::Exception^ ex ) { - GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); - std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception in" - "OnCqConnected: "; - ex_str += mg_exStr.CharPtr; - throw IllegalArgumentException( ex_str.c_str( ) ); - } - } - -} + void ManagedCqStatusListenerGeneric::close() + { + try { + m_managedptr->Close(); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); + std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception in" + "close: "; + ex_str += mg_exStr.CharPtr; + throw IllegalArgumentException(ex_str.c_str()); + } + } + + void ManagedCqStatusListenerGeneric::onCqDisconnected() + { + try { + m_managedptr->OnCqDisconnected(); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); + std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception in" + "onCqDisconnected: "; + ex_str += mg_exStr.CharPtr; + throw IllegalArgumentException(ex_str.c_str()); + } + } + + void ManagedCqStatusListenerGeneric::onCqConnected() + { + try { + m_managedptr->OnCqConnected(); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::ManagedString mg_exStr(ex->ToString()); + std::string ex_str = "ManagedCqStatusListenerGeneric: Got an exception in" + "OnCqConnected: "; + ex_str += mg_exStr.CharPtr; + throw IllegalArgumentException(ex_str.c_str()); + } + } + + } // namespace client + } // namespace geode +} // namespace apache http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCqStatusListener.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCqStatusListener.hpp b/src/clicache/src/impl/ManagedCqStatusListener.hpp index c01a3b4..3850353 100644 --- a/src/clicache/src/impl/ManagedCqStatusListener.hpp +++ b/src/clicache/src/impl/ManagedCqStatusListener.hpp @@ -23,113 +23,117 @@ #include "../ICqStatusListener.hpp" #include "CqStatusListenerProxy.hpp" -namespace gemfire { - - /// <summary> - /// Wraps the managed <see cref="GemStone.GemFire.Cache.ICqStatusListener" /> - /// object and implements the native <c>gemfire::CqStatusListener</c> interface. - /// </summary> - class ManagedCqStatusListenerGeneric - : public gemfire::CqStatusListener - { - public: - - /// <summary> - /// Constructor to initialize with the provided managed object. - /// </summary> - /// <param name="userptr"> - /// The user object. - /// </param> - inline ManagedCqStatusListenerGeneric( Object^ userptr ) - : m_userptr( userptr ) { } - - /// <summary> - /// Static function to create a <c>ManagedCqStatusListenerGeneric</c> using given - /// managed assembly path and given factory function. - /// </summary> - /// <param name="assemblyPath"> - /// The path of the managed assembly that contains the <c>ICqStatusListener</c> - /// factory function. - /// </param> - /// <param name="factoryFunctionName"> - /// The name of the factory function of the managed class for creating - /// an object that implements <c>ICqStatusListener</c>. - /// This should be a static function of the format - /// {Namespace}.{Class Name}.{Method Name}. - /// </param> - /// <exception cref="IllegalArgumentException"> - /// If the managed library cannot be loaded or the factory function fails. - /// </exception> - static CqListener* create( const char* assemblyPath, - const char* factoryFunctionName ); - - /// <summary> - /// Destructor -- does nothing. - /// </summary> - virtual ~ManagedCqStatusListenerGeneric( ) { } - - /// <summary> - /// This method is invoked when an event is occurred on the region - /// that satisfied the query condition of this CQ. - /// This event does not contain an error. - /// </summary> - virtual void onEvent( const gemfire::CqEvent& ev ); - - /// <summary> - /// This method is invoked when there is an error during CQ processing. - /// The error can appear while applying query condition on the event. - /// e.g if the event doesn't has attributes as specified in the CQ query. - /// This event does contain an error. The newValue may or may not be - /// available, and will be NULLPTR if not available. - /// </summary> - virtual void onError( const gemfire::CqEvent& ev ); - - /// <summary> - /// Handles the event of an entry's value being invalidated. - /// </summary> - /// EntryEvent denotes the event object associated with the entry invalidation. - /// </param> - virtual void close(); - - /// <summary> - /// Called when the cq loses connection with all servers - /// </summary> - virtual void onCqDisconnected(); - - /// <summary> - /// Called when the cq establishes a connection with a server - /// </summary> - virtual void onCqConnected(); - - /// <summary> - /// Returns the wrapped managed object reference. - /// </summary> - inline GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^ ptr() const - { - return m_managedptr; - } - - inline void setptr( GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^ managedptr ) - { - m_managedptr = managedptr; - } - - inline Object^ userptr( ) const - { - return m_userptr; - } - private: - - - /// <summary> - /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). - /// Note: not using auto_gcroot since it will result in 'Dispose' of the ICqStatusListener - /// to be called which is not what is desired when this object is destroyed. Normally this - /// managed object may be created by the user and will be handled automatically by the GC. - /// </summary> - gcroot<GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^> m_managedptr; - - gcroot<Object^> m_userptr; - }; - -} +namespace apache { + namespace geode { + namespace client { + + /// <summary> + /// Wraps the managed <see cref="GemStone.GemFire.Cache.ICqStatusListener" /> + /// object and implements the native <c>apache::geode::client::CqStatusListener</c> interface. + /// </summary> + class ManagedCqStatusListenerGeneric + : public apache::geode::client::CqStatusListener + { + public: + + /// <summary> + /// Constructor to initialize with the provided managed object. + /// </summary> + /// <param name="userptr"> + /// The user object. + /// </param> + inline ManagedCqStatusListenerGeneric(Object^ userptr) + : m_userptr(userptr) { } + + /// <summary> + /// Static function to create a <c>ManagedCqStatusListenerGeneric</c> using given + /// managed assembly path and given factory function. + /// </summary> + /// <param name="assemblyPath"> + /// The path of the managed assembly that contains the <c>ICqStatusListener</c> + /// factory function. + /// </param> + /// <param name="factoryFunctionName"> + /// The name of the factory function of the managed class for creating + /// an object that implements <c>ICqStatusListener</c>. + /// This should be a static function of the format + /// {Namespace}.{Class Name}.{Method Name}. + /// </param> + /// <exception cref="IllegalArgumentException"> + /// If the managed library cannot be loaded or the factory function fails. + /// </exception> + static CqListener* create(const char* assemblyPath, + const char* factoryFunctionName); + + /// <summary> + /// Destructor -- does nothing. + /// </summary> + virtual ~ManagedCqStatusListenerGeneric() { } + + /// <summary> + /// This method is invoked when an event is occurred on the region + /// that satisfied the query condition of this CQ. + /// This event does not contain an error. + /// </summary> + virtual void onEvent(const apache::geode::client::CqEvent& ev); + + /// <summary> + /// This method is invoked when there is an error during CQ processing. + /// The error can appear while applying query condition on the event. + /// e.g if the event doesn't has attributes as specified in the CQ query. + /// This event does contain an error. The newValue may or may not be + /// available, and will be NULLPTR if not available. + /// </summary> + virtual void onError(const apache::geode::client::CqEvent& ev); + + /// <summary> + /// Handles the event of an entry's value being invalidated. + /// </summary> + /// EntryEvent denotes the event object associated with the entry invalidation. + /// </param> + virtual void close(); + + /// <summary> + /// Called when the cq loses connection with all servers + /// </summary> + virtual void onCqDisconnected(); + + /// <summary> + /// Called when the cq establishes a connection with a server + /// </summary> + virtual void onCqConnected(); + + /// <summary> + /// Returns the wrapped managed object reference. + /// </summary> + inline GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^ ptr() const + { + return m_managedptr; + } + + inline void setptr(GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^ managedptr) + { + m_managedptr = managedptr; + } + + inline Object^ userptr() const + { + return m_userptr; + } + private: + + + /// <summary> + /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). + /// Note: not using auto_gcroot since it will result in 'Dispose' of the ICqStatusListener + /// to be called which is not what is desired when this object is destroyed. Normally this + /// managed object may be created by the user and will be handled automatically by the GC. + /// </summary> + gcroot<GemStone::GemFire::Cache::Generic::ICqStatusListener<Object^, Object^>^> m_managedptr; + + gcroot<Object^> m_userptr; + }; + + } // namespace client + } // namespace geode +} // namespace apache