http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/DataOutput.cpp
----------------------------------------------------------------------
diff --git a/clicache/src/DataOutput.cpp b/clicache/src/DataOutput.cpp
new file mode 100644
index 0000000..8b1d1cc
--- /dev/null
+++ b/clicache/src/DataOutput.cpp
@@ -0,0 +1,921 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "begin_native.hpp"
+#include <GeodeTypeIdsImpl.hpp>
+#include "CacheRegionHelper.hpp"
+#include "CacheImpl.hpp"
+#include "end_native.hpp"
+
+#include <vcclr.h>
+
+#include "DataOutput.hpp"
+#include "IGeodeSerializable.hpp"
+#include "CacheableObjectArray.hpp"
+#include "impl/PdxHelper.hpp"
+#include "impl/PdxWrapper.hpp"
+
+using namespace System;
+using namespace System::Runtime::InteropServices;
+using namespace apache::geode::client;
+
+namespace Apache
+{
+  namespace Geode
+  {
+    namespace Client
+    {
+
+      void DataOutput::WriteByte(Byte value)
+      {
+        EnsureCapacity(1);
+        m_bytes[m_cursor++] = value;
+      }
+
+      void DataOutput::WriteSByte(SByte value)
+      {
+        EnsureCapacity(1);
+        m_bytes[m_cursor++] = value;
+      }
+
+      void DataOutput::WriteBoolean(bool value)
+      {
+        EnsureCapacity(1);
+        if (value)
+          m_bytes[m_cursor++] = 0x01;
+        else
+          m_bytes[m_cursor++] = 0x00;
+      }
+
+      void DataOutput::WriteChar(Char value)
+      {
+        EnsureCapacity(2);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 8);
+        m_bytes[m_cursor++] = (System::Byte)value;
+      }
+
+      void DataOutput::WriteBytes(array<Byte>^ bytes, System::Int32 len)
+      {
+        if (bytes != nullptr && bytes->Length >= 0)
+        {
+          if (len >= 0 && len <= bytes->Length)
+          {
+            WriteArrayLen(len);
+            EnsureCapacity(len);
+            for (int i = 0; i < len; i++)
+              m_bytes[m_cursor++] = bytes[i];
+          }
+          else
+          {
+            throw gcnew IllegalArgumentException("DataOutput::WriteBytes 
argument len is not in byte array range.");
+          }
+        }
+        else
+        {
+          WriteByte(0xFF);
+        }
+      }
+
+      void DataOutput::WriteArrayLen(System::Int32 len)
+      {
+        if (len == -1) {//0xff
+          WriteByte(0xFF);
+        }
+        else if (len <= 252) { // 252 is java's ((byte)-4 && 0xFF) or 0xfc
+          WriteByte((Byte)(len));
+        }
+        else if (len <= 0xFFFF) {
+          WriteByte(0xFE);//0xfe
+          WriteUInt16((len));
+        }
+        else {
+          WriteByte((0xFD));//0xfd
+          WriteUInt32(len);
+        }
+      }
+
+      void DataOutput::WriteSBytes(array<SByte>^ bytes, System::Int32 len)
+      {
+        if (bytes != nullptr && bytes->Length >= 0)
+        {
+          if (len >= 0 && len <= bytes->Length)
+          {
+            WriteArrayLen(len);
+            EnsureCapacity(len);
+            for (int i = 0; i < len; i++)
+              m_bytes[m_cursor++] = bytes[i];
+          }
+          else
+          {
+            throw gcnew IllegalArgumentException("DataOutput::WriteSBytes 
argument len is not in SByte array range.");
+          }
+        }
+        else
+        {
+          WriteByte(0xFF);
+        }
+      }
+
+      void DataOutput::WriteBytesOnly(array<Byte>^ bytes, System::UInt32 len)
+      {
+        WriteBytesOnly(bytes, len, 0);
+      }
+
+      void DataOutput::WriteBytesOnly(array<Byte>^ bytes, System::UInt32 len, 
System::UInt32 offset)
+      {
+        if (bytes != nullptr)
+        {
+          if (len >= 0 && len <= ((System::UInt32)bytes->Length - offset))
+          {
+            EnsureCapacity(len);
+            for (System::UInt32 i = 0; i < len; i++)
+              m_bytes[m_cursor++] = bytes[offset + i];
+          }
+          else
+          {
+            throw gcnew IllegalArgumentException("DataOutput::WriteBytesOnly 
argument len is not in Byte array range.");
+          }
+        }
+      }
+
+      void DataOutput::WriteSBytesOnly(array<SByte>^ bytes, System::UInt32 len)
+      {
+        if (bytes != nullptr)
+        {
+          if (len >= 0 && len <= (System::UInt32)bytes->Length)
+          {
+            EnsureCapacity(len);
+            for (System::UInt32 i = 0; i < len; i++)
+              m_bytes[m_cursor++] = bytes[i];
+          }
+          else
+          {
+            throw gcnew IllegalArgumentException("DataOutput::WriteSBytesOnly 
argument len is not in SByte array range.");
+          }
+        }
+      }
+
+      void DataOutput::WriteUInt16(System::UInt16 value)
+      {
+        EnsureCapacity(2);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 8);
+        m_bytes[m_cursor++] = (System::Byte)value;
+      }
+
+      void DataOutput::WriteUInt32(System::UInt32 value)
+      {
+        EnsureCapacity(4);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 24);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 16);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 8);
+        m_bytes[m_cursor++] = (System::Byte)value;
+      }
+
+      void DataOutput::WriteUInt64(System::UInt64 value)
+      {
+        EnsureCapacity(8);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 56);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 48);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 40);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 32);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 24);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 16);
+        m_bytes[m_cursor++] = (System::Byte)(value >> 8);
+        m_bytes[m_cursor++] = (System::Byte)value;
+      }
+
+      void DataOutput::WriteInt16(System::Int16 value)
+      {
+        WriteUInt16(value);
+      }
+
+      void DataOutput::WriteInt32(System::Int32 value)
+      {
+        WriteUInt32(value);
+      }
+
+      void DataOutput::WriteInt64(System::Int64 value)
+      {
+        WriteUInt64(value);
+      }
+
+      void DataOutput::WriteFloat(float value)
+      {
+        array<Byte>^ bytes = BitConverter::GetBytes(value);
+        EnsureCapacity(4);
+        for (int i = 4 - 1; i >= 0; i--)
+          m_bytes[m_cursor++] = bytes[i];
+      }
+
+      void DataOutput::WriteDouble(double value)
+      {
+        array<Byte>^ bytes = BitConverter::GetBytes(value);
+        EnsureCapacity(8);
+        for (int i = 8 - 1; i >= 0; i--)
+          m_bytes[m_cursor++] = bytes[i];
+      }
+
+      void DataOutput::WriteDictionary(System::Collections::IDictionary^ dict)
+      {
+        if (dict != nullptr)
+        {
+          this->WriteArrayLen(dict->Count);
+          for each(System::Collections::DictionaryEntry^ entry in dict)
+          {
+            this->WriteObject(entry->Key);
+            this->WriteObject(entry->Value);
+          }
+        }
+        else
+        {
+          WriteByte((int8_t)-1);
+        }
+      }
+
+      void DataOutput::WriteCollection(System::Collections::IList^ collection)
+      {
+        if (collection != nullptr)
+        {
+          this->WriteArrayLen(collection->Count);
+          for each (Object^ obj in collection) {
+            this->WriteObject(obj);
+          }
+        }
+        else
+          this->WriteByte((int8_t)-1);
+      }
+
+      void DataOutput::WriteDate(System::DateTime date)
+      {
+        if (date.Ticks != 0L)
+        {
+          CacheableDate^ cd = gcnew CacheableDate(date);
+          cd->ToData(this);
+        }
+        else
+          this->WriteInt64(-1L);
+      }
+
+      void DataOutput::WriteCharArray(array<Char>^ charArray)
+      {
+        if (charArray != nullptr)
+        {
+          this->WriteArrayLen(charArray->Length);
+          for (int i = 0; i < charArray->Length; i++) {
+            this->WriteObject(charArray[i]);
+          }
+        }
+        else
+          this->WriteByte((int8_t)-1);
+      }
+
+      void DataOutput::WriteObjectArray(List<Object^>^ objectArray)
+      {
+        if (objectArray != nullptr)
+        {
+          CacheableObjectArray^ coa = 
CacheableObjectArray::Create(objectArray);
+          coa->ToData(this);
+        }
+        else
+          this->WriteByte((int8_t)-1);
+      }
+
+      void DataOutput::WriteDotNetObjectArray(Object^ objectArray)
+      {
+        System::Collections::IList^ list = 
(System::Collections::IList^)objectArray;
+        this->WriteArrayLen(list->Count);
+        WriteByte((int8_t)apache::geode::client::GeodeTypeIdsImpl::Class);
+        String^ pdxDomainClassname = 
Serializable::GetPdxTypeName(objectArray->GetType()->GetElementType()->FullName);
+        
WriteByte((int8_t)apache::geode::client::GeodeTypeIds::CacheableASCIIString);
+        WriteUTF(pdxDomainClassname);
+        for each(Object^ o in list)
+          WriteObject(o);
+      }
+
+      void DataOutput::WriteArrayOfByteArrays(array<array<Byte>^>^ byteArrays)
+      {
+        if (byteArrays != nullptr)
+        {
+          int fdLen = byteArrays->Length;
+          this->WriteArrayLen(byteArrays->Length);
+          for (int i = 0; i < fdLen; i++) {
+            this->WriteBytes(byteArrays[i]);
+          }
+        }
+        else
+          this->WriteByte((int8_t)-1);
+      }
+
+      void DataOutput::WriteUTF(String^ value)
+      {
+        if (value != nullptr) {
+          int len = getEncodedLength(value);
+
+          if (len > 0xffff)
+            len = 0xffff;
+
+          WriteUInt16(len);
+          EnsureCapacity(len);
+          EncodeUTF8String(value, len);
+        }
+        else {
+          WriteUInt16(0);
+        }
+      }
+
+      void DataOutput::WriteStringWithType(String^ value)
+      {
+        //value will not be null
+        int len = getEncodedLength(value);
+
+        if (len > 0xffff)
+        {
+          if (len == value->Length)//huge ascii
+          {
+            WriteByte(GeodeTypeIds::CacheableASCIIStringHuge);
+            WriteASCIIHuge(value);
+          }
+          else//huge utf
+          {
+            WriteByte(GeodeTypeIds::CacheableStringHuge);
+            WriteUTFHuge(value);
+          }
+          return;
+        }
+
+        if (len == value->Length)
+        {
+          WriteByte(GeodeTypeIds::CacheableASCIIString);//ascii string
+        }
+        else
+        {
+          WriteByte(GeodeTypeIds::CacheableString);//utf string
+        }
+        WriteUInt16(len);
+        EnsureCapacity(len);
+        EncodeUTF8String(value, len);
+
+      }
+
+      void DataOutput::WriteASCIIHuge(String^ value)
+      {
+        if (value != nullptr) {
+          const int strLength = value->Length;
+          WriteUInt32(strLength);
+          EnsureCapacity(strLength);
+          for (int i = 0; i < strLength; i++) {
+            m_bytes[m_cursor++] = (System::Byte)value[i];
+          }
+        }
+        else {
+          WriteUInt32(0);
+        }
+      }
+
+      /* Write UTF-16 */
+      void DataOutput::WriteUTFHuge(String^ value)
+      {
+        if (value != nullptr) {
+          WriteUInt32(value->Length);
+          EnsureCapacity(value->Length * 2);
+          for (int i = 0; i < value->Length; i++)
+          {
+            Char ch = value[i];
+            m_bytes[m_cursor++] = (Byte)((ch & 0xff00) >> 8);
+            m_bytes[m_cursor++] = (Byte)(ch & 0xff);
+          }
+        }
+        else {
+          WriteUInt32(0);
+        }
+      }
+
+      /*void DataOutput::WriteObject( Object^ obj )
+      {
+      WriteObjectInternal((IGeodeSerializable^)obj);
+      }*/
+
+      /*void DataOutput::WriteObject( Object^ obj )
+      {
+      WriteObject( (IGeodeSerializable^)obj );
+      }*/
+
+      int8_t DataOutput::GetTypeId(System::UInt32 classId)
+      {
+        if (classId >= 0x80000000) {
+          return (int8_t)((classId - 0x80000000) % 0x20000000);
+        }
+        else if (classId <= 0x7F) {
+          return (int8_t)GeodeTypeIdsImpl::CacheableUserData;
+        }
+        else if (classId <= 0x7FFF) {
+          return (int8_t)GeodeTypeIdsImpl::CacheableUserData2;
+        }
+        else {
+          return (int8_t)GeodeTypeIdsImpl::CacheableUserData4;
+        }
+      }
+
+      int8_t DataOutput::DSFID(System::UInt32 classId)
+      {
+        // 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
+        if (classId >= 0x80000000) {
+          return (int8_t)((classId - 0x80000000) / 0x20000000);
+        }
+        return 0;
+      }
+
+      void DataOutput::WriteObject(Object^ obj)
+      {
+
+        if (obj == nullptr)
+        {
+          WriteByte((int8_t)GeodeTypeIds::NullObj);
+          return;
+        }
+
+        if (m_ispdxSerialization && obj->GetType()->IsEnum)
+        {
+          //need to set             
+          int enumVal = 
Internal::PdxHelper::GetEnumValue(obj->GetType()->FullName, 
Enum::GetName(obj->GetType(), obj), obj->GetHashCode(), 
m_nativeptr->get()->getCache());
+          WriteByte(GeodeClassIds::PDX_ENUM);
+          WriteByte(enumVal >> 24);
+          WriteArrayLen(enumVal & 0xFFFFFF);
+          return;
+        }
+
+        //Apache::Geode::Client::Log::Debug("DataOutput::WriteObject " + obj);
+
+        Byte typeId = 
Apache::Geode::Client::Serializable::GetManagedTypeMappingGeneric(obj->GetType());
+
+        switch (typeId)
+        {
+        case apache::geode::client::GeodeTypeIds::CacheableByte:
+        {
+          WriteByte(typeId);
+          WriteSByte((SByte)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableBoolean:
+        {
+          WriteByte(typeId);
+          WriteBoolean((bool)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableWideChar:
+        {
+          WriteByte(typeId);
+          WriteObject((Char)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableDouble:
+        {
+          WriteByte(typeId);
+          WriteDouble((Double)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableASCIIString:
+        {
+          //CacheableString^ cStr = CacheableString::Create((String^)obj);
+          ////  TODO: igfser mapping between generic and non generic
+          //WriteObjectInternal(cStr);
+          WriteStringWithType((String^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableFloat:
+        {
+          WriteByte(typeId);
+          WriteFloat((float)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableInt16:
+        {
+          WriteByte(typeId);
+          WriteInt16((Int16)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableInt32:
+        {
+          WriteByte(typeId);
+          WriteInt32((Int32)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableInt64:
+        {
+          WriteByte(typeId);
+          WriteInt64((Int64)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableDate:
+        {
+          //CacheableDate^ cd = gcnew CacheableDate((DateTime)obj);
+          //  TODO: igfser mapping between generic and non generic
+          //WriteObjectInternal(cd);
+          WriteByte(typeId);
+          WriteDate((DateTime)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableBytes:
+        {
+          WriteByte(typeId);
+          WriteBytes((array<Byte>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableDoubleArray:
+        {
+          WriteByte(typeId);
+          WriteObject((array<Double>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableFloatArray:
+        {
+          WriteByte(typeId);
+          WriteObject((array<float>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableInt16Array:
+        {
+          WriteByte(typeId);
+          WriteObject((array<Int16>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableInt32Array:
+        {
+          WriteByte(typeId);
+          WriteObject((array<Int32>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableInt64Array:
+        {
+          WriteByte(typeId);
+          WriteObject((array<Int64>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::BooleanArray:
+        {
+          WriteByte(typeId);
+          WriteObject((array<bool>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CharArray:
+        {
+          WriteByte(typeId);
+          WriteObject((array<char>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableStringArray:
+        {
+          WriteByte(typeId);
+          WriteObject((array<String^>^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableHashTable:
+        case apache::geode::client::GeodeTypeIds::CacheableHashMap:
+        case apache::geode::client::GeodeTypeIds::CacheableIdentityHashMap:
+        {
+          WriteByte(typeId);
+          WriteDictionary((System::Collections::IDictionary^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableVector:
+        {
+          //CacheableVector^ cv = gcnew 
CacheableVector((System::Collections::IList^)obj);
+          ////  TODO: igfser mapping between generic and non generic
+          //WriteObjectInternal(cv);
+          WriteByte(apache::geode::client::GeodeTypeIds::CacheableVector);
+          WriteList((System::Collections::IList^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableLinkedList:
+        {
+          //CacheableArrayList^ cal = gcnew 
CacheableArrayList((System::Collections::IList^)obj);
+          ////  TODO: igfser mapping between generic and non generic
+          //WriteObjectInternal(cal);
+          WriteByte(apache::geode::client::GeodeTypeIds::CacheableLinkedList);
+          System::Collections::ICollection^ linkedList = 
(System::Collections::ICollection^)obj;
+          this->WriteArrayLen(linkedList->Count);
+          for each (Object^ o in linkedList)
+            this->WriteObject(o);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableArrayList:
+        {
+          //CacheableArrayList^ cal = gcnew 
CacheableArrayList((System::Collections::IList^)obj);
+          ////  TODO: igfser mapping between generic and non generic
+          //WriteObjectInternal(cal);
+          WriteByte(apache::geode::client::GeodeTypeIds::CacheableArrayList);
+          WriteList((System::Collections::IList^)obj);
+          return;
+        }
+        case apache::geode::client::GeodeTypeIds::CacheableStack:
+        {
+          CacheableStack^ cs = gcnew 
CacheableStack((System::Collections::ICollection^)obj);
+          //  TODO: igfser mapping between generic and non generic
+          WriteObjectInternal(cs);
+          return;
+        }
+        default:
+        {
+          IPdxSerializable^ pdxObj = dynamic_cast<IPdxSerializable^>(obj);
+          if (pdxObj != nullptr)
+          {
+            WriteByte(GeodeClassIds::PDX);
+            Internal::PdxHelper::SerializePdx(this, pdxObj);
+            return;
+          }
+          else
+          {
+            //pdx serialization and is array of object
+            if (m_ispdxSerialization && obj->GetType()->IsArray)
+            {
+              
WriteByte(apache::geode::client::GeodeTypeIds::CacheableObjectArray);
+              WriteDotNetObjectArray(obj);
+              return;
+            }
+
+            IGeodeSerializable^ ct = dynamic_cast<IGeodeSerializable^>(obj);
+            if (ct != nullptr) {
+              WriteObjectInternal(ct);
+              return;
+            }
+
+            if (Serializable::IsObjectAndPdxSerializerRegistered(nullptr))
+            {
+              pdxObj = gcnew PdxWrapper(obj);
+              WriteByte(GeodeClassIds::PDX);
+              Internal::PdxHelper::SerializePdx(this, pdxObj);
+              return;
+            }
+          }
+
+          throw gcnew System::Exception("DataOutput not found appropriate type 
to write it for object: " + obj->GetType());
+        }
+        }
+      }
+
+      void DataOutput::WriteStringArray(array<String^>^ strArray)
+      {
+        if (strArray != nullptr)
+        {
+          this->WriteArrayLen(strArray->Length);
+          for (int i = 0; i < strArray->Length; i++)
+          {
+            // this->WriteUTF(strArray[i]);
+            WriteObject(strArray[i]);
+          }
+        }
+        else
+          WriteByte(-1);
+      }
+
+      void DataOutput::WriteObjectInternal(IGeodeSerializable^ obj)
+      {
+        //CacheableKey^ key = gcnew CacheableKey();
+        if (obj == nullptr) {
+          WriteByte((int8_t)GeodeTypeIds::NullObj);
+        }
+        else {
+          int8_t typeId = DataOutput::GetTypeId(obj->ClassId);
+          switch (DataOutput::DSFID(obj->ClassId)) {
+          case GeodeTypeIdsImpl::FixedIDByte:
+            WriteByte((int8_t)GeodeTypeIdsImpl::FixedIDByte);
+            WriteByte(typeId); // write the type ID.
+            break;
+          case GeodeTypeIdsImpl::FixedIDShort:
+            WriteByte((int8_t)GeodeTypeIdsImpl::FixedIDShort);
+            WriteInt16((System::Int16)typeId); // write the type ID.
+            break;
+          case GeodeTypeIdsImpl::FixedIDInt:
+            WriteByte((int8_t)GeodeTypeIdsImpl::FixedIDInt);
+            WriteInt32((System::Int32)typeId); // write the type ID.
+            break;
+          default:
+            WriteByte(typeId); // write the type ID.
+            break;
+          }
+
+          if ((System::Int32)typeId == GeodeTypeIdsImpl::CacheableUserData) {
+            WriteByte((int8_t)obj->ClassId);
+          }
+          else if ((System::Int32)typeId == 
GeodeTypeIdsImpl::CacheableUserData2) {
+            WriteInt16((System::Int16)obj->ClassId);
+          }
+          else if ((System::Int32)typeId == 
GeodeTypeIdsImpl::CacheableUserData4) {
+            WriteInt32((System::Int32)obj->ClassId);
+          }
+          obj->ToData(this); // let the obj serialize itself.
+        }
+      }
+
+      void DataOutput::AdvanceCursor(System::UInt32 offset)
+      {
+        EnsureCapacity(offset);
+        m_cursor += offset;
+      }
+
+      void DataOutput::RewindCursor(System::UInt32 offset)
+      {
+        //first set native one
+        WriteBytesToUMDataOutput();
+        try
+        {
+          m_nativeptr->get()->rewindCursor(offset);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+        SetBuffer();
+      }
+
+      array<Byte>^ DataOutput::GetBuffer()
+      {
+        try
+        {
+          WriteBytesToUMDataOutput();
+          SetBuffer();
+          int buffLen = m_nativeptr->get()->getBufferLength();
+          array<Byte>^ buffer = gcnew array<Byte>(buffLen);
+
+          if (buffLen > 0) {
+            pin_ptr<Byte> pin_buffer = &buffer[0];
+            memcpy((void*)pin_buffer, m_nativeptr->get()->getBuffer(), 
buffLen);
+          }
+          return buffer;
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+
+      System::UInt32 DataOutput::BufferLength::get()
+      {
+        //first set native one
+        WriteBytesToUMDataOutput();
+        SetBuffer();
+
+        try
+        {
+          return m_nativeptr->get()->getBufferLength();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+
+      void DataOutput::Reset()
+      {
+        WriteBytesToUMDataOutput();
+        try
+        {
+          m_nativeptr->get()->reset();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+        SetBuffer();
+      }
+
+      void DataOutput::WriteString(String^ value)
+      {
+        if (value == nullptr)
+        {
+          this->WriteByte(GeodeTypeIds::CacheableNullString);
+        }
+        else
+        {
+          WriteObject(value);
+          /*CacheableString^ cs = gcnew CacheableString(value);
+
+          this->WriteByte( (Byte)(cs->ClassId - 0x80000000));
+          cs->ToData(this);*/
+        }
+      }
+
+      void DataOutput::WriteBytesToUMDataOutput()
+      {
+        try
+        {
+          m_nativeptr->get()->advanceCursor(m_cursor);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+        m_cursor = 0;
+        m_remainingBufferLength = 0;
+        m_bytes = nullptr;
+      }
+
+      void DataOutput::WriteObject(bool% obj)
+      {
+        WriteBoolean(obj);
+      }
+
+      void DataOutput::WriteObject(Byte% obj)
+      {
+        WriteByte(obj);
+      }
+
+      void DataOutput::WriteObject(Char% obj)
+      {
+        unsigned short us = (unsigned short)obj;
+        EnsureCapacity(2);
+        m_bytes[m_cursor++] = us >> 8;
+        m_bytes[m_cursor++] = (Byte)us;
+      }
+
+      void DataOutput::WriteObject(Double% obj)
+      {
+        WriteDouble(obj);
+      }
+
+      void DataOutput::WriteObject(Single% obj)
+      {
+        WriteFloat(obj);
+      }
+
+      void DataOutput::WriteObject(System::Int16% obj)
+      {
+        WriteInt16(obj);
+      }
+
+      void DataOutput::WriteObject(System::Int32% obj)
+      {
+        WriteInt32(obj);
+      }
+
+      void DataOutput::WriteObject(System::Int64% obj)
+      {
+        WriteInt64(obj);
+      }
+
+      void DataOutput::WriteObject(UInt16% obj)
+      {
+        WriteUInt16(obj);
+      }
+
+      void DataOutput::WriteObject(UInt32% obj)
+      {
+        WriteUInt32(obj);
+      }
+
+      void DataOutput::WriteObject(UInt64% obj)
+      {
+        WriteUInt64(obj);
+      }
+
+      void DataOutput::WriteBooleanArray(array<bool>^ boolArray)
+      {
+        WriteObject<bool>(boolArray);
+      }
+
+      void DataOutput::WriteShortArray(array<Int16>^ shortArray)
+      {
+        WriteObject<Int16>(shortArray);
+      }
+
+      void DataOutput::WriteIntArray(array<Int32>^ intArray)
+      {
+        WriteObject<Int32>(intArray);
+      }
+
+      void DataOutput::WriteLongArray(array<Int64>^ longArray)
+      {
+        WriteObject<Int64>(longArray);
+      }
+
+      void DataOutput::WriteFloatArray(array<float>^ floatArray)
+      {
+        WriteObject<float>(floatArray);
+      }
+
+      void DataOutput::WriteDoubleArray(array<double>^ doubleArray)
+      {
+        WriteObject<double>(doubleArray);
+      }
+    }  // namespace Client
+  }  // namespace Geode
+}  // namespace Apache

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/DataOutput.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/DataOutput.hpp b/clicache/src/DataOutput.hpp
new file mode 100644
index 0000000..c98245c
--- /dev/null
+++ b/clicache/src/DataOutput.hpp
@@ -0,0 +1,656 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "geode_defs.hpp"
+#include "begin_native.hpp"
+#include <geode/DataOutput.hpp>
+#include <geode/Cache.hpp>
+#include "end_native.hpp"
+
+#include "native_conditional_unique_ptr.hpp"
+#include "Log.hpp"
+#include "ExceptionTypes.hpp"
+#include "Serializable.hpp"
+
+#include "CacheableString.hpp"
+#include "CacheableDate.hpp"
+#include "CacheableVector.hpp"
+#include "CacheableArrayList.hpp"
+#include "CacheableStack.hpp"
+
+using namespace System;
+using namespace System::Runtime::CompilerServices;
+
+namespace Apache
+{
+  namespace Geode
+  {
+    namespace Client
+    {
+      namespace native = apache::geode::client;
+
+      interface class IGeodeSerializable;
+
+      /// <summary>
+      /// Provides operations for writing primitive data values, and
+      /// user-defined objects implementing IGeodeSerializable, to a byte 
stream.
+      /// This class is intentionally not thread safe.
+      /// </summary>
+      public ref class DataOutput sealed
+      {
+      private:
+        System::Int32 m_cursor;
+        bool m_isManagedObject;
+        System::Byte * m_bytes;
+        System::Int32 m_remainingBufferLength;
+        bool m_ispdxSerialization;
+        native_conditional_unique_ptr<native::DataOutput>^ m_nativeptr;
+
+      public:
+
+        /// <summary>
+        /// Default constructor.
+        /// </summary>
+        inline DataOutput(native::Cache* cache)
+        { 
+          m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DataOutput>(cache->createDataOutput());
+          m_isManagedObject = true;
+          m_cursor = 0;
+          try
+          {
+            m_bytes = const_cast<System::Byte 
*>(m_nativeptr->get()->getCursor());
+            m_remainingBufferLength = 
(System::Int32)m_nativeptr->get()->getRemainingBufferLength();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
+          m_ispdxSerialization = false;
+        }
+
+        /// <summary>
+        /// Write length of the array to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="len">Array len to write.</param>
+        void WriteArrayLen( System::Int32 len );
+        
+        /// <summary>
+        /// Write a signed byte to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The signed byte to write.</param>
+        void WriteSByte( SByte value );
+
+        /// <summary>
+        /// Write a boolean value to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The boolean value to write.</param>
+        void WriteBoolean( bool value );
+
+                               /// <summary>
+        /// Write a char value to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The char value to write.</param>
+        void WriteChar( Char value );
+
+        /// <summary>
+        /// Write a given length of bytes to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="bytes">The array of bytes to write.</param>
+        /// <param name="len">
+        /// The number of bytes from the start of array to write.
+        /// </param>
+        void WriteBytes( array<Byte>^ bytes, System::Int32 len );
+
+        /// <summary>
+        /// Write an array of bytes to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="bytes">The array of bytes to write.</param>
+        inline void WriteBytes( array<Byte>^ bytes )
+        {
+          WriteBytes( bytes, ( bytes == nullptr ? -1 : bytes->Length ) );
+        }
+
+        /// <summary>
+        /// Write a given length of signed bytes to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="bytes">The array of signed bytes to write.</param>
+        /// <param name="len">
+        /// The number of bytes from the start of array to write.
+        /// </param>
+        void WriteSBytes( array<SByte>^ bytes, System::Int32 len );
+
+        /// <summary>
+        /// Write an array of signed bytes to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="bytes">The array of signed bytes to write.</param>
+        inline void WriteSBytes( array<SByte>^ bytes )
+        {
+          WriteSBytes( bytes, ( bytes == nullptr ? -1 : bytes->Length )  );
+        }
+
+        /// <summary>
+        /// Write a given length of bytes without its length to the
+        /// <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="bytes">The array of bytes to write.</param>
+        /// <param name="len">
+        /// The number of bytes from the start of array to write.
+        /// </param>
+        void WriteBytesOnly( array<Byte>^ bytes, System::UInt32 len );
+
+        void WriteBytesOnly( array<Byte>^ bytes, System::UInt32 len, 
System::UInt32 offset );
+
+        /// <summary>
+        /// Write an array of bytes without its length to the
+        /// <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="bytes">The array of bytes to write.</param>
+        inline void WriteBytesOnly( array<Byte>^ bytes )
+        {
+          WriteBytesOnly( bytes, ( bytes == nullptr ? 0 : bytes->Length )  );
+        }
+
+        /// <summary>
+        /// Write a given length of signed bytes without its length
+        /// to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="bytes">The array of signed bytes to write.</param>
+        /// <param name="len">
+        /// The number of bytes from the start of array to write.
+        /// </param>
+        void WriteSBytesOnly( array<SByte>^ bytes, System::UInt32 len );
+
+        /// <summary>
+        /// Write an array of signed bytes without its length
+        /// to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="bytes">The array of signed bytes to write.</param>
+        inline void WriteSBytesOnly( array<SByte>^ bytes )
+        {
+          WriteSBytesOnly( bytes, ( bytes == nullptr ? 0 : bytes->Length )  );
+        }        
+
+        /// <summary>
+        /// Write a 16-bit integer to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The 16-bit integer to write.</param>
+        void WriteInt16( System::Int16 value );
+
+        /// <summary>
+        /// Write a 32-bit integer to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The 32-bit integer to write.</param>
+        void WriteInt32( System::Int32 value );
+
+        /// <summary>
+        /// Write a 64-bit integer to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The 64-bit integer to write.</param>
+        void WriteInt64( System::Int64 value );
+
+        /// <summary>
+        /// Write a float to the DataOutput.
+        /// </summary>
+        /// <param name="value">The float value to write.</param>
+        void WriteFloat( float value );
+
+        /// <summary>
+        /// Write a double precision real number to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">
+        /// The double precision real number to write.
+        /// </param>
+        void WriteDouble( double value );
+
+        /// <summary>
+        /// Write a string using java-modified UTF-8 encoding to
+        /// <c>DataOutput</c>.
+        /// The maximum length supported is 2^16-1 beyond which the string
+        /// shall be truncated.
+        /// </summary>
+        /// <param name="value">The UTF encoded string to write.</param>
+        void WriteUTF( String^ value );
+
+        /// <summary>
+        /// Write a string using java-modified UTF-8 encoding to
+        /// <c>DataOutput</c>.
+        /// Length should be more than 2^16 -1. 
+        /// </summary>
+        /// <param name="value">The UTF encoded string to write.</param>
+        void WriteUTFHuge( String^ value );
+
+        /// <summary>
+        /// Write a string(only ASCII char) to
+        /// <c>DataOutput</c>.
+        /// Length should be more than 2^16 -1.
+        /// </summary>
+        /// <param name="value">The UTF encoded string to write.</param>
+        void WriteASCIIHuge( String^ value );
+
+        /// <summary>
+        /// Write an <c>IGeodeSerializable</c> object to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="obj">The object to write.</param>
+       // void WriteObject( IGeodeSerializable^ obj );
+
+        /// <summary>
+        /// Write a <c>Serializable</c> object to the <c>DataOutput</c>.
+        /// This is provided to conveniently pass primitive types (like string)
+        /// that shall be implicitly converted to corresponding
+        /// <c>IGeodeSerializable</c> wrapper types.
+        /// </summary>
+        /// <param name="obj">The object to write.</param>
+        void WriteObject( Object^ obj );
+
+        /// <summary>
+        /// Advance the buffer cursor by the given offset.
+        /// </summary>
+        /// <param name="offset">
+        /// The offset by which to advance the cursor.
+        /// </param>
+        void AdvanceCursor( System::UInt32 offset );
+
+        /// <summary>
+        /// Rewind the buffer cursor by the given offset.
+        /// </summary>
+        /// <param name="offset">
+        /// The offset by which to rewind the cursor.
+        /// </param>
+        void RewindCursor( System::UInt32 offset );
+
+        /// <summary>
+        /// Get a copy of the current buffer.
+        /// </summary>
+        array<Byte>^ GetBuffer( );
+
+        /// <summary>
+        /// Get the length of current data in the buffer.
+        /// </summary>
+        property System::UInt32 BufferLength
+        {
+          System::UInt32 get( );
+        }
+
+        /// <summary>
+        /// Reset the cursor to the start of the buffer.
+        /// </summary>
+        void Reset( );
+       
+        /// <summary>
+        /// Write a Dictionary to the DataOutput.
+        /// </summary>
+        /// <param name="value">The object which implements IDictionary to 
write.</param>
+                         void 
WriteDictionary(System::Collections::IDictionary^ value);              
+
+        /// <summary>
+        /// Write a date to the DataOutput.
+        /// </summary>
+        /// <param name="value">The date value to write.</param>
+        void WriteDate(System::DateTime value);
+
+        /// <summary>
+        /// Write a collection to the DataOutput.
+        /// </summary>
+        /// <param name="value">The object which implements IList to 
write.</param>
+        void WriteCollection(System::Collections::IList^ value);
+        
+        /// <summary>
+        /// Write a char array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The char array to write.</param>
+        void WriteCharArray(array<Char>^ value);
+
+        /// <summary>
+        /// Write a bool array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The bool array to write.</param>
+                               void WriteBooleanArray(array<bool>^ value);
+
+        /// <summary>
+        /// Write a short array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The short array to write.</param>
+                               void WriteShortArray(array<Int16>^ value);
+
+        /// <summary>
+        /// Write a int array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The int array to write.</param>
+                               void WriteIntArray(array<Int32>^ value);
+
+        /// <summary>
+        /// Write a long array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The long array to write.</param>
+                               void WriteLongArray(array<Int64>^ value);
+
+        /// <summary>
+        /// Write a float array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The float array to write.</param>
+                               void WriteFloatArray(array<float>^ value);
+
+        /// <summary>
+        /// Write a double array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The double array to write.</param>
+                               void WriteDoubleArray(array<double>^ value);
+
+        /// <summary>
+        /// Write a object array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The object array to write.</param>
+        void WriteObjectArray(List<Object^>^ value);
+
+        /// <summary>
+        /// Write a array of sign byte array to the DataOutput.
+        /// </summary>
+        /// <param name="value">The array of sign byte array to write.</param>
+        void WriteArrayOfByteArrays(array<array<Byte>^>^ value);
+               
+      internal:
+
+        native::DataOutput* GetNative()
+        {
+          return m_nativeptr->get();
+        }
+
+        void WriteDotNetObjectArray(Object^ objectArray);
+
+        /// <summary>
+        /// Write a byte to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The byte to write.</param>
+        void WriteByte( Byte value );
+
+        /// <summary>
+        /// Write an unsigned short integer (System::Int16) to the 
<c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The unsigned 16-bit integer to write.</param>
+        void WriteUInt16( System::UInt16 value );
+
+        /// <summary>
+        /// Write an unsigned 32-bit integer to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The unsigned 32-bit integer to write.</param>
+        void WriteUInt32( System::UInt32 value );
+
+        /// <summary>
+        /// Write an unsigned 64-bit integer to the <c>DataOutput</c>.
+        /// </summary>
+        /// <param name="value">The unsigned 64-bit integer to write.</param>
+        void WriteUInt64( System::UInt64 value );
+
+
+                         System::Int32 GetBufferLengthPdx()
+        {
+          try
+          {
+            return (System::Int32)m_nativeptr->get()->getBufferLength();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
+        }
+
+        void WriteString(String^ value);
+
+        System::Int32 GetCursorPdx()
+        {
+          return m_cursor;
+        }
+
+        const char * GetPoolName()
+        {
+          try
+          {
+            return m_nativeptr->get()->getPoolName();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
+        }
+
+        void WriteStringArray(array<String^>^ strArray);
+
+        void EncodeUTF8String( String^ input, int encLength )
+        {
+          const int strLength = input->Length;
+          const int end = m_cursor + encLength;
+          for ( int i = 0; i < strLength && m_cursor < end; i++ )
+          {
+            unsigned short c = (unsigned short)input[i];
+
+            if( c == 0 )
+            {
+                m_bytes[m_cursor++] = 0xc0;
+                m_bytes[m_cursor++] = 0x80;
+            }
+            else if ( c < 0x80 )//ASCII character
+            {
+              // 7-bits done in one byte.
+              m_bytes[m_cursor++] = (System::Byte)c;
+            }
+            else if ( c < 0x800 )
+            {
+              // 8-11 bits done in 2 bytes
+              m_bytes[m_cursor++] = ( 0xC0 | c >> 6 );
+              m_bytes[m_cursor++] = ( 0x80 | c & 0x3F );
+            }
+            else 
+            {
+              // 12-16 bits done in 3 bytes
+              m_bytes[m_cursor++] = ( 0xE0 | c >> 12 );
+              m_bytes[m_cursor++] = ( 0x80 | c >> 6 & 0x3F );
+              m_bytes[m_cursor++] = ( 0x80 | c & 0x3F );
+            }            
+          }
+
+                 // TODO ASSERT end = m_cursor
+        }
+       
+        static int getEncodedLength(String^ input)
+        {
+          int count = 0;
+          for ( int i = 0; i < input->Length; i++ )
+          {
+            unsigned short c = (unsigned short)input[i];
+
+            if( c == 0)
+            {
+              count += 2;
+            }
+            else if ( c < 0x80 )//ASCII character
+            {
+              count++;
+            }
+            else if ( c < 0x800 )
+            {
+              count += 2;
+            }
+            else
+            {
+               count += 3;
+            }
+          }// end for
+
+          return count;
+        }
+
+        void setPdxSerialization(bool val)
+        {
+          m_ispdxSerialization = val;
+        }
+
+        void WriteStringWithType( String^ value );
+
+        static int8_t GetTypeId(System::UInt32 classId );
+        
+        static int8_t DSFID(System::UInt32 classId);        
+  
+        void WriteObjectInternal( IGeodeSerializable^ obj );     
+
+        void WriteBytesToUMDataOutput();
+        
+        void WriteObject(bool% obj);        
+
+        void WriteObject(Byte% obj);        
+
+        void WriteObject(Char% obj);        
+
+        void WriteObject(Double% obj);
+        
+        void WriteObject(Single% obj);
+        
+        void WriteObject(System::Int16% obj);
+        
+        void WriteObject(System::Int32% obj);
+        
+        void WriteObject(System::Int64% obj);
+        
+                               void WriteObject(UInt16% obj);
+        
+        void WriteObject(UInt32% obj);       
+
+        void WriteObject(UInt64% obj);
+
+        
+        template <typename mType>
+        void WriteObject(array<mType>^ %objArray)
+        {
+          if(objArray != nullptr) {
+            int arrayLen = objArray->Length;
+            WriteArrayLen(arrayLen);
+            if(arrayLen > 0) {
+              int i = 0;
+              for( i = 0; i < arrayLen; i++ ){
+                WriteObject(objArray[i]);
+              }
+            }
+          }
+          else {
+            WriteByte(0xff);
+          }
+        }
+
+        bool IsManagedObject()
+        {
+          return m_isManagedObject;
+        }
+
+        void SetBuffer()
+        {
+          m_cursor = 0;
+          try
+          {
+            m_bytes = const_cast<System::Byte 
*>(m_nativeptr->get()->getCursor());
+            m_remainingBufferLength = 
(System::Int32)m_nativeptr->get()->getRemainingBufferLength();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
+        }
+
+                               System::Byte* GetStartBufferPosition()
+        {
+          try
+          {
+            return const_cast<System::Byte *>( 
m_nativeptr->get()->getBuffer());
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          };
+        }
+
+        inline void EnsureCapacity( System::Int32 size )
+        {
+          System::Int32 bytesLeft = m_remainingBufferLength - m_cursor;
+          if ( bytesLeft < size ) {
+            try
+            {
+              auto p = m_nativeptr->get();
+              p->ensureCapacity(m_cursor + size);
+              m_bytes = const_cast<System::Byte *>( p->getCursor());
+              m_remainingBufferLength = 
(System::Int32)p->getRemainingBufferLength();
+            }
+            catch(apache::geode::client::OutOfMemoryException ex )
+            {
+              throw gcnew OutOfMemoryException(ex);
+            }            
+            finally
+            {
+              GC::KeepAlive(m_nativeptr);
+            }
+          }
+        }
+
+        //it expects list is not null
+        inline void WriteList(System::Collections::IList^ list)
+        {
+          this->WriteArrayLen(list->Count);
+          for each (Object^ obj in list) 
+                                               this->WriteObject(obj);
+        }
+
+        System::Byte* GetBytes(System::Byte* src, System::UInt32 size)
+        {
+          try
+          {
+            return m_nativeptr->get()->getBufferCopyFrom(src, size);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
+        }
+ 
+        System::Int32 GetRemainingBufferLength()
+        {
+          try
+          {
+            return (System::Int32) 
m_nativeptr->get()->getRemainingBufferLength();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
+        }
+
+        /// <summary>
+        /// Internal constructor to wrap a native object pointer
+        /// </summary>
+        /// <param name="nativeptr">The native object pointer</param>
+        inline DataOutput( apache::geode::client::DataOutput* nativeptr, bool 
managedObject )
+        {
+          m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DataOutput>(nativeptr);
+          m_isManagedObject = managedObject;
+          m_cursor = 0;
+          m_bytes = const_cast<System::Byte *>(nativeptr->getCursor());
+          m_remainingBufferLength = 
(System::Int32)nativeptr->getRemainingBufferLength();
+          m_ispdxSerialization = false;
+        }
+      };
+    }  // namespace Client
+  }  // namespace Geode
+}  // namespace Apache
+

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/DiskPolicyType.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/DiskPolicyType.hpp b/clicache/src/DiskPolicyType.hpp
new file mode 100644
index 0000000..e9d3953
--- /dev/null
+++ b/clicache/src/DiskPolicyType.hpp
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+
+
+#include "geode_defs.hpp"
+#include "begin_native.hpp"
+#include <geode/DiskPolicyType.hpp>
+#include "end_native.hpp"
+
+
+
+using namespace System;
+
+namespace Apache
+{
+  namespace Geode
+  {
+    namespace Client
+    {
+
+      /// <summary>
+      /// Enumerated type for disk policy.
+      /// Contains values for setting the disk policy type.
+      /// </summary>
+      public enum class DiskPolicyType
+      {
+        /// <summary>No policy.</summary>
+        None = 0,
+
+        /// <summary>Overflow to disk.</summary>
+        Overflows
+      };
+
+
+      /// <summary>
+      /// Static class containing convenience methods for 
<c>DiskPolicyType</c>.
+      /// </summary>
+      /// <seealso cref="RegionAttributes.DiskPolicy" />
+      /// <seealso cref="AttributesFactory.SetDiskPolicy" />
+      public ref class DiskPolicy STATICCLASS
+      {
+      public:
+
+        /// <summary>
+        /// True if the current policy is <c>Overflows</c>.
+        /// </summary>
+        inline static bool IsOverflow( DiskPolicyType type )
+        {
+          return (type == DiskPolicyType::Overflows);
+        }
+
+        /// <summary>
+        /// True if the current policy is <c>None</c>.
+        /// </summary>
+        inline static bool IsNone( DiskPolicyType type )
+        {
+          return (type == DiskPolicyType::None);
+        }
+
+        ///// <summary>
+        ///// True if the current policy is <c>Persist</c>.
+        ///// </summary> -- Persist is NOT YET IMPLEMENTED IN C++
+        //inline static bool IsPersist( DiskPolicyType type )
+        //{
+        //  return (type == DiskPolicyType::Persist);
+        //}
+      };
+    }  // namespace Client
+  }  // namespace Geode
+}  // namespace Apache
+
+

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/DistributedSystem.cpp
----------------------------------------------------------------------
diff --git a/clicache/src/DistributedSystem.cpp 
b/clicache/src/DistributedSystem.cpp
new file mode 100644
index 0000000..7431933
--- /dev/null
+++ b/clicache/src/DistributedSystem.cpp
@@ -0,0 +1,574 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "begin_native.hpp"
+#include <version.h>
+#include <geode/CacheLoader.hpp>
+#include <geode/CacheListener.hpp>
+#include <geode/FixedPartitionResolver.hpp>
+#include <geode/CacheWriter.hpp>
+#include <geode/GeodeTypeIds.hpp>
+#include <geode/Cache.hpp>
+#include <CacheImpl.hpp>
+#include <CacheXmlParser.hpp>
+#include <DistributedSystemImpl.hpp>
+#include <ace/Process.h> // Added to get rid of unresolved token warning
+#include "end_native.hpp"
+
+#include "Cache.hpp"
+#include "Serializable.hpp"
+#include "DistributedSystem.hpp"
+#include "SystemProperties.hpp"
+#include "CacheFactory.hpp"
+#include "CacheableDate.hpp"
+#include "CacheableFileName.hpp"
+#include "CacheableHashMap.hpp"
+#include "CacheableHashSet.hpp"
+#include "CacheableHashTable.hpp"
+#include "CacheableIdentityHashMap.hpp"
+#include "CacheableObjectArray.hpp"
+#include "CacheableString.hpp"
+#include "CacheableStringArray.hpp"
+#include "CacheableUndefined.hpp"
+#include "CacheableVector.hpp"
+#include "CacheableArrayList.hpp"
+#include "CacheableStack.hpp"
+#include "CacheableObject.hpp"
+#include "CacheableObjectXml.hpp"
+#include "CacheableBuiltins.hpp"
+#include "Log.hpp"
+#include "Struct.hpp"
+#include "impl/MemoryPressureHandler.hpp"
+#include "impl/SafeConvert.hpp"
+#include "impl/PdxType.hpp"
+#include "impl/EnumInfo.hpp"
+#include "impl/ManagedPersistenceManager.hpp"
+
+// disable spurious warning
+#pragma warning(disable:4091)
+#include <msclr/lock.h>
+#pragma warning(default:4091)
+
+
+using namespace System;
+
+using namespace Apache::Geode::Client;
+
+namespace apache
+{
+  namespace geode
+  {
+    namespace client
+    {
+      class ManagedCacheLoaderGeneric
+        : public CacheLoader
+      {
+      public:
+
+        static CacheLoader* create(const char* assemblyPath,
+                                   const char* factoryFunctionName);
+      };
+
+      class ManagedCacheListenerGeneric
+        : public CacheListener
+      {
+      public:
+
+        static CacheListener* create(const char* assemblyPath,
+                                     const char* factoryFunctionName);
+      };
+
+      class ManagedFixedPartitionResolverGeneric
+        : public FixedPartitionResolver
+      {
+      public:
+
+        static PartitionResolver* create(const char* assemblyPath,
+                                         const char* factoryFunctionName);
+      };
+
+      class ManagedCacheWriterGeneric
+        : public CacheWriter
+      {
+      public:
+
+        static CacheWriter* create(const char* assemblyPath,
+                                   const char* factoryFunctionName);
+      };
+
+      class ManagedAuthInitializeGeneric
+        : public AuthInitialize
+      {
+      public:
+
+        static AuthInitialize* create(const char* assemblyPath,
+                                      const char* factoryFunctionName);
+      };
+    }  // namespace client
+  }  // namespace geode
+}  // namespace apache
+
+
+namespace Apache
+{
+  namespace Geode
+  {
+    namespace Client
+    {
+
+
+      namespace native = apache::geode::client;
+
+      DistributedSystem^ DistributedSystem::Connect(String^ name, Cache^ cache)
+      {
+        return DistributedSystem::Connect(name, nullptr, cache);
+      }
+
+      DistributedSystem^ DistributedSystem::Connect(String^ name, 
Properties<String^, String^>^ config, Cache ^ cache)
+      {
+        native::DistributedSystemImpl::acquireDisconnectLock();
+
+        _GF_MG_EXCEPTION_TRY2
+
+        ManagedString mg_name(name);
+
+        // this we are calling after all .NET initialization required in
+        // each AppDomain
+        auto nativeptr = native::DistributedSystem::create(mg_name.CharPtr, 
cache->GetNative().get(),
+                                                            
config->GetNative());
+        nativeptr->connect();
+
+        ManagedPostConnect(cache);
+
+        return gcnew DistributedSystem(std::move(nativeptr));
+
+        _GF_MG_EXCEPTION_CATCH_ALL2
+
+          finally {
+          native::DistributedSystemImpl::releaseDisconnectLock();
+        }
+      }
+
+      void DistributedSystem::Disconnect(Cache^ cache)
+      {
+        native::DistributedSystemImpl::acquireDisconnectLock();
+
+        _GF_MG_EXCEPTION_TRY2
+
+
+        Serializable::UnregisterNativesGeneric();
+        DistributedSystem::UnregisterBuiltinManagedTypes(cache);
+        m_nativeptr->get()->disconnect();
+        GC::KeepAlive(m_nativeptr);
+
+        _GF_MG_EXCEPTION_CATCH_ALL2
+
+          finally {
+          native::DistributedSystemImpl::releaseDisconnectLock();
+        }
+      }
+
+      void DistributedSystem::AppDomainInstanceInitialization(Cache^ cache)
+      {
+        _GF_MG_EXCEPTION_TRY2
+
+          // Register wrapper types for built-in types, this are still cpp 
wrapper
+
+        //byte
+        Serializable::RegisterWrapperGeneric(
+        gcnew WrapperDelegateGeneric(CacheableByte::Create),
+        native::GeodeTypeIds::CacheableByte, SByte::typeid);
+
+        //boolean
+        Serializable::RegisterWrapperGeneric(
+          gcnew WrapperDelegateGeneric(CacheableBoolean::Create),
+          native::GeodeTypeIds::CacheableBoolean, Boolean::typeid);
+        //wide char
+        Serializable::RegisterWrapperGeneric(
+          gcnew WrapperDelegateGeneric(CacheableCharacter::Create),
+          native::GeodeTypeIds::CacheableWideChar, Char::typeid);
+        //double
+        Serializable::RegisterWrapperGeneric(
+          gcnew WrapperDelegateGeneric(CacheableDouble::Create),
+          native::GeodeTypeIds::CacheableDouble, Double::typeid);
+        //ascii string
+        Serializable::RegisterWrapperGeneric(
+          gcnew WrapperDelegateGeneric(CacheableString::Create),
+          native::GeodeTypeIds::CacheableASCIIString, String::typeid);
+
+        Serializable::RegisterWrapperGeneric(
+          gcnew WrapperDelegateGeneric(CacheableFloat::Create),
+          native::GeodeTypeIds::CacheableFloat, float::typeid);
+        //int 16
+        Serializable::RegisterWrapperGeneric(
+          gcnew WrapperDelegateGeneric(CacheableInt16::Create),
+          native::GeodeTypeIds::CacheableInt16, Int16::typeid);
+        //int32
+        Serializable::RegisterWrapperGeneric(
+          gcnew WrapperDelegateGeneric(CacheableInt32::Create),
+          native::GeodeTypeIds::CacheableInt32, Int32::typeid);
+        //int64
+        Serializable::RegisterWrapperGeneric(
+          gcnew WrapperDelegateGeneric(CacheableInt64::Create),
+          native::GeodeTypeIds::CacheableInt64, Int64::typeid);
+
+        //Now onwards all will be wrap in managed cacheable key..
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableBytes,
+          gcnew TypeFactoryMethodGeneric(CacheableBytes::CreateDeserializable),
+          Type::GetType("System.Byte[]"), cache);
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableDoubleArray,
+          gcnew 
TypeFactoryMethodGeneric(CacheableDoubleArray::CreateDeserializable),
+          Type::GetType("System.Double[]"), cache);
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableFloatArray,
+          gcnew 
TypeFactoryMethodGeneric(CacheableFloatArray::CreateDeserializable),
+          Type::GetType("System.Single[]"), cache);
+
+        //TODO:
+        //as it is
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableHashSet,
+          gcnew 
TypeFactoryMethodGeneric(CacheableHashSet::CreateDeserializable),
+          nullptr, cache);
+
+        //as it is
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableLinkedHashSet,
+          gcnew 
TypeFactoryMethodGeneric(CacheableLinkedHashSet::CreateDeserializable),
+          nullptr, cache);
+
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableInt16Array,
+          gcnew 
TypeFactoryMethodGeneric(CacheableInt16Array::CreateDeserializable),
+          Type::GetType("System.Int16[]"), cache);
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableInt32Array,
+          gcnew 
TypeFactoryMethodGeneric(CacheableInt32Array::CreateDeserializable),
+          Type::GetType("System.Int32[]"), cache);
+
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableInt64Array,
+          gcnew 
TypeFactoryMethodGeneric(CacheableInt64Array::CreateDeserializable),
+          Type::GetType("System.Int64[]"), cache);
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::BooleanArray,
+          gcnew TypeFactoryMethodGeneric(BooleanArray::CreateDeserializable),
+          Type::GetType("System.Boolean[]"), cache);
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CharArray,
+          gcnew TypeFactoryMethodGeneric(CharArray::CreateDeserializable),
+          Type::GetType("System.Char[]"), cache);
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableStringArray,
+          gcnew 
TypeFactoryMethodGeneric(CacheableStringArray::CreateDeserializable),
+          Type::GetType("System.String[]"), cache);
+
+        //as it is
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::Struct,
+          gcnew TypeFactoryMethodGeneric(Struct::CreateDeserializable),
+          nullptr, cache);
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::EnumInfo,
+          gcnew 
TypeFactoryMethodGeneric(Apache::Geode::Client::Internal::EnumInfo::CreateDeserializable),
+          nullptr, cache);
+
+        // End register generic wrapper types for built-in types
+
+        //if (!native::DistributedSystem::isConnected())
+        //{
+          // Set the Generic ManagedAuthInitialize factory function
+          native::SystemProperties::managedAuthInitializeFn =
+            native::ManagedAuthInitializeGeneric::create;
+
+          // Set the Generic ManagedCacheLoader/Listener/Writer factory 
functions.
+          native::CacheXmlParser::managedCacheLoaderFn =
+            native::ManagedCacheLoaderGeneric::create;
+          native::CacheXmlParser::managedCacheListenerFn =
+            native::ManagedCacheListenerGeneric::create;
+          native::CacheXmlParser::managedCacheWriterFn =
+            native::ManagedCacheWriterGeneric::create;
+
+          // Set the Generic ManagedPartitionResolver factory function
+          native::CacheXmlParser::managedPartitionResolverFn =
+            native::ManagedFixedPartitionResolverGeneric::create;
+
+          // Set the Generic ManagedPersistanceManager factory function
+          native::CacheXmlParser::managedPersistenceManagerFn =
+            native::ManagedPersistenceManagerGeneric::create;
+        //}
+
+        _GF_MG_EXCEPTION_CATCH_ALL2
+      }
+
+      void DistributedSystem::ManagedPostConnect(Cache^ cache)
+      {
+        //  The registration into the native map should be after
+        // native connect since it can be invoked only once
+
+        // Register other built-in types
+      
+        // End register other built-in types
+
+        // Register other built-in types for generics
+        //c# datatime
+
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableDate,
+          gcnew TypeFactoryMethodGeneric(CacheableDate::CreateDeserializable),
+          Type::GetType("System.DateTime"), cache);
+
+        //as it is
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableFileName,
+          gcnew 
TypeFactoryMethodGeneric(CacheableFileName::CreateDeserializable),
+          nullptr, cache);
+
+        //for generic dictionary define its type in static constructor of 
Serializable.hpp
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableHashMap,
+          gcnew 
TypeFactoryMethodGeneric(CacheableHashMap::CreateDeserializable),
+          nullptr, cache);
+
+        //c# hashtable
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableHashTable,
+          gcnew 
TypeFactoryMethodGeneric(CacheableHashTable::CreateDeserializable),
+          Type::GetType("System.Collections.Hashtable"), cache);
+
+        //Need to keep public as no counterpart in c#
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableIdentityHashMap,
+          gcnew TypeFactoryMethodGeneric(
+          CacheableIdentityHashMap::CreateDeserializable),
+          nullptr, cache);
+
+        //keep as it is
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableUndefined,
+          gcnew 
TypeFactoryMethodGeneric(CacheableUndefined::CreateDeserializable),
+          nullptr, cache);
+
+        //c# arraylist
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableVector,
+          gcnew 
TypeFactoryMethodGeneric(CacheableVector::CreateDeserializable),
+          nullptr, cache);
+
+        //as it is
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableObjectArray,
+          gcnew TypeFactoryMethodGeneric(
+          CacheableObjectArray::CreateDeserializable),
+          nullptr, cache);
+
+        //Generic::List
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableArrayList,
+          gcnew 
TypeFactoryMethodGeneric(CacheableArrayList::CreateDeserializable),
+          nullptr, cache);
+
+        //c# generic stack 
+        Serializable::RegisterTypeGeneric(
+          native::GeodeTypeIds::CacheableStack,
+          gcnew TypeFactoryMethodGeneric(CacheableStack::CreateDeserializable),
+          nullptr, cache);
+
+        //as it is
+        Serializable::RegisterTypeGeneric(
+          GeodeClassIds::CacheableManagedObject - 0x80000000,
+          gcnew 
TypeFactoryMethodGeneric(CacheableObject::CreateDeserializable),
+          nullptr, cache);
+
+        //as it is
+        Serializable::RegisterTypeGeneric(
+          GeodeClassIds::CacheableManagedObjectXml - 0x80000000,
+          gcnew 
TypeFactoryMethodGeneric(CacheableObjectXml::CreateDeserializable),
+          nullptr, cache);
+
+        // End register other built-in types
+
+        // TODO: what will happen for following if first appDomain unload ??
+        // Testing shows that there are problems; need to discuss -- maybe
+        // maintain per AppDomainID functions in C++ layer.
+
+        // Log the version of the C# layer being used
+        Log::Config(".NET layer assembly version: {0}({1})", 
System::Reflection::
+                    
Assembly::GetExecutingAssembly()->GetName()->Version->ToString(),
+                    
System::Reflection::Assembly::GetExecutingAssembly()->ImageRuntimeVersion);
+
+        Log::Config(".NET runtime version: {0} ", 
System::Environment::Version);
+        Log::Config(".NET layer source repository (revision): {0} ({1})",
+                    PRODUCT_SOURCE_REPOSITORY, PRODUCT_SOURCE_REVISION);
+      }
+
+      void DistributedSystem::AppDomainInstancePostInitialization()
+      {
+        // TODO global - Is this necessary?
+        //to create .net memory pressure handler 
+        //Create(native::DistributedSystem::getInstance());
+      }
+
+      void DistributedSystem::UnregisterBuiltinManagedTypes(Cache^ cache)
+      {
+        _GF_MG_EXCEPTION_TRY2
+
+          native::DistributedSystemImpl::acquireDisconnectLock();
+
+        Serializable::UnregisterNativesGeneric();
+
+        int remainingInstances =
+          native::DistributedSystemImpl::currentInstances();
+
+        if (remainingInstances == 0) { // last instance
+
+
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableDate, cache);
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableFileName, cache);
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableHashMap, cache);
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableHashTable, cache);
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableIdentityHashMap, cache);
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableVector, cache);
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableObjectArray, cache);
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableArrayList, cache);
+          Serializable::UnregisterTypeGeneric(
+            native::GeodeTypeIds::CacheableStack, cache);
+          Serializable::UnregisterTypeGeneric(
+            GeodeClassIds::CacheableManagedObject - 0x80000000, cache);
+          Serializable::UnregisterTypeGeneric(
+            GeodeClassIds::CacheableManagedObjectXml - 0x80000000, cache);
+
+        }
+
+        _GF_MG_EXCEPTION_CATCH_ALL2
+
+          finally {
+          native::DistributedSystemImpl::releaseDisconnectLock();
+        }
+      }
+
+      Apache::Geode::Client::SystemProperties^ 
DistributedSystem::SystemProperties::get()
+      {
+        _GF_MG_EXCEPTION_TRY2
+
+          return Apache::Geode::Client::SystemProperties::Create(
+          &(m_nativeptr->get()->getSystemProperties()));
+
+        _GF_MG_EXCEPTION_CATCH_ALL2
+      }
+
+      String^ DistributedSystem::Name::get()
+      {
+        try
+        {
+          return ManagedString::Get(m_nativeptr->get()->getName().c_str());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+  
+      void DistributedSystem::HandleMemoryPressure(System::Object^ state)
+      {
+        // TODO global - Need single memory pressue event running?
+        ACE_Time_Value dummy(1);
+        MemoryPressureHandler handler;
+        handler.handle_timeout(dummy, nullptr);
+      }
+
+      DistributedSystem^ DistributedSystem::Create(native::DistributedSystem* 
nativeptr)
+      {
+        auto instance = gcnew DistributedSystem(nativeptr);
+        return instance;
+      }
+      
+      
DistributedSystem::DistributedSystem(std::unique_ptr<native::DistributedSystem> 
nativeptr)
+      {
+        m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DistributedSystem>(std::move(nativeptr));
+      }
+
+      DistributedSystem::DistributedSystem(native::DistributedSystem* 
nativeptr)
+      {
+        m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DistributedSystem>(nativeptr);
+      }
+
+      DistributedSystem::~DistributedSystem()
+      {
+        m_memoryPressureHandler->Dispose(nullptr);
+      }
+
+      void DistributedSystem::acquireDisconnectLock()
+      {
+        native::DistributedSystemImpl::acquireDisconnectLock();
+      }
+
+      void DistributedSystem::disconnectInstance()
+      {
+        native::DistributedSystemImpl::disconnectInstance();
+      }
+
+      void DistributedSystem::releaseDisconnectLock()
+      {
+        native::DistributedSystemImpl::releaseDisconnectLock();
+      }
+
+      void DistributedSystem::connectInstance()
+      {
+        native::DistributedSystemImpl::connectInstance();
+      }
+
+      void DistributedSystem::registerCliCallback()
+      {
+        m_cliCallBackObj = gcnew CliCallbackDelegate();
+        auto nativeCallback =
+          gcnew cliCallback(m_cliCallBackObj,
+          &CliCallbackDelegate::Callback);
+
+        
native::DistributedSystemImpl::registerCliCallback(System::Threading::Thread::GetDomainID(),
+                                                                          
(native::CliCallbackMethod)System::Runtime::InteropServices::
+                                                                          
Marshal::GetFunctionPointerForDelegate(
+                                                                          
nativeCallback).ToPointer());
+      }
+
+      void DistributedSystem::unregisterCliCallback()
+      {
+        
native::DistributedSystemImpl::unregisterCliCallback(System::Threading::Thread::GetDomainID());
+      }
+    }  // namespace Client
+  }  // namespace Geode
+}  // namespace Apache

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/DistributedSystem.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/DistributedSystem.hpp 
b/clicache/src/DistributedSystem.hpp
new file mode 100644
index 0000000..48c2723
--- /dev/null
+++ b/clicache/src/DistributedSystem.hpp
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "geode_defs.hpp"
+#include "begin_native.hpp"
+#include <geode/DistributedSystem.hpp>
+#include "end_native.hpp"
+
+#include "native_conditional_unique_ptr.hpp"
+#include "SystemProperties.hpp"
+#include "Properties.hpp"
+#include "impl/CliCallbackDelgate.hpp"
+
+using namespace System;
+
+namespace Apache
+{
+  namespace Geode
+  {
+    namespace Client
+    {
+
+      namespace native = apache::geode::client;
+
+      /// <summary>
+      /// DistributedSystem encapsulates this applications "connection" into 
the
+      /// Geode Java servers.
+      /// </summary>
+      /// <remarks>
+      /// In order to participate as a client in the Geode Java servers
+      /// distributed system, each application needs to connect to the
+      /// DistributedSystem.
+      /// </remarks>
+      public ref class DistributedSystem sealed
+      {
+      public:
+
+        /// <summary>
+        /// Initializes the Native Client system to be able to connect to the 
Geode Java servers.
+        /// </summary>
+        /// <param name="name">the name of the system to connect to</param>
+        /// <exception cref="IllegalArgumentException">if name is 
null</exception>
+        /// <exception cref="NoSystemException">
+        /// if the connecting target is not running
+        /// </exception>
+        /// <exception cref="AlreadyConnectedException">
+        /// if trying a second connect.
+        /// An application can have one only one connection to a 
DistributedSystem.
+        /// </exception>
+        /// <exception cref="UnknownException">otherwise</exception>
+        DistributedSystem^ Connect(String^ name, Cache^ cache);
+
+        /// <summary>
+        /// Initializes the Native Client system to be able to connect to the
+        /// Geode Java servers.
+        /// </summary>
+        /// <param name="name">the name of the system to connect to</param>
+        /// <param name="config">the set of properties</param>
+        /// <exception cref="IllegalArgumentException">if name is 
null</exception>
+        /// <exception cref="NoSystemException">
+        /// if the connecting target is not running
+        /// </exception>
+        /// <exception cref="AlreadyConnectedException">
+        /// if trying a second connect.
+        /// An application can have one only one connection to a 
DistributedSystem.
+        /// </exception>
+        /// <exception cref="UnknownException">otherwise</exception>
+        static DistributedSystem^ Connect(String^ name, Properties<String^, 
String^>^ config, Cache^ cache);
+
+        /// <summary>
+        /// Disconnect from the distributed system.
+        /// </summary>
+        /// <exception cref="IllegalStateException">if not 
connected</exception>
+        void Disconnect(Cache^ cache);
+
+        /// <summary>
+        /// Returns the SystemProperties used to create this instance of a
+        /// <c>DistributedSystem</c>.
+        /// </summary>
+        /// <returns>the SystemProperties</returns>
+        property Apache::Geode::Client::SystemProperties^ SystemProperties
+        {
+          Apache::Geode::Client::SystemProperties^ get();
+        }
+
+        /// <summary>
+        /// Get the name that identifies this DistributedSystem instance.
+        /// </summary>
+        /// <returns>the name of the DistributedSystem instance.</returns>
+        property String^ Name
+        {
+          String^ get();
+        }
+
+
+      internal:
+
+        /// <summary>
+        /// Internal factory function to wrap a native object pointer inside
+        /// this managed class with null pointer check.
+        /// </summary>
+        /// <param name="nativeptr">The native object pointer</param>
+        /// <returns>
+        /// The managed wrapper object; null if the native pointer is null.
+        /// </returns>
+        static DistributedSystem^ Create(native::DistributedSystem* nativeptr);
+
+        DistributedSystem(std::unique_ptr<native::DistributedSystem> 
nativeptr);
+
+        static void acquireDisconnectLock();
+
+        static void disconnectInstance();
+
+        static void releaseDisconnectLock();
+
+        static void connectInstance();
+
+        delegate void cliCallback(apache::geode::client::Cache& cache);
+
+        static void registerCliCallback();
+
+        static void unregisterCliCallback();
+        /// <summary>
+        /// Stuff that needs to be done for Connect in each AppDomain.
+        /// </summary>
+        static void AppDomainInstanceInitialization(Cache^ cache);
+
+        /// <summary>
+        /// Managed registrations and other stuff to be done for the manage
+        /// layer after the first connect.
+        /// </summary>
+        static void ManagedPostConnect(Cache^ cache);
+
+        /// <summary>
+        /// Stuff that needs to be done for Connect in each AppDomain but
+        /// only after the first Connect has completed.
+        /// </summary>
+        static void AppDomainInstancePostInitialization();
+
+        /// <summary>
+        /// Unregister the builtin managed types like CacheableObject.
+        /// </summary>
+        static void UnregisterBuiltinManagedTypes(Cache^ cache);
+
+        native::DistributedSystem& GetNative()
+        {
+          return *(m_nativeptr->get());
+        }
+
+      private:
+
+        ///// <summary>
+        ///// Stores the task ID of the task that adjusts unmanaged memory
+        ///// pressure in managed GC.
+        ///// </summary>
+        //static long s_memoryPressureTaskID = -1;
+
+        /// <summary>
+        /// Private constructor to wrap a native object pointer
+        /// </summary>
+        /// <param name="nativeptr">The native object pointer</param>
+        DistributedSystem(native::DistributedSystem* nativeptr);
+
+        /// <summary>
+        /// Finalizer for the singleton instance of this class.
+        /// </summary>
+        ~DistributedSystem();
+
+        native_conditional_unique_ptr<native::DistributedSystem>^ m_nativeptr;
+
+
+        /// <summary>
+        /// Periodically adjust memory pressure of unmanaged heap for GC.
+        /// </summary>
+        static void HandleMemoryPressure(System::Object^ state);
+
+        /// <summary>
+        /// Timer task to periodically invoke <c>HandleMemoryPressure</c>.
+        /// </summary>
+        System::Threading::Timer^ m_memoryPressureHandler;
+
+        /// <summary>
+        /// Singleton instance of this class.
+        /// </summary>
+        static volatile DistributedSystem^ m_instance;
+
+        /// <summary>
+        /// Static lock object to protect the singleton instance of this class.
+        /// </summary>
+        static System::Object^ m_singletonSync = gcnew System::Object();
+
+        static CliCallbackDelegate^ m_cliCallBackObj;
+      };
+    }  // namespace Client
+  }  // namespace Geode
+}  // namespace Apache
+

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/EntryEvent.cpp
----------------------------------------------------------------------
diff --git a/clicache/src/EntryEvent.cpp b/clicache/src/EntryEvent.cpp
new file mode 100644
index 0000000..51a0ef5
--- /dev/null
+++ b/clicache/src/EntryEvent.cpp
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "EntryEvent.hpp"
+#include "Region.hpp"
+#include "impl/SafeConvert.hpp"
+
+using namespace System;
+
+namespace Apache
+{
+  namespace Geode
+  {
+    namespace Client
+    {
+
+      generic<class TKey, class TValue>
+      IRegion<TKey, TValue>^ EntryEvent<TKey, TValue>::Region::get( )
+      {
+        apache::geode::client::RegionPtr regionptr = m_nativeptr->getRegion();
+        return Client::Region<TKey, TValue>::Create( regionptr );
+      }
+
+      generic<class TKey, class TValue>
+      TKey EntryEvent<TKey, TValue>::Key::get( )
+      {
+        apache::geode::client::CacheableKeyPtr& keyptr( m_nativeptr->getKey( ) 
);
+        return Serializable::GetManagedValueGeneric<TKey>( keyptr );
+      }
+
+      generic<class TKey, class TValue>
+      TValue EntryEvent<TKey, TValue>::OldValue::get( )
+      {
+        apache::geode::client::CacheablePtr& valptr( m_nativeptr->getOldValue( 
) );
+        return Serializable::GetManagedValueGeneric<TValue>( valptr );
+      }
+
+      generic<class TKey, class TValue>
+      TValue EntryEvent<TKey, TValue>::NewValue::get( )
+      {
+        apache::geode::client::CacheablePtr& valptr( m_nativeptr->getNewValue( 
) );
+        return Serializable::GetManagedValueGeneric<TValue>( valptr );
+      }
+
+      generic<class TKey, class TValue>
+      Object^ EntryEvent<TKey, TValue>::CallbackArgument::get()
+      {
+        apache::geode::client::UserDataPtr& 
valptr(m_nativeptr->getCallbackArgument());
+        return Serializable::GetManagedValueGeneric<Object^>( valptr );
+      }
+
+      generic<class TKey, class TValue>
+      bool EntryEvent<TKey, TValue>::RemoteOrigin::get()
+      {
+        return m_nativeptr->remoteOrigin();
+      }
+    }  // namespace Client
+  }  // namespace Geode
+}  // namespace Apache
+

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/EntryEvent.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/EntryEvent.hpp b/clicache/src/EntryEvent.hpp
new file mode 100644
index 0000000..36008ea
--- /dev/null
+++ b/clicache/src/EntryEvent.hpp
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "geode_defs.hpp"
+#include "begin_native.hpp"
+#include <geode/EntryEvent.hpp>
+#include "end_native.hpp"
+
+#include "IRegion.hpp"
+
+using namespace System;
+
+namespace Apache
+{
+  namespace Geode
+  {
+    namespace Client
+    {
+      namespace native = apache::geode::client;
+
+      interface class IGeodeSerializable;
+
+     // ref class Region;
+      //interface class ICacheableKey;
+
+      /// <summary>
+      /// This class encapsulates events that occur for an entry in a region.
+      /// </summary>
+      generic<class TKey, class TValue>
+      public ref class EntryEvent sealed
+      {
+      public:
+
+        /// <summary>
+        /// Return the region this event occurred in.
+        /// </summary>
+        property IRegion<TKey, TValue>^ Region
+        {
+          IRegion<TKey, TValue>^ get( );
+        }
+
+        /// <summary>
+        /// Returns the key this event describes.
+        /// </summary>
+        property TKey Key
+        {
+          TKey get( );
+        }
+
+        /// <summary>
+        /// Returns 'null' if there was no value in the cache. If the prior 
state
+        ///  of the entry was invalid, or non-existent/destroyed, then the old
+        /// value will be 'null'.
+        /// </summary>
+        property TValue OldValue
+        {
+          TValue get( );
+        }
+
+        /// <summary>
+        /// Return the updated value from this event. If the event is a destroy
+        /// or invalidate operation, then the new value will be NULL.
+        /// </summary>
+        property TValue NewValue
+        {
+          TValue get( );
+        }
+
+        /// <summary>
+        /// Returns the callbackArgument passed to the method that generated
+        /// this event. See the <see cref="Region" /> interface methods
+        /// that take a callbackArgument parameter.
+        /// </summary>
+        property Object^ CallbackArgument
+        {
+          Object^ get();
+        }
+
+        /// <summary>
+        /// If the event originated in a remote process, returns true.
+        /// </summary>
+        property bool RemoteOrigin
+        {
+          bool get( );
+        }
+
+      internal:
+        const native::EntryEvent* GetNative()
+        {
+          return m_nativeptr;
+        }
+
+        /// <summary>
+        /// Private constructor to wrap a native object pointer
+        /// </summary>
+        /// <param name="nativeptr">The native object pointer</param>
+        inline EntryEvent<TKey, TValue>( const native::EntryEvent* nativeptr )
+          : m_nativeptr( nativeptr )
+        {
+        }
+      private:
+        const native::EntryEvent* m_nativeptr;
+      };
+    }  // namespace Client
+  }  // namespace Geode
+}  // namespace Apache
+

Reply via email to