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

org.enodeframework.messaging.impl.MultiMessageDispatching Maven / Gradle / Ivy

There is a newer version: 1.1.10
Show newest version
package org.enodeframework.messaging.impl;

import org.enodeframework.infrastructure.IObjectProxy;
import org.enodeframework.infrastructure.ITypeNameProvider;
import org.enodeframework.messaging.IMessage;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class MultiMessageDispatching {
    private final IMessage[] messages;
    private final ConcurrentMap handlerDict;
    private final RootDispatching rootDispatching;

    public MultiMessageDispatching(List messages, List handlers, RootDispatching rootDispatching, ITypeNameProvider typeNameProvider) {
        this.messages = messages.toArray(new IMessage[0]);
        handlerDict = new ConcurrentHashMap<>();
        handlers.forEach(x -> handlerDict.putIfAbsent(typeNameProvider.getTypeName(x.getInnerObject().getClass()), x));
        this.rootDispatching = rootDispatching;
        this.rootDispatching.addChildDispatching(this);
    }

    public IMessage[] getMessages() {
        return messages;
    }

    public void removeHandledHandler(String handlerTypeName) {
        if (handlerDict.remove(handlerTypeName) != null) {
            if (handlerDict.isEmpty()) {
                rootDispatching.onChildDispatchingFinished(this);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy