/** * Convenience method for creating an async result. * @param result the result * @return result of type T */ public static final <T> AsyncResultImpl<T> create(T result, Class<T> type) { return new AsyncResultImpl<>(result); }
/** * @see io.apiman.gateway.engine.io.IWriteStream#end() */ @Override public void end() { // Called when the upload to the 'API' is complete. This is when we // need to response with the connection response. handler.handle(AsyncResultImpl.<IApiConnectionResponse>create(this)); }
/** * Convenience method for creating an async result. * @param result the result * @return result of type T */ public static final <T> AsyncResultImpl<T> create(T result) { return new AsyncResultImpl<>(result); }
/** * Convenience method for creating an async result. * @param t the throwable * @param type the type * @return result of type T */ public static final <T> AsyncResultImpl<T> create(Throwable t, Class<T> type) { return new AsyncResultImpl<>(t); }
/** * Creates the handler to use when an error is detected during the processing * of a chain. */ private IAsyncHandler<Throwable> createPolicyErrorHandler() { return error -> resultHandler.handle(AsyncResultImpl.<IEngineResult> create(error)); } }
/** * Convenience method for creating an async result. * @param t the throwable * @return result of type T */ public static final <T> AsyncResultImpl<T> create(Throwable t) { return new AsyncResultImpl<>(t); }
private <T> Handler<AsyncResult<T>> handleSuccessfulResult(IAsyncResultHandler<Void> failureHandler, Handler<T> successHandler) { return result -> { if (result.succeeded()) { successHandler.handle(result.result()); } else { failureHandler.handle(AsyncResultImpl.create(result.cause())); } }; }
/** * @see io.apiman.gateway.engine.components.jdbc.IJdbcConnection#setAutoCommit(boolean, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void setAutoCommit(boolean autoCommit, IAsyncResultHandler<Void> handler) { try { connection.setAutoCommit(autoCommit); handler.handle(AsyncResultImpl.create((Void) null, Void.class)); } catch (SQLException e) { handler.handle(AsyncResultImpl.create(e, Void.class)); } }
/** * @see io.apiman.gateway.engine.components.ISharedStateComponent#clearProperty(java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public <T> void clearProperty(String namespace, String propertyName, IAsyncResultHandler<Void> handler) { QName key = new QName(namespace, propertyName); synchronized (sharedState) { sharedState.remove(key); } handler.handle(AsyncResultImpl.create((Void) null)); }
protected void checkLoadingStatus() { if (handler != null && !failed && finishedLoading && asyncInitializeAwaiting.get() == 0) { handler.handle(AsyncResultImpl.create((Void) null)); } }
@Override public void abort(Throwable t) { done = true; payloadResultHandler.handle(AsyncResultImpl.create(new RuntimeException("Inbound request stream aborted.", t))); //$NON-NLS-1$ }
private void checkSuccess(URILoadingRegistry reg) { if (!failed) { handlers.get(reg).handle(AsyncResultImpl.create((Void) null)); } } }
@SuppressWarnings("unchecked") private <T> Handler<AsyncResult<CompositeFuture>> handleCompositeResult(IAsyncResultHandler<T> apimanResultHandler) { return result -> { if (result.succeeded()) { apimanResultHandler.handle(AsyncResultImpl.create((T) result.result())); } else { apimanResultHandler.handle(AsyncResultImpl.create(result.cause())); } }; }
@SuppressWarnings("unchecked") private <T, Q> Handler<AsyncResult<Q>> handleResult(IAsyncResultHandler<T> apimanResultHandler) { return result -> { if (result.succeeded()) { apimanResultHandler.handle(AsyncResultImpl.create((T) result.result())); } else { apimanResultHandler.handle(AsyncResultImpl.create(result.cause())); } }; }
private Handler<AsyncResult<Void>> handleResultVoid(IAsyncResultHandler<Void> apimanResultHandler) { return result -> { if (result.succeeded()) { apimanResultHandler.handle(AsyncResultImpl.create(result.result())); } else { apimanResultHandler.handle(AsyncResultImpl.create(result.cause())); } }; } }
static <T, R> Handler<AsyncResult<T>> translateFailureHandler(IAsyncResultHandler<R> apimanResult) { return result -> { if (!result.succeeded()) { apimanResult.handle(AsyncResultImpl.create(result.cause())); } }; } }
@Override public void abort(Throwable t) { done = true; payloadResultHandler.handle(AsyncResultImpl.create(new RuntimeException("Inbound request stream aborted.", t))); //$NON-NLS-1$ }
/** * @see io.apiman.gateway.engine.components.jdbc.IJdbcConnection#rollback(io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void rollback(IAsyncResultHandler<Void> handler) { try { connection.rollback(); handler.handle(AsyncResultImpl.create((Void) null, Void.class)); } catch (SQLException e) { handler.handle(AsyncResultImpl.create(e, Void.class)); } }