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

org.umlg.runtime.notification.UmlgNotificationManager Maven / Gradle / Ivy

There is a newer version: 2.0.15
Show newest version
package org.umlg.runtime.notification;

import org.umlg.runtime.adaptor.TransactionThreadNotificationVar;
import org.umlg.runtime.collection.UmlgRuntimeProperty;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * Date: 2014/08/31
 * Time: 12:53 PM
 */
public class UmlgNotificationManager {

    private Map listenerMap = new HashMap<>();

    public final static UmlgNotificationManager INSTANCE = new UmlgNotificationManager();

    private UmlgNotificationManager() {
    }

    public void registerListener(UmlgRuntimeProperty umlgRuntimeProperty, NotificationListener listener) {
        this.listenerMap.put(umlgRuntimeProperty, listener);
    }

    public NotificationListener get(UmlgRuntimeProperty umlgRuntimeProperty) {
        return this.listenerMap.get(umlgRuntimeProperty);
    }

    public void notify(UmlgRuntimeProperty umlgRuntimeProperty, ChangeHolder changeHolder) {

        Optional.ofNullable(UmlgNotificationManager.INSTANCE.get(umlgRuntimeProperty))
                .ifPresent(
                        n -> TransactionThreadNotificationVar.add(n, changeHolder)
                );

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy