@Override public void destroy(ControllableApplication application, CompletionListener<Void> listener) { // SKIP: there's no standard method to stop and destroy a // regular Java console application running in a container if (listener != null) { listener.onCompletion(null); } } }
/** * Constructs a {@link RandomIterator} for numbers between * 0 and the specified range (exclusive). * * @param range the upper bound of the range */ public RandomIterator(long range) { this(new PerpetualIterator<Long>(range)); }
/** * Obtains the captured value. Should a value not be captured, * {@link #next()} is invoked to capture a value. * * @return the captured value */ public T get() { return next(); }
return new RandomIterator(new FibonacciIterator()); return new RandomIterator(new ExponentialIterator(0, 50)); return new FibonacciIterator(); return new ExponentialIterator(0, 50); return new PerpetualIterator<Long>(250L);
/** * {@inheritDoc} */ @Override public Operation execute(long sequence) { CompletionListener listener = pendingListeners.remove(sequence); if (listener != null) { try { if (response instanceof Exception) { listener.onException((Exception) response); } else { listener.onCompletion(response); } } catch (Exception e) { // TODO: we ignore any exceptions that the listener may throw } } return null; }
/** * Create an Object via reflection (using the specified {@link ClassLoader}). * * @param className The name of the class to instantiate. * @param classLoader The {@link ClassLoader} to use to load the class. * @param constructorParameterList The set of parameters to pass to the constructor * * @return A new instance of the class specified by the className * * @throws ClassNotFoundException if the class is not found * @throws NoSuchMethodException if there is no such constructor * @throws InstantiationException if it failed to instantiate * @throws IllegalAccessException if security doesn't allow the call * @throws InvocationTargetException if the constructor failed */ public static Object createObject(String className, ClassLoader classLoader, Object... constructorParameterList) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { Class<?> clazz = Class.forName(className, true, classLoader); Class<?>[] parameterTypes = getClassArrayFromObjectArray(constructorParameterList); Constructor<?> con = ReflectionHelper.getCompatibleConstructor(clazz, parameterTypes); return con.newInstance(constructorParameterList); }
/** * Submits a {@link Callable} for remote execution by the * {@link Application} and blocks waiting for the result. * * @param callable the {@link Callable} to execute * @param <T> the type of the result */ public <T> T submit(Callable<T> callable) { FutureCompletionListener<T> future = new FutureCompletionListener<T>(); submit(callable, future); try { return future.get(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Failed to execute the Callable: " + callable, e); } }
@Override public boolean hasNext() { return hasValue() || iterator.hasNext(); }
@Override public Iterator<Action<A, G>> getActions() { return new RepetitiveIterator<Action<A, G>>(action, count); } }
/** * {@inheritDoc} */ public void addBuilder(B bldrApplication, S schema, String sApplicationPrefix, int cRequiredInstances) { m_builders.put(sApplicationPrefix, new Triple<B, S, Integer>(bldrApplication, schema, cRequiredInstances)); }
/** * Creates a dynamic proxy of the specified {@link Object} routing all * method calls to the specified {@link MethodInterceptor}. * * @param object the {@link Object} to proxy * @param interceptor the {@link MethodInterceptor} * * @return a dynamic proxy of the specified {@link Object} */ @SuppressWarnings("unchecked") public static <T> T createProxyOf(T object, MethodInterceptor interceptor) { return (T) createProxyOf(object.getClass(), interceptor); }
/** * Starts the application. */ public void start() { if (m_controller == null) { m_startListener = null; } else { m_startListener = new FutureCompletionListener<Void>(); m_controller.start(this, m_startListener); } }
@Override public int waitFor() throws InterruptedException { // when there's no application controller we don't have to wait to terminate // (as we've already been terminated) if (m_controller != null) { // here we simply try to wait for the application's start future // to complete executing. try { if (m_startListener != null) { m_startListener.get(); } } catch (InterruptedException e) { throw e; } catch (ExecutionException e) { throw new RuntimeException(e.getCause()); } } return 0; }
@Override public Iterator<Action<A, G>> getActions() { return new PerpetualIterator<Action<A, G>>(action); } }
/** * {@inheritDoc} */ @Override public void start(ControllableApplication application, CompletionListener<Void> listener) { if (listener != null) { listener.onCompletion(null); } }
@Override public T next() { if (!hasValue()) { capture = new AtomicReference<T>(iterator.next()); } return capture.get(); }
/** * Obtains an ensured of the specified {@link Deferred}. * * @param deferred the {@link Deferred} to ensure * @param retryDelayDuration the time to wait between retrying * @param retryDelayDurationUnits the {@link TimeUnit}s for the retry delay duration * @param totalRetryDuration the maximum duration for retrying * @param totalRetryDurationUnits the {@link TimeUnit}s for the duration * * @return an {@link Ensured} of the {@link Deferred} */ public static <T> Deferred<T> ensured(Deferred<T> deferred, long retryDelayDuration, TimeUnit retryDelayDurationUnits, long totalRetryDuration, TimeUnit totalRetryDurationUnits) { Iterator<Long> retryDurationsMS = new PerpetualIterator<Long>(retryDelayDurationUnits.toMillis(retryDelayDuration < 0 ? 0 : retryDelayDuration)); return deferred instanceof Ensured ? deferred : new Ensured<T>(deferred, retryDurationsMS, totalRetryDurationUnits .toMillis(totalRetryDuration)); }
/** * {@inheritDoc} */ @Override public void destroy(ControllableApplication application, CompletionListener<Void> listener) { if (listener != null) { listener.onCompletion(null); } } }
@Override public void start(ControllableApplication application, CompletionListener<Void> listener) { if (m_callableStartStaticMethod == null) { if (listener != null) { listener.onCompletion(null); } } else { application.submit(m_callableStartStaticMethod, listener); } }
@Override public void destroy(ControllableApplication application, CompletionListener<Void> listener) { if (m_callableDestroyStaticMethod == null) { if (listener != null) { listener.onCompletion(null); } } else { application.submit(m_callableDestroyStaticMethod, listener); } } }