Search in sources :

Example 1 with ServerCQProxyImpl

use of org.apache.geode.cache.client.internal.ServerCQProxyImpl in project geode by apache.

the class CqServiceImpl method newCq.

@Override
public synchronized ClientCQ newCq(String cqName, String queryString, CqAttributes cqAttributes, InternalPool pool, boolean isDurable) throws QueryInvalidException, CqExistsException, CqException {
    if (queryString == null) {
        throw new IllegalArgumentException(LocalizedStrings.CqService_NULL_ARGUMENT_0.toLocalizedString("queryString"));
    } else if (cqAttributes == null) {
        throw new IllegalArgumentException(LocalizedStrings.CqService_NULL_ARGUMENT_0.toLocalizedString("cqAttribute"));
    }
    if (isServer()) {
        throw new IllegalStateException(LocalizedStrings.CqService_CLIENT_SIDE_NEWCQ_METHOD_INVOCATION_ON_SERVER.toLocalizedString());
    }
    // Check if the given cq already exists.
    if (cqName != null && isCqExists(cqName)) {
        throw new CqExistsException(LocalizedStrings.CqService_CQ_WITH_THE_GIVEN_NAME_ALREADY_EXISTS_CQNAME_0.toLocalizedString(cqName));
    }
    ServerCQProxyImpl serverProxy = pool == null ? null : new ServerCQProxyImpl(pool);
    ClientCQImpl cQuery = new ClientCQImpl(this, cqName, queryString, cqAttributes, serverProxy, isDurable);
    cQuery.updateCqCreateStats();
    // cQuery.initCq();
    // Check if query is valid.
    cQuery.validateCq();
    // Check if Name needs to be generated.
    if (cqName == null) {
        // to be taken care internally.
        while (true) {
            cQuery.setName(generateCqName());
            try {
                addToCqMap(cQuery);
            } catch (CqExistsException ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Got CqExistsException while intializing cq : {} Error : {}", cQuery.getName(), ex.getMessage());
                }
                continue;
            }
            break;
        }
    } else {
        addToCqMap(cQuery);
    }
    this.addToBaseRegionToCqNameMap(cQuery.getBaseRegionName(), cQuery.getServerCqName());
    return cQuery;
}
Also used : CqExistsException(org.apache.geode.cache.query.CqExistsException) ServerCQProxyImpl(org.apache.geode.cache.client.internal.ServerCQProxyImpl)

Example 2 with ServerCQProxyImpl

use of org.apache.geode.cache.client.internal.ServerCQProxyImpl 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.");
    }
}
Also used : RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) CqException(org.apache.geode.cache.query.CqException) ServerCQProxyImpl(org.apache.geode.cache.client.internal.ServerCQProxyImpl)

Aggregations

ServerCQProxyImpl (org.apache.geode.cache.client.internal.ServerCQProxyImpl)2 ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)1 CqException (org.apache.geode.cache.query.CqException)1 CqExistsException (org.apache.geode.cache.query.CqExistsException)1 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)1