Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 85CFC2009D9 for ; Thu, 19 May 2016 17:14:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 843AB160A1D; Thu, 19 May 2016 15:14:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 56DDA160A00 for ; Thu, 19 May 2016 17:14:20 +0200 (CEST) Received: (qmail 96821 invoked by uid 500); 19 May 2016 15:14:19 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 96801 invoked by uid 99); 19 May 2016 15:14:19 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 May 2016 15:14:19 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id C9AB6C006B for ; Thu, 19 May 2016 15:14:18 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.221 X-Spam-Level: X-Spam-Status: No, score=-3.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 6LB-6W5rZq2q for ; Thu, 19 May 2016 15:14:09 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id AA6F95F244 for ; Thu, 19 May 2016 15:14:08 +0000 (UTC) Received: (qmail 95666 invoked by uid 99); 19 May 2016 15:14:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 May 2016 15:14:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1B767DFF13; Thu, 19 May 2016 15:14:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rvs@apache.org To: commits@geode.incubator.apache.org Date: Thu, 19 May 2016 15:14:11 -0000 Message-Id: In-Reply-To: <36005b127eed45f98bd13948d6bffa2b@git.apache.org> References: <36005b127eed45f98bd13948d6bffa2b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [04/51] [partial] incubator-geode git commit: Add source for geode c++ and .net clients archived-at: Thu, 19 May 2016 15:14:22 -0000 http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableHashTableMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableHashTableMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableHashTableMN.hpp new file mode 100644 index 0000000..e717c73 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableHashTableMN.hpp @@ -0,0 +1,108 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include "CacheableHashMapMN.hpp" +#include "DataInputMN.hpp" + + +using namespace System; +using namespace System::Collections::Generic; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// A mutable ICacheableKey to IGFSerializable hash table + /// that can serve as a distributable object for caching. This class + /// extends .NET generic Dictionary class. + /// + ref class CacheableHashTable + : public CacheableHashMap + { + public: + + /// + /// Allocates a new empty instance. + /// + inline CacheableHashTable() + : CacheableHashMap() + { } + + /// + /// Allocates a new instance copying from the given dictionary. + /// + /// + /// The dictionary whose elements are copied to this HashTable. + /// + inline CacheableHashTable(Object^ dictionary) + : CacheableHashMap(dictionary) + { } + + /// + /// Allocates a new empty instance with given initial size. + /// + /// + /// The initial capacity of the HashTable. + /// + inline CacheableHashTable(int32_t capacity) + : CacheableHashMap(capacity) + { } + + + // Region: IGFSerializable Members + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + virtual uint32_t get() override + { + return GemFireClassIds::CacheableHashTable; + } + } + + // End Region: IGFSerializable Members + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableHashTable(); + } + + virtual IGFSerializable^ FromData(DataInput^ input) override + { + m_dictionary = input->ReadHashtable(); + return this; + } + internal: + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ Create(Object^ hashtable) + { + return gcnew CacheableHashTable(hashtable); + } + }; + + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableIdentityHashMapMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableIdentityHashMapMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableIdentityHashMapMN.hpp new file mode 100644 index 0000000..d3aa3b1 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableIdentityHashMapMN.hpp @@ -0,0 +1,118 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include "CacheableHashMapMN.hpp" + + +using namespace System; +using namespace System::Collections::Generic; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// A mutable ICacheableKey to IGFSerializable hash map + /// that can serve as a distributable object for caching. This class + /// extends .NET generic Dictionary class. This class is meant + /// as a means to interoperate with java server side + /// IdentityHashMap class objects but is intentionally not + /// intended to provide java.util.IdentityHashMap semantics. + /// + ref class CacheableIdentityHashMap + : public CacheableHashMap + { + public: + /// + /// Allocates a new empty instance. + /// + inline CacheableIdentityHashMap() + : CacheableHashMap() + { } + + /// + /// Allocates a new instance copying from the given dictionary. + /// + /// + /// The dictionary whose elements are copied to this HashMap. + /// + inline CacheableIdentityHashMap(Object^ dictionary) + : CacheableHashMap(dictionary) + { } + + /// + /// Allocates a new empty instance with given initial size. + /// + /// + /// The initial capacity of the HashMap. + /// + inline CacheableIdentityHashMap(int32_t capacity) + : CacheableHashMap(capacity) + { } + + /// + /// Static function to create a new empty instance. + /// + inline static CacheableIdentityHashMap^ Create() + { + return gcnew CacheableIdentityHashMap(); + } + + /// + /// Static function to create a new instance copying from the + /// given dictionary. + /// + inline static CacheableIdentityHashMap^ Create( + Object^ dictionary) + { + return gcnew CacheableIdentityHashMap(dictionary); + } + + /// + /// Static function to create a new instance with given initial size. + /// + inline static CacheableIdentityHashMap^ Create(int32_t capacity) + { + return gcnew CacheableIdentityHashMap(capacity); + } + + // Region: IGFSerializable Members + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + virtual uint32_t get() override + { + return GemFireClassIds::CacheableIdentityHashMap; + } + } + + // End Region: IGFSerializable Members + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableIdentityHashMap(); + } + }; + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableKeyMN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableKeyMN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableKeyMN.cpp new file mode 100644 index 0000000..176b148 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableKeyMN.cpp @@ -0,0 +1,108 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +//#include "gf_includesN.hpp" +#include "CacheableKeyMN.hpp" +#include "CacheableStringMN.hpp" +#include "CacheableBuiltinsMN.hpp" + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + // generic + int32_t CacheableKey::GetHashCode() + { + return static_cast(NativePtr())->hashcode(); + } + + // generic + bool CacheableKey::Equals(Generic::ICacheableKey^ other) + { + if (other == nullptr || other->ClassId != ClassId) { + return false; + } + return static_cast(NativePtr())->operator==( + *static_cast( + ((Generic::CacheableKey^)other)->NativePtr())); + } + + //generic + bool CacheableKey::Equals(Object^ obj) + { + CacheableKey^ otherKey = + dynamic_cast(obj); + + if (otherKey != nullptr) { + return static_cast(NativePtr())->operator==( + *static_cast(otherKey->NativePtr())); + } + return false; + } + + //generic + CacheableKey::operator CacheableKey^ (Byte value) + { + return (CacheableKey^) CacheableByte::Create(value); + } + + //generic + CacheableKey::operator CacheableKey^ (bool value) + { + return (CacheableKey^) CacheableBoolean::Create(value); + } + + //generic + CacheableKey::operator CacheableKey^ (Char value) + { + return (CacheableKey^) CacheableCharacter::Create(value); + } + + //generic + CacheableKey::operator CacheableKey^ (Double value) + { + return (CacheableKey^) CacheableDouble::Create(value); + } + + //generic + CacheableKey::operator CacheableKey^ (Single value) + { + return (CacheableKey^) CacheableFloat::Create(value); + } + + //generic + CacheableKey::operator CacheableKey^ (int16_t value) + { + return (CacheableKey^) CacheableInt16::Create(value); + } + + //generic + CacheableKey::operator CacheableKey^ (int32_t value) + { + return (CacheableKey^) CacheableInt32::Create(value); + } + + // generic + CacheableKey::operator CacheableKey^ (int64_t value) + { + return (CacheableKey^) CacheableInt64::Create(value); + } + + //generic + CacheableKey::operator CacheableKey^ (String^ value) + { + return dynamic_cast(CacheableString::Create(value)); + } + } + } +} +} //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableKeyMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableKeyMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableKeyMN.hpp new file mode 100644 index 0000000..f6c6042 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableKeyMN.hpp @@ -0,0 +1,129 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include +//#include "impl/NativeWrapperN.hpp" +#include "SerializableMN.hpp" +#include "ICacheableKeyN.hpp" + + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// This class wraps the native C++ gemfire::Serializable objects + /// as managed objects. + /// + public ref class CacheableKey + : public Serializable, public ICacheableKey + { + public: + /// + /// Return the hashcode for this key. + /// It gets the hash code by calling the hashcode() function + /// of the underlying gemfire::CacheableKey object. + /// + virtual int32_t GetHashCode() override; + + /// + /// Return true if this key matches other object. It invokes the '==' + /// operator of the underlying gemfire::CacheableKey object. + /// + virtual bool Equals(ICacheableKey^ other); + + /// + /// Return true if this key matches other object. + /// It invokes the '==' operator if the underlying object is a + /// gemfire::CacheableKey, else returns + /// System.Object.Equals() + /// + virtual bool Equals(Object^ obj) override; + + // Static conversion functions from primitive types. + + /// + /// Implicit conversion operator from a boolean + /// to a CacheableKey. + /// + static operator CacheableKey^ (bool value); + + /// + /// Implicit conversion operator from a byte + /// to a CacheableKey. + /// + static operator CacheableKey^ (Byte value); + + /// + /// Implicit conversion operator from a double + /// to a CacheableKey. + /// + static operator CacheableKey^ (Double value); + + /// + /// Implicit conversion operator from a float + /// to a CacheableKey. + /// + static operator CacheableKey^ (Single value); + + /// + /// Implicit conversion operator from a 16-bit integer + /// to a CacheableKey. + /// + static operator CacheableKey^ (int16_t value); + + /// + /// Implicit conversion operator from a character + /// to a CacheableKey. + /// + static operator CacheableKey^ (Char value); + + /// + /// Implicit conversion operator from a 32-bit integer + /// to a CacheableKey. + /// + static operator CacheableKey^ (int32_t value); + + /// + /// Implicit conversion operator from a 64-bit integer + /// to a CacheableKey. + /// + static operator CacheableKey^ (int64_t value); + + /// + /// Implicit conversion operator from a string + /// to a CacheableKey. + /// + static operator CacheableKey^ (String^ value); + + internal: + /// + /// Default constructor. + /// + inline CacheableKey() + : Generic::Serializable() { } + + /// + /// Internal constructor to wrap a native object pointer + /// + /// The native object pointer + inline CacheableKey(gemfire::Serializable* nativeptr) + : Generic::Serializable(nativeptr) { } + }; + } + } +} +} //namespace + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableLinkedListMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableLinkedListMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableLinkedListMN.hpp new file mode 100644 index 0000000..d56cc8a --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableLinkedListMN.hpp @@ -0,0 +1,142 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include "CacheableVectorMN.hpp" + + +using namespace System; +using namespace System::Collections::Generic; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// A mutable IGFSerializable vector wrapper that can serve as + /// a distributable object for caching. This class extends .NET generic + /// List class. + /// + ref class CacheableLinkedList + : public IGFSerializable + { + System::Collections::Generic::LinkedList^ m_linkedList; + public: + /// + /// Allocates a new empty instance. + /// + inline CacheableLinkedList(System::Collections::Generic::LinkedList^ list) + { + m_linkedList = list; + } + + + /// + /// Static function to create a new empty instance. + /// + inline static CacheableLinkedList^ Create() + { + return gcnew CacheableLinkedList(gcnew System::Collections::Generic::LinkedList()); + } + + /// + /// Static function to create a new empty instance. + /// + inline static CacheableLinkedList^ Create(System::Collections::Generic::LinkedList^ list) + { + return gcnew CacheableLinkedList(list); + } + + + // Region: IGFSerializable Members + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + virtual uint32_t get() + { + return GemFireClassIds::CacheableLinkedList; + } + } + + // Region: IGFSerializable Members + + virtual void ToData(DataOutput^ output) + { + if(m_linkedList != nullptr) + { + output->WriteArrayLen(m_linkedList->Count); + for each (Object^ obj in m_linkedList) { + //TODO::split + output->WriteObject(obj); + } + } + else + output->WriteByte(0xFF); + } + + virtual IGFSerializable^ FromData(DataInput^ input) + { + int len = input->ReadArrayLen(); + for( int i = 0; i < len; i++) + { + m_linkedList->AddLast(input->ReadObject()); + } + return this; + } + + /*uint32_t ObjectSize::get() + { + //TODO::hitesh + uint32_t size = static_cast (sizeof(CacheableVector^)); + for each (IGFSerializable^ val in this) { + if (val != nullptr) { + size += val->ObjectSize; + } + } + return m_linkedList->Count; + }*/ + + virtual property uint32_t ObjectSize + { + virtual uint32_t get() + { + return m_linkedList->Count; + } + } + + virtual property System::Collections::Generic::LinkedList^ Value + { + virtual System::Collections::Generic::LinkedList^ get() + { + return m_linkedList; + } + } + // End Region: IGFSerializable Members + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableLinkedList(gcnew System::Collections::Generic::LinkedList()); + } + }; + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableObjectArrayMN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableObjectArrayMN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableObjectArrayMN.cpp new file mode 100644 index 0000000..6744012 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableObjectArrayMN.cpp @@ -0,0 +1,114 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + + + +//#include "gf_includesN.hpp" +#include +#include "CacheableObjectArrayMN.hpp" +#include "DataOutputMN.hpp" +#include "DataInputMN.hpp" +#include "ExceptionTypesMN.hpp" +#include "impl/SafeConvertN.hpp" +#include "impl/PdxTypeRegistry.hpp" + +using namespace System; +using namespace System::Collections::Generic; + +using namespace GemStone::GemFire::Cache::Generic; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + // Region: IGFSerializable Members + + void CacheableObjectArray::ToData(DataOutput^ output) + { + output->WriteArrayLen((int32_t)Count); + output->WriteByte((int8_t)gemfire::GemfireTypeIdsImpl::Class); + output->WriteByte((int8_t)gemfire::GemfireTypeIds::CacheableASCIIString); + output->WriteUTF("java.lang.Object"); + + for each (Object^ obj in this) { + //TODO::split + output->WriteObject(obj); + } + + /*_GF_MG_EXCEPTION_TRY + + gemfire::DataOutput& nativeOutput = *(output->_NativePtr); + nativeOutput.writeArrayLen((int32_t)Count); + nativeOutput.write((int8_t)gemfire::GemfireTypeIdsImpl::Class); + nativeOutput.write((int8_t)gemfire::GemfireTypeIds::CacheableASCIIString); + nativeOutput.writeASCII("java.lang.Object"); + for each (IGFSerializable^ obj in this) { + gemfire::SerializablePtr objPtr(SafeMSerializableConvert(obj)); + nativeOutput.writeObject(objPtr); + } + + _GF_MG_EXCEPTION_CATCH_ALL*/ + } + + IGFSerializable^ CacheableObjectArray::FromData(DataInput^ input) + { + int len = input->ReadArrayLen(); + if (len >= 0) { + //int8_t typeCode; + input->ReadByte(); // ignore CLASS typeid + input->ReadByte(); // ignore string typeid + unsigned short classLen; + classLen = input->ReadInt16(); + input->AdvanceCursor(classLen); + //nativeInput.readInt(&classLen); + //nativeInput.advanceCursor(classLen); + } + for (int32_t index = 0; index < len; ++index) { + Add(input->ReadObject()); + } + return this; + /*_GF_MG_EXCEPTION_TRY + + gemfire::DataInput& nativeInput = *(input->_NativePtr); + int32_t len; + nativeInput.readArrayLen(&len); + if (len >= 0) { + int8_t typeCode; + nativeInput.read(&typeCode); // ignore CLASS typeid + nativeInput.read(&typeCode); // ignore string typeid + uint16_t classLen; + nativeInput.readInt(&classLen); + nativeInput.advanceCursor(classLen); + } + gemfire::CacheablePtr value; + for (int32_t index = 0; index < len; ++index) { + nativeInput.readObject(value); + Add(SafeUMSerializableConvert(value.ptr())); + } + + _GF_MG_EXCEPTION_CATCH_ALL + return this;*/ + } + + uint32_t CacheableObjectArray::ObjectSize::get() + { + /* uint32_t size = static_cast (sizeof(CacheableObjectArray^)); + for each (IGFSerializable^ val in this) { + if (val != nullptr) { + size += val->ObjectSize; + } + }*/ + return Count; + } + // End Region: IGFSerializable Members + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableObjectArrayMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableObjectArrayMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableObjectArrayMN.hpp new file mode 100644 index 0000000..9889c37 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableObjectArrayMN.hpp @@ -0,0 +1,145 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include "IGFSerializableN.hpp" +#include "GemFireClassIdsMN.hpp" + + +using namespace System; +using namespace System::Collections::Generic; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + + /// + /// A mutable IGFSerializable object array wrapper that can serve + /// as a distributable object for caching. Though this class provides + /// compatibility with java Object[] serialization, it provides the + /// semantics of .NET generic List class. + /// + public ref class CacheableObjectArray + : public List, public IGFSerializable + { + public: + /// + /// Allocates a new empty instance. + /// + inline CacheableObjectArray() + : List() + { } + + /// + /// Allocates a new instance copying from the given collection. + /// + /// + /// The collection whose elements are copied to this list. + /// + inline CacheableObjectArray(IEnumerable^ collection) + : List(collection) + { } + + /// + /// Allocates a new empty instance with given initial size. + /// + /// + /// The initial capacity of the vector. + /// + inline CacheableObjectArray(int32_t capacity) + : List(capacity) + { } + + /// + /// Static function to create a new empty instance. + /// + inline static CacheableObjectArray^ Create() + { + return gcnew CacheableObjectArray(); + } + + /// + /// Static function to create a new instance copying from the + /// given collection. + /// + inline static CacheableObjectArray^ Create( + IEnumerable^ collection) + { + return gcnew CacheableObjectArray(collection); + } + + /// + /// Static function to create a new instance with given initial size. + /// + inline static CacheableObjectArray^ Create(int32_t capacity) + { + return gcnew CacheableObjectArray(capacity); + } + + // Region: IGFSerializable Members + + /// + /// Serializes this object. + /// + /// + /// the DataOutput object to use for serializing the object + /// + virtual void ToData(DataOutput^ output); + + /// + /// Deserialize this object, typical implementation should return + /// the 'this' pointer. + /// + /// + /// the DataInput stream to use for reading the object data + /// + /// the deserialized object + virtual IGFSerializable^ FromData(DataInput^ input); + + /// + /// return the size of this object in bytes + /// + virtual property uint32_t ObjectSize + { + virtual uint32_t get(); + } + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + virtual uint32_t get() + { + return GemFireClassIds::CacheableObjectArray; + } + } + + // End Region: IGFSerializable Members + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableObjectArray(); + } + }; + + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableObjectN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableObjectN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableObjectN.cpp new file mode 100644 index 0000000..fdae998 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableObjectN.cpp @@ -0,0 +1,72 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + + +//#include "gf_includesN.hpp" +#include "CacheableObjectN.hpp" +#include "DataInputMN.hpp" +#include "DataOutputMN.hpp" +#include "impl/GFNullStreamN.hpp" +#include "impl/GFDataInputStreamN.hpp" +#include "impl/GFDataOutputStreamN.hpp" + +using namespace System; +using namespace System::IO; +using namespace System::Runtime::Serialization::Formatters::Binary; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + void CacheableObject::ToData(DataOutput^ output) + { + if(m_obj != nullptr) + { + output->AdvanceCursor(4); // placeholder for object size bytes needed while reading back. + + GFDataOutputStream dos(output); + BinaryFormatter bf; + int64_t checkpoint = dos.Length; + bf.Serialize(%dos, m_obj); + m_objectSize = (uint32_t) (dos.Length - checkpoint); + + output->RewindCursor(m_objectSize + 4); + output->WriteInt32(m_objectSize); + output->AdvanceCursor(m_objectSize); + } + } + + IGFSerializable^ CacheableObject::FromData(DataInput^ input) + { + int maxSize = input->ReadInt32(); + GFDataInputStream dis(input, maxSize); + uint32_t checkpoint = dis.BytesRead; + BinaryFormatter bf; + m_obj = bf.Deserialize(%dis); + m_objectSize = dis.BytesRead - checkpoint; + return this; + } + + uint32_t CacheableObject::ObjectSize::get() + { + if (m_objectSize == 0) { + GFNullStream ns; + BinaryFormatter bf; + bf.Serialize(%ns, m_obj); + + m_objectSize = (uint32_t)sizeof(CacheableObject^) + (uint32_t)ns.Length; + } + return m_objectSize; + } + } + } +} + } //namespace + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableObjectN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableObjectN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableObjectN.hpp new file mode 100644 index 0000000..556b571 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableObjectN.hpp @@ -0,0 +1,146 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include "IGFSerializableN.hpp" +#include "GemFireClassIdsMN.hpp" + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// An mutable generic wrapper that can + /// serve as a distributable value for caching. + /// + /// + /// + /// This class can serialize any class which has either the + /// [Serializable] attribute set or implements + /// interface. + /// However, for better efficiency the latter should be avoided and the + /// user should implement instead. + /// + /// The user must keep in mind that the rules that apply to runtime + /// serialization would be the rules that apply to this class. For + /// the serialization will be carried out by serializing all the + /// members (public/private/protected) of the class. Each of the + /// contained classes should also have either the [Serializable] + /// attribute set or implement ISerializable interface. + /// + /// + public ref class CacheableObject + : public IGFSerializable + { + public: + /// + /// Static function to create a new instance from the given object. + /// + /// + /// If the given object is null then this method returns null. + /// + inline static CacheableObject^ Create(Object^ value) + { + return (value != nullptr ? gcnew CacheableObject(value) : + nullptr); + } + + /// + /// Serializes this using + /// class. + /// + /// + /// the DataOutput object to use for serializing the object + /// + virtual void ToData(DataOutput^ output); + + /// + /// Deserializes the using + /// class. + /// + /// + /// the DataInput stream to use for reading the object data + /// + /// the deserialized object + virtual IGFSerializable^ FromData(DataInput^ input); + + /// + /// return the size of this object in bytes + /// + virtual property uint32_t ObjectSize + { + virtual uint32_t get(); + } + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + inline virtual uint32_t get() + { + return GemFireClassIds::CacheableManagedObject; + } + } + + /// + /// Gets the object value. + /// + /// + /// The user can modify the object and the changes shall be reflected + /// immediately in the local cache. For this change to be propagate to + /// other members of the distributed system, the object needs to be + /// put into the cache. + /// + property Object^ Value + { + inline Object^ get() + { + return m_obj; + } + } + + virtual String^ ToString() override + { + return (m_obj == nullptr ? nullptr : m_obj->ToString()); + } + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableObject(nullptr); + } + + internal: + /// + /// Allocates a new instance from the given object. + /// + inline CacheableObject(Object^ value) + : m_obj(value), m_objectSize(0) { } + + + + private: + Object^ m_obj; + uint32_t m_objectSize; + }; + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableObjectXmlN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableObjectXmlN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableObjectXmlN.cpp new file mode 100644 index 0000000..8ec060b --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableObjectXmlN.cpp @@ -0,0 +1,101 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + + + +//#include "gf_includesN.hpp" +#include "CacheableObjectXmlN.hpp" +#include "DataInputMN.hpp" +#include "DataOutputMN.hpp" +#include "LogMN.hpp" +#include "impl/GFNullStreamN.hpp" +#include "impl/GFDataInputStreamN.hpp" +#include "impl/GFDataOutputStreamN.hpp" + +using namespace System; +using namespace System::IO; +using namespace System::Xml::Serialization; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + void CacheableObjectXml::ToData(DataOutput^ output) + { + if (m_obj == nullptr) { + output->WriteByte((Byte)1); + } + else + { + output->WriteByte((Byte)0); + Type^ objType = m_obj->GetType(); + + output->WriteUTF(objType->AssemblyQualifiedName); + + output->AdvanceCursor(4); // placeholder for object size bytes needed while reading back. + + XmlSerializer xs(objType); + GFDataOutputStream dos(output); + int64_t checkpoint = dos.Length; + xs.Serialize(%dos, m_obj); + m_objectSize = (uint32_t) (dos.Length - checkpoint); + + output->RewindCursor(m_objectSize + 4); + output->WriteInt32(m_objectSize); + output->AdvanceCursor(m_objectSize); + } + } + + IGFSerializable^ CacheableObjectXml::FromData(DataInput^ input) + { + Byte isNull = input->ReadByte(); + if (isNull) { + m_obj = nullptr; + } + else { + String^ typeName = input->ReadUTF(); + Type^ objType = Type::GetType(typeName); + if (objType == nullptr) + { + Log::Error("CacheableObjectXml.FromData(): Cannot find type '" + + typeName + "'."); + m_obj = nullptr; + } + else { + int maxSize = input->ReadInt32(); + GFDataInputStream dis(input, maxSize); + XmlSerializer xs(objType); + uint32_t checkpoint = dis.BytesRead; + m_obj = xs.Deserialize(%dis); + m_objectSize = dis.BytesRead - checkpoint; + } + } + return this; + } + + uint32_t CacheableObjectXml::ObjectSize::get() + { + if (m_objectSize == 0) { + if (m_obj != nullptr) { + Type^ objType = m_obj->GetType(); + XmlSerializer xs(objType); + GFNullStream ns; + xs.Serialize(%ns, m_obj); + + m_objectSize = (uint32_t)sizeof(CacheableObjectXml^) + (uint32_t)ns.Length; + } + } + return m_objectSize; + } + } + } +} + } //namespace + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableObjectXmlN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableObjectXmlN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableObjectXmlN.hpp new file mode 100644 index 0000000..47bf408 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableObjectXmlN.hpp @@ -0,0 +1,147 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include "IGFSerializableN.hpp" +#include "GemFireClassIdsMN.hpp" + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// A mutable generic wrapper that can + /// serve as a distributable value for caching. + /// + /// + /// + /// This class can contain any object and uses the + /// to + /// serialize and deserialize the object. So the user must use the + /// XmlSerializer attributes to control the serialization/deserialization + /// of the object (or implement the ) + /// to change the serialization/deserialization. However, the latter should + /// be avoided for efficiency reasons and the user should implement + /// instead. + /// + /// The user must keep in mind that the rules that apply to XmlSerializer + /// would be the rules that apply to this class. For instance the user + /// cannot pass objects of class implementing or containing + /// class, must use + /// to + /// mark user-defined types etc. + /// + /// + public ref class CacheableObjectXml + : public IGFSerializable + { + public: + /// + /// Static function to create a new instance from the given object. + /// + /// + /// If the given object is null then this method returns null. + /// + inline static CacheableObjectXml^ Create(Object^ value) + { + return (value != nullptr ? gcnew CacheableObjectXml(value) : + nullptr); + } + + /// + /// Serializes this using + /// class. + /// + /// + /// the DataOutput object to use for serializing the object + /// + virtual void ToData(DataOutput^ output); + + /// + /// Deserializes the using + /// class. + /// + /// + /// the DataInput stream to use for reading the object data + /// + /// the deserialized object + virtual IGFSerializable^ FromData(DataInput^ input); + + /// + /// return the size of this object in bytes + /// + virtual property uint32_t ObjectSize + { + virtual uint32_t get(); + } + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + inline virtual uint32_t get() + { + return GemFireClassIds::CacheableManagedObjectXml; + } + } + + /// + /// Gets the object value. + /// + /// + /// The user can modify the object and the changes shall be reflected + /// immediately in the local cache. For this change to be propagate to + /// other members of the distributed system, the object needs to be + /// put into the cache. + /// + property Object^ Value + { + inline Object^ get() + { + return m_obj; + } + } + + virtual String^ ToString() override + { + return (m_obj == nullptr ? nullptr : m_obj->ToString()); + } + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableObjectXml(nullptr); + } + + internal: + /// + /// Allocates a new instance from the given object. + /// + inline CacheableObjectXml(Object^ value) + : m_obj(value), m_objectSize(0) { } + + private: + Object^ m_obj; + uint32_t m_objectSize; + }; + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableStackMN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableStackMN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableStackMN.cpp new file mode 100644 index 0000000..39efaa6 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableStackMN.cpp @@ -0,0 +1,82 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + + + +//#include "gf_includesN.hpp" +#include "CacheableStackMN.hpp" +#include "DataOutputMN.hpp" +#include "DataInputMN.hpp" +#include +#include "impl/SafeConvertN.hpp" +#include "GemFireClassIdsMN.hpp" + +using namespace System; +using namespace System::Collections::Generic; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + // Region: IGFSerializable Members + + void CacheableStack::ToData(DataOutput^ output) + { + if(m_stack != nullptr) + { + output->WriteArrayLen((int32_t)m_stack->Count); + for each (Object^ obj in m_stack) { + output->WriteObject(obj); + } + } + else + { + output->WriteByte(0xFF); + } + } + + IGFSerializable^ CacheableStack::FromData(DataInput^ input) + { + int len = input->ReadArrayLen(); + if (len > 0) + { + System::Collections::Generic::Stack^ stack = safe_cast^>(m_stack); + for( int i = 0; i < len; i++) + { + (stack)->Push(input->ReadObject()); +// Push(input->ReadObject()); + } + } + return this; + } + + uint32_t CacheableStack::ClassId::get() + { + return GemFireClassIds::CacheableStack; + } + + uint32_t CacheableStack::ObjectSize::get() + { + //TODO:hitesh + /*uint32_t size = static_cast (sizeof(CacheableStack^)); + for each (IGFSerializable^ val in this) { + if (val != nullptr) { + size += val->ObjectSize; + } + }*/ + return m_stack->Count; + } + + // End Region: IGFSerializable Members + } + } +} + } //namespace + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableStackMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableStackMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableStackMN.hpp new file mode 100644 index 0000000..9ce3e7d --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableStackMN.hpp @@ -0,0 +1,120 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include "IGFSerializableN.hpp" + + +using namespace System; +using namespace System::Collections::Generic; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// A mutable IGFSerializable vector wrapper that can serve as + /// a distributable object for caching. + /// + ref class CacheableStack + : public IGFSerializable + { + public: + /// + /// Allocates a new empty instance. + /// + inline CacheableStack(System::Collections::ICollection^ stack) + { + m_stack = stack; + } + + /// + /// Static function to create a new empty instance. + /// + inline static CacheableStack^ Create() + { + return gcnew CacheableStack(gcnew System::Collections::Generic::Stack()); + } + + /// + /// Static function to create a new empty instance. + /// + inline static CacheableStack^ Create(System::Collections::ICollection^ stack) + { + return gcnew CacheableStack(stack); + } + + + + // Region: IGFSerializable Members + + /// + /// Serializes this object. + /// + /// + /// the DataOutput object to use for serializing the object + /// + virtual void ToData(DataOutput^ output); + + /// + /// Deserialize this object, typical implementation should return + /// the 'this' pointer. + /// + /// + /// the DataInput stream to use for reading the object data + /// + /// the deserialized object + virtual IGFSerializable^ FromData(DataInput^ input); + + /// + /// return the size of this object in bytes + /// + virtual property uint32_t ObjectSize + { + virtual uint32_t get(); + } + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + virtual uint32_t get(); + } + + virtual property System::Collections::ICollection^ Value + { + virtual System::Collections::ICollection^ get() + { + return m_stack; + } + } + // End Region: IGFSerializable Members + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableStack(gcnew System::Collections::Generic::Stack()); + } + + private: + System::Collections::ICollection^ m_stack; + }; + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableStringArrayMN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableStringArrayMN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableStringArrayMN.cpp new file mode 100644 index 0000000..cf2029b --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableStringArrayMN.cpp @@ -0,0 +1,88 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + + +#include "CacheableStringArrayMN.hpp" +#include "CacheableStringMN.hpp" +#include "DataInputMN.hpp" +#include "DataOutputMN.hpp" +#include "ExceptionTypesMN.hpp" + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + + CacheableStringArray::CacheableStringArray(array^ strings) + : Serializable() + { + m_value = strings; + } + + + array^ CacheableStringArray::GetValues() + { + return m_value; + } + + String^ CacheableStringArray::default::get(int32_t 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); + } + } + } + + + IGFSerializable^ CacheableStringArray::FromData(DataInput^ input) + { + int len = input->ReadArrayLen(); + if ( len == -1) + { + m_value = nullptr; + return nullptr; + } + else + { + m_value = gcnew array(len); + if (len > 0) + { + for( int i = 0; i < len; i++) + { + m_value[i] = dynamic_cast(input->ReadObject()); + } + } + return this; + } + } + + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableStringArrayMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableStringArrayMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableStringArrayMN.hpp new file mode 100644 index 0000000..cfba324 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableStringArrayMN.hpp @@ -0,0 +1,180 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + + + +#include "../../gf_defs.hpp" +#include +#include "SerializableMN.hpp" +#include "GemFireClassIdsMN.hpp" +#include "CacheableStringMN.hpp" + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + ref class CacheableString; + + /// + /// An immutable wrapper for array of strings that can serve as + /// a distributable object for caching. + /// + ref class CacheableStringArray + : public Serializable + { + public: + /// + /// Static function to create a new instance copying from the given + /// string array. + /// + /// + /// If the given array of strings is null or of zero-length then + /// this method returns null. + /// + /// + /// If the array contains a string greater than or equal 64K in length. + /// + inline static CacheableStringArray^ Create(array^ strings) + { + return (strings != nullptr && strings->Length > 0 ? + gcnew CacheableStringArray(strings) : nullptr); + } + + /// + /// Serializes this managed object. + /// + /// + /// the DataOutput object to use for serializing the object + /// + virtual void ToData(DataOutput^ output) override; + + /// + /// Deserializes the managed object -- returns an instance of the + /// IGFSerializable class. + /// + /// + /// the DataInput stream to use for reading the object data + /// + /// the deserialized object + virtual IGFSerializable^ FromData(DataInput^ input) override; + + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + virtual uint32_t get() override + { + return GemFireClassIds::CacheableStringArray; + } + } + + /// + /// return the size of this object in bytes + /// + virtual property uint32_t ObjectSize + { + virtual uint32_t get() override + { + int size = 0; + for( int i = 0; i < m_value->Length; i++ ) + { + size += m_value[i]->Length; + } + return (uint32_t) (size + sizeof(this)); + } + + } + + /// + /// Returns a copy of the underlying array of strings. + /// + array^ GetValues(); + + /// + /// Returns a copy of the underlying string at the given index. + /// + property String^ GFINDEXER(int32_t) + { + String^ get(int32_t index); + } + + /// + /// Gets the length of the array. + /// + property int32_t Length + { + inline int32_t get() + { + return m_value->Length; + } + } + + virtual String^ ToString() override + { + return m_value->ToString(); + } + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableStringArray(); + } + + internal: + /// + /// Factory function to register wrapper + /// + static IGFSerializable^ Create(gemfire::Serializable* obj) + { + return (obj != nullptr ? + gcnew CacheableStringArray(obj) : nullptr); + } + + private: + array^ m_value; + /// + /// Allocates a new instance copying from the given string array. + /// + /// + /// If the array contains a string greater than or equal 64K in length. + /// + CacheableStringArray(array^ strings); + + + inline CacheableStringArray() + : Serializable() + { + //gemfire::Serializable* sp = gemfire::CacheableStringArray::createDeserializable(); + //SetSP(sp); + } + + /// + /// Private constructor to wrap a native object pointer + /// + /// The native object pointer + inline CacheableStringArray(gemfire::Serializable* nativeptr) + : Serializable(nativeptr) { } + }; + } + } +} + } //namespace + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableStringMN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableStringMN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableStringMN.cpp new file mode 100644 index 0000000..6588028 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableStringMN.cpp @@ -0,0 +1,202 @@ +/*========================================================================= +* Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. +*========================================================================= +*/ + + +#include "DataOutputMN.hpp" +#include "DataInputMN.hpp" + +//#include "gf_includesN.hpp" +#include "CacheableStringMN.hpp" +#include "ExceptionTypesMN.hpp" + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + + void CacheableString::ToData(DataOutput^ output) + { + if (m_type == GemFireClassIds::CacheableASCIIString || + m_type == GemFireClassIds::CacheableString) + { + output->WriteUTF(m_value); + } + else if (m_type == GemFireClassIds::CacheableASCIIStringHuge) + { + output->WriteASCIIHuge(m_value); + } + else + { + output->WriteUTFHuge(m_value); + } + } + + IGFSerializable^ CacheableString::FromData(DataInput^ input) + { + if (m_type == GemFireClassIds::CacheableASCIIString || + m_type == GemFireClassIds::CacheableString) + { + m_value = input->ReadUTF(); + } + else if (m_type == GemFireClassIds::CacheableASCIIStringHuge) + { + m_value = input->ReadASCIIHuge(); + } + else + { + m_value = input->ReadUTFHuge(); + } + + return this; + } + + + inline void CacheableString::GetCacheableString(String^ value, + gemfire::CacheableStringPtr& cStr) + { + size_t len; + if (value != nullptr && (len = value->Length) > 0) { + pin_ptr pin_value = PtrToStringChars(value); + cStr = gemfire::CacheableString::create(pin_value, (int32_t)len); + } + else { + cStr = (gemfire::CacheableString*) + gemfire::CacheableString::createDeserializable(); + } + } + + inline void CacheableString::GetCacheableString(array^ value, + gemfire::CacheableStringPtr& cStr) + { + size_t len; + if (value != nullptr && (len = value->Length) > 0) { + pin_ptr pin_value = &value[0]; + cStr = gemfire::CacheableString::create( + (const wchar_t*)pin_value, (int32_t)len); + } + else { + cStr = (gemfire::CacheableString*) + gemfire::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^ 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^ value, bool noParamCheck) + : CacheableKey() + { + m_value = gcnew String(value); + this->SetStringType(); + } + + uint32_t CacheableString::ObjectSize::get() + { + return (m_value->Length * sizeof(char)); + } + + bool CacheableString::Equals(GemStone::GemFire::Cache::Generic::ICacheableKey^ other) + { + if (other == nullptr || other->ClassId != ClassId) { + return false; + } + + CacheableString^ otherStr = + dynamic_cast(other); + + if (otherStr == nullptr) + return false; + + return m_value->Equals(otherStr->Value);//TODO::Hitesh + } + + bool CacheableString::Equals(Object^ obj) + { + CacheableString^ otherStr = + dynamic_cast(obj); + + if (otherStr != nullptr) { + return m_value->Equals(otherStr->Value); + } + return false; + } + + int32_t CacheableString::GetHashCode() + { + if (String::IsNullOrEmpty(m_value)) { + return 0; + } + //TODO:hitesh need to need java hashcode + //return m_value->GetHashCode(); + if(m_hashcode == 0) + { + int32_t prime = 31; + int32_t localHash = 0; + for (int32_t 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 = GemFireClassIds::CacheableASCIIStringHuge; + else + m_type = GemFireClassIds::CacheableASCIIString; + } + else + { + if (len > 0xFFFF) + m_type = GemFireClassIds::CacheableStringHuge; + else + m_type = GemFireClassIds::CacheableString; + } + } + } + } +} + } //namespace + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableStringMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableStringMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableStringMN.hpp new file mode 100644 index 0000000..012a8be --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableStringMN.hpp @@ -0,0 +1,313 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + + + +#include "../../gf_defs.hpp" +#include +#include "impl/ManagedStringN.hpp" +#include "CacheableKeyMN.hpp" +#include "GemFireClassIdsMN.hpp" + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// An immutable string wrapper that can serve as a distributable + /// key object for caching as well as being a string value. + /// + ref class CacheableString + : public CacheableKey + { + public: + /// + /// Allocates a new instance copying from the given string. + /// + /// the string value of the new instance + /// + /// if the provided string is null or has zero length + /// + CacheableString(String^ value); + + /// + /// Allocates a new instance copying from the given character array. + /// + /// + /// the character array value of the new instance + /// + /// + /// if the provided array is null or has zero length + /// + CacheableString(array^ value); + + /// + /// Static function to create a new instance copying from + /// the given string. + /// + /// + /// Providing a null or zero size string will return a null + /// CacheableString object. + /// + /// the string value of the new instance + inline static CacheableString^ Create(String^ value) + { + return (value != nullptr ? + gcnew CacheableString(value, true) : nullptr); + } + + /// + /// Serializes this managed object. + /// + /// + /// the DataOutput object to use for serializing the object + /// + virtual void ToData(DataOutput^ output) override; + + /// + /// Deserializes the managed object -- returns an instance of the + /// IGFSerializable class. + /// + /// + /// the DataInput stream to use for reading the object data + /// + /// the deserialized object + virtual IGFSerializable^ FromData(DataInput^ input) override; + + // + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + virtual uint32_t get() override + { + return m_type; + } + } + + + /// + /// return the size of this object in bytes + /// + virtual property uint32_t ObjectSize + { + virtual uint32_t get() override; + } + + /// + /// Static function to create a new instance copying from + /// the given character array. + /// + /// + /// Providing a null or zero size character array will return a null + /// CacheableString object. + /// + /// + /// the character array value of the new instance + /// + inline static CacheableString^ Create(array^ value) + { + return (value != nullptr && value->Length > 0 ? + gcnew CacheableString(value, true) : nullptr); + } + + /// + /// Return a string representation of the object. + /// This returns the same string as Value property. + /// + virtual String^ ToString() override + { + return m_value; + } + + /// + /// Return true if this key matches other object. + /// It invokes the '==' operator of the underlying + /// gemfire::CacheableString object. + /// + virtual bool Equals(GemStone::GemFire::Cache::Generic::ICacheableKey^ other) override; + + /// + /// Return true if this key matches other object. + /// It invokes the '==' operator of the underlying + /// gemfire::CacheableString object. + /// + virtual bool Equals(Object^ obj) override; + + /// + /// Return the hashcode for this key. + /// + virtual int32_t GetHashCode() override; + + /// + /// Gets the string value. + /// + property String^ Value + { + inline String^ get() + { + return m_value; + } + } + + /// + /// Static function to check whether IsNullOrEmpty. + /// + /// + /// This is similar to the C# string.IsNullOrEmpty method. + /// + /// the CacheableString value to check + inline static bool IsNullOrEmpty(CacheableString^ value) + { + return (value == nullptr || value->Length == 0); + } + + /// + /// Implicit conversion operator to underlying System.String. + /// + inline static operator String^ (CacheableString^ str) + { + return (str != nullptr ? CacheableString::GetString(str) : nullptr); + } + + /// + /// Gets the length of the underlying C string. + /// + property uint32_t Length + { + inline uint32_t get() + { + return m_value->Length; + } + } + + /// + /// True when the underlying C string is a wide-character string. + /// + property bool IsWideString + { + inline bool get() + { + return true;//TODO:hitesh + } + } + + internal: + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableString(GemFireClassIds::CacheableASCIIString); + } + + static IGFSerializable^ createDeserializableHuge() + { + return gcnew CacheableString(GemFireClassIds::CacheableASCIIStringHuge); + } + + static IGFSerializable^ createUTFDeserializable() + { + return gcnew CacheableString(GemFireClassIds::CacheableString); + } + + static IGFSerializable^ createUTFDeserializableHuge() + { + return gcnew CacheableString(GemFireClassIds::CacheableStringHuge); + } + /// + /// Factory function to register wrapper + /// + static IGFSerializable^ Create(gemfire::Serializable* obj) + { + return (obj != nullptr ? + gcnew CacheableString(obj) : nullptr); + } + + /// + /// Internal function to create a gemfire::CacheableString + /// from the given managed string. + /// + static void GetCacheableString(String^ value, + gemfire::CacheableStringPtr& cStr); + + /// + /// Internal function to create a gemfire::CacheableString + /// from the given managed array of characters. + /// + static void GetCacheableString(array^ value, + gemfire::CacheableStringPtr& cStr); + + /// + /// Get the System.String from the given + /// gemfire::CacheableString + /// + inline static String^ GetString(gemfire::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(uint32_t type): CacheableKey() + { + m_type = type; + } + + private: + String^ m_value; + uint32_t m_type; + int m_hashcode; + + CacheableString(): CacheableKey() + { + m_type = GemFireClassIds::CacheableASCIIString; + } + + void SetStringType(); + /// + /// Private constructor to create a CacheableString without checking + /// for arguments. + /// + CacheableString(String^ value, bool noParamCheck); + + /// + /// Private constructor to create a CacheableString without checking + /// for arguments. + /// + CacheableString(array^ value, bool noParamCheck); + + /// + /// Private constructor to wrap a native object pointer + /// + /// The native object pointer + inline CacheableString(gemfire::Serializable* nativeptr) + : CacheableKey(nativeptr) { } + }; + } + } +} + } //namespace + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableUndefinedMN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableUndefinedMN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableUndefinedMN.cpp new file mode 100644 index 0000000..3ddc35c --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableUndefinedMN.cpp @@ -0,0 +1,45 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + + + +//#include "gf_includesN.hpp" +#include "CacheableUndefinedMN.hpp" +#include "DataOutputMN.hpp" +#include "DataInputMN.hpp" + + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + // Region: IGFSerializable Members + + void CacheableUndefined::ToData(DataOutput^ output) + { + } + + IGFSerializable^ CacheableUndefined::FromData(DataInput^ input) + { + return this; + } + + uint32_t CacheableUndefined::ObjectSize::get() + { + return static_cast (sizeof(CacheableUndefined^)); + } + + // End Region: IGFSerializable Members + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableUndefinedMN.hpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableUndefinedMN.hpp b/geode-client-native/src/clicache/com/vmware/CacheableUndefinedMN.hpp new file mode 100644 index 0000000..d61d1e5 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableUndefinedMN.hpp @@ -0,0 +1,99 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + +#pragma once + +#include "../../gf_defs.hpp" +#include "IGFSerializableN.hpp" +#include "GemFireClassIdsMN.hpp" +#include "LogMN.hpp" + +using namespace System; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + /// + /// Encapsulate an undefined result. + /// + public ref class CacheableUndefined + : public IGFSerializable + { + public: + /// + /// Allocates a new empty instance. + /// + inline CacheableUndefined() { } + + /// + /// Static function to create a new empty instance. + /// + inline static CacheableUndefined^ Create() + { + return gcnew CacheableUndefined(); + } + + // Region: IGFSerializable Members + + /// + /// Serializes this object. + /// + /// + /// the DataOutput object to use for serializing the object + /// + virtual void ToData(DataOutput^ output); + + /// + /// Deserialize this object, typical implementation should return + /// the 'this' pointer. + /// + /// + /// the DataInput stream to use for reading the object data + /// + /// the deserialized object + virtual IGFSerializable^ FromData(DataInput^ input); + + /// + /// return the size of this object in bytes + /// + virtual property uint32_t ObjectSize + { + virtual uint32_t get(); + } + + /// + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// + /// the classId + virtual property uint32_t ClassId + { + inline virtual uint32_t get() + { + return GemFireClassIds::CacheableUndefined; + } + } + + // End Region: IGFSerializable Members + + /// + /// Factory function to register this class. + /// + static IGFSerializable^ CreateDeserializable() + { + return gcnew CacheableUndefined(); + } + }; + } + } +} + } //namespace http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac967000/geode-client-native/src/clicache/com/vmware/CacheableVectorMN.cpp ---------------------------------------------------------------------- diff --git a/geode-client-native/src/clicache/com/vmware/CacheableVectorMN.cpp b/geode-client-native/src/clicache/com/vmware/CacheableVectorMN.cpp new file mode 100644 index 0000000..82483f9 --- /dev/null +++ b/geode-client-native/src/clicache/com/vmware/CacheableVectorMN.cpp @@ -0,0 +1,70 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ + + + +//#include "gf_includesN.hpp" +#include "CacheableVectorMN.hpp" +#include "DataOutputMN.hpp" +#include "DataInputMN.hpp" +#include "ExceptionTypesMN.hpp" +#include "impl/SafeConvertN.hpp" + +using namespace System; +using namespace System::Collections::Generic; + +namespace GemStone +{ + namespace GemFire + { + namespace Cache { namespace Generic + { + // Region: IGFSerializable 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); + } + + IGFSerializable^ CacheableVector::FromData(DataInput^ input) + { + int len = input->ReadArrayLen(); + for( int i = 0; i < len; i++) + { + m_arrayList->Add(input->ReadObject()); + } + return this; + } + + uint32_t CacheableVector::ObjectSize::get() + { + //TODO::hitesh + /*uint32_t size = static_cast (sizeof(CacheableVector^)); + for each (IGFSerializable^ val in this) { + if (val != nullptr) { + size += val->ObjectSize; + } + }*/ + return m_arrayList->Count; + } + + // End Region: IGFSerializable Members + } + } +} + } //namespace +