use of ratpack.exec.Execution in project ratpack by ratpack.
the class HystrixRegistryBackedRequestVariable method get.
@Override
@SuppressWarnings("unchecked")
public T get() {
Execution execution = getExecution();
HystrixCommandCache commandCache = execution.maybeGet(HystrixCommandCache.class).orElseGet(() -> {
HystrixCommandCache cache = new HystrixCommandCache();
execution.add(cache);
return cache;
});
Object command = commandCache.get(this);
if (command == null) {
command = rv.initialValue();
commandCache.putIfAbsent(this, command);
}
return (T) command;
}
use of ratpack.exec.Execution in project ratpack by ratpack.
the class Transaction method unbind.
/**
* Unbinds this transaction from the current execution.
* <p>
* If the transaction is not bound, this method is effectively a noop and returns false.
*
* @return whether this transaction was actually bound
* @throws TransactionException if a different transaction is bound to the execution
* @see #bind()
*/
default default boolean unbind() {
Execution execution = Execution.current();
Optional<Transaction> transaction = execution.maybeGet(Transaction.class);
if (transaction.isPresent() && transaction.get() == this) {
execution.remove(Transaction.class);
return true;
} else {
return false;
}
}
use of ratpack.exec.Execution in project ratpack by ratpack.
the class DefaultContext method start.
public static void start(EventLoop eventLoop, final RequestConstants requestConstants, Registry registry, Handler[] handlers, Action<? super Execution> onComplete) {
ChainIndex index = new ChainIndex(handlers, registry, true);
requestConstants.indexes.push(index);
DefaultContext context = new DefaultContext(requestConstants);
requestConstants.context = context;
context.pathBindings = new PathBindingStorage(new RootPathBinding(requestConstants.request.getPath()));
requestConstants.applicationConstants.execController.fork().onError(throwable -> requestConstants.context.error(throwable instanceof HandlerException ? throwable.getCause() : throwable)).onComplete(onComplete).register(s -> s.add(Context.TYPE, context).add(Request.TYPE, requestConstants.request).add(Response.TYPE, requestConstants.response).add(PathBindingStorage.TYPE, context.pathBindings).addLazy(RequestId.TYPE, () -> registry.get(RequestId.Generator.TYPE).generate(requestConstants.request))).eventLoop(eventLoop).onStart(e -> DefaultRequest.setDelegateRegistry(requestConstants.request, e)).start(e -> {
requestConstants.execution = e;
context.joinedRegistry = new ContextRegistry(context).join(requestConstants.execution);
context.next();
});
}
use of ratpack.exec.Execution in project ratpack by ratpack.
the class ExecutionBasedScope method getScopedObjectMap.
private Map<Key<?>, Object> getScopedObjectMap(Key<?> key) {
try {
Execution execution = Execution.current();
if (!inScope(execution)) {
throw new OutOfScopeException("Cannot access " + key + " outside of " + name);
}
return execution.maybeGet(storeType).orElseGet(() -> {
S store = createStore();
execution.add(storeType, store);
return store;
});
} catch (UnmanagedThreadException e) {
throw new OutOfScopeException("Cannot access " + key + " outside of " + name);
}
}
use of ratpack.exec.Execution in project ratpack by ratpack.
the class Transaction method bind.
/**
* Binds this transaction to the current execution.
* <p>
* The instance is added to the current execution's registry.
* <p>
* It is typically not necessary to call this directly.
* Transactions default to “auto binding”.
* That is, this method is called implicitly when the transaction starts.
*
* @return {@code this}
* @throws TransactionException if a different transaction is bound to the execution
*/
default default Transaction bind() throws TransactionException {
Execution execution = Execution.current();
execution.maybeGet(Transaction.class).ifPresent(t -> {
if (t != this) {
throw new TransactionException("A transaction is already bound");
}
});
execution.add(Transaction.class, this);
return this;
}
Aggregations