blob: 724025bc6b851e1fafb4ab25e4c7307eee6e314c [file] [log] [blame]
/*=========================================================================
* Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
* This product is protected by U.S. and international copyright
* and intellectual property laws. Pivotal products are covered by
* one or more patents listed at http://www.pivotal.io/patents.
*=========================================================================
*/
#include "CqAttributesImpl.hpp"
#include "../ExceptionTypes.hpp"
using namespace gemfire;
void CqAttributesImpl::getCqListeners(VectorOfCqListener& vl )
{
ACE_Guard< ACE_Recursive_Thread_Mutex > _guard( m_mutex );
vl.clear();
// vl.reserve(m_cqListeners.size());
vl = m_cqListeners;
// for(size_t i=0; i < m_cqListeners.size(); i++)
// vl[i] = m_cqListeners[i];
}
void CqAttributesImpl::addCqListener(CqListenerPtr& cql)
{
if (cql == NULLPTR) {
throw IllegalArgumentException("addCqListener parameter was null");
}
ACE_Guard< ACE_Recursive_Thread_Mutex > _guard( m_mutex );
m_cqListeners.push_back(cql);
}
CqAttributesImpl* CqAttributesImpl::clone()
{
CqAttributesImpl* ptr = new CqAttributesImpl();
ptr->setCqListeners(m_cqListeners);
return ptr;
}
void CqAttributesImpl::setCqListeners(VectorOfCqListener& addedListeners)
{
if(addedListeners.empty()==true)
{
LOGWARN("setCqListeners parameter had a null element, nothing to be set");
return;
}
VectorOfCqListener oldListeners(m_cqListeners);
{
ACE_Guard< ACE_Recursive_Thread_Mutex > _guard( m_mutex );
m_cqListeners = addedListeners;
}
if (!oldListeners.empty()) {
for (int32_t i=0; i< oldListeners.length();i++){
try {
oldListeners[i]->close();
// Handle client side exceptions.
} catch (Exception& ex) {
LOGWARN("Exception occured while closing CQ Listener %s Error", ex.getMessage());
}
}
oldListeners.clear();
}
}
void CqAttributesImpl::removeCqListener(CqListenerPtr& cql)
{
if (cql == NULLPTR) {
throw IllegalArgumentException("removeCqListener parameter was null");
}
ACE_Guard< ACE_Recursive_Thread_Mutex > _guard( m_mutex );
if (!m_cqListeners.empty()) {
for(int32_t i=0; i < m_cqListeners.size(); i++){
if(m_cqListeners.at(i) == cql)
{
m_cqListeners.erase(i);
}
}
try {
cql->close();
// Handle client side exceptions.
} catch (Exception& ex) {
LOGWARN("Exception closing CQ Listener %s Error ", ex.getMessage());
}
}
}