Search in sources :

Example 21 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class LocalizedMessageJUnitTest method testGetThrowable.

@Test
public void testGetThrowable() {
    final Throwable t = new Throwable();
    final StringId stringId = new StringId(100, "This is a message for testGetThrowable");
    final LocalizedMessage message = LocalizedMessage.create(stringId, t);
    assertNotNull(message.getThrowable());
    assertEquals(t, message.getThrowable());
    assertTrue(t == message.getThrowable());
}
Also used : StringId(org.apache.geode.i18n.StringId) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 22 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class ServerCQImpl method registerCq.

@Override
public void registerCq(ClientProxyMembershipID p_clientProxyId, CacheClientNotifier p_ccn, int p_cqState) throws CqException, RegionNotFoundException {
    CacheClientProxy clientProxy = null;
    this.clientProxyId = p_clientProxyId;
    if (p_ccn != null) {
        this.ccn = p_ccn;
        clientProxy = p_ccn.getClientProxy(p_clientProxyId, true);
    }
    validateCq();
    final boolean isDebugEnabled = logger.isDebugEnabled();
    StringId msg = LocalizedStrings.ONE_ARG;
    Throwable t = null;
    try {
        this.query = constructServerSideQuery();
        if (isDebugEnabled) {
            logger.debug("Server side query for the cq: {} is: {}", cqName, this.query.getQueryString());
        }
    } catch (Exception ex) {
        t = ex;
        if (ex instanceof ClassNotFoundException) {
            msg = LocalizedStrings.CqQueryImpl_CLASS_NOT_FOUND_EXCEPTION_THE_ANTLRJAR_OR_THE_SPCIFIED_CLASS_MAY_BE_MISSING_FROM_SERVER_SIDE_CLASSPATH_ERROR_0;
        } else {
            msg = LocalizedStrings.CqQueryImpl_ERROR_WHILE_PARSING_THE_QUERY_ERROR_0;
        }
    } finally {
        if (t != null) {
            String s = msg.toLocalizedString(t);
            if (isDebugEnabled) {
                logger.debug(s, t);
            }
            throw new CqException(s);
        }
    }
    // Update Regions Book keeping.
    // TODO replace getRegion() with getRegionByPathForProcessing() so this doesn't block
    // if the region is still being initialized
    this.cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(regionName);
    if (this.cqBaseRegion == null) {
        throw new RegionNotFoundException(LocalizedStrings.CqQueryImpl_REGION__0_SPECIFIED_WITH_CQ_NOT_FOUND_CQNAME_1.toLocalizedString(new Object[] { regionName, this.cqName }));
    }
    // Make sure that the region is partitioned or
    // replicated with distributed ack or global.
    DataPolicy dp = this.cqBaseRegion.getDataPolicy();
    this.isPR = dp.withPartitioning();
    if (!(this.isPR || dp.withReplication())) {
        String errMsg = null;
        // replicated regions with eviction set to local destroy get turned into preloaded
        if (dp.withPreloaded() && cqBaseRegion.getAttributes().getEvictionAttributes() != null && cqBaseRegion.getAttributes().getEvictionAttributes().getAction().equals(EvictionAction.LOCAL_DESTROY)) {
            errMsg = LocalizedStrings.CqQueryImpl_CQ_NOT_SUPPORTED_FOR_REPLICATE_WITH_LOCAL_DESTROY.toString(this.regionName, cqBaseRegion.getAttributes().getEvictionAttributes().getAction());
        } else {
            errMsg = "The region " + this.regionName + "  specified in CQ creation is neither replicated nor partitioned; " + "only replicated or partitioned regions are allowed in CQ creation.";
        }
        if (isDebugEnabled) {
            logger.debug(errMsg);
        }
        throw new CqException(errMsg);
    }
    if ((dp.withReplication() && (!(cqBaseRegion.getAttributes().getScope().isDistributedAck() || cqBaseRegion.getAttributes().getScope().isGlobal())))) {
        String errMsg = "The replicated region " + this.regionName + " specified in CQ creation does not have scope supported by CQ." + " The CQ supported scopes are DISTRIBUTED_ACK and GLOBAL.";
        if (isDebugEnabled) {
            logger.debug(errMsg);
        }
        throw new CqException(errMsg);
    }
    // Can be null by the time we are here
    if (clientProxy != null) {
        clientProxy.incCqCount();
        if (clientProxy.hasOneCq()) {
            cqService.stats().incClientsWithCqs();
        }
        if (isDebugEnabled) {
            logger.debug("Added CQ to the base region: {} With key as: {}", cqBaseRegion.getFullPath(), serverCqName);
        }
    }
    this.updateCqCreateStats();
    // Initialize the state of CQ.
    if (this.cqState.getState() != p_cqState) {
        setCqState(p_cqState);
    }
    // it to other matching cqs for performance reasons
    if (p_cqState == CqStateImpl.RUNNING) {
        // Add to the matchedCqMap.
        cqService.addToMatchingCqMap(this);
    }
    // Initialize CQ results (key) cache.
    if (CqServiceProvider.MAINTAIN_KEYS) {
        this.cqResultKeys = new HashMap<Object, Object>();
        // added to the results cache (not from the CQ Results).
        if (this.isPR) {
            this.setCqResultsCacheInitialized();
        } else {
            this.destroysWhileCqResultsInProgress = new HashSet<Object>();
        }
    }
    if (p_ccn != null) {
        try {
            cqService.addToCqMap(this);
        } catch (CqExistsException cqe) {
            // Should not happen.
            throw new CqException(LocalizedStrings.CqQueryImpl_UNABLE_TO_CREATE_CQ_0_ERROR__1.toLocalizedString(new Object[] { cqName, cqe.getMessage() }));
        }
        this.cqBaseRegion.getFilterProfile().registerCq(this);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CqException(org.apache.geode.cache.query.CqException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) QueryException(org.apache.geode.cache.query.QueryException) StringId(org.apache.geode.i18n.StringId) CqExistsException(org.apache.geode.cache.query.CqExistsException) DataPolicy(org.apache.geode.cache.DataPolicy)

Example 23 with StringId

use of org.apache.geode.i18n.StringId 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);
}
Also used : StringId(org.apache.geode.i18n.StringId) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) TimeoutException(org.apache.geode.cache.TimeoutException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CqClosedException(org.apache.geode.cache.query.CqClosedException) QueryException(org.apache.geode.cache.query.QueryException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 24 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class DirectChannel method handleAckTimeout.

/**
   * 
   * @param ackTimeout ack wait threshold
   * @param ackSATimeout severe alert threshold
   * @param c
   * @param processor
   * @throws ConnectionException
   */
private void handleAckTimeout(long ackTimeout, long ackSATimeout, Connection c, DirectReplyProcessor processor) throws ConnectionException {
    DM dm = getDM();
    Set activeMembers = dm.getDistributionManagerIds();
    // Increment the stat
    dm.getStats().incReplyTimeouts();
    // an alert that will show up in the console
    {
        final StringId msg = LocalizedStrings.DirectChannel_0_SECONDS_HAVE_ELAPSED_WHILE_WAITING_FOR_REPLY_FROM_1_ON_2_WHOSE_CURRENT_MEMBERSHIP_LIST_IS_3;
        final Object[] msgArgs = new Object[] { Long.valueOf(ackTimeout / 1000), c.getRemoteAddress(), dm.getId(), activeMembers };
        logger.warn(LocalizedMessage.create(msg, msgArgs));
        msgArgs[3] = "(omitted)";
        Breadcrumbs.setProblem(msg, msgArgs);
        if (ReplyProcessor21.THROW_EXCEPTION_ON_TIMEOUT) {
            // init the cause to be a TimeoutException so catchers can determine cause
            TimeoutException cause = new TimeoutException(LocalizedStrings.TIMED_OUT_WAITING_FOR_ACKS.toLocalizedString());
            throw new InternalGemFireException(msg.toLocalizedString(msgArgs), cause);
        }
    }
    if (activeMembers.contains(c.getRemoteAddress())) {
        // wait for ack-severe-alert-threshold period first, then wait forever
        if (ackSATimeout > 0) {
            try {
                c.readAck((int) ackSATimeout, ackSATimeout, processor);
                return;
            } catch (SocketTimeoutException e) {
                Object[] args = new Object[] { Long.valueOf((ackSATimeout + ackTimeout) / 1000), c.getRemoteAddress(), dm.getId(), activeMembers };
                logger.fatal(LocalizedMessage.create(LocalizedStrings.DirectChannel_0_SECONDS_HAVE_ELAPSED_WHILE_WAITING_FOR_REPLY_FROM_1_ON_2_WHOSE_CURRENT_MEMBERSHIP_LIST_IS_3, args));
            }
        }
        try {
            c.readAck(0, 0, processor);
        } catch (SocketTimeoutException ex) {
            // this can never happen when called with timeout of 0
            logger.error(LocalizedMessage.create(LocalizedStrings.DirectChannel_UNEXPECTED_TIMEOUT_WHILE_WAITING_FOR_ACK_FROM__0, c.getRemoteAddress()), ex);
        }
    } else {
        logger.warn(LocalizedMessage.create(LocalizedStrings.DirectChannel_VIEW_NO_LONGER_HAS_0_AS_AN_ACTIVE_MEMBER_SO_WE_WILL_NO_LONGER_WAIT_FOR_IT, c.getRemoteAddress()));
        processor.memberDeparted(c.getRemoteAddress(), true);
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) StringId(org.apache.geode.i18n.StringId) TimeoutException(org.apache.geode.cache.TimeoutException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 25 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class DistributionManager method removeUnfinishedStartup.

public void removeUnfinishedStartup(InternalDistributedMember m, boolean departed) {
    synchronized (unfinishedStartupsLock) {
        if (logger.isDebugEnabled()) {
            logger.debug("removeUnfinishedStartup for {} wtih {}", m, unfinishedStartups);
        }
        if (unfinishedStartups == null)
            // not yet done with startup
            return;
        if (!unfinishedStartups.remove(m))
            return;
        StringId msg = null;
        if (departed) {
            msg = LocalizedStrings.DistributionManager_STOPPED_WAITING_FOR_STARTUP_REPLY_FROM_0_BECAUSE_THE_PEER_DEPARTED_THE_VIEW;
        } else {
            msg = LocalizedStrings.DistributionManager_STOPPED_WAITING_FOR_STARTUP_REPLY_FROM_0_BECAUSE_THE_REPLY_WAS_FINALLY_RECEIVED;
        }
        logger.info(LocalizedMessage.create(msg, m));
        int numLeft = unfinishedStartups.size();
        if (numLeft != 0) {
            logger.info(LocalizedMessage.create(LocalizedStrings.DistributionManager_STILL_AWAITING_0_RESPONSES_FROM_1, new Object[] { Integer.valueOf(numLeft), unfinishedStartups }));
        }
    }
// synchronized
}
Also used : StringId(org.apache.geode.i18n.StringId)

Aggregations

StringId (org.apache.geode.i18n.StringId)43 IOException (java.io.IOException)14 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)11 LocalRegion (org.apache.geode.internal.cache.LocalRegion)10 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)8 Part (org.apache.geode.internal.cache.tier.sockets.Part)8 TimeoutException (org.apache.geode.cache.TimeoutException)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 InterestResultPolicy (org.apache.geode.cache.InterestResultPolicy)4 RegisterInterestOperationContext (org.apache.geode.cache.operations.RegisterInterestOperationContext)4 CqClosedException (org.apache.geode.cache.query.CqClosedException)4 CqException (org.apache.geode.cache.query.CqException)4 CqExistsException (org.apache.geode.cache.query.CqExistsException)4 QueryException (org.apache.geode.cache.query.QueryException)4 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)4 LinkedHashSet (java.util.LinkedHashSet)3