http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheStatistics.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheStatistics.hpp b/clicache/src/CacheStatistics.hpp new file mode 100644 index 0000000..ec006ac --- /dev/null +++ b/clicache/src/CacheStatistics.hpp @@ -0,0 +1,159 @@ +/* + * 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/CacheStatistics.hpp> +#include "end_native.hpp" + +#include "native_shared_ptr.hpp" + + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + /// <summary> + /// Defines common statistical information for both the region and its entries. + /// </summary> + /// <remarks> + /// All of these methods may throw a <c>CacheClosedException</c>, + /// <c>RegionDestroyedException</c>, or <c>EntryDestroyedException</c>. + /// </remarks> + /// <seealso cref="Region.Statistics" /> + /// <seealso cref="RegionEntry.Statistics" /> + public ref class CacheStatistics sealed + { + public: + + /// <summary> + /// For an entry, returns the time that the entry's value was last modified. + /// For a region, returns the last time any of the region's entries' values or + /// the values in subregions' entries were modified. + /// </summary> + /// <remarks> + /// <para> + /// The modification may have been initiated locally, or it may have been + /// an update distributed from another cache. It may also have been a new + /// value provided by a loader. The modification time on a region is + /// propagated upward to parent regions, transitively, to the root region. + /// </para><para> + /// The number is expressed as the number of milliseconds since January 1, 1970. + /// The granularity may be as coarse as 100ms, so the accuracy may be off by + /// up to 50ms. + /// </para><para> + /// Entry and subregion creation will update the modification time on a + /// region, but <c>Region.Destroy</c>, <c>Region.DestroyRegion</c>, + /// <c>Region.Invalidate</c>, and <c>Region.InvalidateRegion</c> + /// do not update the modification time. + /// </para> + /// </remarks> + /// <returns> + /// the last modification time of the region or the entry; + /// returns 0 if the entry is invalid or the modification time is uninitialized. + /// </returns> + /// <seealso cref="Region.Put" /> + /// <seealso cref="Region.Get" /> + /// <seealso cref="Region.Create" /> + /// <seealso cref="Region.CreateSubRegion" /> + property System::UInt32 LastModifiedTime + { + /// <summary> + /// Get the last modified time of an entry or a region. + /// </summary> + /// <returns> + /// the last accessed time expressed as the number of milliseconds since + /// January 1, 1970. + /// </returns> + System::UInt32 get( ); + } + + /// <summary> + /// For an entry, returns the last time it was accessed via <c>Region.Get</c>. + /// For a region, returns the last time any of its entries or the entries of + /// its subregions were accessed with <c>Region.Get</c>. + /// </summary> + /// <remarks> + /// <para> + /// Any modifications will also update the <c>LastAccessedTime</c>, + /// so <c>LastAccessedTime</c> is always greater than or equal to + /// <c>LastModifiedTime</c>. The <c>LastAccessedTime</c> on a region is + /// propagated upward to parent regions, transitively, to the the root region. + /// </para><para> + /// The number is expressed as the number of milliseconds since + /// January 1, 1970. The granularity may be as coarse as 100ms, so + /// the accuracy may be off by up to 50ms. + /// </para> + /// </remarks> + /// <returns> + /// the last access time of the region or the entry's value; + /// returns 0 if entry is invalid or access time is uninitialized. + /// </returns> + /// <seealso cref="Region.Get" /> + /// <seealso cref="LastModifiedTime" /> + property System::UInt32 LastAccessedTime + { + /// <summary> + /// Get the last accessed time of an entry or a region. + /// </summary> + /// <returns> + /// the last accessed time expressed as the number of milliseconds since + /// January 1, 1970. + /// </returns> + System::UInt32 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> + inline static CacheStatistics^ Create( apache::geode::client::CacheStatisticsPtr nativeptr ) + { + return __nullptr == nativeptr ? nullptr : + gcnew CacheStatistics( nativeptr ); + } + + + private: + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CacheStatistics( apache::geode::client::CacheStatisticsPtr nativeptr ) + { + m_nativeptr = gcnew native_shared_ptr<native::CacheStatistics>(nativeptr); + } + native_shared_ptr<native::CacheStatistics>^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache +
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheTransactionManager.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheTransactionManager.cpp b/clicache/src/CacheTransactionManager.cpp new file mode 100644 index 0000000..68c1ddb --- /dev/null +++ b/clicache/src/CacheTransactionManager.cpp @@ -0,0 +1,295 @@ +/* + * 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 "impl/SafeConvert.hpp" +#include "impl/ManagedTransactionListener.hpp" +#include "impl/ManagedTransactionWriter.hpp" +#include "CacheTransactionManager.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + void CacheTransactionManager::Begin( ) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + m_nativeptr->get()->begin( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + void CacheTransactionManager::Prepare( ) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + m_nativeptr->get()->prepare( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + void CacheTransactionManager::Commit( ) + { + _GF_MG_EXCEPTION_TRY2 + try + { + m_nativeptr->get()->commit( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + void CacheTransactionManager::Rollback( ) + { + _GF_MG_EXCEPTION_TRY2 + try + { + m_nativeptr->get()->rollback( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + bool CacheTransactionManager::Exists( ) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return m_nativeptr->get()->exists( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + Apache::Geode::Client::TransactionId^ CacheTransactionManager::Suspend( ) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return Apache::Geode::Client::TransactionId::Create( m_nativeptr->get()->suspend() ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + Apache::Geode::Client::TransactionId^ CacheTransactionManager::TransactionId::get( ) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return Apache::Geode::Client::TransactionId::Create( m_nativeptr->get()->getTransactionId() ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + void CacheTransactionManager::Resume(Apache::Geode::Client::TransactionId^ transactionId) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return m_nativeptr->get()->resume(transactionId->GetNative()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + bool CacheTransactionManager::IsSuspended(Apache::Geode::Client::TransactionId^ transactionId) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return m_nativeptr->get()->isSuspended(transactionId->GetNative()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + bool CacheTransactionManager::TryResume(Apache::Geode::Client::TransactionId^ transactionId) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return m_nativeptr->get()->tryResume(transactionId->GetNative()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + bool CacheTransactionManager::TryResume(Apache::Geode::Client::TransactionId^ transactionId, System::Int32 waitTimeInMilliSec) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return m_nativeptr->get()->tryResume(transactionId->GetNative(), waitTimeInMilliSec); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + bool CacheTransactionManager::Exists(Apache::Geode::Client::TransactionId^ transactionId) + { + _GF_MG_EXCEPTION_TRY2 + + try + { + return m_nativeptr->get()->exists(transactionId->GetNative()); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + +#ifdef CSTX_COMMENTED + generic<class TKey, class TValue> + ITransactionWriter<TKey, TValue>^ CacheTransactionManager::GetWriter( ) + { + _GF_MG_EXCEPTION_TRY2 + + // Conver the unmanaged object to managed generic object + apache::geode::client::TransactionWriterPtr& writerPtr( m_nativeptr->getGCKeepAlive()->getWriter( ) ); + apache::geode::client::ManagedTransactionWriterGeneric* twg = + dynamic_cast<apache::geode::client::ManagedTransactionWriterGeneric*>( writerPtr.get() ); + + if (twg != nullptr) + { + return (ITransactionWriter<TKey, TValue>^)twg->userptr( ); + } + + _GF_MG_EXCEPTION_CATCH_ALL2 + + return nullptr; + } + + generic<class TKey, class TValue> + void CacheTransactionManager::SetWriter(ITransactionWriter<TKey, TValue>^ transactionWriter) + { + _GF_MG_EXCEPTION_TRY2 + // Create a unmanaged object using the ManagedTransactionWriterGeneric. + // Set the generic object inside the TransactionWriterGeneric that is a non generic object + apache::geode::client::TransactionWriterPtr writerPtr; + if ( transactionWriter != nullptr ) + { + TransactionWriterGeneric<TKey, TValue>^ twg = gcnew TransactionWriterGeneric<TKey, TValue> (); + twg->SetTransactionWriter(transactionWriter); + writerPtr = new apache::geode::client::ManagedTransactionWriterGeneric( transactionWriter ); + ((apache::geode::client::ManagedTransactionWriterGeneric*)writerPtr.get())->setptr(twg); + } + m_nativeptr->getGCKeepAlive()->setWriter( writerPtr ); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + generic<class TKey, class TValue> + void CacheTransactionManager::AddListener(ITransactionListener<TKey, TValue>^ transactionListener) + { + _GF_MG_EXCEPTION_TRY2 + // Create a unmanaged object using the ManagedTransactionListenerGeneric. + // Set the generic object inside the TransactionListenerGeneric that is a non generic object + apache::geode::client::TransactionListenerPtr listenerPtr; + if ( transactionListener != nullptr ) + { + TransactionListenerGeneric<TKey, TValue>^ twg = gcnew TransactionListenerGeneric<TKey, TValue> (); + twg->SetTransactionListener(transactionListener); + listenerPtr = new apache::geode::client::ManagedTransactionListenerGeneric( transactionListener ); + ((apache::geode::client::ManagedTransactionListenerGeneric*)listenerPtr.get())->setptr(twg); + } + m_nativeptr->getGCKeepAlive()->addListener( listenerPtr ); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + generic<class TKey, class TValue> + void CacheTransactionManager::RemoveListener(ITransactionListener<TKey, TValue>^ transactionListener) + { + _GF_MG_EXCEPTION_TRY2 + // Create an unmanaged non generic object using the managed generic object + // use this to call the remove listener + apache::geode::client::TransactionListenerPtr listenerPtr; + if ( transactionListener != nullptr ) + { + TransactionListenerGeneric<TKey, TValue>^ twg = gcnew TransactionListenerGeneric<TKey, TValue> (); + twg->SetTransactionListener(transactionListener); + listenerPtr = new apache::geode::client::ManagedTransactionListenerGeneric( transactionListener ); + ((apache::geode::client::ManagedTransactionListenerGeneric*)listenerPtr.get())->setptr(twg); + } + m_nativeptr->getGCKeepAlive()->removeListener( listenerPtr ); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } +#endif + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheTransactionManager.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheTransactionManager.hpp b/clicache/src/CacheTransactionManager.hpp new file mode 100644 index 0000000..07f6954 --- /dev/null +++ b/clicache/src/CacheTransactionManager.hpp @@ -0,0 +1,228 @@ +/* + * 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/CacheTransactionManager.hpp> +#include <geode/InternalCacheTransactionManager2PC.hpp> +#include "end_native.hpp" +#include "native_shared_ptr.hpp" +#include "TransactionId.hpp" + +using namespace System; +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + /// <summary> + /// CacheTransactionManager encapsulates the transactions for a cache + /// </summary> + public ref class CacheTransactionManager sealed + { + public: + /// <summary> + /// Creates a new transaction and associates it with the current thread. + /// </summary> + /// <exception cref="IllegalStateException"> + /// Throws exception if the thread is already associated with a transaction + /// </exception> + void Begin(); + + /// <summary> + /// Prepare the first message of two-phase-commit transaction associated + /// with the current thread. + /// </summary> + /// <exception cref="IllegalStateException"> + /// if the thread is not associated with a transaction + /// </exception> + /// <exception cref="CommitConflictException"> + /// if the commit operation fails due to a write conflict. + /// </exception> + void Prepare(); + + /// <summary> + /// Commit the transaction associated with the current thread. If + /// the commit operation fails due to a conflict it will destroy + /// the transaction state and throw a <c>CommitConflictException</c>. + /// If the commit operation succeeds,it returns after the transaction + /// state has been merged with committed state. When this method + /// completes, the thread is no longer associated with a transaction. + /// </summary> + /// <exception cref="IllegalStateException"> + /// if the thread is not associated with a transaction + /// </exception> + /// <exception cref="CommitConflictException"> + /// if the commit operation fails due to a write conflict. + /// </exception> + void Commit(); + + /// <summary> + /// Roll back the transaction associated with the current thread. When + /// this method completes, the thread is no longer associated with a + /// transaction and the transaction context is destroyed. + /// </summary> + /// <exception cref="IllegalStateException"> + /// if the thread is not associated with a transaction + /// </exception> + void Rollback(); + + /// <summary> + /// Reports the existence of a Transaction for this thread + /// </summary> + /// <returns>true if a transaction exists, false otherwise</returns> + bool Exists(); + + /// <summary> + /// Suspends the transaction on the current thread. All subsequent operations + /// performed by this thread will be non-transactional. The suspended + /// transaction can be resumed by calling <see cref="TransactionId"/> + /// <para> + /// Since 3.6.2 + /// </para> + /// </summary> + /// <returns>the transaction identifier of the suspended transaction or null if + /// the thread was not associated with a transaction</returns> + Apache::Geode::Client::TransactionId^ Suspend(); + + /// <summary> + /// On the current thread, resumes a transaction that was previously suspended + /// using <see cref="suspend"/> + /// <para> + /// Since 3.6.2 + /// </para> + /// </summary> + /// <param name="transactionId">the transaction to resume</param> + /// <exception cref="IllegalStateException">if the thread is associated with a transaction or if + /// would return false for the given transactionId</exception> + /// <see cref="TransactionId"/> + void Resume(Apache::Geode::Client::TransactionId^ transactionId); + + /// <summary> + /// This method can be used to determine if a transaction with the given + /// transaction identifier is currently suspended locally. This method does not + /// check other members for transaction status. + /// <para> + /// Since 3.6.2 + /// </para> + /// </summary> + /// <param name="transactionId"></param> + /// <returns>true if the transaction is in suspended state, false otherwise</returns> + /// <see cref="TransactionId"/> + bool IsSuspended(Apache::Geode::Client::TransactionId^ transactionId); + + + /// <summary> + /// On the current thread, resumes a transaction that was previously suspended + /// using <see cref="suspend"/>. + /// This method is equivalent to + /// <code> + /// if (isSuspended(txId)) { + /// resume(txId); + /// } + /// </code> + /// except that this action is performed atomically + /// <para> + /// Since 3.6.2 + /// </para> + /// </summary> + /// <param name="transactionId">the transaction to resume</param> + /// <returns>true if the transaction was resumed, false otherwise</returns> + bool TryResume(Apache::Geode::Client::TransactionId^ transactionId); + + + /// <summary> + /// On the current thread, resumes a transaction that was previously suspended + /// using <see cref="suspend"/>, or waits for the specified timeout interval if + /// the transaction has not been suspended. This method will return if: + /// <para> + /// Another thread suspends the transaction + /// </para> + /// <para> + /// Another thread calls commit/rollback on the transaction + /// </para> + /// <para> + /// This thread has waited for the specified timeout + /// </para> + /// This method returns immediately if <see cref="TransactionId"/> returns false. + /// <para> + /// Since 3.6.2 + /// </para> + /// </summary> + /// <param name="transactionId">the transaction to resume</param> + /// <param name="waitTimeInMilliSec">the maximum milliseconds to wait </param> + /// <returns>true if the transaction was resumed, false otherwise</returns> + bool TryResume(Apache::Geode::Client::TransactionId^ transactionId, System::Int32 waitTimeInMilliSec); + + + + /// <summary> + /// Reports the existence of a transaction for the given transactionId. This + /// method can be used to determine if a transaction with the given transaction + /// identifier is currently in progress locally. + /// <para> + /// Since 3.6.2 + /// </para> + /// </summary> + /// <param name="transactionId">the given transaction identifier</param> + /// <returns>true if the transaction is in progress, false otherwise.</returns> + /// <see cref="isSuspended"/> + bool Exists(Apache::Geode::Client::TransactionId^ transactionId); + + + /// <summary> + /// Returns the transaction identifier for the current thread + /// <para> + /// Since 3.6.2 + /// </para> + /// </summary> + /// <returns>the transaction identifier or null if no transaction exists</returns> + property Apache::Geode::Client::TransactionId^ TransactionId + { + //TODO::split + Apache::Geode::Client::TransactionId^ get( ); + } + + internal: + + inline static CacheTransactionManager^ Create( native::InternalCacheTransactionManager2PCPtr nativeptr ) + { + return ( nativeptr != nullptr ? + gcnew CacheTransactionManager( nativeptr ) : nullptr ); + } + + + private: + + /// <summary> + /// Private constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CacheTransactionManager( native::InternalCacheTransactionManager2PCPtr nativeptr ) + { + m_nativeptr = gcnew native_shared_ptr<native::InternalCacheTransactionManager2PC>(nativeptr); + } + + native_shared_ptr<native::InternalCacheTransactionManager2PC>^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheWriterAdapter.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheWriterAdapter.hpp b/clicache/src/CacheWriterAdapter.hpp new file mode 100644 index 0000000..47cb717 --- /dev/null +++ b/clicache/src/CacheWriterAdapter.hpp @@ -0,0 +1,73 @@ +/* + * 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 "ICacheWriter.hpp" + + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// Utility class that implements all methods in <c>ICacheWriter</c> + /// with empty implementations. Applications can subclass this class + /// and only override the methods for the events of interest. + /// </summary> + generic<class TKey, class TValue> + public ref class CacheWriterAdapter + : public ICacheWriter<TKey, TValue> + { + public: + virtual bool BeforeUpdate(EntryEvent<TKey, TValue>^ ev) + { + return true; + } + + virtual bool BeforeCreate(EntryEvent<TKey, TValue>^ ev) + { + return true; + } + + virtual bool BeforeDestroy(EntryEvent<TKey, TValue>^ ev) + { + return true; + } + + virtual bool BeforeRegionDestroy(RegionEvent<TKey, TValue>^ ev) + { + return true; + } + + virtual bool BeforeRegionClear(RegionEvent<TKey, TValue>^ ev) + { + return true; + } + + virtual void Close(IRegion<TKey, TValue>^ region) + { + } + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableArrayList.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableArrayList.hpp b/clicache/src/CacheableArrayList.hpp new file mode 100644 index 0000000..adc26a3 --- /dev/null +++ b/clicache/src/CacheableArrayList.hpp @@ -0,0 +1,97 @@ +/* + * 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 "CacheableVector.hpp" + + +using namespace System; +using namespace System::Collections::Generic; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// A mutable <c>IGeodeSerializable</c> vector wrapper that can serve as + /// a distributable object for caching. This class extends .NET generic + /// <c>List</c> class. + /// </summary> + ref class CacheableArrayList + : public CacheableVector + { + public: + /// <summary> + /// Allocates a new empty instance. + /// </summary> + inline CacheableArrayList(System::Collections::IList^ list) + : CacheableVector(list) + { } + + + /// <summary> + /// Static function to create a new empty instance. + /// </summary> + inline static CacheableArrayList^ Create() + { + return gcnew CacheableArrayList(gcnew System::Collections::Generic::List<Object^>()); + } + + /// <summary> + /// Static function to create a new empty instance. + /// </summary> + inline static CacheableArrayList^ Create(System::Collections::IList^ list) + { + return gcnew CacheableArrayList(list); + } + + + // Region: IGeodeSerializable Members + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + virtual System::UInt32 get() override + { + return GeodeClassIds::CacheableArrayList; + } + } + + // End Region: IGeodeSerializable Members + + /// <summary> + /// Factory function to register this class. + /// </summary> + static IGeodeSerializable^ CreateDeserializable() + { + return gcnew CacheableArrayList(gcnew System::Collections::Generic::List<Object^>()); + } + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableBuiltins.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableBuiltins.hpp b/clicache/src/CacheableBuiltins.hpp new file mode 100644 index 0000000..ce96b61 --- /dev/null +++ b/clicache/src/CacheableBuiltins.hpp @@ -0,0 +1,603 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + + + +#include "geode_defs.hpp" +#include "begin_native.hpp" +#include <geode/CacheableBuiltins.hpp> +#include "end_native.hpp" + +#include "CacheableKey.hpp" +#include "Serializable.hpp" +#include "ExceptionTypes.hpp" +#include "GeodeClassIds.hpp" +#include "DataOutput.hpp" +#include "DataInput.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + namespace native = apache::geode::client; + + + /// <summary> + /// An immutable template wrapper for C++ <c>CacheableKey</c>s that can + /// serve as a distributable key object for caching. + /// </summary> + template <typename TNative, typename TManaged, System::UInt32 TYPEID> + ref class CacheableBuiltinKey + : public CacheableKey + { + public: + /// <summary> + /// Allocates a new instance + /// </summary> + CacheableBuiltinKey() + { + auto nativeptr = TNative::create(); + m_nativeptr = gcnew native_shared_ptr<native::Serializable>(nativeptr); + } + + /// <summary> + /// Allocates a new instance with the given value. + /// </summary> + /// <param name="value">the value of the new instance</param> + CacheableBuiltinKey(TManaged value) + { + auto nativeptr = TNative::create(value); + m_nativeptr = gcnew native_shared_ptr<native::Serializable>(nativeptr); + } + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + virtual System::UInt32 get() override + { + return TYPEID; + } + } + + /// <summary> + /// Return a string representation of the object. + /// This returns the string for the <c>Value</c> property. + /// </summary> + virtual String^ ToString() override + { + try + { + return static_cast<TNative*>(m_nativeptr->get())->value().ToString(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + /// <summary> + /// Return true if this key matches other object. + /// It invokes the '==' operator of the underlying + /// native object. + /// </summary> + virtual bool Equals(CacheableBuiltinKey^ other) override + { + if (other == nullptr) + { + return false; + } + + try + { + return static_cast<TNative*>(m_nativeptr->get())->operator==( + *static_cast<TNative*>(other->m_nativeptr->get())); + } + finally + { + GC::KeepAlive(m_nativeptr); + GC::KeepAlive(other->m_nativeptr); + } + } + + /// <summary> + /// Return true if this key matches other object. + /// It invokes the '==' operator of the underlying + /// native object. + /// </summary> + virtual bool Equals(Object^ obj) override + { + return Equals(dynamic_cast<CacheableBuiltinKey^>(obj)); + } + + /// <summary> + /// Comparison operator against another value. + /// </summary> + bool operator == (TManaged other) + { + try + { + return (static_cast<TNative*>(m_nativeptr->get())->value() == other); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + + /// <summary> + /// Gets the value. + /// </summary> + property TManaged Value + { + inline TManaged get() + { + try + { + return static_cast<TNative*>(m_nativeptr->get())->value(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + + } + } + + protected: + + /// <summary> + /// Protected constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CacheableBuiltinKey(native::SerializablePtr nativeptr) + : CacheableKey(nativeptr) { } + }; + + + /// <summary> + /// An immutable template array wrapper that can serve as a + /// distributable object for caching. + /// </summary> + template <typename TNative, typename TNativePtr, typename TManaged, + System::UInt32 TYPEID> + ref class CacheableBuiltinArray + : public Serializable + { + public: + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + virtual System::UInt32 get() override + { + return TYPEID; + } + } + + virtual void ToData(DataOutput^ output) override + { + output->WriteObject(m_value); + } + + virtual IGeodeSerializable^ FromData(DataInput^ input) override + { + input->ReadObject(m_value); + return this; + } + + virtual property System::UInt32 ObjectSize + { + virtual System::UInt32 get() override + { + return (System::UInt32)(m_value->Length) * sizeof(TManaged); + } + } + /// <summary> + /// Returns a copy of the underlying array. + /// </summary> + property array<TManaged>^ Value + { + inline array<TManaged>^ get() + { + return m_value; + } + } + + /// <summary> + /// Returns the size of this array. + /// </summary> + property System::Int32 Length + { + inline System::Int32 get() + { + return m_value->Length; + } + } + + virtual String^ ToString() override + { + return m_value->ToString(); + } + + /// <summary> + /// Returns the value at the given index. + /// </summary> + property TManaged GFINDEXER(System::Int32) + { + inline TManaged get(System::Int32 index) + { + return m_value[index]; + } + } + + + protected: + + array<TManaged>^ m_value; + /// <summary> + /// Protected constructor + /// </summary> + inline CacheableBuiltinArray() + { + //TODO: + //native::Serializable* sp = TNative::createDeserializable(); + //SetSP(sp); + } + + /// <summary> + /// Protected constructor to wrap a native object pointer + /// </summary> + /// <param name="nativeptr">The native object pointer</param> + inline CacheableBuiltinArray(native::SerializablePtr nptr) + : Serializable(nptr) + { + auto nativeptr = std::static_pointer_cast<TNative>(nptr); + System::Int32 len = nativeptr->length(); + if (len > 0) + { + array<TManaged>^ buffer = gcnew array<TManaged>(len); + pin_ptr<TManaged> pin_buffer = &buffer[0]; + + memcpy((void*)pin_buffer, nativeptr->value(), + len * sizeof(TManaged)); + m_value = buffer; + } + } + + /// <summary> + /// Allocates a new instance copying from the given array. + /// </summary> + /// <remarks> + /// This method performs no argument checking which is the + /// responsibility of the caller. + /// </remarks> + /// <param name="buffer">the array to copy from</param> + CacheableBuiltinArray(array<TManaged>^ buffer) + { + m_value = buffer; + //setting local value as well + //m_value = gcnew array<TManaged>(buffer->Length); + //System::Array::Copy(buffer, 0, m_value,0, buffer->Length); + } + + /// <summary> + /// Allocates a new instance copying given length from the + /// start of given array. + /// </summary> + /// <remarks> + /// This method performs no argument checking which is the + /// responsibility of the caller. + /// </remarks> + /// <param name="buffer">the array to copy from</param> + /// <param name="length">length of array from start to copy</param> + CacheableBuiltinArray(array<TManaged>^ buffer, System::Int32 length) + { + //TODO: + if (length > buffer->Length) { + length = buffer->Length; + } + //setting local value as well + m_value = gcnew array<TManaged>(length); + System::Array::Copy(buffer, 0, m_value, 0, length); + } + }; + + + + + //n = native type + //m = CacheableInt(managed cacheable) + //mt = managed type(bool, int) +#define _GFCLI_CACHEABLE_KEY_DEF_NEW(n, m, mt) \ + ref class m : public CacheableBuiltinKey<n, mt, \ + GeodeClassIds::m> \ + { \ + public: \ + /** <summary> + * Allocates a new instance with the given value. + * </summary> + * <param name="value">the value of the new instance</param> + */ \ + inline m() \ + : CacheableBuiltinKey() { } \ + /** <summary> + * Allocates a new instance with the given value. + * </summary> + * <param name="value">the value of the new instance</param> + */ \ + inline m(mt value) \ + : CacheableBuiltinKey(value) { } \ + /** <summary> + * Static function to create a new instance given value. + * </summary> + * <param name="value">the value of the new instance</param> + */ \ + inline static m^ Create(mt value) \ + { \ + return gcnew m(value); \ + } \ + /** <summary> + * Explicit conversion operator to contained value type. + * </summary> + */ \ + inline static explicit operator mt (m^ value) \ + { \ + return value->Value; \ + } \ + \ + /** <summary> + * Factory function to register this class. + * </summary> + */ \ + static IGeodeSerializable^ CreateDeserializable() \ + { \ + return gcnew m(); \ + } \ + \ + internal: \ + static IGeodeSerializable^ Create(native::SerializablePtr obj) \ + { \ + return (obj != nullptr ? gcnew m(obj) : nullptr); \ + } \ + \ + private: \ + inline m(native::SerializablePtr nativeptr) \ + : CacheableBuiltinKey(nativeptr) { } \ + }; + + +#define _GFCLI_CACHEABLE_ARRAY_DEF_NEW(m, mt) \ + ref class m : public CacheableBuiltinArray< \ + native::m, native::m##Ptr, mt, GeodeClassIds::m> \ + { \ + public: \ + /** <summary> + * Static function to create a new instance copying + * from the given array. + * </summary> + * <remarks> + * Providing a null or zero size array will return a null object. + * </remarks> + * <param name="value">the array to create the new instance</param> + */ \ + inline static m^ Create(array<mt>^ value) \ + { \ + return (value != nullptr /*&& value->Length > 0*/ ? \ + gcnew m(value) : nullptr); \ + } \ + /** <summary> + * Static function to create a new instance copying + * from the given array. + * </summary> + * <remarks> + * Providing a null or zero size array will return a null object. + * </remarks> + * <param name="value">the array to create the new instance</param> + */ \ + inline static m^ Create(array<mt>^ value, System::Int32 length) \ + { \ + return (value != nullptr && value->Length > 0 ? \ + gcnew m(value, length) : nullptr); \ + } \ + /** <summary> + * Explicit conversion operator to contained array type. + * </summary> + */ \ + inline static explicit operator array<mt> ^ (m^ value) \ + { \ + return (value != nullptr ? value->Value : nullptr); \ + } \ + \ + /** <summary> + * Factory function to register this class. + * </summary> + */ \ + static IGeodeSerializable^ CreateDeserializable() \ + { \ + return gcnew m(); \ + } \ + \ + internal: \ + static IGeodeSerializable^ Create(native::SerializablePtr obj) \ + { \ + return (obj != nullptr ? gcnew m(obj) : nullptr); \ + } \ + \ + private: \ + /** <summary> + * Allocates a new instance + * </summary> + */ \ + inline m() \ + : CacheableBuiltinArray() { } \ + /** <summary> + * Allocates a new instance copying from the given array. + * </summary> + * <remarks> + * Providing a null or zero size array will return a null object. + * </remarks> + * <param name="value">the array to create the new instance</param> + */ \ + inline m(array<mt>^ value) \ + : CacheableBuiltinArray(value) { } \ + /** <summary> + * Allocates a new instance copying given length from the + * start of given array. + * </summary> + * <remarks> + * Providing a null or zero size array will return a null object. + * </remarks> + * <param name="value">the array to create the new instance</param> + */ \ + inline m(array<mt>^ value, System::Int32 length) \ + : CacheableBuiltinArray(value, length) { } \ + inline m(native::SerializablePtr nativeptr) \ + : CacheableBuiltinArray(nativeptr) { } \ + }; + + + // Built-in CacheableKeys + + /// <summary> + /// An immutable wrapper for booleans that can serve + /// as a distributable key object for caching. + /// </summary> + _GFCLI_CACHEABLE_KEY_DEF_NEW(native::CacheableBoolean, + CacheableBoolean, bool); + + /// <summary> + /// An immutable wrapper for bytes that can serve + /// as a distributable key object for caching. + /// </summary> + _GFCLI_CACHEABLE_KEY_DEF_NEW(native::CacheableByte, + CacheableByte, Byte); + + /// <summary> + /// An immutable wrapper for 16-bit characters that can serve + /// as a distributable key object for caching. + /// </summary> + _GFCLI_CACHEABLE_KEY_DEF_NEW(native::CacheableWideChar, + CacheableCharacter, Char); + + /// <summary> + /// An immutable wrapper for doubles that can serve + /// as a distributable key object for caching. + /// </summary> + _GFCLI_CACHEABLE_KEY_DEF_NEW(native::CacheableDouble, + CacheableDouble, Double); + + /// <summary> + /// An immutable wrapper for floats that can serve + /// as a distributable key object for caching. + /// </summary> + _GFCLI_CACHEABLE_KEY_DEF_NEW(native::CacheableFloat, + CacheableFloat, Single); + + /// <summary> + /// An immutable wrapper for 16-bit integers that can serve + /// as a distributable key object for caching. + /// </summary> + _GFCLI_CACHEABLE_KEY_DEF_NEW(native::CacheableInt16, + CacheableInt16, System::Int16); + + /// <summary> + /// An immutable wrapper for 32-bit integers that can serve + /// as a distributable key object for caching. + /// </summary> + _GFCLI_CACHEABLE_KEY_DEF_NEW(native::CacheableInt32, + CacheableInt32, System::Int32); + + /// <summary> + /// An immutable wrapper for 64-bit integers that can serve + /// as a distributable key object for caching. + /// </summary> + _GFCLI_CACHEABLE_KEY_DEF_NEW(native::CacheableInt64, + CacheableInt64, System::Int64); + + + // Built-in Cacheable array types + + /// <summary> + /// An immutable wrapper for byte arrays that can serve + /// as a distributable object for caching. + /// </summary> + _GFCLI_CACHEABLE_ARRAY_DEF_NEW(CacheableBytes, Byte); + + /// <summary> + /// An immutable wrapper for array of doubles that can serve + /// as a distributable object for caching. + /// </summary> + _GFCLI_CACHEABLE_ARRAY_DEF_NEW(CacheableDoubleArray, Double); + + /// <summary> + /// An immutable wrapper for array of floats that can serve + /// as a distributable object for caching. + /// </summary> + _GFCLI_CACHEABLE_ARRAY_DEF_NEW(CacheableFloatArray, Single); + + /// <summary> + /// An immutable wrapper for array of 16-bit integers that can serve + /// as a distributable object for caching. + /// </summary> + _GFCLI_CACHEABLE_ARRAY_DEF_NEW(CacheableInt16Array, System::Int16); + + /// <summary> + /// An immutable wrapper for array of 32-bit integers that can serve + /// as a distributable object for caching. + /// </summary> + _GFCLI_CACHEABLE_ARRAY_DEF_NEW(CacheableInt32Array, System::Int32); + + /// <summary> + /// An immutable wrapper for array of 64-bit integers that can serve + /// as a distributable object for caching. + /// </summary> + _GFCLI_CACHEABLE_ARRAY_DEF_NEW(CacheableInt64Array, System::Int64); + + /// <summary> + /// An immutable wrapper for array of booleans that can serve + /// as a distributable object for caching. + /// </summary> + _GFCLI_CACHEABLE_ARRAY_DEF_NEW(BooleanArray, bool); + + /// <summary> + /// An immutable wrapper for array of 16-bit characters that can serve + /// as a distributable object for caching. + /// </summary> + _GFCLI_CACHEABLE_ARRAY_DEF_NEW(CharArray, Char); + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableDate.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableDate.cpp b/clicache/src/CacheableDate.cpp new file mode 100644 index 0000000..824b16c --- /dev/null +++ b/clicache/src/CacheableDate.cpp @@ -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. + */ + +#include "CacheableDate.hpp" +#include "DataInput.hpp" +#include "DataOutput.hpp" +#include "Log.hpp" +#include "GeodeClassIds.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + CacheableDate::CacheableDate(DateTime dateTime) + : m_dateTime(dateTime), m_hashcode(0) + { + + // Round off dateTime to the nearest millisecond. + System::Int64 ticksToAdd = m_dateTime.Ticks % TimeSpan::TicksPerMillisecond; + ticksToAdd = (ticksToAdd >= (TimeSpan::TicksPerMillisecond / 2) ? + (TimeSpan::TicksPerMillisecond - ticksToAdd) : -ticksToAdd); + m_dateTime = m_dateTime.AddTicks(ticksToAdd); + + } + + void CacheableDate::ToData(DataOutput^ output) + { + //put as universal time + TimeSpan epochSpan = m_dateTime.ToUniversalTime() - EpochTime; + System::Int64 millisSinceEpoch = + epochSpan.Ticks / TimeSpan::TicksPerMillisecond; + output->WriteInt64(millisSinceEpoch); + + //Log::Fine("CacheableDate::Todata time " + m_dateTime.Ticks); + } + + IGeodeSerializable^ CacheableDate::FromData(DataInput^ input) + { + DateTime epochTime = EpochTime; + System::Int64 millisSinceEpoch = input->ReadInt64(); + m_dateTime = epochTime.AddTicks( + millisSinceEpoch * TimeSpan::TicksPerMillisecond); + m_dateTime = m_dateTime.ToLocalTime(); + //Log::Fine("CacheableDate::Fromadata time " + m_dateTime.Ticks); + return this; + } + + System::UInt32 CacheableDate::ObjectSize::get() + { + return (System::UInt32)sizeof(DateTime); + } + + System::UInt32 CacheableDate::ClassId::get() + { + return GeodeClassIds::CacheableDate; + } + + String^ CacheableDate::ToString() + { + return m_dateTime.ToString( + System::Globalization::CultureInfo::CurrentCulture); + } + + System::Int32 CacheableDate::GetHashCode() + { + if (m_hashcode == 0) { + TimeSpan epochSpan = m_dateTime - EpochTime; + System::Int64 millitime = + epochSpan.Ticks / TimeSpan::TicksPerMillisecond; + m_hashcode = (int)millitime ^ (int)((System::Int64)millitime >> 32); + } + return m_hashcode; + } + + bool CacheableDate::Equals(ICacheableKey^ other) + { + if (other == nullptr || + other->ClassId != GeodeClassIds::CacheableDate) { + return false; + } + return m_dateTime.Equals(static_cast<CacheableDate^>( + other)->m_dateTime); + } + + bool CacheableDate::Equals(Object^ obj) + { + CacheableDate^ otherDate = + dynamic_cast<CacheableDate^>(obj); + + if (otherDate != nullptr) { + return (m_dateTime == otherDate->m_dateTime); + } + return false; + } // namespace Client + } // namespace Geode + } // namespace Apache + +} //namespace + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableDate.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableDate.hpp b/clicache/src/CacheableDate.hpp new file mode 100644 index 0000000..9530ef2 --- /dev/null +++ b/clicache/src/CacheableDate.hpp @@ -0,0 +1,174 @@ +/* + * 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 "ICacheableKey.hpp" + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// An immutable date wrapper that can serve as a distributable + /// key object for caching as well as being a string value. + /// </summary> + public ref class CacheableDate + : public ICacheableKey + { + public: + /// <summary> + /// Allocates a new default instance. + /// </summary> + inline CacheableDate() + { } + + /// <summary> + /// Initializes a new instance of the <c>CacheableDate</c> to the + /// given <c>System.DateTime</c> value. + /// </summary> + /// <param name="dateTime"> + /// A <c>System.DateTime</c> value to initialize this instance. + /// </param> + CacheableDate(DateTime dateTime); + + /// <summary> + /// Static function that returns a new default instance. + /// </summary> + inline static CacheableDate^ Create() + { + return gcnew CacheableDate(); + } + + /// <summary> + /// Static function that returns a new instance initialized to the + /// given <c>System.DateTime</c> value. + /// </summary> + inline static CacheableDate^ Create(DateTime dateTime) + { + return gcnew CacheableDate(dateTime); + } + + // Region: IGeodeSerializable Members + + /// <summary> + /// Serializes this object. + /// </summary> + /// <param name="output"> + /// the DataOutput object to use for serializing the object + /// </param> + virtual void ToData(DataOutput^ output); + + /// <summary> + /// Deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + /// <param name="input"> + /// the DataInput stream to use for reading the object data + /// </param> + /// <returns>the deserialized object</returns> + virtual IGeodeSerializable^ FromData(DataInput^ input); + + /// <summary> + /// return the size of this object in bytes + /// </summary> + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual property System::UInt32 ObjectSize + { + virtual System::UInt32 get(); + } + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + virtual System::UInt32 get(); + } + + /// <summary> + /// Return a string representation of the object. + /// </summary> + virtual String^ ToString() override; + + // End Region: IGeodeSerializable Members + + + // Region: ICacheableKey Members + + /// <summary> + /// Return the hashcode for this key. + /// </summary> + virtual System::Int32 GetHashCode() override; + + /// <summary> + /// Return true if this key matches other object. + /// </summary> + virtual bool Equals(ICacheableKey^ other); + + /// <summary> + /// Return true if this key matches other object. + /// </summary> + virtual bool Equals(Object^ obj) override; + + // End Region: ICacheableKey Members + + /// <summary> + /// Gets the <c>System.DateTime</c> value. + /// </summary> + property DateTime Value + { + inline DateTime get() + { + return m_dateTime; + } + } + + /// <summary> + /// <c>DataTime</c> value since 1/1/1970 + /// </summary> + static initonly DateTime EpochTime = DateTime(1970, 1, 1, + 0, 0, 0, DateTimeKind::Utc); + + /// <summary> + /// Factory function to register this class. + /// </summary> + static IGeodeSerializable^ CreateDeserializable() + { + return gcnew CacheableDate(); + } + + private: + DateTime m_dateTime; + int m_hashcode; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableFileName.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableFileName.cpp b/clicache/src/CacheableFileName.cpp new file mode 100644 index 0000000..fb3cb10 --- /dev/null +++ b/clicache/src/CacheableFileName.cpp @@ -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. + */ + + + + +//#include "geode_includes.hpp" +#include "CacheableFileName.hpp" +#include "DataOutput.hpp" +#include "DataInput.hpp" +#include "GeodeClassIds.hpp" +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + void CacheableFileName::ToData(DataOutput^ output) + { + if (m_str->Length <= 0xFFFF) { + output->WriteByte(apache::geode::client::GeodeTypeIds::CacheableString); + output->WriteUTF(m_str); + } + else { + output->WriteByte(apache::geode::client::GeodeTypeIds::CacheableStringHuge); + output->WriteUTFHuge(m_str); + } + } + + IGeodeSerializable^ CacheableFileName::FromData(DataInput^ input) + { + unsigned char filetype = input->ReadByte(); + if (filetype == apache::geode::client::GeodeTypeIds::CacheableString) { + m_str = input->ReadUTF(); + } + else { + m_str = input->ReadUTFHuge(); + } + return this; + } + + System::UInt32 CacheableFileName::ClassId::get() + { + return GeodeClassIds::CacheableFileName; + } + + System::UInt32 CacheableFileName::ObjectSize::get() + { + return (System::UInt32)(m_str->Length * sizeof(char)); + } + + System::Int32 CacheableFileName::GetHashCode() + { + if (m_str->IsNullOrEmpty(m_str)) { + return 0; + } + if (m_hashcode == 0) { + int localHashcode = 0; + System::UInt32 prime = 31; + + pin_ptr<const wchar_t> pin_value = PtrToStringChars(m_str); + for (System::Int32 i = 0; i < m_str->Length; i++) { + localHashcode = prime*localHashcode + Char::ToLower(pin_value[i]); + } + m_hashcode = localHashcode ^ 1234321; + } + return m_hashcode; + } + + bool CacheableFileName::Equals(ICacheableKey^ other) + { + if (other == nullptr || + other->ClassId != GeodeClassIds::CacheableFileName) { + return false; + } + return (m_str == static_cast<CacheableFileName^>(other)->m_str); + } + + bool CacheableFileName::Equals(Object^ obj) + { + CacheableFileName^ otherFileName = + dynamic_cast<CacheableFileName^>(obj); + + if (otherFileName != nullptr) { + return (m_str == otherFileName->m_str); + } + return false; + } // namespace Client + } // namespace Geode + } // namespace Apache + +} //namespace + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableFileName.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableFileName.hpp b/clicache/src/CacheableFileName.hpp new file mode 100644 index 0000000..bb1279e --- /dev/null +++ b/clicache/src/CacheableFileName.hpp @@ -0,0 +1,172 @@ +/* + * 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 "ICacheableKey.hpp" + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// An immutable filename wrapper that can serve as a distributable + /// key object for caching as well as being a string value. + /// </summary> + public ref class CacheableFileName + : public ICacheableKey + { + public: + /// <summary> + /// Static function to create a new instance from the given string. + /// </summary> + inline static CacheableFileName^ Create(String^ value) + { + return (value != nullptr && value->Length > 0 ? + gcnew CacheableFileName(value) : nullptr); + } + + /// <summary> + /// Static function to create a new instance from the + /// given character array. + /// </summary> + inline static CacheableFileName^ Create(array<Char>^ value) + { + return (value != nullptr && value->Length > 0 ? + gcnew CacheableFileName(value) : nullptr); + } + + // Region: IGeodeSerializable Members + + /// <summary> + /// Serializes this object. + /// </summary> + /// <param name="output"> + /// the DataOutput object to use for serializing the object + /// </param> + virtual void ToData(DataOutput^ output); + + /// <summary> + /// Deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + /// <param name="input"> + /// the DataInput stream to use for reading the object data + /// </param> + /// <returns>the deserialized object</returns> + virtual IGeodeSerializable^ FromData(DataInput^ input); + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual property System::UInt32 ObjectSize + { + virtual System::UInt32 get(); + } + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + virtual System::UInt32 get(); + } + + /// <summary> + /// Return a string representation of the object. + /// This returns the same string as <c>Value</c> property. + /// </summary> + virtual String^ ToString() override + { + return m_str; + } + + // End Region: IGeodeSerializable Members + + // Region: ICacheableKey Members + + /// <summary> + /// Return the hashcode for this key. + /// </summary> + virtual System::Int32 GetHashCode() override; + + /// <summary> + /// Return true if this key matches other object. + /// </summary> + virtual bool Equals(ICacheableKey^ other); + + /// <summary> + /// Return true if this key matches other object. + /// </summary> + virtual bool Equals(Object^ obj) override; + + // End Region: ICacheableKey Members + + /// <summary> + /// Gets the string value. + /// </summary> + property String^ Value + { + inline String^ get() + { + return m_str; + } + } + + internal: + /// <summary> + /// Factory function to register this class. + /// </summary> + static IGeodeSerializable^ CreateDeserializable() + { + return gcnew CacheableFileName((String^)nullptr); + } + + private: + /// <summary> + /// Allocates a new instance from the given string. + /// </summary> + inline CacheableFileName(String^ value) + : m_str(value == nullptr ? String::Empty : value),m_hashcode(0) { } + + /// <summary> + /// Allocates a new instance copying from the given character array. + /// </summary> + inline CacheableFileName(array<Char>^ value) + : m_str(gcnew String(value)),m_hashcode(0) { } + + String^ m_str; + int m_hashcode; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + + + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableHashMap.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableHashMap.cpp b/clicache/src/CacheableHashMap.cpp new file mode 100644 index 0000000..a4c96e0 --- /dev/null +++ b/clicache/src/CacheableHashMap.cpp @@ -0,0 +1,54 @@ +/* + * 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 "CacheableHashMap.hpp" +#include "DataOutput.hpp" +#include "DataInput.hpp" +#include "impl/SafeConvert.hpp" + +using namespace System; +using namespace System::Collections::Generic; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + // Region: IGeodeSerializable Members + + void Client::CacheableHashMap::ToData(DataOutput^ output) + { + output->WriteDictionary((System::Collections::IDictionary^)m_dictionary); + } + + IGeodeSerializable^ Client::CacheableHashMap::FromData(DataInput^ input) + { + m_dictionary = input->ReadDictionary(); + return this; + } + + System::UInt32 Client::CacheableHashMap::ObjectSize::get() + { + return ((System::Collections::IDictionary^)m_dictionary)->Count; + } // namespace Client + } // namespace Geode +} // namespace Apache + + } //namespace http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/CacheableHashMap.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/CacheableHashMap.hpp b/clicache/src/CacheableHashMap.hpp new file mode 100644 index 0000000..6d64461 --- /dev/null +++ b/clicache/src/CacheableHashMap.hpp @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "geode_defs.hpp" +#include "IGeodeSerializable.hpp" +#include "ICacheableKey.hpp" +#include "GeodeClassIds.hpp" + +using namespace System; +using namespace System::Collections::Generic; + + + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// A mutable <c>ICacheableKey</c> to <c>IGeodeSerializable</c> hash map + /// that can serve as a distributable object for caching. This class + /// extends .NET generic <c>Dictionary</c> class. + /// </summary> + ref class CacheableHashMap + : public IGeodeSerializable + { + protected: + Object^ m_dictionary; + public: + /// <summary> + /// Allocates a new empty instance. + /// </summary> + inline CacheableHashMap() + { } + + /// <summary> + /// Allocates a new instance copying from the given dictionary. + /// </summary> + /// <param name="dictionary"> + /// The dictionary whose elements are copied to this HashMap. + /// </param> + inline CacheableHashMap(Object^ dictionary) + { + m_dictionary = dictionary; + } + + + /// <summary> + /// Static function to create a new empty instance. + /// </summary> + inline static CacheableHashMap^ Create() + { + return gcnew CacheableHashMap(); + } + + /// <summary> + /// Static function to create a new instance copying from the + /// given dictionary. + /// </summary> + inline static CacheableHashMap^ Create(Object^ dictionary) + { + return gcnew CacheableHashMap(dictionary); + } + + + // Region: IGeodeSerializable Members + + /// <summary> + /// Serializes this object. + /// </summary> + /// <param name="output"> + /// the DataOutput object to use for serializing the object + /// </param> + virtual void ToData(DataOutput^ output); + + /// <summary> + /// Deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + /// <param name="input"> + /// the DataInput stream to use for reading the object data + /// </param> + /// <returns>the deserialized object</returns> + virtual IGeodeSerializable^ FromData(DataInput^ input); + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual property System::UInt32 ObjectSize + { + virtual System::UInt32 get(); + } + + /// <summary> + /// Returns the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + /// <returns>the classId</returns> + virtual property System::UInt32 ClassId + { + inline virtual System::UInt32 get() + { + return GeodeClassIds::CacheableHashMap; + } + } + + property Object^ Value + { + Object^ get() + { + return m_dictionary; + } + } + + // End Region: IGeodeSerializable Members + + /// <summary> + /// Factory function to register this class. + /// </summary> + static IGeodeSerializable^ CreateDeserializable() + { + return gcnew CacheableHashMap(); + } + }; + } // namespace Client + } // namespace Geode +} // namespace Apache +