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

de.objektkontor.wsc.container.common.HashMapDispatcher Maven / Gradle / Ivy

package de.objektkontor.wsc.container.common;

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

import de.objektkontor.wsc.container.Pipeline;
import de.objektkontor.wsc.container.Processor;
import de.objektkontor.wsc.container.core.AbstractDispatcher;

public abstract class HashMapDispatcher extends AbstractDispatcher> {

    private final ConcurrentMap>> processors = new ConcurrentHashMap<>();

    public HashMapDispatcher(String id) {
        super(id);
    }

    @Override
    public Pipeline dispatch(K key) {
        Processor> processor = processors.get(key);
        return processor == null ? null : processor.pipeline();
    }

    @Override
    protected void addProcessor(Processor> processor) throws Exception {
        SimpleKeySelector selector = processor.selector();
        Processor> registeredService = processors.putIfAbsent(selector.key(), processor);
        if (registeredService != null && ! registeredService.equals(processor))
            throw new IllegalArgumentException("Another Processor allready registered for selector: " + selector);
        processors.put(selector.key(), processor);
    }

    @Override
    protected void removeProcessor(Processor> processor) throws Exception {
        processors.remove(processor.selector().key());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy