org.ikasan.dashboard.ui.scheduler.util.ContextViewUpdateEventBroadcaster Maven / Gradle / Ivy
package org.ikasan.dashboard.ui.scheduler.util;
import com.vaadin.flow.shared.Registration;
import org.ikasan.dashboard.ui.util.VaadimThreadFactory;
import org.ikasan.spec.scheduled.context.model.ContextTemplate;
import org.ikasan.spec.scheduled.event.model.SchedulerJobInstanceStateChangeEvent;
import java.util.LinkedList;
import java.util.WeakHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
public class ContextViewUpdateEventBroadcaster
{
static Executor executor = Executors.newSingleThreadExecutor(new VaadimThreadFactory("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));
}
}
}