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

io.bootique.linkmove.connector.URIConnectorFactoryFactory Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package io.bootique.linkmove.connector;

import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.inject.Injector;
import com.nhl.link.move.connect.StreamConnector;
import com.nhl.link.move.connect.URIConnector;
import com.nhl.link.move.runtime.connect.IConnectorFactory;
import io.bootique.annotation.BQConfig;
import io.bootique.annotation.BQConfigProperty;
import io.bootique.resource.ResourceFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@BQConfig
@JsonTypeName("uri")
public class URIConnectorFactoryFactory implements IConnectorFactoryFactory {

    private Map connectors;

    public URIConnectorFactoryFactory() {
        this.connectors = Collections.emptyMap();
    }

    @BQConfigProperty
    public void setConnectors(Map connectors) {
        this.connectors = connectors;
    }

    @Override
    public Class getConnectorType() {
        return StreamConnector.class;
    }

    @Override
    public IConnectorFactory getConnectorFactory(Injector injector) {

        Map connectorUris = new HashMap<>((int)(connectors.size() / 0.75d) + 1);
        connectors.forEach((id, uri) -> {
            try {
                connectorUris.put(id, uri.getUrl().toURI());
            } catch (URISyntaxException e) {
                throw new IllegalArgumentException("Invalid URI for connector with ID: " + id, e);
            }
        });

        return id -> {
            if (!connectorUris.containsKey(id)) {
                throw new IllegalArgumentException("Unknown connector ID: " + id);
            }
            return new URIConnector(connectorUris.get(id));
        };
    }

    public Map getConnectors() {
        return connectors;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy