Search in sources :

Example 1 with AssetConnectionConfig

use of de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig in project FAAAST-Service by FraunhoferIOSB.

the class Service method init.

private void init() throws ConfigurationException {
    if (config.getPersistence() == null) {
        throw new InvalidConfigurationException("config.persistence must be non-null");
    }
    persistence = (Persistence) config.getPersistence().newInstance(config.getCore(), this);
    if (config.getMessageBus() == null) {
        throw new InvalidConfigurationException("config.messagebus must be non-null");
    }
    messageBus = (MessageBus) config.getMessageBus().newInstance(config.getCore(), this);
    if (config.getAssetConnections() != null) {
        List<AssetConnection> assetConnections = new ArrayList<>();
        for (AssetConnectionConfig assetConnectionConfig : config.getAssetConnections()) {
            assetConnections.add((AssetConnection) assetConnectionConfig.newInstance(config.getCore(), this));
        }
        assetConnectionManager = new AssetConnectionManager(config.getCore(), assetConnections, this);
    }
    if (config.getEndpoints() == null || config.getEndpoints().isEmpty()) {
        // TODO maybe be less restrictive and only print warning
        // throw new InvalidConfigurationException("at least endpoint must be defined in the configuration");
        logger.warn("no endpoint configuration found, starting service without endpoint which means the service will not be accessible via any kind of API");
    } else {
        endpoints = new ArrayList<>();
        for (EndpointConfig endpointConfig : config.getEndpoints()) {
            Endpoint endpoint = (Endpoint) endpointConfig.newInstance(config.getCore(), this);
            endpoints.add(endpoint);
        }
    }
    this.requestHandler = new RequestHandlerManager(this.config.getCore(), this.persistence, this.messageBus, this.assetConnectionManager);
}
Also used : AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) Endpoint(de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) ArrayList(java.util.ArrayList) AssetConnectionConfig(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig) EndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig) InvalidConfigurationException(de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException) AssetConnection(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)

Example 2 with AssetConnectionConfig

use of de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig in project FAAAST-Service by FraunhoferIOSB.

the class ConfigFactory method applyToServiceConfig.

private void applyToServiceConfig(ServiceConfig serviceConfig, List<Config> configs) throws Exception {
    boolean isEndpointAlreadySet = false;
    for (Config c : configs) {
        LOGGER.debug("Apply custom config parameter '" + c.getClass().getSimpleName() + "'");
        if (EndpointConfig.class.isAssignableFrom(c.getClass())) {
            // if yet no endpoint was set remove old enpoints (most likely default endpoint) and set new endpoint
            // else add the new endpoint to the existing list of endpoints
            serviceConfig.setEndpoints(!isEndpointAlreadySet ? new ArrayList<>() {

                {
                    add((EndpointConfig) c);
                }
            } : new ArrayList<>() {

                {
                    addAll(serviceConfig.getEndpoints());
                    add((EndpointConfig) c);
                }
            });
            isEndpointAlreadySet = true;
            continue;
        }
        if (PersistenceConfig.class.isAssignableFrom(c.getClass())) {
            serviceConfig.setPersistence((PersistenceConfig) c);
            continue;
        }
        if (MessageBusConfig.class.isAssignableFrom(c.getClass())) {
            serviceConfig.setMessageBus((MessageBusConfig) c);
            continue;
        }
        if (AssetConnectionConfig.class.isAssignableFrom(c.getClass())) {
            serviceConfig.getAssetConnections().add((AssetConnectionConfig) c);
            continue;
        }
        throw new Exception("Cannot set config component '" + c.getClass().getSimpleName() + "'");
    }
}
Also used : EndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig) ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) MessageBusInternalConfig(de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig) MessageBusConfig(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBusConfig) Config(de.fraunhofer.iosb.ilt.faaast.service.config.Config) HttpEndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig) PersistenceInMemoryConfig(de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) AssetConnectionConfig(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig) PersistenceConfig(de.fraunhofer.iosb.ilt.faaast.service.persistence.PersistenceConfig) ArrayList(java.util.ArrayList) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Aggregations

AssetConnectionConfig (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig)2 EndpointConfig (de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig)2 ArrayList (java.util.ArrayList)2 AssetConnection (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)1 AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)1 Config (de.fraunhofer.iosb.ilt.faaast.service.config.Config)1 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)1 ServiceConfig (de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig)1 Endpoint (de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint)1 HttpEndpointConfig (de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig)1 InvalidConfigurationException (de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException)1 MessageBusConfig (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBusConfig)1 MessageBusInternalConfig (de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig)1 PersistenceConfig (de.fraunhofer.iosb.ilt.faaast.service.persistence.PersistenceConfig)1 PersistenceInMemoryConfig (de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig)1 RequestHandlerManager (de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1