use of io.joynr.exceptions.JoynrShutdownException in project joynr by bmwcarit.
the class LongPollingChannelLifecycle method startLongPolling.
public synchronized void startLongPolling(final MessageArrivedListener messageArrivedListener, final ReceiverStatusListener... receiverStatusListeners) {
if (channelMonitorExecutorService == null) {
throw new JoynrShutdownException("Channel Monitor already shutdown");
}
if (started == true) {
throw new IllegalStateException("only one long polling thread can be started per ChannelMonitor");
}
started = true;
Callable<Void> channelLifecycleCallable = new Callable<Void>() {
@Override
public Void call() {
try {
checkServerTime();
final int maxRetries = settings.getMaxRetriesCount();
while (true) {
channelCreated = false;
// Create the channel with maximal "maxRetries" retries
createChannelLoop(maxRetries);
// signal that the channel has been created
for (ReceiverStatusListener statusListener : receiverStatusListeners) {
statusListener.receiverStarted();
}
// If it was not possible to create the channel exit
if (!isChannelCreated()) {
String message = "registerMessageReceiver channelId: " + channelId + " error occured. Exiting.";
logger.error(message);
// signal that the channel is in exception
for (ReceiverStatusListener statusListener : receiverStatusListeners) {
statusListener.receiverException(new JoynrShutdownException(message));
}
}
// Start LONG POLL lifecycle. The future will only
// return when the long poll loop has ended,
// otherwise will terminate with a JoynrShutdownException
longPollLoop(messageArrivedListener, maxRetries);
}
} finally {
started = false;
}
}
};
longPollingFuture = channelMonitorExecutorService.submit(channelLifecycleCallable);
}
use of io.joynr.exceptions.JoynrShutdownException in project joynr by bmwcarit.
the class LongPollingMessageReceiver method start.
@Override
public synchronized Future<Void> start(MessageArrivedListener messageListener, ReceiverStatusListener... receiverStatusListeners) {
synchronized (shutdownSynchronizer) {
if (shutdown) {
throw new JoynrShutdownException("Cannot register Message Listener: " + messageListener + ": LongPollingMessageReceiver is already shutting down");
}
}
if (isStarted()) {
return Futures.immediateFailedFuture(new IllegalStateException("receiver is already started"));
}
final SettableFuture<Void> channelCreatedFuture = SettableFuture.create();
ReceiverStatusListener[] statusListeners = ObjectArrays.concat(new ReceiverStatusListener() {
@Override
public // Register the ChannelUrl once the receiver is started
void receiverStarted() {
if (channelMonitor.isChannelCreated()) {
for (ChannelCreatedListener listener : channelCreatedListeners) {
listener.channelCreated(channelMonitor.getChannelUrl());
}
// Signal that the channel is now created for anyone blocking on the future
channelCreatedFuture.set(null);
}
}
@Override
public // Shutdown the receiver if an exception is thrown
void receiverException(Throwable e) {
channelCreatedFuture.setException(e);
channelMonitor.shutdown();
}
}, receiverStatusListeners);
channelMonitor.startLongPolling(messageListener, statusListeners);
return channelCreatedFuture;
}
use of io.joynr.exceptions.JoynrShutdownException 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.JoynrShutdownException in project joynr by bmwcarit.
the class AbstractMessageRouter method createFailureAction.
private FailureAction createFailureAction(final ImmutableMessage message, final int retriesCount) {
final FailureAction failureAction = new FailureAction() {
final String messageId = message.getId();
private boolean failureActionExecutedOnce = false;
@Override
public void execute(Throwable error) {
synchronized (this) {
if (failureActionExecutedOnce) {
logger.trace("Failure action for message with id {} already executed once. Ignoring further call.", messageId);
return;
}
failureActionExecutedOnce = true;
}
if (error instanceof JoynrShutdownException) {
logger.warn("{}", error.getMessage());
return;
} else if (error instanceof JoynrMessageNotSentException) {
logger.error(" ERROR SENDING: aborting send of messageId: {}. Error: {}", new Object[] { messageId, error.getMessage() });
callMessageProcessedListeners(messageId);
return;
}
logger.warn("PROBLEM SENDING, will retry. messageId: {}. Error: {} Message: {}", new Object[] { messageId, error.getClass().getName(), error.getMessage() });
long delayMs;
if (error instanceof JoynrDelayMessageException) {
delayMs = ((JoynrDelayMessageException) error).getDelayMs();
} else {
delayMs = createDelayWithExponentialBackoff(sendMsgRetryIntervalMs, retriesCount);
}
logger.error("Rescheduling messageId: {} with delay {} ms, TTL is: {}", messageId, delayMs, dateFormatter.format(message.getTtlMs()));
try {
routeInternal(message, delayMs, retriesCount + 1);
} catch (Exception e) {
logger.warn("Rescheduling of message failed (messageId {})", messageId);
callMessageProcessedListeners(messageId);
}
return;
}
};
return failureAction;
}
use of io.joynr.exceptions.JoynrShutdownException in project joynr by bmwcarit.
the class RequestReplyManagerImpl method sendSyncRequest.
@Override
public Object sendSyncRequest(String fromParticipantId, DiscoveryEntryWithMetaInfo toDiscoveryEntry, Request request, SynchronizedReplyCaller synchronizedReplyCaller, MessagingQos messagingQos) {
if (!running) {
throw new IllegalStateException("Request: " + request.getRequestReplyId() + " failed. SenderImpl ID: " + System.identityHashCode(this) + ": joynr is shutting down");
}
final ArrayList<Object> responsePayloadContainer = new ArrayList<Object>(1);
// the synchronizedReplyCaller will call notify on the responsePayloadContainer when a message arrives
synchronizedReplyCaller.setResponseContainer(responsePayloadContainer);
sendRequest(fromParticipantId, toDiscoveryEntry, request, messagingQos);
long entryTime = System.currentTimeMillis();
// saving all calling threads so that they can be interrupted at shutdown
outstandingRequestThreads.add(Thread.currentThread());
synchronized (responsePayloadContainer) {
while (running && responsePayloadContainer.isEmpty() && entryTime + messagingQos.getRoundTripTtl_ms() > System.currentTimeMillis()) {
try {
responsePayloadContainer.wait(messagingQos.getRoundTripTtl_ms());
} catch (InterruptedException e) {
if (running) {
throw new JoynrRequestInterruptedException("Request: " + request.getRequestReplyId() + " interrupted.");
}
throw new JoynrShutdownException("Request: " + request.getRequestReplyId() + " interrupted by shutdown");
}
}
}
outstandingRequestThreads.remove(Thread.currentThread());
if (responsePayloadContainer.isEmpty()) {
throw new JoynrCommunicationException("Request: " + request.getRequestReplyId() + " failed. The response didn't arrive in time");
}
Object response = responsePayloadContainer.get(0);
if (response instanceof Throwable) {
Throwable error = (Throwable) response;
throw new JoynrMessageNotSentException("Request: " + request.getRequestReplyId() + " failed: " + error.getMessage(), error);
}
return response;
}
Aggregations