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

org.ikasan.dashboard.ui.scheduler.util.ContextViewUpdateEventBroadcaster Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
package org.ikasan.dashboard.ui.scheduler.util;

import org.ikasan.dashboard.ui.util.VaadinThreadFactory;

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

public class ContextViewUpdateEventBroadcaster
{
    static Executor executor = Executors.newSingleThreadExecutor(new VaadinThreadFactory("ContextViewUpdateEventBroadcaster"));

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

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

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

    public static synchronized void broadcast(final String contextTemplate) {
        for (final ContextViewUpdateEventBroadcastListener listener: listeners.keySet()) {
            executor.execute(() -> listener.receiveBroadcast(contextTemplate));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy