/** * @see Scope#get(String, ObjectFactory) */ @Override public Object get(String name, ObjectFactory<?> objectFactory) { JobContext context = getContext(); Object scopedObject = context.getAttribute(name); if (scopedObject == null) { synchronized (mutex) { scopedObject = context.getAttribute(name); if (scopedObject == null) { if (logger.isDebugEnabled()) { logger.debug(String.format("Creating object in scope=%s, name=%s", this.getName(), name)); } scopedObject = objectFactory.getObject(); context.setAttribute(name, scopedObject); } } } return scopedObject; }
@Test public void testNestedScopedProxy() throws Exception { nested.execute(new JobExecution(11L)); assertTrue(TestJob.getContext().attributeNames().length > 0); String collaborator = (String) TestJob.getContext().getAttribute("collaborator"); assertNotNull(collaborator); assertEquals("foo", collaborator); String parent = (String) TestJob.getContext().getAttribute("parent"); assertNotNull(parent); assertEquals("bar", parent); assertTrue("Scoped proxy not created", ((String) TestJob.getContext().getAttribute("parent.class")) .matches(PROXY_TO_STRING_REGEX)); }
@Test public void testScopedProxy() throws Exception { proxied.execute(new JobExecution(11L)); assertTrue(TestJob.getContext().attributeNames().length > 0); String collaborator = (String) TestJob.getContext().getAttribute("collaborator"); assertNotNull(collaborator); assertEquals("bar", collaborator); assertTrue("Scoped proxy not created", ((String) TestJob.getContext().getAttribute("collaborator.class")) .matches(PROXY_TO_STRING_REGEX)); }
@Test public void testScopedProxyForSecondReference() throws Exception { doubleEnhanced.execute(new JobExecution(11L)); assertTrue(TestJob.getContext().attributeNames().length > 0); String collaborator = (String) TestJob.getContext().getAttribute("collaborator"); assertNotNull(collaborator); assertEquals("bar", collaborator); }
@Test public void testScopedProxyForReference() throws Exception { enhanced.execute(new JobExecution(11L)); assertTrue(TestJob.getContext().attributeNames().length > 0); String collaborator = (String) TestJob.getContext().getAttribute("collaborator"); assertNotNull(collaborator); assertEquals("bar", collaborator); }
@Test public void testExecutionContext() throws Exception { JobExecution stepExecution = new JobExecution(11L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("name", "spam"); stepExecution.setExecutionContext(executionContext); proxied.execute(stepExecution); assertTrue(TestJob.getContext().attributeNames().length > 0); String collaborator = (String) TestJob.getContext().getAttribute("collaborator"); assertNotNull(collaborator); assertEquals("bar", collaborator); }
/** * @see Scope#get(String, ObjectFactory) */ @Override public Object get(String name, ObjectFactory<?> objectFactory) { JobContext context = getContext(); Object scopedObject = context.getAttribute(name); if (scopedObject == null) { synchronized (mutex) { scopedObject = context.getAttribute(name); if (scopedObject == null) { logger.debug(String.format("Creating object in scope=%s, name=%s", this.getName(), name)); scopedObject = objectFactory.getObject(); context.setAttribute(name, scopedObject); } } } return scopedObject; }
/** * @see Scope#get(String, ObjectFactory) */ @Override public Object get(String name, ObjectFactory<?> objectFactory) { JobContext context = getContext(); Object scopedObject = context.getAttribute(name); if (scopedObject == null) { synchronized (mutex) { scopedObject = context.getAttribute(name); if (scopedObject == null) { if (logger.isDebugEnabled()) { logger.debug(String.format("Creating object in scope=%s, name=%s", this.getName(), name)); } scopedObject = objectFactory.getObject(); context.setAttribute(name, scopedObject); } } } return scopedObject; }
/** * @see Scope#get(String, ObjectFactory) */ @Override public Object get(String name, ObjectFactory<?> objectFactory) { JobContext context = getContext(); Object scopedObject = context.getAttribute(name); if (scopedObject == null) { synchronized (mutex) { scopedObject = context.getAttribute(name); if (scopedObject == null) { if (logger.isDebugEnabled()) { logger.debug(String.format("Creating object in scope=%s, name=%s", this.getName(), name)); } scopedObject = objectFactory.getObject(); context.setAttribute(name, scopedObject); } } } return scopedObject; }