@Override public final void run() { while(isStarted()) { if(fibers.size() == 0) { try { Thread.sleep(1); } catch(final InterruptedException e) { break; } } else { for(final Fiber nextFiber : fibers) { try { if(nextFiber.isStarted() || nextFiber.isShutdown()) { nextFiber.invoke(); } } catch(final RuntimeException e) { throw e; // don't catch the unchecked exceptions } catch(final Throwable t) { LOG.log(Level.WARNING, "Fiber \"" + nextFiber + "\" failed", t); } if(backgroundFlag) { LockSupport.parkNanos(1); } } } } } }
@Override public void close() throws IOException { super.close(); updateTask.close(); } }
public AsyncValueUpdatingSupplier( final FibersExecutor executor, final T initialValue, final InitCallable<T> updateAction) throws NullPointerException { super(initialValue, null); if (updateAction == null) { throw new NullPointerException("Argument should not be null"); } updateTask = new ExclusiveFiberBase(executor) { @Override protected final void invokeTimedExclusively(final long startTimeNanos) { try { lastValue = updateAction.call(); } catch (final Exception e) { LogUtil.trace( Loggers.ERR, Level.WARN, e, "Failed to execute the value update action"); } } @Override protected final void doClose() { lastValue = null; } }; try { updateTask.start(); } catch (final RemoteException ignored) { } }
@Override protected final void doClose() throws InterruptRunException { try (final Instance logCtx = CloseableThreadContext.put(KEY_STEP_ID, id) .put(KEY_CLASS_NAME, getClass().getSimpleName())) { try { generator.close(); } catch (final IOException e) { LogUtil.exception( Level.ERROR, e, "Failed to close the load generator \"{}\"", generator.toString()); } try { driver.close(); } catch (final IOException e) { LogUtil.exception( Level.ERROR, e, "Failed to close the storage driver \"{}\"", driver.toString()); } try { resultsTransferTask.close(); } catch (final IOException e) { LogUtil.exception( Level.WARN, e, "{}: failed to stop the service coroutine {}", resultsTransferTask); } Loggers.MSG.debug("{}: closed the load step context", id); } } }
@Override protected void doStart() throws IllegalStateException { try { resultsTransferTask.start(); } catch (final RemoteException ignored) { } try { driver.start(); } catch (final RemoteException ignored) { } catch (final IllegalStateException e) { LogUtil.exception(Level.WARN, e, "{}: failed to start the storage driver \"{}\"", id, driver); } try { generator.start(); } catch (final RemoteException ignored) { } catch (final IllegalStateException e) { LogUtil.exception( Level.WARN, e, "{}: failed to start the load generator \"{}\"", id, generator); } }