/** * @see Scope#registerDestructionCallback(String, Runnable) */ @Override public void registerDestructionCallback(String name, Runnable callback) { JobContext context = getContext(); if (logger.isDebugEnabled()) { logger.debug(String.format("Registered destruction callback in scope=%s, name=%s", this.getName(), name)); } context.registerDestructionCallback(name, callback); }
@Test public void testDestructionCallbackMissingAttribute() throws Exception { context.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("bar"); } }); context.close(); // Yes the callback should be called even if the attribute is missing - // for inner beans assertEquals(1, list.size()); }
@Test public void testDestructionCallbackSunnyDay() throws Exception { context.setAttribute("foo", "FOO"); context.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("bar"); } }); context.close(); assertEquals(1, list.size()); assertEquals("bar", list.get(0)); }
@Test public void testRelease() { JobContext context = JobSynchronizationManager.register(jobExecution); final List<String> list = new ArrayList<>(); context.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("foo"); } }); // On release we expect the destruction callbacks to be called JobSynchronizationManager.release(); assertNull(JobSynchronizationManager.getContext()); assertEquals(1, list.size()); }
@Test public void testClose() throws Exception { final List<String> list = new ArrayList<>(); JobContext context = JobSynchronizationManager.register(jobExecution); context.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("foo"); } }); JobSynchronizationManager.close(); assertNull(JobSynchronizationManager.getContext()); assertEquals(0, list.size()); }
context.setAttribute("foo", "FOO"); context.setAttribute("bar", "BAR"); context.registerDestructionCallback("bar", new Runnable() { @Override public void run() { context.registerDestructionCallback("foo", new Runnable() { @Override public void run() {
/** * @see Scope#registerDestructionCallback(String, Runnable) */ @Override public void registerDestructionCallback(String name, Runnable callback) { JobContext context = getContext(); if (logger.isDebugEnabled()) { logger.debug(String.format("Registered destruction callback in scope=%s, name=%s", this.getName(), name)); } context.registerDestructionCallback(name, callback); }
/** * @see Scope#registerDestructionCallback(String, Runnable) */ @Override public void registerDestructionCallback(String name, Runnable callback) { JobContext context = getContext(); if (logger.isDebugEnabled()) { logger.debug(String.format("Registered destruction callback in scope=%s, name=%s", this.getName(), name)); } context.registerDestructionCallback(name, callback); }
/** * @see Scope#registerDestructionCallback(String, Runnable) */ @Override public void registerDestructionCallback(String name, Runnable callback) { JobContext context = getContext(); logger.debug(String.format("Registered destruction callback in scope=%s, name=%s", this.getName(), name)); context.registerDestructionCallback(name, callback); }