class ConnectorService implements IConnectorService {

    @SuppressWarnings("unchecked")
    @Override
    public <T extends Connector> T getConnector(Class<T> type, String id) {

        if (id == null) {
            throw new LmRuntimeException("Null connector id");
        }

        Connector connector = connectors.computeIfAbsent(id, i -> {
            IConnectorFactory<?> factory = factories.get(type.getName());
            if (factory == null) {
                throw new IllegalStateException("No factory mapped for Connector type of '" + type.getName() + "'");
            }

            return factory.createConnector(id);
        });

        if (!type.isAssignableFrom(connector.getClass())) {
            throw new LmRuntimeException("Connector for id '" + id + "' is not a " + type.getName()
                    + ". The actual type is " + connector.getClass().getName());
        }

        return (T) connector;
    }

    public  ConnectorService(
            @Inject Map<String, IConnectorFactory> factories,
            @Inject Map<String, Connector> connectors);

}