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 2018/04/23 22:13:08 UTC

[geode-native] branch develop updated: GEODE-4854: return CqAttributesMutator value (#282)

This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 7a5194f  GEODE-4854: return CqAttributesMutator value (#282)
7a5194f is described below

commit 7a5194f6fb05124aeb1756d8bd169e7ce706519e
Author: Ivan Godwin <ig...@pivotal.io>
AuthorDate: Mon Apr 23 15:13:05 2018 -0700

    GEODE-4854: return CqAttributesMutator value (#282)
    
    Signed-off-by: Ivan Godwin <ig...@pivotal.io>
    Signed-off-by: Ryan McMahon <rm...@pivotal.io>
---
 clicache/src/CqAttributesMutator.hpp               | 24 +++----
 clicache/src/CqQuery.cpp                           |  2 +-
 cppcache/include/geode/CqAttributesMutator.hpp     | 19 +++--
 cppcache/include/geode/CqQuery.hpp                 |  3 +-
 cppcache/integration-test/testThinClientCq.cpp     |  8 +--
 ...utesMutatorImpl.cpp => CqAttributesMutator.cpp} | 13 ++--
 cppcache/src/CqAttributesMutatorImpl.hpp           | 83 ----------------------
 cppcache/src/CqQueryImpl.cpp                       | 35 ++++-----
 cppcache/src/CqQueryImpl.hpp                       |  4 +-
 9 files changed, 53 insertions(+), 138 deletions(-)

diff --git a/clicache/src/CqAttributesMutator.hpp b/clicache/src/CqAttributesMutator.hpp
index ca1ea0e..f7c29e4 100644
--- a/clicache/src/CqAttributesMutator.hpp
+++ b/clicache/src/CqAttributesMutator.hpp
@@ -17,15 +17,13 @@
 
 #pragma once
 
-
 #include "geode_defs.hpp"
 #include "begin_native.hpp"
 #include <geode/CqAttributesMutator.hpp>
 #include "end_native.hpp"
 
-
 #include "native_shared_ptr.hpp"
-
+#include "native_conditional_unique_ptr.hpp"
 
 using namespace System;
 using namespace System::Collections::Generic;
@@ -77,40 +75,40 @@ namespace Apache
 
 
         /// <summary>
-	/// Initialize with an array of listeners
+	      /// Initialize with an array of listeners
         /// </summary>
         
         void SetCqListeners(array<Client::ICqListener<TKey, TResult>^>^ newListeners);
 
 
       internal:
+
         /// <summary>
         /// Internal factory function to wrap a native object pointer inside
-        /// this managed class with null pointer check.
+        /// this managed class.
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
         /// <returns>
-        /// The managed wrapper object; null if the native pointer is null.
+        /// The managed wrapper object
         /// </returns>
-        inline static Client::CqAttributesMutator<TKey, TResult>^ Create( std::shared_ptr<native::CqAttributesMutator> nativeptr )
+        inline static Client::CqAttributesMutator<TKey, TResult>^ Create(native::CqAttributesMutator* nativeptr)
         {
-          return __nullptr == nativeptr ? nullptr :
-            gcnew  Client::CqAttributesMutator<TKey, TResult>( nativeptr );
+          auto instance = gcnew CqAttributesMutator(nativeptr);
+          return instance;
         }
 
-
       private:
 
         /// <summary>
         /// Private constructor to wrap a native object pointer
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
-        inline CqAttributesMutator<TKey, TResult>( std::shared_ptr<native::CqAttributesMutator> nativeptr )
+        inline CqAttributesMutator<TKey, TResult>(native::CqAttributesMutator* nativeptr)
         {
-          m_nativeptr = gcnew native_shared_ptr<native::CqAttributesMutator>(nativeptr);
+            m_nativeptr = gcnew native_conditional_unique_ptr<native::CqAttributesMutator>(nativeptr);
         }
 
-        native_shared_ptr<native::CqAttributesMutator>^ m_nativeptr;
+        native_conditional_unique_ptr<native::CqAttributesMutator>^ m_nativeptr;
       };
     }  // namespace Client
   }  // namespace Geode
diff --git a/clicache/src/CqQuery.cpp b/clicache/src/CqQuery.cpp
index 62c1aab..d1a67c8 100644
--- a/clicache/src/CqQuery.cpp
+++ b/clicache/src/CqQuery.cpp
@@ -141,7 +141,7 @@ namespace Apache
       {
         try
         {
-          return CqAttributesMutator<TKey, TResult>::Create(m_nativeptr->get()->getCqAttributesMutator());
+          return CqAttributesMutator<TKey, TResult>::Create(&(m_nativeptr->get()->getCqAttributesMutator()));
         }
         finally
         {
diff --git a/cppcache/include/geode/CqAttributesMutator.hpp b/cppcache/include/geode/CqAttributesMutator.hpp
index 39a0eab..42870b8 100644
--- a/cppcache/include/geode/CqAttributesMutator.hpp
+++ b/cppcache/include/geode/CqAttributesMutator.hpp
@@ -19,10 +19,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <memory>
+#include <vector>
 
+#include "CqAttributes.hpp"
 #include "internal/geode_globals.hpp"
-#include <vector>
-#include <memory>
 /**
  * @file
  */
@@ -41,12 +42,14 @@ class CqListener;
  */
 class APACHE_GEODE_EXPORT CqAttributesMutator {
  public:
+  CqAttributesMutator(const std::shared_ptr<CqAttributes>& impl);
+
   /**
    * Adds a CQ listener to the end of the list of CQ listeners on this CqQuery.
    * @param aListener the user defined CQ listener to add to the CqQuery.
    * @throws IllegalArgumentException if <code>aListener</code> is nullptr
    */
-  virtual void addCqListener(const std::shared_ptr<CqListener>& aListener) = 0;
+  void addCqListener(const std::shared_ptr<CqListener>& aListener);
 
   /**
    * Removes given CQ listener from the list of CQ listeners on this CqQuery.
@@ -56,8 +59,7 @@ class APACHE_GEODE_EXPORT CqAttributesMutator {
    * @param aListener the CQ listener to remove from the CqQuery.
    * @throws IllegalArgumentException if <code>aListener</code> is nullptr
    */
-  virtual void removeCqListener(
-      const std::shared_ptr<CqListener>& aListener) = 0;
+  void removeCqListener(const std::shared_ptr<CqListener>& aListener);
 
   /**
    * Adds the given set CqListner on this CQ. If the CQ already has CqListeners,
@@ -68,8 +70,11 @@ class APACHE_GEODE_EXPORT CqAttributesMutator {
    * @throws IllegalArgumentException if the <code>newListeners</code> array
    * has a nullptr element
    */
-  virtual void setCqListeners(
-      const std::vector<std::shared_ptr<CqListener>>& newListeners) = 0;
+  void setCqListeners(
+      const std::vector<std::shared_ptr<CqListener>>& newListeners);
+
+ private:
+  std::shared_ptr<CqAttributes> m_cqAttributes;
 };
 }  // namespace client
 }  // namespace geode
diff --git a/cppcache/include/geode/CqQuery.hpp b/cppcache/include/geode/CqQuery.hpp
index a39ca26..f7a70f5 100644
--- a/cppcache/include/geode/CqQuery.hpp
+++ b/cppcache/include/geode/CqQuery.hpp
@@ -89,8 +89,7 @@ class APACHE_GEODE_EXPORT CqQuery {
    * Get the AttributesMutator of this CQ.
    * @return CqAttributesMutator, the CqAttributesMutator object.
    */
-  virtual std::shared_ptr<CqAttributesMutator> getCqAttributesMutator()
-      const = 0;
+  virtual CqAttributesMutator getCqAttributesMutator() const = 0;
 
   /**
    * Start executing the CQ or if this CQ is stopped earlier, resumes execution
diff --git a/cppcache/integration-test/testThinClientCq.cpp b/cppcache/integration-test/testThinClientCq.cpp
index fc1dc83..7e5d142 100644
--- a/cppcache/integration-test/testThinClientCq.cpp
+++ b/cppcache/integration-test/testThinClientCq.cpp
@@ -570,7 +570,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, StepFour)
        LOG("removing listener");
        auto cqAttrMtor = cqy->getCqAttributesMutator();
        auto ptr = vl[0];
-       cqAttrMtor->removeCqListener(ptr);
+       cqAttrMtor.removeCqListener(ptr);
        vl = cqAttr->getCqListeners();
        sprintf(buf, "number of listeners for cq[%s] is %zd", cqNames[i],
                vl.size());
@@ -1108,13 +1108,13 @@ DUNIT_TASK_DEFINITION(CLIENT1, ProcessCQ)
 
    auto cqAttrMtor = cq->getCqAttributesMutator();
    auto ptr = vl[0];
-   cqAttrMtor->removeCqListener(ptr);
+   cqAttrMtor.removeCqListener(ptr);
    vl = cqAttr->getCqListeners();
    LOGINFO("number of listeners = %d", vl.size());
 
    ASSERT(vl.size() == 1, "incorrect number of listeners");
 
-   cqAttrMtor->removeCqListener(vl[0]);
+   cqAttrMtor.removeCqListener(vl[0]);
    LOGINFO("removeCqListener again");
    vl = cqAttr->getCqListeners();
    LOGINFO("number of listeners = %d", vl.size());
@@ -1124,7 +1124,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, ProcessCQ)
    std::vector<std::shared_ptr<CqListener>> v2;
    v2.push_back(cqStatusLstner);
    v2.push_back(cqLstner);
-   cqAttrMtor->setCqListeners(v2);
+   cqAttrMtor.setCqListeners(v2);
    LOG("ProcessCQ setCqListeneres done.");
 
    cqAttr = cq->getCqAttributes();
diff --git a/cppcache/src/CqAttributesMutatorImpl.cpp b/cppcache/src/CqAttributesMutator.cpp
similarity index 83%
rename from cppcache/src/CqAttributesMutatorImpl.cpp
rename to cppcache/src/CqAttributesMutator.cpp
index 9e14199..1b14fd4 100644
--- a/cppcache/src/CqAttributesMutatorImpl.cpp
+++ b/cppcache/src/CqAttributesMutator.cpp
@@ -14,26 +14,27 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "CqAttributesMutatorImpl.hpp"
+#include <geode/CqAttributesMutator.hpp>
+
 #include "CqAttributesImpl.hpp"
+
 using namespace apache::geode::client;
-CqAttributesMutatorImpl::CqAttributesMutatorImpl(
-    const std::shared_ptr<CqAttributes>& impl)
+CqAttributesMutator::CqAttributesMutator(const std::shared_ptr<CqAttributes>& impl)
     : m_cqAttributes(impl) {}
 
-void CqAttributesMutatorImpl::addCqListener(
+void CqAttributesMutator::addCqListener(
     const std::shared_ptr<CqListener>& aListener) {
   std::static_pointer_cast<CqAttributesImpl>(m_cqAttributes)
       ->addCqListener(aListener);
 }
 
-void CqAttributesMutatorImpl::removeCqListener(
+void CqAttributesMutator::removeCqListener(
     const std::shared_ptr<CqListener>& aListener) {
   std::static_pointer_cast<CqAttributesImpl>(m_cqAttributes)
       ->removeCqListener(aListener);
 }
 
-void CqAttributesMutatorImpl::setCqListeners(
+void CqAttributesMutator::setCqListeners(
     const CqAttributesImpl::listener_container_type& newListeners) {
   std::static_pointer_cast<CqAttributesImpl>(m_cqAttributes)
       ->setCqListeners(newListeners);
diff --git a/cppcache/src/CqAttributesMutatorImpl.hpp b/cppcache/src/CqAttributesMutatorImpl.hpp
deleted file mode 100644
index 2f367f0..0000000
--- a/cppcache/src/CqAttributesMutatorImpl.hpp
+++ /dev/null
@@ -1,83 +0,0 @@
-#pragma once
-
-#ifndef GEODE_CQATTRIBUTESMUTATORIMPL_H_
-#define GEODE_CQATTRIBUTESMUTATORIMPL_H_
-
-/*
- * 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/internal/geode_globals.hpp>
-#include <geode/CqAttributesMutator.hpp>
-#include <geode/CqAttributes.hpp>
-
-/**
- * @file
- */
-
-namespace apache {
-namespace geode {
-namespace client {
-
-/**
- * @class CqAttributesMutatorImpl CqAttributesMutatorImpl.hpp
- *
- * This interface is used to modify the listeners that are associated with a CQ.
- * Each CqQuery has an CqAttributesMutatorImpl interface which supports
- * modification
- * of certain CQ attributes after the CQ has been created.
- *
- */
-class APACHE_GEODE_EXPORT CqAttributesMutatorImpl : public CqAttributesMutator {
- public:
-  CqAttributesMutatorImpl(const std::shared_ptr<CqAttributes>& impl);
-
-  /**
-   * Adds a CQ listener to the end of the list of CQ listeners on this CqQuery.
-   * @param aListener the user defined CQ listener to add to the CqQuery.
-   * @throws IllegalArgumentException if <code>aListener</code> is null
-   */
-  void addCqListener(const std::shared_ptr<CqListener>& aListener);
-
-  /**
-   * Removes given CQ listener from the list of CQ listeners on this CqQuery.
-   * Does nothing if the specified listener has not been added.
-   * If the specified listener has been added then will
-   * be called on it; otherwise does nothing.
-   * @param aListener the CQ listener to remove from the CqQuery.
-   * @throws IllegalArgumentException if <code>aListener</code> is null
-   */
-  void removeCqListener(const std::shared_ptr<CqListener>& aListener);
-
-  /**
-   * Adds the given set CqListner on this CQ. If the CQ already has CqListeners,
-   * this
-   * removes those old CQs and initializes with the newListeners.
-   * @param newListeners a possibly null or empty array of listeners to add
-   * to this CqQuery.
-   * @throws IllegalArgumentException if the <code>newListeners</code> array
-   * has a null element
-   */
-  void setCqListeners(const std::vector<std::shared_ptr<CqListener>>& newListeners);
-
- private:
-  std::shared_ptr<CqAttributes> m_cqAttributes;
-};
-}  // namespace client
-}  // namespace geode
-}  // namespace apache
-
-#endif  // GEODE_CQATTRIBUTESMUTATORIMPL_H_
diff --git a/cppcache/src/CqQueryImpl.cpp b/cppcache/src/CqQueryImpl.cpp
index ba6051c..6577cec 100644
--- a/cppcache/src/CqQueryImpl.cpp
+++ b/cppcache/src/CqQueryImpl.cpp
@@ -17,9 +17,9 @@
 
 #include <geode/CqAttributesFactory.hpp>
 #include <geode/ExceptionTypes.hpp>
+#include <geode/CqAttributesMutator.hpp>
 
 #include "CqQueryImpl.hpp"
-#include "CqAttributesMutatorImpl.hpp"
 #include "ResultSetImpl.hpp"
 #include "StructSetImpl.hpp"
 #include "ThinClientRegion.hpp"
@@ -40,18 +40,16 @@ CqQueryImpl::CqQueryImpl(
     const std::shared_ptr<UserAttributes>& userAttributesPtr)
     : m_cqName(cqName),
       m_queryString(queryString),
+      m_cqAttributes(CqAttributesFactory(cqAttributes).create()),
+      m_cqAttributesMutator(m_cqAttributes),
       m_cqService(cqService),
-      m_serverCqName(
-          cqName),  // On Client Side serverCqName and cqName will be same.
+      // On Client Side serverCqName and cqName will be same.
+      m_serverCqName(cqName),
       m_isDurable(isDurable),
       m_stats(std::make_shared<CqQueryVsdStats>(factory, m_cqName)),
       m_cqState(CqState::STOPPED),  // Initial state is stopped
       m_cqOperation(CqOperation::OP_TYPE_INVALID),
       m_tccdm(m_cqService->getDM()) {
-  CqAttributesFactory cqAf(cqAttributes);
-  m_cqAttributes = cqAf.create();
-  m_cqAttributesMutator =
-      std::make_shared<CqAttributesMutatorImpl>(m_cqAttributes);
   if (userAttributesPtr != nullptr) {
     m_authenticatedView = userAttributesPtr->getAuthenticatedView();
   } else {
@@ -220,17 +218,17 @@ const std::string& CqQueryImpl::getQueryString() const { return m_queryString; }
  * Return the query
  * @return the Query for the query string
  */
- std::shared_ptr<Query> CqQueryImpl::getQuery() const { return m_query; }
+std::shared_ptr<Query> CqQueryImpl::getQuery() const { return m_query; }
 
 /**
  * @see org.apache.geode.cache.query.CqQuery#getStatistics()
  */
- std::shared_ptr<CqStatistics> CqQueryImpl::getStatistics() const {
-   return m_stats;
- }
+std::shared_ptr<CqStatistics> CqQueryImpl::getStatistics() const {
+  return m_stats;
+}
 
- std::shared_ptr<CqAttributes> CqQueryImpl::getCqAttributes() const {
-   return m_cqAttributes;
+std::shared_ptr<CqAttributes> CqQueryImpl::getCqAttributes() const {
+  return m_cqAttributes;
 }
 
 /**
@@ -410,8 +408,7 @@ std::shared_ptr<CqResults> CqQueryImpl::executeWithInitialResults(
     if (err == GF_CACHESERVER_EXCEPTION) {
       throw CqQueryException(
           std::string("CqQuery::executeWithInitialResults: exception ") +
-          "at the server side: " +
-          reply.getException());
+          "at the server side: " + reply.getException());
     } else {
       GfErrTypeToException("CqQuery::executeWithInitialResults", err);
     }
@@ -529,16 +526,14 @@ void CqQueryImpl::setCqState(CqState state) {
   m_cqState = state;
 }
 
-std::shared_ptr<CqAttributesMutator> CqQueryImpl::getCqAttributesMutator()
-    const {
+CqAttributesMutator CqQueryImpl::getCqAttributesMutator() const {
   return m_cqAttributesMutator;
 }
+
 /**
  * @return Returns the cqOperation.
  */
-CqOperation CqQueryImpl::getCqOperation() const {
-  return m_cqOperation;
-}
+CqOperation CqQueryImpl::getCqOperation() const { return m_cqOperation; }
 
 /**
  * @param cqOperation The cqOperation to set.
diff --git a/cppcache/src/CqQueryImpl.hpp b/cppcache/src/CqQueryImpl.hpp
index 1ea30e3..507115b 100644
--- a/cppcache/src/CqQueryImpl.hpp
+++ b/cppcache/src/CqQueryImpl.hpp
@@ -63,7 +63,7 @@ class CqQueryImpl : public CqQuery,
  private:
   std::shared_ptr<Query> m_query;
   std::shared_ptr<CqAttributes> m_cqAttributes;
-  std::shared_ptr<CqAttributesMutator> m_cqAttributesMutator;
+  CqAttributesMutator m_cqAttributesMutator;
   std::shared_ptr<CqService> m_cqService;
   std::string m_serverCqName;
   bool m_isDurable;
@@ -223,7 +223,7 @@ class CqQueryImpl : public CqQuery,
    */
   void setCqState(CqState state);
 
-  std::shared_ptr<CqAttributesMutator> getCqAttributesMutator() const override;
+  CqAttributesMutator getCqAttributesMutator() const override;
 
   /**
    * @return Returns the cqOperation.

-- 
To stop receiving notification emails like this one, please contact
jbarrett@apache.org.