Search in sources :

Example 1 with ProcessorListener

use of io.kubernetes.client.informer.cache.ProcessorListener in project java by kubernetes-client.

the class DefaultSharedIndexInformer method addEventHandlerWithResyncPeriod.

/**
 * add event callback with a resync period
 */
@Override
public void addEventHandlerWithResyncPeriod(ResourceEventHandler<ApiType> handler, long resyncPeriodMillis) {
    if (stopped) {
        log.info("DefaultSharedIndexInformer#Handler was not added to shared informer because it has stopped already");
        return;
    }
    if (resyncPeriodMillis > 0) {
        if (resyncPeriodMillis < MINIMUM_RESYNC_PERIOD_MILLIS) {
            log.warn("DefaultSharedIndexInformer#resyncPeriod {} is too small. Changing it to the minimum allowed rule of {}", resyncPeriodMillis, MINIMUM_RESYNC_PERIOD_MILLIS);
            resyncPeriodMillis = MINIMUM_RESYNC_PERIOD_MILLIS;
        }
        if (resyncPeriodMillis < this.resyncCheckPeriodMillis) {
            if (started) {
                log.warn("DefaultSharedIndexInformer#resyncPeriod {} is smaller than resyncCheckPeriod {} and the informer has already started. Changing it to {}", resyncPeriodMillis, resyncCheckPeriodMillis, resyncCheckPeriodMillis);
                resyncPeriodMillis = resyncCheckPeriodMillis;
            } else {
                // if the event handler's resyncPeriod is smaller than the current
                // resyncCheckPeriod,
                // update resyncCheckPeriod to match resyncPeriod and adjust the resync periods
                // of all
                // the listeners accordingly
                this.resyncCheckPeriodMillis = resyncPeriodMillis;
            }
        }
    }
    ProcessorListener<ApiType> listener = new ProcessorListener(handler, determineResyncPeriod(resyncCheckPeriodMillis, this.resyncCheckPeriodMillis));
    if (!started) {
        this.processor.addListener(listener);
        return;
    }
    this.processor.addAndStartListener(listener);
    List<ApiType> objectList = this.indexer.list();
    for (Object item : objectList) {
        listener.add(new ProcessorListener.AddNotification(item));
    }
}
Also used : ProcessorListener(io.kubernetes.client.informer.cache.ProcessorListener) KubernetesListObject(io.kubernetes.client.common.KubernetesListObject) KubernetesObject(io.kubernetes.client.common.KubernetesObject)

Aggregations

KubernetesListObject (io.kubernetes.client.common.KubernetesListObject)1 KubernetesObject (io.kubernetes.client.common.KubernetesObject)1 ProcessorListener (io.kubernetes.client.informer.cache.ProcessorListener)1