public void waitForState(StateComparator<D> stateComparator, long timeout) throws InterruptedException, TimeoutException { synchronized (stateMonitor) { long timeWaited = 0; while (!Thread.currentThread().isInterrupted()) { try { if (stateComparator.equalState(unitRemote.getData())) { return; } logger.info("State not yet reached. Waiting..."); } catch (NotAvailableException ex) { logger.info("Waiting because unit data not available!"); } // wait till timeout long currentTime = System.currentTimeMillis(); stateMonitor.wait(timeout); timeWaited += System.currentTimeMillis() - currentTime; logger.info("Woke up! Time waited " + timeWaited + "ms"); if (timeout != 0 && timeWaited > timeout) { throw new TimeoutException("Timeout expired!"); } } } } }
@Override public void waitForConnectionState(ConnectionState connectionState, long timeout) throws InterruptedException, TimeoutException { synchronized (connectionStateLock) { if (connectionState == getConnectionState()) { return; } final long startingTime = System.currentTimeMillis(); long timeWaited = 0; while (connectionState != getConnectionState()) { if (timeout > 0) { connectionStateLock.wait(timeout - timeWaited); timeWaited = System.currentTimeMillis() - startingTime; if (timeout - timeWaited <= 0) { throw new TimeoutException(); } } else { connectionState.wait(); } } } } }
} else { if ((System.currentTimeMillis() - requestTimestamp) > timeUnit.toMillis(timeout)) { throw new TimeoutException();
throw new TimeoutException("Timeout expired!");
@Override public Event call(final String name, final double timeout) throws CouldNotPerformException, InterruptedException { try { if (name == null || name.isEmpty()) { throw new NotAvailableException("name"); } try { synchronized (participantLock) { return getParticipant().call(name, timeout); } } catch (ExecutionException ex) { throw rsbInterruptedHack(ex); } } catch (InterruptedException ex) { throw ex; } catch (TimeoutException ex) { throw new org.openbase.jul.exception.TimeoutException("Could not call Method[" + name + "] in time!", ex); } catch (RuntimeException | RSBException ex) { throw new InvalidStateException("Could not call Method[" + name + "] asynchronous because of a middleware issue!", ex); } catch (Exception ex) { throw new CouldNotPerformException("Could not call Method[" + name + "]!", ex); } }
@Override public <ReplyType, RequestType> ReplyType call(final String name, final RequestType data) throws CouldNotPerformException, InterruptedException { try { if (name == null || name.isEmpty()) { throw new NotAvailableException("name"); } try { synchronized (participantLock) { return getParticipant().call(name, data); } } catch (ExecutionException ex) { throw rsbInterruptedHack(ex); } } catch (InterruptedException ex) { throw ex; } catch (TimeoutException ex) { throw new org.openbase.jul.exception.TimeoutException("Could not call Method[" + name + "] in time!", ex); } catch (RuntimeException | RSBException ex) { throw new InvalidStateException("Could not call Method[" + name + "] asynchronous because of a middleware issue!", ex); } catch (Exception ex) { throw new CouldNotPerformException("Could not call Method[" + name + "]!", ex); } }
@Override public <ReplyType, RequestType> ReplyType call(final String name, final RequestType data, final double timeout) throws CouldNotPerformException, InterruptedException { try { if (name == null || name.isEmpty()) { throw new NotAvailableException("name"); } try { synchronized (participantLock) { return getParticipant().call(name, data, timeout); } } catch (ExecutionException ex) { throw rsbInterruptedHack(ex); } } catch (InterruptedException ex) { throw ex; } catch (TimeoutException ex) { throw new org.openbase.jul.exception.TimeoutException("Could not call Method[" + name + "] in time!", ex); } catch (RuntimeException | RSBException ex) { throw new InvalidStateException("Could not call Method[" + name + "] asynchronous because of a middleware issue!", ex); } catch (Exception ex) { throw new CouldNotPerformException("Could not call Method[" + name + "]!", ex); } } }
@Override public Event call(final String name, final Event event) throws CouldNotPerformException, InterruptedException { try { if (name == null || name.isEmpty()) { throw new NotAvailableException("name"); } try { synchronized (participantLock) { return getParticipant().call(name, event); } } catch (ExecutionException ex) { throw rsbInterruptedHack(ex); } } catch (InterruptedException ex) { throw ex; } catch (TimeoutException ex) { throw new org.openbase.jul.exception.TimeoutException("Could not call Method[" + name + "] in time!", ex); } catch (RuntimeException | RSBException ex) { throw new InvalidStateException("Could not call Method[" + name + "] asynchronous because of a middleware issue!", ex); } catch (Exception ex) { throw new CouldNotPerformException("Could not call Method[" + name + "]!", ex); } }
@Override public Event call(final String name, final Event event, final double timeout) throws CouldNotPerformException, InterruptedException { try { if (name == null || name.isEmpty()) { throw new NotAvailableException("name"); } try { synchronized (participantLock) { return getParticipant().call(name, event, timeout); } } catch (ExecutionException ex) { throw rsbInterruptedHack(ex); } } catch (InterruptedException ex) { throw ex; } catch (TimeoutException ex) { throw new org.openbase.jul.exception.TimeoutException("Could not call Method[" + name + "] in time!", ex); } catch (RuntimeException | RSBException ex) { throw new InvalidStateException("Could not call Method[" + name + "] asynchronous because of a middleware issue!", ex); } catch (Exception ex) { throw new CouldNotPerformException("Could not call Method[" + name + "]!", ex); } }
throw new TimeoutException("RPCMethod call timeout");
@Override public Event call(final String name) throws CouldNotPerformException, InterruptedException { try { if (name == null || name.isEmpty()) { throw new NotAvailableException("name"); } try { synchronized (participantLock) { return getParticipant().call(name); } } catch (ExecutionException ex) { throw rsbInterruptedHack(ex); } } catch (InterruptedException ex) { throw ex; } catch (TimeoutException ex) { throw new org.openbase.jul.exception.TimeoutException("Could not call Method[" + name + "] in time!", ex); } catch (RuntimeException | RSBException ex) { throw new InvalidStateException("Could not call Method[" + name + "] asynchronous because of a middleware issue!", ex); } catch (Exception ex) { throw new CouldNotPerformException("Could not call Method[" + name + "]!", ex); } }
if (validTimeout <= 0) { ExceptionPrinter.printHistory(ex, logger, LogLevel.WARN); throw new TimeoutException("Could not call remote Method[" + methodName + "(" + shortArgument + ")] on Scope[" + remoteServer.getScope() + "] in Time[" + timeout + "ms].");