use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqServiceImpl method processRegionEvent.
private void processRegionEvent(CacheEvent event, Profile localProfile, Profile[] profiles, FilterRoutingInfo frInfo) throws CqException {
final boolean isDebugEnabled = logger.isDebugEnabled();
if (isDebugEnabled) {
logger.debug("CQ service processing region event {}", event);
}
Integer cqRegionEvent = generateCqRegionEvent(event);
for (int i = -1; i < profiles.length; i++) {
CacheProfile cf;
if (i < 0) {
cf = (CacheProfile) localProfile;
if (cf == null)
continue;
} else {
cf = (CacheProfile) profiles[i];
}
FilterProfile pf = cf.filterProfile;
if (pf == null || pf.getCqMap().isEmpty()) {
continue;
}
Map cqs = pf.getCqMap();
HashMap<Long, Integer> cqInfo = new HashMap<>();
Iterator cqIter = cqs.entrySet().iterator();
while (cqIter.hasNext()) {
Map.Entry cqEntry = (Map.Entry) cqIter.next();
ServerCQImpl cQuery = (ServerCQImpl) cqEntry.getValue();
if (!event.isOriginRemote() && event.getOperation().isRegionDestroy() && !((LocalRegion) event.getRegion()).isUsedForPartitionedRegionBucket()) {
try {
if (isDebugEnabled) {
logger.debug("Closing CQ on region destroy event. CqName : {}", cQuery.getName());
}
cQuery.close(false);
} catch (Exception ex) {
if (isDebugEnabled) {
logger.debug("Failed to Close CQ on region destroy. CqName : {}", cQuery.getName(), ex);
}
}
}
cqInfo.put(cQuery.getFilterID(), cqRegionEvent);
cQuery.getVsdStats().updateStats(cqRegionEvent);
}
if (pf.isLocalProfile()) {
frInfo.setLocalCqInfo(cqInfo);
} else {
frInfo.setCqRoutingInfo(cf.getDistributedMember(), cqInfo);
}
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqServiceImpl method getAllDurableClientCqs.
@Override
public List<String> getAllDurableClientCqs(ClientProxyMembershipID clientProxyId) throws CqException {
if (clientProxyId == null) {
throw new CqException(LocalizedStrings.CqService_UNABLE_TO_RETRIEVE_DURABLE_CQS_FOR_CLIENT_PROXY_ID.toLocalizedString());
}
List<ServerCQ> cqs = getAllClientCqs(clientProxyId);
ArrayList<String> durableClientCqs = new ArrayList<>();
for (ServerCQ cq : cqs) {
ServerCQImpl cQuery = (ServerCQImpl) cq;
if (cQuery != null && cQuery.isDurable()) {
ClientProxyMembershipID id = cQuery.getClientProxyId();
if (id != null && id.equals(clientProxyId)) {
durableClientCqs.add(cQuery.getName());
}
}
}
return durableClientCqs;
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqServiceImpl method stopCq.
/**
* Called directly on server side.
*/
@Override
public void stopCq(String cqName, ClientProxyMembershipID clientId) throws CqException {
String serverCqName = cqName;
if (clientId != null) {
serverCqName = this.constructServerCqName(cqName, clientId);
removeFromCacheForServerToConstructedCQName(cqName, clientId);
}
ServerCQImpl cQuery = null;
StringId errMsg = null;
Exception ex = null;
try {
HashMap<String, CqQueryImpl> cqMap = cqQueryMap;
if (!cqMap.containsKey(serverCqName)) {
/*
* gregp 052808: We should silently fail here instead of throwing error. This is to deal
* with races in recovery
*/
return;
}
cQuery = (ServerCQImpl) getCq(serverCqName);
} catch (CacheLoaderException e1) {
errMsg = LocalizedStrings.CqService_CQ_NOT_FOUND_IN_THE_CQ_META_REGION_CQNAME_0;
ex = e1;
} catch (TimeoutException e2) {
errMsg = LocalizedStrings.CqService_TIMEOUT_WHILE_TRYING_TO_GET_CQ_FROM_META_REGION_CQNAME_0;
ex = e2;
} finally {
if (ex != null) {
String s = errMsg.toLocalizedString(cqName);
if (logger.isDebugEnabled()) {
logger.debug(s);
}
throw new CqException(s, ex);
}
}
try {
if (!cQuery.isStopped()) {
cQuery.stop();
}
} catch (CqClosedException cce) {
throw new CqException(cce.getMessage());
} finally {
// If this CQ is stopped, disable caching event keys for this CQ.
// this.removeCQFromCaching(cQuery.getServerCqName());
this.removeFromMatchingCqMap(cQuery);
}
// Send stop message to peers.
cQuery.getCqBaseRegion().getFilterProfile().stopCq(cQuery);
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class ClientCQImpl method initConnectionProxy.
/**
* Initializes the connection using the pool from the client region. Also sets the cqBaseRegion
* value of this CQ.
*/
private void initConnectionProxy() throws CqException, RegionNotFoundException {
cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(regionName);
// is obtained by the Bridge Client/writer/loader on the local region.
if (cqBaseRegion == null) {
throw new RegionNotFoundException(LocalizedStrings.CqQueryImpl_REGION_ON_WHICH_QUERY_IS_SPECIFIED_NOT_FOUND_LOCALLY_REGIONNAME_0.toLocalizedString(regionName));
}
ServerRegionProxy srp = cqBaseRegion.getServerProxy();
if (srp != null) {
if (logger.isTraceEnabled()) {
logger.trace("Found server region proxy on region. RegionName: {}", regionName);
}
this.cqProxy = new ServerCQProxyImpl(srp);
if (!srp.getPool().getSubscriptionEnabled()) {
throw new CqException("The 'queueEnabled' flag on Pool installed on Region " + regionName + " is set to false.");
}
} else {
throw new CqException("Unable to get the connection pool. The Region does not have a pool configured.");
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class ClientCQImpl method executeCqOnRedundantsAndPrimary.
/**
* This executes the CQ first on the redundant server and then on the primary server. This is
* required to keep the redundancy behavior in accordance with the HAQueue expectation (wherein
* the events are delivered only from the primary).
*
* @param executeWithInitialResults boolean
* @return Object SelectResults in case of executeWithInitialResults
*/
private Object executeCqOnRedundantsAndPrimary(boolean executeWithInitialResults) throws CqClosedException, RegionNotFoundException, CqException {
Object initialResults = null;
synchronized (this.cqState) {
if (this.isClosed()) {
throw new CqClosedException(LocalizedStrings.CqQueryImpl_CQ_IS_CLOSED_CQNAME_0.toLocalizedString(this.cqName));
}
if (this.isRunning()) {
throw new IllegalStateException(LocalizedStrings.CqQueryImpl_CQ_IS_IN_RUNNING_STATE_CQNAME_0.toLocalizedString(this.cqName));
}
if (logger.isDebugEnabled()) {
logger.debug("Performing Execute {} request for CQ. CqName: {}", ((executeWithInitialResults) ? "WithInitialResult" : ""), this.cqName);
}
this.cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(this.regionName);
// If not server send the request to server.
if (!cqService.isServer()) {
// pool that initializes the CQ. Else its set using the Region proxy.
if (this.cqProxy == null) {
initConnectionProxy();
}
boolean success = false;
try {
if (this.proxyCache != null) {
if (this.proxyCache.isClosed()) {
throw new CacheClosedException("Cache is closed for this user.");
}
UserAttributes.userAttributes.set(this.proxyCache.getUserAttributes());
}
if (executeWithInitialResults) {
initialResults = cqProxy.createWithIR(this);
if (initialResults == null) {
String errMsg = "Failed to execute the CQ. CqName: " + this.cqName + ", Query String is: " + this.queryString;
throw new CqException(errMsg);
}
} else {
cqProxy.create(this);
}
success = true;
} catch (Exception ex) {
// Check for system shutdown.
if (this.shutdownInProgress()) {
throw new CqException("System shutdown in progress.");
}
if (ex.getCause() instanceof GemFireSecurityException) {
if (securityLogWriter.warningEnabled()) {
securityLogWriter.warning(LocalizedStrings.CqQueryImpl_EXCEPTION_WHILE_EXECUTING_CQ_EXCEPTION_0, ex, null);
}
throw new CqException(ex.getCause().getMessage(), ex.getCause());
} else if (ex instanceof CqException) {
throw (CqException) ex;
} else {
String errMsg = LocalizedStrings.CqQueryImpl_FAILED_TO_EXECUTE_THE_CQ_CQNAME_0_QUERY_STRING_IS_1_ERROR_FROM_LAST_SERVER_2.toLocalizedString(this.cqName, this.queryString, ex.getLocalizedMessage());
if (logger.isDebugEnabled()) {
logger.debug(errMsg, ex);
}
throw new CqException(errMsg, ex);
}
} finally {
if (!success && !this.shutdownInProgress()) {
try {
cqProxy.close(this);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Exception cleaning up failed cq", e);
}
UserAttributes.userAttributes.set(null);
}
}
UserAttributes.userAttributes.set(null);
}
}
this.cqState.setState(CqStateImpl.RUNNING);
}
// If client side, alert listeners that a cqs have been connected
if (!cqService.isServer()) {
connected = true;
CqListener[] cqListeners = getCqAttributes().getCqListeners();
for (int lCnt = 0; lCnt < cqListeners.length; lCnt++) {
if (cqListeners[lCnt] != null) {
if (cqListeners[lCnt] instanceof CqStatusListener) {
CqStatusListener listener = (CqStatusListener) cqListeners[lCnt];
listener.onCqConnected();
}
}
}
}
// Update CQ-base region for book keeping.
this.cqService.stats().incCqsActive();
this.cqService.stats().decCqsStopped();
return initialResults;
}
Aggregations