public static void transaction(Runnable action, boolean readOnly) { Ctx ctx = Ctxs.get(); boolean newContext = ctx == null; if (newContext) { ctx = Ctxs.open("transaction"); } try { EntityManager em = ctx.persister(); JPA.with(em).transactional(action, readOnly); } finally { if (newContext) { Ctxs.close(); } } }
@Override public void run() { U.must(!Ctxs.hasContext(), "Detected context leak!"); try { Ctxs.open(context); } catch (Throwable e) { Log.error("Job context initialization failed!", e); throw U.rte("Job context initialization failed!", e); } try { job.run(); } catch (Throwable e) { Log.error("Job execution failed!", e); throw U.rte("Job execution failed!", e); } finally { Ctxs.close(); } }
Ctxs.attach(ctx); } else { Ctxs.open("job"); Log.debug("Opening new context");
public static Ctx open(WithContext context) { Ctx ctx = Ctxs.open(context.tag()); ctx.setExchange(context.exchange()); ctx.setPersister(context.persister()); ctx.setUser(context.user()); Coll.assign(ctx.extras(), U.safe(context.extras())); return ctx; }
public static synchronized void executeInCtx(String tag, Runnable action) { Ctxs.open(tag); try { Jobs.execute(action); } finally { Ctxs.close(); } }
public static WebApp openRootContext() { WebApp app = WebAppGroup.root(); WebAppGroup.main().setDefaultApp(app); Ctxs.open("root"); Ctxs.ctx().setApp(app); Plugins.register(new AppClasspathEntitiesPlugin()); return app; }
@Override public void run() { U.must(!Ctxs.hasContext(), "Detected context leak!"); try { if (ctx != null) { // U.must(ctx.app() != null, "Application wasn't attached to the context: %s", ctx); Ctxs.attach(ctx); } else { Ctxs.open("job"); Log.debug("Opening new context"); } } catch (Throwable e) { Log.error("Job context initialization failed!", e); throw U.rte("Job context initialization failed!", e); } try { job.run(); } catch (Throwable e) { Log.error("Job execution failed!", e); throw U.rte("Job execution failed!", e); } finally { Ctxs.close(); } }
@Override public void process(Channel ctx) { T exchange = pool(ctx.helper()).get(); assert Cls.instanceOf(exchange, exchangeType); exchange.reset(); exchange.setConnection(ctx); Ctxs.open("x-request"); try { Ctxs.ctx().setExchange(exchange); process(ctx, exchange); } finally { Ctxs.close(); } }
public static synchronized <T> T executeInCtx(CtxData cd, Callable<T> action) { Ctx ctx = Ctxs.open("call"); ctx.setApp(cd.app()); ctx.setExchange(null); ctx.setUser(new UserInfo(cd.username(), cd.roles())); U.assign(ctx.extras(), cd.extras()); try { return Lmbd.call(action); } finally { Ctxs.close(); } }
Ctxs.open("request"); Ctxs.ctx().setExchange(x);