use of de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException in project FAAAST-Service by FraunhoferIOSB.
the class MqttAssetConnectionTest method invokeValueProvider.
public String invokeValueProvider(ContentFormat contentFormat, DataElementValue newValue, String query) throws AssetConnectionException, InterruptedException, MqttException, ConfigurationInitializationException {
MqttAssetConnection assetConnection = newConnection(MqttValueProviderConfig.builder().contentFormat(contentFormat).query(query).build());
MqttClient client = newMqttClient();
final AtomicReference<String> response = new AtomicReference<>();
CountDownLatch condition = new CountDownLatch(1);
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable throwable) {
}
@Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
response.set(new String(mqttMessage.getPayload()));
condition.countDown();
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
});
client.subscribe(DEFAULT_TOPIC);
assetConnection.getValueProviders().get(DEFAULT_REFERENCE).setValue(newValue);
condition.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
return response.get();
}
use of de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaAssetConnection method init.
@Override
public void init(CoreConfig coreConfig, OpcUaAssetConnectionConfig config, ServiceContext context) throws ConfigurationInitializationException {
this.serviceContext = context;
this.config = config;
try {
connect();
for (var provider : config.getValueProviders().entrySet()) {
registerValueProvider(provider.getKey(), provider.getValue());
}
for (var provider : config.getOperationProviders().entrySet()) {
registerOperationProvider(provider.getKey(), provider.getValue());
}
for (var provider : config.getSubscriptionProviders().entrySet()) {
registerSubscriptionProvider(provider.getKey(), provider.getValue());
}
} catch (AssetConnectionException e) {
throw new ConfigurationInitializationException("initializaing OPC UA asset connection failed", e);
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException in project FAAAST-Service by FraunhoferIOSB.
the class MqttAssetConnection method init.
/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if coreConfig is null
* @throws IllegalArgumentException if config is null
* @throws IllegalArgumentException if serviceContext if null
*/
@Override
public void init(CoreConfig coreConfig, MqttAssetConnectionConfig config, ServiceContext serviceContext) throws ConfigurationInitializationException {
if (coreConfig == null) {
throw new IllegalArgumentException("coreConfig must be non-null");
}
if (config == null) {
throw new IllegalArgumentException("config must be non-null");
}
if (serviceContext == null) {
throw new IllegalArgumentException("serviceContext must be non-null");
}
this.config = config;
this.serviceContext = serviceContext;
try {
client = new MqttClient(config.getServerUri(), config.getClientId(), new MemoryPersistence());
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable throwable) {
LOGGER.warn("MQTT asset connection lost (url: {}, reason: {})", config.getServerUri(), throwable.getMessage(), throwable);
}
@Override
public void deliveryComplete(IMqttDeliveryToken imdt) {
// intentionally left empty
}
@Override
public void messageArrived(String string, MqttMessage mm) throws Exception {
// intentionally left empty
}
});
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true);
client.connect(options);
for (var providerConfig : config.getValueProviders().entrySet()) {
registerValueProvider(providerConfig.getKey(), providerConfig.getValue());
}
for (var providerConfig : config.getOperationProviders().entrySet()) {
registerOperationProvider(providerConfig.getKey(), providerConfig.getValue());
}
for (var providerConfig : config.getSubscriptionProviders().entrySet()) {
registerSubscriptionProvider(providerConfig.getKey(), providerConfig.getValue());
}
} catch (MqttException | AssetConnectionException e) {
throw new ConfigurationInitializationException("initializaing MQTT asset connection failed", e);
}
}
Aggregations