Skip to content
Permalink
Browse files
GEODE-4854: return CqAttributesMutator value (#282)
Signed-off-by: Ivan Godwin <igodwin@pivotal.io>
Signed-off-by: Ryan McMahon <rmcmahon@pivotal.io>
  • Loading branch information
igodwin authored and pivotal-jbarrett committed Apr 23, 2018
1 parent 0baf411 commit 7a5194f6fb05124aeb1756d8bd169e7ce706519e
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 138 deletions.
@@ -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
@@ -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
{
@@ -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
@@ -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
@@ -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();
@@ -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);

This file was deleted.

@@ -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.
@@ -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.

0 comments on commit 7a5194f

Please sign in to comment.