Search in sources :

Example 1 with SystemTimer

use of org.apache.geode.internal.SystemTimer in project geode by apache.

the class GemFireCacheImplTest method checkEvictorsClosed.

@Test
public void checkEvictorsClosed() {
    InternalDistributedSystem ds = Fakes.distributedSystem();
    CacheConfig cc = new CacheConfig();
    TypeRegistry typeRegistry = mock(TypeRegistry.class);
    SystemTimer ccpTimer = mock(SystemTimer.class);
    HeapEvictor he = mock(HeapEvictor.class);
    OffHeapEvictor ohe = mock(OffHeapEvictor.class);
    GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry);
    try {
        gfc.setHeapEvictor(he);
        gfc.setOffHeapEvictor(ohe);
    } finally {
        gfc.close();
    }
    verify(he, times(1)).close();
    verify(ohe, times(1)).close();
}
Also used : OffHeapEvictor(org.apache.geode.internal.cache.lru.OffHeapEvictor) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) HeapEvictor(org.apache.geode.internal.cache.lru.HeapEvictor) OffHeapEvictor(org.apache.geode.internal.cache.lru.OffHeapEvictor) SystemTimer(org.apache.geode.internal.SystemTimer) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 2 with SystemTimer

use of org.apache.geode.internal.SystemTimer in project geode by apache.

the class DSClock method cancelAndScheduleNewCacheTimerTask.

/**
   * Cancel the previous slow down task (If it exists) and schedule a new one.
   */
private void cancelAndScheduleNewCacheTimerTask(long offset) {
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && !cache.isClosed()) {
        if (this.cacheTimeTask != null) {
            this.cacheTimeTask.cancel();
        }
        cacheTimeTask = new CacheTimeTask(offset);
        SystemTimer timer = cache.getCCPTimer();
        timer.scheduleAtFixedRate(cacheTimeTask, 1, /* Start after 1ms */
        2);
        if (logger.isDebugEnabled()) {
            logger.debug("Started a timer task to suspend cache time for new lower offset of {}ms and current offset is: {}", offset, cacheTimeDelta);
        }
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) SystemTimer(org.apache.geode.internal.SystemTimer)

Example 3 with SystemTimer

use of org.apache.geode.internal.SystemTimer in project geode by apache.

the class PRSanityCheckMessage method schedule.

/**
   * Send a sanity check message and schedule a timer to send another one in
   * gemfire.PRSanityCheckInterval (default 5000) milliseconds. This can be enabled with
   * gemfire.PRSanityCheckEnabled=true.
   */
public static void schedule(final PartitionedRegion pr) {
    if (Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "PRSanityCheckEnabled")) {
        final DM dm = pr.getDistributionManager();
        // RegionAdvisor ra = pr.getRegionAdvisor();
        // final Set recipients = ra.adviseAllPRNodes();
        DistributedRegion prRoot = (DistributedRegion) PartitionedRegionHelper.getPRRoot(pr.getCache(), false);
        if (prRoot == null) {
            return;
        }
        final Set recipients = prRoot.getDistributionAdvisor().adviseGeneric();
        if (recipients.size() <= 0) {
            return;
        }
        final PRSanityCheckMessage delayedInstance = new PRSanityCheckMessage(recipients, pr.getPRId(), null, pr.getRegionIdentifier());
        PRSanityCheckMessage instance = new PRSanityCheckMessage(recipients, pr.getPRId(), null, pr.getRegionIdentifier());
        dm.putOutgoing(instance);
        int sanityCheckInterval = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "PRSanityCheckInterval", 5000).intValue();
        if (sanityCheckInterval != 0) {
            final SystemTimer tm = new SystemTimer(dm.getSystem(), true);
            SystemTimer.SystemTimerTask st = new SystemTimer.SystemTimerTask() {

                @Override
                public void run2() {
                    try {
                        if (!pr.isLocallyDestroyed && !pr.isClosed && !pr.isDestroyed()) {
                            dm.putOutgoing(delayedInstance);
                        }
                    } catch (CancelException cce) {
                    // cache is closed - can't send the message
                    } finally {
                        tm.cancel();
                    }
                }
            };
            tm.schedule(st, sanityCheckInterval);
        }
    }
}
Also used : Set(java.util.Set) DM(org.apache.geode.distributed.internal.DM) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) SystemTimer(org.apache.geode.internal.SystemTimer)

Example 4 with SystemTimer

use of org.apache.geode.internal.SystemTimer in project geode by apache.

the class GMSMembershipManager method startCleanupTimer.

/** starts periodic task to perform cleanup chores such as expire surprise members */
private void startCleanupTimer() {
    if (this.listener == null || listener.getDM() == null) {
        return;
    }
    DistributedSystem ds = this.listener.getDM().getSystem();
    this.cleanupTimer = new SystemTimer(ds, true);
    SystemTimer.SystemTimerTask st = new SystemTimer.SystemTimerTask() {

        @Override
        public void run2() {
            cleanUpSurpriseMembers();
        }
    };
    this.cleanupTimer.scheduleAtFixedRate(st, surpriseMemberTimeout, surpriseMemberTimeout / 3);
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem) SystemTimer(org.apache.geode.internal.SystemTimer)

Example 5 with SystemTimer

use of org.apache.geode.internal.SystemTimer in project geode by apache.

the class Connection method scheduleAckTimeouts.

/** ensure that a task is running to monitor transmission and reading of acks */
public synchronized void scheduleAckTimeouts() {
    if (ackTimeoutTask == null) {
        final long msAW = this.owner.getDM().getConfig().getAckWaitThreshold() * 1000;
        final long msSA = this.owner.getDM().getConfig().getAckSevereAlertThreshold() * 1000;
        ackTimeoutTask = new SystemTimer.SystemTimerTask() {

            @Override
            public void run2() {
                if (owner.isClosed()) {
                    return;
                }
                byte connState = -1;
                synchronized (stateLock) {
                    connState = connectionState;
                }
                boolean sentAlert = false;
                synchronized (Connection.this) {
                    if (socketInUse) {
                        switch(connState) {
                            case Connection.STATE_IDLE:
                                break;
                            case Connection.STATE_SENDING:
                                sentAlert = doSevereAlertProcessing();
                                break;
                            case Connection.STATE_POST_SENDING:
                                break;
                            case Connection.STATE_READING_ACK:
                                sentAlert = doSevereAlertProcessing();
                                break;
                            case Connection.STATE_RECEIVED_ACK:
                                break;
                            default:
                        }
                    }
                }
                List group = ackConnectionGroup;
                if (sentAlert && group != null) {
                    // the time stamps and give others more time
                    for (Iterator it = group.iterator(); it.hasNext(); ) {
                        Connection con = (Connection) it.next();
                        if (con != Connection.this) {
                            con.transmissionStartTime += con.ackSATimeout;
                        }
                    }
                }
            }
        };
        synchronized (owner) {
            SystemTimer timer = owner.getIdleConnTimer();
            if (timer != null) {
                if (msSA > 0) {
                    timer.scheduleAtFixedRate(ackTimeoutTask, msAW, Math.min(msAW, msSA));
                } else {
                    timer.schedule(ackTimeoutTask, msAW);
                }
            }
        }
    }
}
Also used : SystemTimerTask(org.apache.geode.internal.SystemTimer.SystemTimerTask) Iterator(java.util.Iterator) List(java.util.List) LinkedList(java.util.LinkedList) SystemTimer(org.apache.geode.internal.SystemTimer)

Aggregations

SystemTimer (org.apache.geode.internal.SystemTimer)7 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)4 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Test (org.junit.Test)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 CancelException (org.apache.geode.CancelException)1 DistributedSystem (org.apache.geode.distributed.DistributedSystem)1 DM (org.apache.geode.distributed.internal.DM)1 SystemTimerTask (org.apache.geode.internal.SystemTimer.SystemTimerTask)1 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 HeapEvictor (org.apache.geode.internal.cache.lru.HeapEvictor)1 OffHeapEvictor (org.apache.geode.internal.cache.lru.OffHeapEvictor)1