Search in sources :

Example 1 with MainTuning

use of oracle.kubernetes.operator.TuningParameters.MainTuning in project weblogic-kubernetes-operator by oracle.

the class Main method scheduleDomainStatusUpdating.

private static void scheduleDomainStatusUpdating(DomainPresenceInfo info) {
    AtomicInteger unchangedCount = new AtomicInteger(0);
    AtomicReference<ScheduledFuture<?>> statusUpdater = info.getStatusUpdater();
    Runnable command = new Runnable() {

        public void run() {
            // resolve visibility
            Runnable r = this;
            Packet packet = new Packet();
            packet.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info, version));
            MainTuning main = tuningAndConfig.getMainTuning();
            Step strategy = DomainStatusUpdater.createStatusStep(main.statusUpdateTimeoutSeconds, null);
            engine.createFiber().start(strategy, packet, new CompletionCallback() {

                @Override
                public void onCompletion(Packet packet) {
                    Boolean isStatusUnchanged = (Boolean) packet.get(ProcessingConstants.STATUS_UNCHANGED);
                    ScheduledFuture<?> existing = null;
                    if (Boolean.TRUE.equals(isStatusUnchanged)) {
                        if (unchangedCount.incrementAndGet() == main.unchangedCountToDelayStatusRecheck) {
                            // slow down retries because of sufficient unchanged statuses
                            existing = statusUpdater.getAndSet(engine.getExecutor().scheduleWithFixedDelay(r, main.eventualLongDelay, main.eventualLongDelay, TimeUnit.SECONDS));
                        }
                    } else {
                        // reset to trying after shorter delay because of changed status
                        unchangedCount.set(0);
                        existing = statusUpdater.getAndSet(engine.getExecutor().scheduleWithFixedDelay(r, main.initialShortDelay, main.initialShortDelay, TimeUnit.SECONDS));
                        if (existing != null) {
                            existing.cancel(false);
                        }
                    }
                    if (existing != null) {
                        existing.cancel(false);
                    }
                }

                @Override
                public void onThrowable(Packet packet, Throwable throwable) {
                    LOGGER.severe(MessageKeys.EXCEPTION, throwable);
                    // retry to trying after shorter delay because of exception
                    unchangedCount.set(0);
                    ScheduledFuture<?> existing = statusUpdater.getAndSet(engine.getExecutor().scheduleWithFixedDelay(r, main.initialShortDelay, main.initialShortDelay, TimeUnit.SECONDS));
                    if (existing != null) {
                        existing.cancel(false);
                    }
                }
            });
        }
    };
    MainTuning main = tuningAndConfig.getMainTuning();
    ScheduledFuture<?> existing = statusUpdater.getAndSet(engine.getExecutor().scheduleWithFixedDelay(command, main.initialShortDelay, main.initialShortDelay, TimeUnit.SECONDS));
    if (existing != null) {
        existing.cancel(false);
    }
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletionCallback(oracle.kubernetes.operator.work.Fiber.CompletionCallback) MainTuning(oracle.kubernetes.operator.TuningParameters.MainTuning) Step(oracle.kubernetes.operator.work.Step) ResponseStep(oracle.kubernetes.operator.helpers.ResponseStep) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Aggregations

ScheduledFuture (java.util.concurrent.ScheduledFuture)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MainTuning (oracle.kubernetes.operator.TuningParameters.MainTuning)1 ResponseStep (oracle.kubernetes.operator.helpers.ResponseStep)1 CompletionCallback (oracle.kubernetes.operator.work.Fiber.CompletionCallback)1 Packet (oracle.kubernetes.operator.work.Packet)1 Step (oracle.kubernetes.operator.work.Step)1