All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ikasan.dashboard.cache.CacheStateBroadcaster Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
package org.ikasan.dashboard.cache;

import org.ikasan.dashboard.broadcast.FlowState;
import org.ikasan.dashboard.ui.util.VaadimThreadFactory;

import java.util.WeakHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class CacheStateBroadcaster
{
    static Executor executor = Executors.newSingleThreadExecutor(new VaadimThreadFactory("CacheStateBroadcaster"));

    private static WeakHashMap listeners =
        new WeakHashMap<>();

    public static synchronized void register(CacheStateBroadcastListener listener) {
        listeners.put(listener, null);
    }

    public static synchronized void unregister(CacheStateBroadcastListener listener) {
        listeners.remove(listener);
    }

    public static synchronized void broadcast(final FlowState flowState) {
        for (final CacheStateBroadcastListener listener: listeners.keySet()) {
            executor.execute(() -> listener.receiveCacheStateBroadcast(flowState));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy