use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class WebSocketJettyClient method start.
@Override
public synchronized void start() {
if (jettyClient == null) {
jettyClient = new WebSocketClient();
jettyClient.getPolicy().setMaxTextMessageSize(maxMessageSize);
jettyClient.getPolicy().setMaxBinaryMessageSize(maxMessageSize);
jettyClient.setMaxIdleTimeout(websocketIdleTimeout);
}
try {
jettyClient.start();
sessionFuture = jettyClient.connect(this, toUrl(serverAddress));
sendInitializationMessage();
} catch (JoynrShutdownException | JoynrIllegalStateException e) {
logger.error("unrecoverable error starting WebSocket client: {}", e);
return;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
// TODO which exceptions are recoverable? Only catch those ones
// JoynrCommunicationExeption is thrown if the initialization message could not be sent
logger.debug("error starting WebSocket client. Will retry", e);
if (shutdown) {
return;
}
if (reconnectTimerRunning.compareAndSet(false, true)) {
reconnectTimer.schedule(new TimerTask() {
@Override
public void run() {
reconnectTimerRunning.set(false);
start();
}
}, reconnectDelay);
}
}
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class MqttPahoClient method start.
@Override
public void start() {
while (!shutdown.get() && !mqttClient.isConnected()) {
try {
synchronized (this) {
logger.debug("Started MqttPahoClient");
mqttClient.setCallback(this);
mqttClient.setTimeToWait(timeToWaitMs);
mqttClient.connect(getConnectOptions());
logger.debug("MQTT Connected client");
mqttStatusReceiver.notifyConnectionStatusChanged(MqttStatusReceiver.ConnectionStatus.CONNECTED);
reestablishSubscriptions();
}
} catch (MqttException mqttError) {
logger.error("MQTT Connect failed. Error code {}", mqttError.getReasonCode(), mqttError);
switch(mqttError.getReasonCode()) {
case MqttException.REASON_CODE_CLIENT_EXCEPTION:
if (isSecureConnection) {
logger.error("Failed to establish TLS connection, error: " + mqttError);
if (mqttError instanceof MqttSecurityException || (mqttError.getCause() != null && mqttError.getCause() instanceof SSLHandshakeException)) {
throw new JoynrIllegalStateException("Unable to create TLS MqttPahoClient: " + mqttError);
}
}
case MqttException.REASON_CODE_BROKER_UNAVAILABLE:
case MqttException.REASON_CODE_CLIENT_DISCONNECTING:
case MqttException.REASON_CODE_CLIENT_NOT_CONNECTED:
case MqttException.REASON_CODE_CLIENT_TIMEOUT:
case MqttException.REASON_CODE_CONNECT_IN_PROGRESS:
case MqttException.REASON_CODE_CONNECTION_LOST:
case MqttException.REASON_CODE_MAX_INFLIGHT:
case MqttException.REASON_CODE_NO_MESSAGE_IDS_AVAILABLE:
case MqttException.REASON_CODE_SERVER_CONNECT_ERROR:
case MqttException.REASON_CODE_SUBSCRIBE_FAILED:
case MqttException.REASON_CODE_UNEXPECTED_ERROR:
case MqttException.REASON_CODE_WRITE_TIMEOUT:
if (shutdown.get()) {
return;
}
synchronized (this) {
try {
this.wait(reconnectSleepMs);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
continue;
case MqttException.REASON_CODE_CLIENT_CONNECTED:
continue;
}
} catch (Exception e) {
throw new JoynrIllegalStateException("Unable to start MqttPahoClient: " + e.getMessage(), e);
}
}
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class MqttPahoClient method subscribe.
@Override
public void subscribe(String topic) {
boolean subscribed = false;
while (!subscribed && !shutdown.get()) {
logger.debug("MQTT subscribing to: {}", topic);
try {
synchronized (subscribedTopics) {
if (!subscribedTopics.contains(topic)) {
mqttClient.subscribe(topic);
subscribedTopics.add(topic);
}
subscribed = true;
}
} catch (MqttException mqttError) {
logger.debug("MQTT subscribe to {} failed: {}. Error code {}", topic, mqttError.getMessage(), mqttError.getReasonCode(), mqttError);
switch(mqttError.getReasonCode()) {
case MqttException.REASON_CODE_CLIENT_EXCEPTION:
case MqttException.REASON_CODE_BROKER_UNAVAILABLE:
case MqttException.REASON_CODE_CLIENT_TIMEOUT:
case MqttException.REASON_CODE_CONNECT_IN_PROGRESS:
case MqttException.REASON_CODE_MAX_INFLIGHT:
case MqttException.REASON_CODE_NO_MESSAGE_IDS_AVAILABLE:
case MqttException.REASON_CODE_SERVER_CONNECT_ERROR:
case MqttException.REASON_CODE_SUBSCRIBE_FAILED:
case MqttException.REASON_CODE_UNEXPECTED_ERROR:
case MqttException.REASON_CODE_WRITE_TIMEOUT:
case MqttException.REASON_CODE_CONNECTION_LOST:
case MqttException.REASON_CODE_CLIENT_NOT_CONNECTED:
case MqttException.REASON_CODE_CLIENT_DISCONNECTING:
try {
Thread.sleep(reconnectSleepMs);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
continue;
default:
throw new JoynrIllegalStateException("Unexpected exception while subscribing to " + topic + ", error: " + mqttError);
}
} catch (Exception e) {
throw new JoynrRuntimeException("Unable to start MqttPahoClient", e);
}
}
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class JoynrMessagingConnectorInvocationHandler method executeSyncMethod.
@CheckForNull
@Override
public Object executeSyncMethod(Method method, Object[] args) throws ApplicationException {
// TODO does a method with 0 args pass in an empty args array, or null for args?
if (method == null) {
throw new IllegalArgumentException("Method cannot be null");
}
if (toDiscoveryEntries.size() > 1) {
throw new JoynrIllegalStateException("You can't execute sync methods for multiple participants.");
}
if (toDiscoveryEntries.isEmpty()) {
throw new JoynrIllegalStateException("You must have exactly one participant to be able to execute a sync method.");
}
MethodMetaInformation methodMetaInformation = JoynrMessagingConnectorFactory.ensureMethodMetaInformationPresent(method);
Request request = new Request(method.getName(), args, method.getParameterTypes());
Reply reply;
String requestReplyId = request.getRequestReplyId();
SynchronizedReplyCaller synchronizedReplyCaller = new SynchronizedReplyCaller(fromParticipantId, requestReplyId, request);
ExpiryDate expiryDate = DispatcherUtils.convertTtlToExpirationDate(qosSettings.getRoundTripTtl_ms());
replyCallerDirectory.addReplyCaller(requestReplyId, synchronizedReplyCaller, expiryDate);
reply = (Reply) requestReplyManager.sendSyncRequest(fromParticipantId, toDiscoveryEntries.iterator().next(), request, synchronizedReplyCaller, qosSettings);
if (reply.getError() == null) {
if (method.getReturnType().equals(void.class)) {
return null;
}
Object response = RpcUtils.reconstructReturnedObject(method, methodMetaInformation, reply.getResponse());
logger.debug("REQUEST returns successful: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), response);
return response;
} else if (reply.getError() instanceof ApplicationException) {
logger.debug("REQUEST returns error: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), reply.getError());
throw (ApplicationException) reply.getError();
} else {
logger.debug("REQUEST returns error: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), reply.getError());
throw (JoynrRuntimeException) reply.getError();
}
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class ProxyInvocationHandlerImpl method invoke.
@Override
@CheckForNull
public Object invoke(@Nonnull Method method, Object[] args) throws ApplicationException {
logger.trace("calling proxy.{}({}) on domain: {} and interface {}, proxy participant ID: {}", method.getName(), args, domains, interfaceName, proxyParticipantId);
Class<?> methodInterfaceClass = method.getDeclaringClass();
try {
if (JoynrSubscriptionInterface.class.isAssignableFrom(methodInterfaceClass) || JoynrBroadcastSubscriptionInterface.class.isAssignableFrom(methodInterfaceClass)) {
return executeSubscriptionMethod(method, args);
} else if (methodInterfaceClass.getAnnotation(FireAndForget.class) != null) {
return executeOneWayMethod(method, args);
} else if (methodInterfaceClass.getAnnotation(Sync.class) != null) {
return executeSyncMethod(method, args);
} else if (methodInterfaceClass.getAnnotation(Async.class) != null) {
return executeAsyncMethod(method, args);
} else {
throw new JoynrIllegalStateException("Method is not part of sync, async or subscription interface");
}
} catch (JoynrRuntimeException | ApplicationException e) {
throw e;
} catch (Exception e) {
throw new JoynrRuntimeException(e);
}
}
Aggregations