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

org.enodeframework.messaging.impl.SingleMessageDispatching 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;

public class SingleMessageDispatching {
    private final ConcurrentHashMap handlerDict;
    private final QueueMessageDispatching queueMessageDispatching;
    private final IMessage message;

    public SingleMessageDispatching(IMessage message, QueueMessageDispatching queueMessageDispatching, List handlers, ITypeNameProvider typeNameProvider) {
        this.message = message;
        this.queueMessageDispatching = queueMessageDispatching;
        this.handlerDict = new ConcurrentHashMap<>();
        handlers.forEach(x -> handlerDict.putIfAbsent(typeNameProvider.getTypeName(x.getInnerObject().getClass()), x));
    }

    public void removeHandledHandler(String handlerTypeName) {
        if (handlerDict.remove(handlerTypeName) != null) {
            if (handlerDict.isEmpty()) {
                queueMessageDispatching.onMessageHandled(message);
            }
        }
    }

    public IMessage getMessage() {
        return message;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy