You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/08/11 23:52:22 UTC
[06/52] [partial] geode-native git commit: GEODE-3165: Reogranized
sources relative to the root for better CMake IDE integration.
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/CqStatusListenerProxy.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/CqStatusListenerProxy.hpp b/clicache/src/impl/CqStatusListenerProxy.hpp
new file mode 100644
index 0000000..4ddcb2f
--- /dev/null
+++ b/clicache/src/impl/CqStatusListenerProxy.hpp
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "../ICqStatusListener.hpp"
+#include "SafeConvert.hpp"
+
+using namespace System;
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+
+ generic<class TKey, class TResult>
+ public ref class CqStatusListenerGeneric : Apache::Geode::Client::ICqStatusListener<Object^, Object^>
+ {
+ private:
+
+ ICqStatusListener<TKey, TResult>^ m_listener;
+
+ public:
+
+ virtual void AddCqListener(ICqListener<TKey, TResult>^ listener)
+ {
+ m_listener = dynamic_cast<ICqStatusListener<TKey, TResult>^>(listener);
+ }
+
+ virtual void OnEvent(Apache::Geode::Client::CqEvent<Object^, Object^>^ ev)
+ {
+ //TODO:split---Done
+ CqEvent<TKey, TResult> gevent(ev->GetNative());
+ m_listener->OnEvent(%gevent);
+ }
+
+ virtual void OnError( Apache::Geode::Client::CqEvent<Object^, Object^>^ ev)
+ {
+ //TODO::split--Done
+ CqEvent<TKey, TResult> gevent(ev->GetNative());
+ m_listener->OnError(%gevent);
+ }
+
+ virtual void Close()
+ {
+ m_listener->Close();
+ }
+
+ virtual void OnCqDisconnected()
+ {
+ m_listener->OnCqDisconnected();
+ }
+
+ virtual void OnCqConnected()
+ {
+ m_listener->OnCqConnected();
+ }
+ };
+ } // namespace Client
+ } // namespace Geode
+} // namespace Apache
+
+
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/DelegateWrapper.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/DelegateWrapper.hpp b/clicache/src/impl/DelegateWrapper.hpp
new file mode 100644
index 0000000..68da9f9
--- /dev/null
+++ b/clicache/src/impl/DelegateWrapper.hpp
@@ -0,0 +1,110 @@
+/*
+ * 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 "begin_native.hpp"
+#include "CacheImpl.hpp"
+#include "CacheRegionHelper.hpp"
+#include "end_native.hpp"
+
+#include "Cache.hpp"
+#include "../geode_defs.hpp"
+#include "../Serializable.hpp"
+#include "ManagedCacheableKey.hpp"
+#include "SafeConvert.hpp"
+#include "../Log.hpp"
+
+using namespace System;
+
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+ namespace native = apache::geode::client;
+ /// <summary>
+ /// Template class to wrap a managed <see cref="TypeFactoryMethod" />
+ /// delegate that returns an <see cref="IGeodeSerializable" /> object. It contains
+ /// a method that converts the managed object gotten by invoking the
+ /// delegate to the native <c>apache::geode::client::Serializable</c> object
+ /// (using the provided wrapper class constructor).
+ /// </summary>
+ /// <remarks>
+ /// This class is to enable interopibility between the managed and unmanaged
+ /// worlds when registering types.
+ /// In the managed world a user would register a managed type by providing
+ /// a factory delegate returning an object of that type. However, the
+ /// native implementation requires a factory function that returns an
+ /// object implementing <c>apache::geode::client::Serializable</c>. Normally this would not
+ /// be possible since we require to dynamically generate a new function
+ /// for a given delegate.
+ ///
+ /// Fortunately in the managed world the delegates contain an implicit
+ /// 'this' pointer. Thus we can have a universal delegate that contains
+ /// the given managed delegate (in the 'this' pointer) and returns the
+ /// native <c>apache::geode::client::Serializable</c> object. Additionally marshalling
+ /// services provide <c>Marshal.GetFunctionPointerForDelegate</c> which gives
+ /// a function pointer for a delegate which completes the conversion.
+ /// </remarks>
+ ref class DelegateWrapperGeneric
+ {
+ public:
+
+ /// <summary>
+ /// Constructor to wrap the given managed delegate.
+ /// </summary>
+ inline DelegateWrapperGeneric( TypeFactoryMethodGeneric^ typeDelegate, Cache^ cache )
+ : m_delegate( typeDelegate ), m_cache(cache) { }
+
+ /// <summary>
+ /// Returns the native <c>apache::geode::client::Serializable</c> object by invoking the
+ /// managed delegate provided in the constructor.
+ /// </summary>
+ /// <returns>
+ /// Native <c>apache::geode::client::Serializable</c> object after invoking the managed
+ /// delegate and wrapping inside a <c>ManagedCacheableKey</c> object.
+ /// </returns>
+ apache::geode::client::Serializable* NativeDelegateGeneric( )
+ {
+ IGeodeSerializable^ tempObj = m_delegate( );
+ IGeodeDelta^ tempDelta =
+ dynamic_cast<IGeodeDelta^>(tempObj);
+ if( tempDelta != nullptr )
+ {
+ if(!SafeConvertClassGeneric::isAppDomainEnabled)
+ return new apache::geode::client::ManagedCacheableDeltaGeneric( tempDelta );
+ else
+ return new apache::geode::client::ManagedCacheableDeltaBytesGeneric( tempDelta, false );
+ }
+ else if(!SafeConvertClassGeneric::isAppDomainEnabled)
+ return new apache::geode::client::ManagedCacheableKeyGeneric( tempObj, CacheRegionHelper::getCacheImpl(m_cache->GetNative().get())->getSerializationRegistry().get());
+ else
+ return new apache::geode::client::ManagedCacheableKeyBytesGeneric( tempObj, false);
+ }
+
+
+ private:
+
+ TypeFactoryMethodGeneric^ m_delegate;
+
+ Cache^ m_cache;
+ };
+ } // namespace Client
+ } // namespace Geode
+} // namespace Apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/DotNetTypes.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/DotNetTypes.hpp b/clicache/src/impl/DotNetTypes.hpp
new file mode 100755
index 0000000..61265e8
--- /dev/null
+++ b/clicache/src/impl/DotNetTypes.hpp
@@ -0,0 +1,61 @@
+/*
+ * 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
+
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+
+ namespace Internal
+ {
+ public ref class DotNetTypes sealed
+ {
+ public:
+ static Type^ IntType = Int32::typeid;
+ static Type^ StringType = String::typeid;
+ static Type^ BooleanType = Boolean::typeid;
+ static Type^ FloatType = float::typeid;
+ static Type^ DoubleType = Double::typeid;
+ static Type^ CharType = Char::typeid;
+ static Type^ SByteType = SByte::typeid;
+ static Type^ ShortType = Int16::typeid;
+ static Type^ LongType = Int64::typeid;
+ static Type^ ByteArrayType = Type::GetType("System.Byte[]");
+ static Type^ DoubleArrayType = Type::GetType("System.Double[]");
+ static Type^ FloatArrayType = Type::GetType("System.Single[]");
+ static Type^ ShortArrayType = Type::GetType("System.Int16[]");
+ static Type^ IntArrayType = Type::GetType("System.Int32[]");
+ static Type^ LongArrayType = Type::GetType("System.Int64[]");
+ static Type^ BoolArrayType = Type::GetType("System.Boolean[]");
+ static Type^ CharArrayType = Type::GetType("System.Char[]");
+ static Type^ StringArrayType = Type::GetType("System.String[]");
+ static Type^ DateType = Type::GetType("System.DateTime");
+ static Type^ ByteArrayOfArrayType = Type::GetType("System.Byte[][]");
+ static Type^ ObjectArrayType = Type::GetType("System.Collections.Generic.List`1[System.Object]");
+
+ static Type^ VoidType = Type::GetType("System.Void");
+ static Type^ ObjectType = Type::GetType("System.Object");
+ };
+ } // namespace Client
+ } // namespace Geode
+} // namespace Apache
+
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/EnumInfo.cpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/EnumInfo.cpp b/clicache/src/impl/EnumInfo.cpp
new file mode 100755
index 0000000..feacdc8
--- /dev/null
+++ b/clicache/src/impl/EnumInfo.cpp
@@ -0,0 +1,61 @@
+/*
+ * 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 "EnumInfo.hpp"
+#include "../DataOutput.hpp"
+#include "../DataInput.hpp"
+using namespace System;
+
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+
+ namespace Internal
+ {
+ void EnumInfo::ToData( DataOutput^ output )
+ {
+ output->WriteString(_enumClassName);
+ output->WriteString(_enumName);
+ output->WriteInt32(_hashcode);
+ }
+
+ IGeodeSerializable^ EnumInfo::FromData( DataInput^ input )
+ {
+ _enumClassName = input->ReadString();
+ _enumName = input->ReadString();
+ _hashcode = input->ReadInt32();
+ return this;
+ }
+
+ Object^ EnumInfo::GetEnum()
+ {
+ String^ tmp = Serializable::GetLocalTypeName(_enumClassName);
+ Type^ t = Serializable::GetType(tmp);
+ Object^ obj = Enum::Parse(t, _enumName);
+
+ return obj;
+ } // namespace Client
+ } // namespace Geode
+} // namespace Apache
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/EnumInfo.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/EnumInfo.hpp b/clicache/src/impl/EnumInfo.hpp
new file mode 100755
index 0000000..4ee4797
--- /dev/null
+++ b/clicache/src/impl/EnumInfo.hpp
@@ -0,0 +1,104 @@
+/*
+ * 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 "../IGeodeSerializable.hpp"
+#include "../GeodeClassIds.hpp"
+using namespace System;
+using namespace System::Collections::Generic;
+
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+
+ namespace Internal
+ {
+ public ref class EnumInfo : public IGeodeSerializable
+ {
+ private:
+ String^ _enumClassName;
+ String^ _enumName;
+ Int32 _hashcode;
+ public:
+
+ EnumInfo()
+ {
+ _hashcode = -1;
+ }
+
+ EnumInfo(String^ enumClassName, String^ enumName, int hashcode)
+ {
+ _enumClassName = enumClassName;
+ _enumName = enumName;
+ _hashcode = hashcode;
+ }
+
+ static IGeodeSerializable^ CreateDeserializable()
+ {
+ return gcnew EnumInfo();
+ }
+ virtual void ToData(DataOutput^ output);
+ virtual IGeodeSerializable^ FromData(DataInput^ input);
+ virtual property System::UInt32 ObjectSize
+ {
+ System::UInt32 get(){ return 0; }
+ }
+ virtual property System::UInt32 ClassId
+ {
+ System::UInt32 get(){ return GeodeClassIds::EnumInfo; }
+ }
+ virtual String^ ToString() override
+ {
+ return "EnumInfo";
+ }
+
+ virtual int GetHashCode()override
+ {
+ if (_hashcode != -1)
+ return _hashcode;
+
+ return ((_enumClassName != nullptr ? _enumClassName->GetHashCode() : 0)
+ + (_enumName != nullptr ? _enumName->GetHashCode() : 0));
+ }
+
+ virtual bool Equals(Object^ obj)override
+ {
+ if (obj != nullptr)
+ {
+ EnumInfo^ other = dynamic_cast<EnumInfo^>(obj);
+ if (other != nullptr)
+ {
+ return _enumClassName == other->_enumClassName
+ && _enumName == other->_enumName
+ && _hashcode == other->_hashcode;
+ }
+ return false;
+ }
+ return false;
+ }
+
+ Object^ GetEnum();
+
+ };
+ } // namespace Client
+ } // namespace Geode
+ } // namespace Apache
+
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/FixedPartitionResolver.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/FixedPartitionResolver.hpp b/clicache/src/impl/FixedPartitionResolver.hpp
new file mode 100644
index 0000000..38a3fa3
--- /dev/null
+++ b/clicache/src/impl/FixedPartitionResolver.hpp
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+#include "../IFixedPartitionResolver.hpp"
+#include "../Region.hpp"
+#include "ManagedString.hpp"
+#include "SafeConvert.hpp"
+
+using namespace System;
+using namespace System::Collections::Generic;
+using namespace System::Threading;
+
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+
+ public interface class IFixedPartitionResolverProxy
+ {
+ public:
+ apache::geode::client::CacheableKeyPtr getRoutingObject(const apache::geode::client::EntryEvent& ev);
+ const char * getName();
+ const char* getPartitionName(const apache::geode::client::EntryEvent& opDetails);
+ };
+
+ generic<class TKey, class TValue>
+ public ref class FixedPartitionResolverGeneric : IFixedPartitionResolverProxy
+ {
+ private:
+
+ IPartitionResolver<TKey, TValue>^ m_resolver;
+ IFixedPartitionResolver<TKey, TValue>^ m_fixedResolver;
+ Dictionary<String^, ManagedString^> ^m_strList;
+ public:
+
+ void SetPartitionResolver(IPartitionResolver<TKey, TValue>^ resolver)
+ {
+ m_resolver = resolver;
+ m_fixedResolver = dynamic_cast<IFixedPartitionResolver<TKey, TValue>^>(resolver);
+ m_strList = gcnew Dictionary<String^, ManagedString^>();
+ }
+
+ virtual apache::geode::client::CacheableKeyPtr getRoutingObject(const apache::geode::client::EntryEvent& ev)
+ {
+ EntryEvent<TKey, TValue> gevent(&ev);
+ Object^ groutingobject = m_resolver->GetRoutingObject(%gevent);
+ return Serializable::GetUnmanagedValueGeneric<Object^>(groutingobject, nullptr);
+ }
+
+ virtual const char * getName()
+ {
+ ManagedString mg_name(m_resolver->GetName());
+ return mg_name.CharPtr;
+ }
+
+ virtual const char* getPartitionName(const apache::geode::client::EntryEvent& opDetails)
+ {
+ if (m_fixedResolver == nullptr)
+ {
+ throw apache::geode::client::IllegalStateException("GetPartitionName() called on non fixed partition resolver.");
+ }
+
+ EntryEvent<TKey, TValue> gevent(&opDetails);
+ String^ str = m_fixedResolver->GetPartitionName(%gevent);
+ ManagedString ^mnStr = nullptr;
+ try
+ {
+ Monitor::Enter( m_strList );
+ if(!m_strList->TryGetValue(str,mnStr))
+ {
+ mnStr= gcnew ManagedString(str);
+ m_strList->Add(str,mnStr);
+ }
+ }
+ finally
+ {
+ Monitor::Exit( m_strList );
+ }
+
+ return mnStr->CharPtr;
+ }
+ };
+ } // namespace Client
+ } // namespace Geode
+} // namespace Apache
+
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/GeodeDataInputStream.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/GeodeDataInputStream.hpp b/clicache/src/impl/GeodeDataInputStream.hpp
new file mode 100644
index 0000000..8f3bb77
--- /dev/null
+++ b/clicache/src/impl/GeodeDataInputStream.hpp
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "../geode_defs.hpp"
+#include "../DataInput.hpp"
+#include "../ExceptionTypes.hpp"
+
+using namespace System;
+using namespace System::IO;
+
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+
+ ref class GeodeDataInputStream : public Stream
+ {
+ public:
+
+ GeodeDataInputStream(DataInput^ input)
+ {
+ m_buffer = input;
+ m_maxSize = input->BytesRemaining;
+ }
+
+ GeodeDataInputStream(DataInput^ input, int maxSize)
+ {
+ m_buffer = input;
+ m_maxSize = maxSize;
+ m_buffer->AdvanceUMCursor();
+ m_buffer->SetBuffer();
+ }
+
+ virtual property bool CanSeek { bool get() override { return false; } }
+ virtual property bool CanRead { bool get() override { return true; } }
+ virtual property bool CanWrite { bool get() override { return false; } }
+
+ virtual void Close() override { Stream::Close(); }
+
+ virtual property System::Int64 Length
+ {
+ System::Int64 get() override
+ {
+ //return (System::Int64) m_buffer->BytesRead + m_buffer->BytesRemaining;
+ return (System::Int64) m_maxSize;
+ }
+ }
+
+ virtual property System::Int64 Position
+ {
+ System::Int64 get() override
+ {
+ return (System::Int64) m_position;
+ }
+
+ void set(System::Int64 value) override
+ {
+ m_position = (int) value;
+ }
+ }
+
+ virtual System::Int64 Seek(System::Int64 offset, SeekOrigin origin) override
+ {
+ throw gcnew System::NotSupportedException("Seek not supported by GeodeDataInputStream");
+ }
+
+ virtual void SetLength(System::Int64 value) override { /* do nothing */ }
+
+ virtual void Write(array<Byte> ^ buffer, int offset, int count) override
+ {
+ throw gcnew System::NotSupportedException("Write not supported by GeodeDataInputStream");
+ }
+
+ virtual void WriteByte(unsigned char value) override
+ {
+ throw gcnew System::NotSupportedException("WriteByte not supported by GeodeDataInputStream");
+ }
+
+ virtual int Read(array<Byte> ^ buffer, int offset, int count) override
+ {
+ _GF_MG_EXCEPTION_TRY2/* due to auto replace */
+ int bytesRemaining = m_maxSize - (int) m_buffer->BytesReadInternally;
+ if(bytesRemaining == 0)
+ return bytesRemaining;
+ int actual = bytesRemaining < count ? bytesRemaining : count;
+ if (actual > 0)
+ {
+ /*
+ array<Byte>::ConstrainedCopy(m_buffer->ReadBytesOnly(actual), 0,
+ buffer, offset, actual);
+ */
+ //pin_ptr<Byte> pin_buffer = &buffer[offset];
+ //m_buffer->NativePtr->readBytesOnly((System::Byte*)pin_buffer, actual);
+ m_buffer->ReadBytesOnly(buffer, offset, actual);
+ m_position += actual;
+ }
+ return actual;
+ _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+ }
+
+ virtual void Flush() override { /* do nothing */ }
+
+ property System::UInt32 BytesRead
+ {
+ System::UInt32 get()
+ {
+ return m_buffer->BytesReadInternally;
+ }
+ }
+
+ private:
+ int m_position;
+ int m_maxSize;
+ DataInput ^ m_buffer;
+ };
+ } // namespace Client
+ } // namespace Geode
+} // namespace Apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/GeodeDataOutputStream.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/GeodeDataOutputStream.hpp b/clicache/src/impl/GeodeDataOutputStream.hpp
new file mode 100644
index 0000000..dc8fc49
--- /dev/null
+++ b/clicache/src/impl/GeodeDataOutputStream.hpp
@@ -0,0 +1,118 @@
+/*
+ * 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 "../DataOutput.hpp"
+#include "../ExceptionTypes.hpp"
+
+using namespace System;
+using namespace System::IO;
+
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+
+ ref class GeodeDataOutputStream : public Stream
+ {
+ public:
+
+ GeodeDataOutputStream(DataOutput^ output)
+ {
+ m_buffer = output;
+ }
+
+ virtual property bool CanSeek { bool get() override { return false; } }
+ virtual property bool CanRead { bool get() override { return false; } }
+ virtual property bool CanWrite { bool get() override { return true; } }
+
+ virtual void Close() override { Stream::Close(); }
+
+ virtual property System::Int64 Length
+ {
+ System::Int64 get() override
+ {
+ return (System::Int64) m_buffer->BufferLength;
+ }
+ }
+
+ virtual property System::Int64 Position
+ {
+ System::Int64 get() override
+ {
+ return (System::Int64) m_position;
+ }
+
+ void set(System::Int64 value) override
+ {
+ m_position = (int) value;
+ }
+ }
+
+ virtual System::Int64 Seek(System::Int64 offset, SeekOrigin origin) override
+ {
+ throw gcnew System::NotSupportedException("Seek not supported by GeodeDataOutputStream");
+ }
+
+ virtual void SetLength(System::Int64 value) override
+ {
+ //TODO: overflow check
+ //m_buffer->NativePtr->ensureCapacity((System::UInt32)value);
+ }
+
+ virtual void Write(array<Byte> ^ buffer, int offset, int count) override
+ {
+ _GF_MG_EXCEPTION_TRY2/* due to auto replace */
+ /*
+ array<Byte> ^ chunk = gcnew array<Byte>(count);
+ array<Byte>::ConstrainedCopy(buffer, offset, chunk, 0, count);
+ m_buffer->WriteBytesOnly(chunk, count);
+ */
+ //pin_ptr<const Byte> pin_bytes = &buffer[offset];
+ //m_buffer->NativePtr->writeBytesOnly((const System::Byte*)pin_bytes, count);
+ m_buffer->WriteBytesOnly(buffer, count, offset);
+ m_position += count;
+ _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+ }
+
+ virtual void WriteByte(unsigned char value) override
+ {
+ _GF_MG_EXCEPTION_TRY2/* due to auto replace */
+ m_buffer->WriteByte(value);
+ m_position++;
+ _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+ }
+
+ virtual int Read(array<Byte> ^ buffer, int offset, int count) override
+ {
+ throw gcnew System::NotSupportedException("Read not supported by GeodeDataOutputStream");
+ }
+
+ virtual void Flush() override { /* do nothing */ }
+
+ private:
+ int m_position;
+ DataOutput ^ m_buffer;
+ };
+ } // namespace Client
+ } // namespace Geode
+} // namespace Apache
+
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/GeodeNullStream.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/GeodeNullStream.hpp b/clicache/src/impl/GeodeNullStream.hpp
new file mode 100644
index 0000000..12a87f9
--- /dev/null
+++ b/clicache/src/impl/GeodeNullStream.hpp
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "../geode_defs.hpp"
+
+using namespace System;
+using namespace System::IO;
+
+namespace Apache
+{
+ namespace Geode
+ {
+ namespace Client
+ {
+
+ ref class GeodeNullStream : public Stream
+ {
+ public:
+
+ virtual property bool CanSeek { bool get() override { return false; } }
+ virtual property bool CanRead { bool get() override { return false; } }
+ virtual property bool CanWrite { bool get() override { return true; } }
+
+ virtual void Close() override { Stream::Close(); }
+
+ virtual property System::Int64 Length
+ {
+ System::Int64 get() override
+ {
+ return (System::Int64) m_position;
+ }
+ }
+
+ virtual property System::Int64 Position
+ {
+ System::Int64 get() override
+ {
+ return (System::Int64) m_position;
+ }
+
+ void set(System::Int64 value) override
+ {
+ m_position = (int) value;
+ }
+ }
+
+ virtual System::Int64 Seek(System::Int64 offset, SeekOrigin origin) override
+ {
+ throw gcnew System::NotSupportedException("Seek not supported by GeodeNullStream");
+ /*
+ int actual = 0;
+ switch (origin)
+ {
+ case SeekOrigin::Begin:
+ actual = (int) offset;
+ m_position = (int) actual;
+ break;
+
+ case SeekOrigin::Current:
+ actual = (int) offset;
+ m_position += (int) actual;
+ break;
+
+ case SeekOrigin::End:
+ actual = (int) offset;
+ m_position += (int) actual;
+ break;
+ }
+ // Seek is meaningless here?
+ return m_position;
+ */
+ }
+
+ virtual void SetLength(System::Int64 value) override { /* do nothing */ }
+
+ virtual void Write(array<Byte> ^ buffer, int offset, int count) override
+ {
+ m_position += count;
+ }
+
+ virtual void WriteByte(unsigned char value) override
+ {
+ m_position++;
+ }
+
+ virtual int Read(array<Byte> ^ buffer, int offset, int count) override
+ {
+ throw gcnew System::NotSupportedException("Seek not supported by GeodeNullStream");
+ /*
+ int actual = count;
+ m_position += actual;
+ return actual;
+ */
+ }
+
+ virtual void Flush() override { /* do nothing */ }
+
+ private:
+ int m_position;
+ };
+ } // namespace Client
+ } // namespace Geode
+} // namespace Apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/ManagedAuthInitialize.cpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/ManagedAuthInitialize.cpp b/clicache/src/impl/ManagedAuthInitialize.cpp
new file mode 100644
index 0000000..61e0683
--- /dev/null
+++ b/clicache/src/impl/ManagedAuthInitialize.cpp
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#include "../geode_includes.hpp"
+#include "ManagedAuthInitialize.hpp"
+#include "../IAuthInitialize.hpp"
+#include "ManagedString.hpp"
+#include "../ExceptionTypes.hpp"
+#include "Properties.hpp"
+#include <string>
+
+using namespace System;
+using namespace System::Text;
+using namespace System::Reflection;
+
+namespace apache
+{
+ namespace geode
+ {
+ namespace client
+ {
+
+ AuthInitialize* ManagedAuthInitializeGeneric::create(const char* assemblyPath,
+ const char* factoryFunctionName)
+ {
+ try
+ {
+ String^ mg_assemblyPath =
+ Apache::Geode::Client::ManagedString::Get(assemblyPath);
+ String^ mg_factoryFunctionName =
+ Apache::Geode::Client::ManagedString::Get(factoryFunctionName);
+ String^ mg_typeName = nullptr;
+ System::Int32 dotIndx = -1;
+
+ if (mg_factoryFunctionName == nullptr ||
+ (dotIndx = mg_factoryFunctionName->LastIndexOf('.')) < 0)
+ {
+ std::string ex_str = "ManagedAuthInitializeGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain type name";
+ throw AuthenticationRequiredException(ex_str.c_str());
+ }
+
+ mg_typeName = mg_factoryFunctionName->Substring(0, dotIndx);
+ mg_factoryFunctionName = mg_factoryFunctionName->Substring(dotIndx + 1);
+
+ Assembly^ assmb = nullptr;
+ try
+ {
+ assmb = Assembly::Load(mg_assemblyPath);
+ }
+ catch (System::Exception^)
+ {
+ assmb = nullptr;
+ }
+ if (assmb == nullptr)
+ {
+ std::string ex_str = "ManagedAuthInitializeGeneric: Could not load assembly: ";
+ ex_str += assemblyPath;
+ throw AuthenticationRequiredException(ex_str.c_str());
+ }
+
+ Object^ typeInst = assmb->CreateInstance(mg_typeName, true);
+
+ //Type^ typeInst = assmb->GetType(mg_typeName, false, true);
+
+ if (typeInst != nullptr)
+ {
+ /*
+ array<Type^>^ types = gcnew array<Type^>(2);
+ types[0] = Type::GetType(mg_genericKey, false, true);
+ types[1] = Type::GetType(mg_genericVal, false, true);
+
+ if (types[0] == nullptr || types[1] == nullptr)
+ {
+ std::string ex_str = "ManagedAuthInitializeGeneric: Could not get both generic type argument instances";
+ throw apache::geode::client::IllegalArgumentException( ex_str.c_str( ) );
+ }
+ */
+
+ //typeInst = typeInst->GetType()->MakeGenericType(types);
+ Apache::Geode::Client::Log::Info("Loading function: [{0}]", mg_factoryFunctionName);
+
+ /*
+ MethodInfo^ mInfo = typeInst->GetMethod( mg_factoryFunctionName,
+ BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase );
+ */
+
+ MethodInfo^ mInfo = typeInst->GetType()->GetMethod(mg_factoryFunctionName,
+ BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase);
+
+ if (mInfo != nullptr)
+ {
+ Object^ userptr = nullptr;
+ try
+ {
+ userptr = mInfo->Invoke(typeInst, nullptr);
+ }
+ catch (System::Exception^)
+ {
+ userptr = nullptr;
+ }
+ if (userptr == nullptr)
+ {
+ std::string ex_str = "ManagedAuthInitializeGeneric: Could not create "
+ "object on invoking factory function [";
+ ex_str += factoryFunctionName;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw AuthenticationRequiredException(ex_str.c_str());
+ }
+ ManagedAuthInitializeGeneric * maig = new ManagedAuthInitializeGeneric(safe_cast<Apache::Geode::Client::IAuthInitialize^>(userptr));
+ return maig;
+ }
+ else
+ {
+ std::string ex_str = "ManagedAuthInitializeGeneric: Could not load "
+ "function with name [";
+ ex_str += factoryFunctionName;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw AuthenticationRequiredException(ex_str.c_str());
+ }
+ }
+ else
+ {
+ Apache::Geode::Client::ManagedString typeName(mg_typeName);
+ std::string ex_str = "ManagedAuthInitializeGeneric: Could not load type [";
+ ex_str += typeName.CharPtr;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw AuthenticationRequiredException(ex_str.c_str());
+ }
+ }
+ catch (const apache::geode::client::AuthenticationRequiredException&)
+ {
+ throw;
+ }
+ catch (const apache::geode::client::Exception& ex)
+ {
+ std::string ex_str = "ManagedAuthInitializeGeneric: Got an exception while "
+ "loading managed library: ";
+ ex_str += ex.getName();
+ ex_str += ": ";
+ ex_str += ex.getMessage();
+ throw AuthenticationRequiredException(ex_str.c_str());
+ }
+ catch (System::Exception^ ex)
+ {
+ Apache::Geode::Client::ManagedString mg_exStr(ex->ToString());
+ std::string ex_str = "ManagedAuthInitializeGeneric: Got an exception while "
+ "loading managed library: ";
+ ex_str += mg_exStr.CharPtr;
+ throw AuthenticationRequiredException(ex_str.c_str());
+ }
+ return NULL;
+ }
+
+ PropertiesPtr ManagedAuthInitializeGeneric::getCredentials(const PropertiesPtr&
+ securityprops, const char* server)
+ {
+ try {
+ auto mprops = Apache::Geode::Client::Properties<String^, String^>::Create(securityprops);
+ String^ mg_server = Apache::Geode::Client::ManagedString::Get(server);
+
+ return m_getCredentials->Invoke(mprops, mg_server)->GetNative();
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ return nullptr;
+ }
+
+ void ManagedAuthInitializeGeneric::close()
+ {
+ try {
+ m_close->Invoke();
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ } // namespace client
+ } // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/ManagedAuthInitialize.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/ManagedAuthInitialize.hpp b/clicache/src/impl/ManagedAuthInitialize.hpp
new file mode 100644
index 0000000..83f7961
--- /dev/null
+++ b/clicache/src/impl/ManagedAuthInitialize.hpp
@@ -0,0 +1,134 @@
+/*
+ * 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/AuthInitialize.hpp>
+#include "end_native.hpp"
+
+#include <vcclr.h>
+#include "../IAuthInitialize.hpp"
+
+//using namespace apache::geode::client;
+
+namespace apache
+{
+ namespace geode
+ {
+ namespace client
+ {
+
+ /// <summary>
+ /// Wraps the managed <see cref="Apache.Geode.Client.IAuthInitialize" />
+ /// object and implements the native <c>apache::geode::client::AuthInitialize</c> interface.
+ /// </summary>
+ class ManagedAuthInitializeGeneric
+ : public apache::geode::client::AuthInitialize
+ {
+ public:
+
+ /// <summary>
+ /// Constructor to initialize with the provided managed object.
+ /// </summary>
+ /// <param name="managedptr">
+ /// The managed object.
+ /// </param>
+ inline ManagedAuthInitializeGeneric(Apache::Geode::Client::IAuthInitialize^ managedptr)
+ : m_managedptr(managedptr) {
+ m_getCredentials = gcnew Apache::Geode::Client::IAuthInitialize::GetCredentialsDelegate(managedptr,
+ &Apache::Geode::Client::IAuthInitialize::GetCredentials);
+ m_close = gcnew Apache::Geode::Client::IAuthInitialize::CloseDelegate(managedptr,
+ &Apache::Geode::Client::IAuthInitialize::Close);
+ }
+
+ /// <summary>
+ /// Static function to create a <c>ManagedAuthInitialize</c> using given
+ /// managed assembly path and given factory function.
+ /// </summary>
+ /// <param name="assemblyPath">
+ /// The path of the managed assembly that contains the <c>IAuthInitialize</c>
+ /// factory function.
+ /// </param>
+ /// <param name="factoryFunctionName">
+ /// The name of the factory function of the managed class for creating
+ /// an object that implements <c>IAuthInitialize</c>.
+ /// This should be a static function of the format
+ /// {Namespace}.{Class Name}.{Method Name}.
+ /// </param>
+ /// <exception cref="IllegalArgumentException">
+ /// If the managed library cannot be loaded or the factory function fails.
+ /// </exception>
+ static AuthInitialize* create(const char* assemblyPath,
+ const char* factoryFunctionName);
+
+ /// <summary>
+ /// Called when the cache is going down
+ /// </summary>
+ /// <remarks>
+ /// Implementations should clean up any external
+ /// resources, such as database connections. Any runtime exceptions this method
+ /// throws will be logged.
+ /// <para>
+ /// It is possible for this method to be called multiple times on a single
+ /// callback instance, so implementations must be tolerant of this.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Apache.Geode.Client.Cache.Close" />
+ virtual void close();
+
+ /// <summary>
+ /// Initialize with the given set of security properties and return the
+ /// credentials for the given client as properties.
+ /// </summary>
+ /// <param name="securityprops">Given set of properties with which
+ /// to initialize
+ /// </param>
+ /// <param name="server">It is the ID of the endpoint
+ /// </param>
+ virtual PropertiesPtr getCredentials(const PropertiesPtr& securityprops, const char* server);
+
+ virtual ~ManagedAuthInitializeGeneric() { }
+
+ /// <summary>
+ /// Returns the wrapped managed object reference.
+ /// </summary>
+ inline Apache::Geode::Client::IAuthInitialize^ ptr() const
+ {
+ return m_managedptr;
+ }
+
+ private:
+
+ /// <summary>
+ /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly).
+ /// Note: not using auto_gcroot since it will result in 'Dispose' of the ICacheLoader
+ /// to be called which is not what is desired when this object is destroyed. Normally this
+ /// managed object may be created by the user and will be handled automatically by the GC.
+ /// </summary>
+ gcroot<Apache::Geode::Client::IAuthInitialize^> m_managedptr;
+ gcroot<Apache::Geode::Client::IAuthInitialize::GetCredentialsDelegate^> m_getCredentials;
+ gcroot<Apache::Geode::Client::IAuthInitialize::CloseDelegate^> m_close;
+
+ // Disable the copy and assignment constructors
+ ManagedAuthInitializeGeneric(const ManagedAuthInitializeGeneric&);
+ ManagedAuthInitializeGeneric& operator = (const ManagedAuthInitializeGeneric&);
+ };
+ } // namespace client
+ } // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/ManagedCacheListener.cpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/ManagedCacheListener.cpp b/clicache/src/impl/ManagedCacheListener.cpp
new file mode 100644
index 0000000..171eeb4
--- /dev/null
+++ b/clicache/src/impl/ManagedCacheListener.cpp
@@ -0,0 +1,362 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#include "../geode_includes.hpp"
+#include "ManagedCacheListener.hpp"
+#include "../ICacheListener.hpp"
+#include "../EntryEvent.hpp"
+#include "../RegionEvent.hpp"
+#include "../Region.hpp"
+#include "../Log.hpp"
+#include "../ExceptionTypes.hpp"
+#include "../EntryEvent.hpp"
+#include "ManagedString.hpp"
+
+
+using namespace System;
+using namespace System::Text;
+using namespace System::Reflection;
+
+namespace apache
+{
+ namespace geode
+ {
+ namespace client
+ {
+
+ apache::geode::client::CacheListener* ManagedCacheListenerGeneric::create(const char* assemblyPath,
+ const char* factoryFunctionName)
+ {
+ try
+ {
+ String^ mg_assemblyPath =
+ Apache::Geode::Client::ManagedString::Get(assemblyPath);
+ String^ mg_factoryFunctionName =
+ Apache::Geode::Client::ManagedString::Get(factoryFunctionName);
+ String^ mg_typeName = nullptr;
+
+ String^ mg_genericKey = nullptr;
+ String^ mg_genericVal = nullptr;
+
+ System::Int32 dotIndx = -1;
+ System::Int32 genericsOpenIndx = -1;
+ System::Int32 genericsCloseIndx = -1;
+ System::Int32 commaIndx = -1;
+
+ if (mg_factoryFunctionName == nullptr ||
+ (dotIndx = mg_factoryFunctionName->LastIndexOf('.')) < 0)
+ {
+ std::string ex_str = "ManagedCacheListenerGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain type name";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ if ((genericsCloseIndx = mg_factoryFunctionName->LastIndexOf('>')) < 0)
+ {
+ std::string ex_str = "ManagedCacheListenerGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain any generic type parameters";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ if ((genericsOpenIndx = mg_factoryFunctionName->LastIndexOf('<')) < 0 ||
+ genericsOpenIndx > genericsCloseIndx)
+ {
+ std::string ex_str = "ManagedCacheListenerGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain expected generic type parameters";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ if ((commaIndx = mg_factoryFunctionName->LastIndexOf(',')) < 0 ||
+ (commaIndx < genericsOpenIndx || commaIndx > genericsCloseIndx))
+ {
+ std::string ex_str = "ManagedCacheListenerGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain expected generic type parameter comma separator";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ StringBuilder^ typeBuilder = gcnew StringBuilder(mg_factoryFunctionName->Substring(0, genericsOpenIndx));
+ mg_typeName = typeBuilder->ToString();
+ mg_genericKey = mg_factoryFunctionName->Substring(genericsOpenIndx + 1, commaIndx - genericsOpenIndx - 1);
+ mg_genericKey = mg_genericKey->Trim();
+ mg_genericVal = mg_factoryFunctionName->Substring(commaIndx + 1, genericsCloseIndx - commaIndx - 1);
+ mg_genericVal = mg_genericVal->Trim();
+ mg_factoryFunctionName = mg_factoryFunctionName->Substring(dotIndx + 1);
+
+ Apache::Geode::Client::Log::Fine("Attempting to instantiate a [{0}<{1}, {2}>] via the [{3}] factory method.",
+ mg_typeName, mg_genericKey, mg_genericVal, mg_factoryFunctionName);
+
+ typeBuilder->Append("`2");
+ mg_typeName = typeBuilder->ToString();
+
+ Assembly^ assmb = nullptr;
+ try
+ {
+ assmb = Assembly::Load(mg_assemblyPath);
+ }
+ catch (System::Exception^)
+ {
+ assmb = nullptr;
+ }
+ if (assmb == nullptr)
+ {
+ std::string ex_str = "ManagedCacheListenerGeneric: Could not load assembly: ";
+ ex_str += assemblyPath;
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ Apache::Geode::Client::Log::Debug("Loading type: [{0}]", mg_typeName);
+
+ Type^ typeInst = assmb->GetType(mg_typeName, false, true);
+
+ if (typeInst != nullptr)
+ {
+ array<Type^>^ types = gcnew array<Type^>(2);
+ types[0] = Type::GetType(mg_genericKey, false, true);
+ types[1] = Type::GetType(mg_genericVal, false, true);
+
+ if (types[0] == nullptr || types[1] == nullptr)
+ {
+ std::string ex_str = "ManagedCacheListenerGeneric: Could not get both generic type argument instances";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ typeInst = typeInst->MakeGenericType(types);
+ Apache::Geode::Client::Log::Info("Loading function: [{0}]", mg_factoryFunctionName);
+
+ MethodInfo^ mInfo = typeInst->GetMethod(mg_factoryFunctionName,
+ BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase);
+
+ if (mInfo != nullptr)
+ {
+ Object^ userptr = nullptr;
+ try
+ {
+ userptr = mInfo->Invoke(typeInst, nullptr);
+ }
+ catch (System::Exception^ ex)
+ {
+ Apache::Geode::Client::Log::Debug("{0}: {1}", ex->GetType()->Name, ex->Message);
+ userptr = nullptr;
+ }
+ if (userptr == nullptr)
+ {
+ std::string ex_str = "ManagedCacheListenerGeneric: Could not create "
+ "object on invoking factory function [";
+ ex_str += factoryFunctionName;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ ManagedCacheListenerGeneric * mgcl = new ManagedCacheListenerGeneric(userptr);
+
+ Type^ clgType = Type::GetType("Apache.Geode.Client.CacheListenerGeneric`2");
+ clgType = clgType->MakeGenericType(types);
+ Object^ clg = Activator::CreateInstance(clgType);
+
+ mInfo = clgType->GetMethod("SetCacheListener");
+ array<Object^>^ params = gcnew array<Object^>(1);
+ params[0] = userptr;
+ mInfo->Invoke(clg, params);
+
+ mgcl->setptr((Apache::Geode::Client::ICacheListener<Object^, Object^>^)clg);
+
+ return mgcl;
+ }
+ else
+ {
+ std::string ex_str = "ManagedCacheListenerGeneric: Could not load "
+ "function with name [";
+ ex_str += factoryFunctionName;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+ }
+ else
+ {
+ Apache::Geode::Client::ManagedString typeName(mg_typeName);
+ std::string ex_str = "ManagedCacheListenerGeneric: Could not load type [";
+ ex_str += typeName.CharPtr;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+ }
+ catch (const apache::geode::client::Exception&)
+ {
+ throw;
+ }
+ catch (System::Exception^ ex)
+ {
+ Apache::Geode::Client::ManagedString mg_exStr(ex->ToString());
+ std::string ex_str = "ManagedCacheListenerGeneric: Got an exception while "
+ "loading managed library: ";
+ ex_str += mg_exStr.CharPtr;
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+ return NULL;
+ }
+
+ void ManagedCacheListenerGeneric::afterCreate(const apache::geode::client::EntryEvent& ev)
+ {
+ try {
+ Apache::Geode::Client::EntryEvent<Object^, Object^> mevent(&ev);
+ m_managedptr->AfterCreate(%mevent);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ void ManagedCacheListenerGeneric::afterUpdate(const apache::geode::client::EntryEvent& ev)
+ {
+ try {
+ Apache::Geode::Client::EntryEvent<Object^, Object^> mevent(&ev);
+ m_managedptr->AfterUpdate(%mevent);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ void ManagedCacheListenerGeneric::afterInvalidate(const apache::geode::client::EntryEvent& ev)
+ {
+ try {
+ Apache::Geode::Client::EntryEvent<Object^, Object^> mevent(&ev);
+ m_managedptr->AfterInvalidate(%mevent);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ void ManagedCacheListenerGeneric::afterDestroy(const apache::geode::client::EntryEvent& ev)
+ {
+ try {
+ Apache::Geode::Client::EntryEvent<Object^, Object^> mevent(&ev);
+ m_managedptr->AfterDestroy(%mevent);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+ void ManagedCacheListenerGeneric::afterRegionClear(const apache::geode::client::RegionEvent& ev)
+ {
+ try {
+ Apache::Geode::Client::RegionEvent<Object^, Object^> mevent(&ev);
+ m_managedptr->AfterRegionClear(%mevent);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ void ManagedCacheListenerGeneric::afterRegionInvalidate(const apache::geode::client::RegionEvent& ev)
+ {
+ try {
+ Apache::Geode::Client::RegionEvent<Object^, Object^> mevent(&ev);
+ m_managedptr->AfterRegionInvalidate(%mevent);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ void ManagedCacheListenerGeneric::afterRegionDestroy(const apache::geode::client::RegionEvent& ev)
+ {
+ try {
+ Apache::Geode::Client::RegionEvent<Object^, Object^> mevent(&ev);
+ m_managedptr->AfterRegionDestroy(%mevent);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ void ManagedCacheListenerGeneric::afterRegionLive(const apache::geode::client::RegionEvent& ev)
+ {
+ try {
+ Apache::Geode::Client::RegionEvent<Object^, Object^> mevent(&ev);
+ m_managedptr->AfterRegionLive(%mevent);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ void ManagedCacheListenerGeneric::close(const apache::geode::client::RegionPtr& region)
+ {
+ try {
+ Apache::Geode::Client::IRegion<Object^, Object^>^ mregion =
+ Apache::Geode::Client::Region<Object^, Object^>::Create(region);
+
+ m_managedptr->Close(mregion);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+ void ManagedCacheListenerGeneric::afterRegionDisconnected(const apache::geode::client::RegionPtr& region)
+ {
+ try {
+ Apache::Geode::Client::IRegion<Object^, Object^>^ mregion =
+ Apache::Geode::Client::Region<Object^, Object^>::Create(region);
+ m_managedptr->AfterRegionDisconnected(mregion);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ } // namespace client
+ } // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/ManagedCacheListener.hpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/ManagedCacheListener.hpp b/clicache/src/impl/ManagedCacheListener.hpp
new file mode 100644
index 0000000..ccc80d7
--- /dev/null
+++ b/clicache/src/impl/ManagedCacheListener.hpp
@@ -0,0 +1,232 @@
+/*
+ * 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 <vcclr.h>
+#include "begin_native.hpp"
+#include <geode/CacheListener.hpp>
+#include "end_native.hpp"
+
+#include "../ICacheListener.hpp"
+
+namespace apache {
+ namespace geode {
+ namespace client {
+
+ /// <summary>
+ /// Wraps the managed <see cref="Apache.Geode.Client.ICacheListener" />
+ /// object and implements the native <c>apache::geode::client::CacheListener</c> interface.
+ /// </summary>
+ class ManagedCacheListenerGeneric
+ : public apache::geode::client::CacheListener
+ {
+ public:
+
+ /// <summary>
+ /// Constructor to initialize with the provided managed object.
+ /// </summary>
+ /// <param name="userptr">
+ /// The managed object.
+ /// </param>
+ inline ManagedCacheListenerGeneric(
+ /*Apache::Geode::Client::ICacheListener^ managedptr,*/ Object^ userptr)
+ : /*m_managedptr( managedptr ),*/ m_userptr(userptr) { }
+
+ /// <summary>
+ /// Static function to create a <c>ManagedCacheListener</c> using given
+ /// managed assembly path and given factory function.
+ /// </summary>
+ /// <param name="assemblyPath">
+ /// The path of the managed assembly that contains the <c>ICacheListener</c>
+ /// factory function.
+ /// </param>
+ /// <param name="factoryFunctionName">
+ /// The name of the factory function of the managed class for creating
+ /// an object that implements <c>ICacheListener</c>.
+ /// This should be a static function of the format
+ /// {Namespace}.{Class Name}.{Method Name}.
+ /// </param>
+ /// <exception cref="IllegalArgumentException">
+ /// If the managed library cannot be loaded or the factory function fails.
+ /// </exception>
+ static apache::geode::client::CacheListener* create(const char* assemblyPath,
+ const char* factoryFunctionName);
+
+ /// <summary>
+ /// Destructor -- does nothing.
+ /// </summary>
+ virtual ~ManagedCacheListenerGeneric() { }
+
+ /// <summary>
+ /// Handles the event of a new key being added to a region.
+ /// </summary>
+ /// <remarks>
+ /// The entry did not previously exist in this region in the local cache
+ /// (even with a null value).
+ /// <para>
+ /// This function does not throw any exception.
+ /// </para>
+ /// </remarks>
+ /// <param name="ev">
+ /// Denotes the event object associated with the entry creation.
+ /// </param>
+ /// <seealso cref="Apache.Geode.Client.Region.Create" />
+ /// <seealso cref="Apache.Geode.Client.Region.Put" />
+ /// <seealso cref="Apache.Geode.Client.Region.Get" />
+ virtual void afterCreate(const apache::geode::client::EntryEvent& ev);
+
+ /// <summary>
+ /// Handles the event of an entry's value being modified in a region.
+ /// </summary>
+ /// <remarks>
+ /// This entry previously existed in this region in the local cache,
+ /// but its previous value may have been null.
+ /// </remarks>
+ /// <param name="ev">
+ /// EntryEvent denotes the event object associated with updating the entry.
+ /// </param>
+ /// <seealso cref="Apache.Geode.Client.Region.Put" />
+ virtual void afterUpdate(const apache::geode::client::EntryEvent& ev);
+
+ /// <summary>
+ /// Handles the event of an entry's value being invalidated.
+ /// </summary>
+ /// <param name="ev">
+ /// EntryEvent denotes the event object associated with the entry invalidation.
+ /// </param>
+ virtual void afterInvalidate(const apache::geode::client::EntryEvent& ev);
+
+ /// <summary>
+ /// Handles the event of an entry being destroyed.
+ /// </summary>
+ /// <param name="ev">
+ /// EntryEvent denotes the event object associated with the entry destruction.
+ /// </param>
+ /// <seealso cref="Apache.Geode.Client.Region.Destroy" />
+ virtual void afterDestroy(const apache::geode::client::EntryEvent& ev);
+
+ /// <summary>
+ /// Handles the event of a region being cleared.
+ /// </summary>
+ virtual void afterRegionClear(const apache::geode::client::RegionEvent& ev);
+
+ /// <summary>
+ /// Handles the event of a region being invalidated.
+ /// </summary>
+ /// <remarks>
+ /// Events are not invoked for each individual value that is invalidated
+ /// as a result of the region being invalidated. Each subregion, however,
+ /// gets its own <c>regionInvalidated</c> event invoked on its listener.
+ /// </remarks>
+ /// <param name="ev">
+ /// RegionEvent denotes the event object associated with the region invalidation.
+ /// </param>
+ /// <seealso cref="Apache.Geode.Client.Region.InvalidateRegion" />
+ virtual void afterRegionInvalidate(const apache::geode::client::RegionEvent& ev);
+
+ /// <summary>
+ /// Handles the event of a region being destroyed.
+ /// </summary>
+ /// <remarks>
+ /// Events are not invoked for each individual entry that is destroyed
+ /// as a result of the region being destroyed. Each subregion, however,
+ /// gets its own <c>afterRegionDestroyed</c> event invoked on its listener.
+ /// </remarks>
+ /// <param name="ev">
+ /// RegionEvent denotes the event object associated with the region destruction.
+ /// </param>
+ /// <seealso cref="Apache.Geode.Client.Region.DestroyRegion" />
+ virtual void afterRegionDestroy(const apache::geode::client::RegionEvent& ev);
+
+ /// <summary>
+ /// Handles the event of a region being live.
+ /// </summary>
+ /// <remarks>
+ /// Each subregion gets its own <c>afterRegionLive</c> event invoked on its listener.
+ /// </remarks>
+ /// <param name="ev">
+ /// RegionEvent denotes the event object associated with the region going live.
+ /// </param>
+ /// <seealso cref="Apache.Geode.Client.Cache.ReadyForEvents" />
+ virtual void afterRegionLive(const apache::geode::client::RegionEvent& ev);
+
+ /// <summary>
+ /// Called when the region containing this callback is destroyed, when
+ /// the cache is closed.
+ /// </summary>
+ /// <remarks>
+ /// Implementations should clean up any external resources,
+ /// such as database connections. Any runtime exceptions this method
+ /// throws will be logged.
+ /// <para>
+ /// It is possible for this method to be called multiple times on a single
+ /// callback instance, so implementations must be tolerant of this.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Apache.Geode.Client.Cache.Close" />
+ /// <seealso cref="Apache.Geode.Client.Region.DestroyRegion" />
+ virtual void close(const apache::geode::client::RegionPtr& region);
+
+ ///<summary>
+ ///Called when all the endpoints associated with region are down.
+ ///This will be called when all the endpoints are down for the first time.
+ ///If endpoints come up and again go down it will be called again.
+ ///This will also be called when all endpoints are down and region is attached to the pool.
+ ///</summary>
+ ///<remarks>
+ ///</remark>
+ ///<param>
+ ///region Region^ denotes the assosiated region.
+ ///</param>
+ virtual void afterRegionDisconnected(const apache::geode::client::RegionPtr& region);
+
+ /// <summary>
+ /// Returns the wrapped managed object reference.
+ /// </summary>
+ inline Apache::Geode::Client::ICacheListener<Object^, Object^>^ ptr() const
+ {
+ return m_managedptr;
+ }
+
+ inline void setptr(Apache::Geode::Client::ICacheListener<Object^, Object^>^ managedptr)
+ {
+ m_managedptr = managedptr;
+ }
+
+ inline Object^ userptr() const
+ {
+ return m_userptr;
+ }
+
+ private:
+
+ /// <summary>
+ /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly).
+ /// Note: not using auto_gcroot since it will result in 'Dispose' of the ICacheListener
+ /// to be called which is not what is desired when this object is destroyed. Normally this
+ /// managed object may be created by the user and will be handled automatically by the GC.
+ /// </summary>
+ gcroot<Apache::Geode::Client::ICacheListener<Object^, Object^>^> m_managedptr;
+
+ gcroot<Object^> m_userptr;
+ };
+
+ } // namespace client
+ } // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/impl/ManagedCacheLoader.cpp
----------------------------------------------------------------------
diff --git a/clicache/src/impl/ManagedCacheLoader.cpp b/clicache/src/impl/ManagedCacheLoader.cpp
new file mode 100644
index 0000000..21e9657
--- /dev/null
+++ b/clicache/src/impl/ManagedCacheLoader.cpp
@@ -0,0 +1,252 @@
+/*
+ * 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 "../gf_includesN.hpp"
+#include "ManagedCacheLoader.hpp"
+#include "../Region.hpp"
+#include "ManagedString.hpp"
+//#include "../legacy/impl/SafeConvert.hpp"
+//#include "../../../LogM.hpp"
+//#include "../../../RegionM.hpp"
+#include "CacheLoader.hpp"
+
+using namespace System;
+using namespace System::Text;
+using namespace System::Reflection;
+
+
+namespace apache
+{
+ namespace geode
+ {
+ namespace client
+ {
+
+ CacheLoader* ManagedCacheLoaderGeneric::create(const char* assemblyPath,
+ const char* factoryFunctionName)
+ {
+ try
+ {
+ String^ mg_assemblyPath =
+ Apache::Geode::Client::ManagedString::Get(assemblyPath);
+ String^ mg_factoryFunctionName =
+ Apache::Geode::Client::ManagedString::Get(factoryFunctionName);
+ String^ mg_typeName = nullptr;
+
+ String^ mg_genericKey = nullptr;
+ String^ mg_genericVal = nullptr;
+
+ System::Int32 dotIndx = -1;
+ System::Int32 genericsOpenIndx = -1;
+ System::Int32 genericsCloseIndx = -1;
+ System::Int32 commaIndx = -1;
+
+ if (mg_factoryFunctionName == nullptr ||
+ (dotIndx = mg_factoryFunctionName->LastIndexOf('.')) < 0)
+ {
+ std::string ex_str = "ManagedCacheLoaderGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain type name";
+ throw IllegalArgumentException(ex_str.c_str());
+ }
+
+ if ((genericsCloseIndx = mg_factoryFunctionName->LastIndexOf('>')) < 0)
+ {
+ std::string ex_str = "ManagedCacheLoaderGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain any generic type parameters";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ if ((genericsOpenIndx = mg_factoryFunctionName->LastIndexOf('<')) < 0 ||
+ genericsOpenIndx > genericsCloseIndx)
+ {
+ std::string ex_str = "ManagedCacheLoaderGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain expected generic type parameters";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ if ((commaIndx = mg_factoryFunctionName->LastIndexOf(',')) < 0 ||
+ (commaIndx < genericsOpenIndx || commaIndx > genericsCloseIndx))
+ {
+ std::string ex_str = "ManagedCacheLoaderGeneric: Factory function name '";
+ ex_str += factoryFunctionName;
+ ex_str += "' does not contain expected generic type parameter comma separator";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ StringBuilder^ typeBuilder = gcnew StringBuilder(mg_factoryFunctionName->Substring(0, genericsOpenIndx));
+ mg_typeName = typeBuilder->ToString();
+ mg_genericKey = mg_factoryFunctionName->Substring(genericsOpenIndx + 1, commaIndx - genericsOpenIndx - 1);
+ mg_genericKey = mg_genericKey->Trim();
+ mg_genericVal = mg_factoryFunctionName->Substring(commaIndx + 1, genericsCloseIndx - commaIndx - 1);
+ mg_genericVal = mg_genericVal->Trim();
+ mg_factoryFunctionName = mg_factoryFunctionName->Substring(dotIndx + 1);
+
+ Apache::Geode::Client::Log::Fine("Attempting to instantiate a [{0}<{1}, {2}>] via the [{3}] factory method.",
+ mg_typeName, mg_genericKey, mg_genericVal, mg_factoryFunctionName);
+
+ typeBuilder->Append("`2");
+ mg_typeName = typeBuilder->ToString();
+
+ Assembly^ assmb = nullptr;
+ try
+ {
+ assmb = Assembly::Load(mg_assemblyPath);
+ }
+ catch (System::Exception^)
+ {
+ assmb = nullptr;
+ }
+ if (assmb == nullptr)
+ {
+ std::string ex_str = "ManagedCacheLoaderGeneric: Could not load assembly: ";
+ ex_str += assemblyPath;
+ throw IllegalArgumentException(ex_str.c_str());
+ }
+
+ Apache::Geode::Client::Log::Debug("Loading type: [{0}]", mg_typeName);
+
+ Type^ typeInst = assmb->GetType(mg_typeName, false, true);
+
+ if (typeInst != nullptr)
+ {
+ array<Type^>^ types = gcnew array<Type^>(2);
+ types[0] = Type::GetType(mg_genericKey, false, true);
+ types[1] = Type::GetType(mg_genericVal, false, true);
+
+ if (types[0] == nullptr || types[1] == nullptr)
+ {
+ std::string ex_str = "ManagedCacheLoaderGeneric: Could not get both generic type argument instances";
+ throw apache::geode::client::IllegalArgumentException(ex_str.c_str());
+ }
+
+ typeInst = typeInst->MakeGenericType(types);
+ Apache::Geode::Client::Log::Info("Loading function: [{0}]", mg_factoryFunctionName);
+
+ MethodInfo^ mInfo = typeInst->GetMethod(mg_factoryFunctionName,
+ BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase);
+
+ if (mInfo != nullptr)
+ {
+ Object^ managedptr = nullptr;
+ try
+ {
+ managedptr = mInfo->Invoke(typeInst, nullptr);
+ }
+ catch (System::Exception^ ex)
+ {
+ Apache::Geode::Client::Log::Debug("{0}: {1}", ex->GetType()->Name, ex->Message);
+ managedptr = nullptr;
+ }
+ if (managedptr == nullptr)
+ {
+ std::string ex_str = "ManagedCacheLoaderGeneric: Could not create "
+ "object on invoking factory function [";
+ ex_str += factoryFunctionName;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw IllegalArgumentException(ex_str.c_str());
+ }
+
+ ManagedCacheLoaderGeneric* mgcl = new ManagedCacheLoaderGeneric(managedptr);
+
+ Type^ clgType = Type::GetType("Apache.Geode.Client.CacheLoaderGeneric`2");
+ clgType = clgType->MakeGenericType(types);
+ Object^ clg = Activator::CreateInstance(clgType);
+
+ mInfo = clgType->GetMethod("SetCacheLoader");
+ array<Object^>^ params = gcnew array<Object^>(1);
+ params[0] = managedptr;
+ mInfo->Invoke(clg, params);
+
+ mgcl->setptr((Apache::Geode::Client::ICacheLoaderProxy^)clg);
+
+ return mgcl;
+ }
+ else
+ {
+ std::string ex_str = "ManagedCacheLoaderGeneric: Could not load "
+ "function with name [";
+ ex_str += factoryFunctionName;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw IllegalArgumentException(ex_str.c_str());
+ }
+ }
+ else
+ {
+ Apache::Geode::Client::ManagedString typeName(mg_typeName);
+ std::string ex_str = "ManagedCacheLoaderGeneric: Could not load type [";
+ ex_str += typeName.CharPtr;
+ ex_str += "] in assembly: ";
+ ex_str += assemblyPath;
+ throw IllegalArgumentException(ex_str.c_str());
+ }
+ }
+ catch (const apache::geode::client::Exception&)
+ {
+ throw;
+ }
+ catch (System::Exception^ ex)
+ {
+ Apache::Geode::Client::ManagedString mg_exStr(ex->ToString());
+ std::string ex_str = "ManagedCacheLoaderGeneric: Got an exception while "
+ "loading managed library: ";
+ ex_str += mg_exStr.CharPtr;
+ throw IllegalArgumentException(ex_str.c_str());
+ }
+ return NULL;
+ }
+
+ CacheablePtr ManagedCacheLoaderGeneric::load(const RegionPtr& region,
+ const CacheableKeyPtr& key, const UserDataPtr& aCallbackArgument)
+ {
+ try {
+ return m_managedptr->load(region, key, aCallbackArgument);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ return nullptr;
+ }
+
+ void ManagedCacheLoaderGeneric::close(const RegionPtr& region)
+ {
+ try {
+ /*
+ Apache::Geode::Client::Region^ mregion =
+ Apache::Geode::Client::Region::Create( region.get() );
+ */
+
+ m_managedptr->close(region);
+ }
+ catch (Apache::Geode::Client::GeodeException^ ex) {
+ ex->ThrowNative();
+ }
+ catch (System::Exception^ ex) {
+ Apache::Geode::Client::GeodeException::ThrowNative(ex);
+ }
+ }
+
+ } // namespace client
+ } // namespace geode
+} // namespace apache