Package org.springframework.batch.core.scope.context

Examples of org.springframework.batch.core.scope.context.JobContext


  /**
   * This will be used to resolve expressions in job-scoped beans.
   */
  @Override
  public Object resolveContextualObject(String key) {
    JobContext context = getContext();
    // TODO: support for attributes as well maybe (setters not exposed yet
    // so not urgent).
    return new BeanWrapperImpl(context).getPropertyValue(key);
  }
View Full Code Here


  /**
   * @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);

        }

      }

View Full Code Here

  /**
   * @see Scope#getConversationId()
   */
  @Override
  public String getConversationId() {
    JobContext context = getContext();
    return context.getId();
  }
View Full Code Here

  /**
   * @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);
  }
View Full Code Here

  /**
   * @see Scope#remove(String)
   */
  @Override
  public Object remove(String name) {
    JobContext context = getContext();
    logger.debug(String.format("Removing from scope=%s, name=%s", this.getName(), name));
    return context.removeAttribute(name);
  }
View Full Code Here

   *
   * @return the current job context which we can use as a scope storage
   *         medium
   */
  private JobContext getContext() {
    JobContext context = JobSynchronizationManager.getContext();
    if (context == null) {
      throw new IllegalStateException("No context holder available for job scope");
    }
    return context;
  }
View Full Code Here

        @Override
        public String call() throws Exception {
          JobExecution jobExecution = new JobExecution(id);
          ExecutionContext executionContext = jobExecution.getExecutionContext();
          executionContext.put("foo", value);
          JobContext context = JobSynchronizationManager.register(jobExecution);
          logger.debug("Registered: " + context.getJobExecutionContext());
          try {
            return simple.getName();
          }
          finally {
            JobSynchronizationManager.close();
View Full Code Here

      FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
        @Override
        public String call() throws Exception {
          ExecutionContext executionContext = jobExecution.getExecutionContext();
          executionContext.put("foo", value);
          JobContext context = JobSynchronizationManager.register(jobExecution);
          logger.debug("Registered: " + context.getJobExecutionContext());
          try {
            return simple.getName();
          }
          finally {
            JobSynchronizationManager.close();
View Full Code Here

  @Test
  public void testDefaultJobContext() throws Exception {
    TestContext testContext = getTestContext(new Object());
    listener.prepareTestInstance(testContext);
    listener.beforeTestMethod(testContext);
    JobContext context = JobSynchronizationManager.getContext();
    assertNotNull(context);
    listener.afterTestMethod(testContext);
    assertNull(JobSynchronizationManager.getContext());
  }
View Full Code Here

  private void testExecutionContext(Object target) throws Exception {
    TestContext testContext = getTestContext(target);
    listener.prepareTestInstance(testContext);
    try {
      listener.beforeTestMethod(testContext);
      JobContext context = JobSynchronizationManager.getContext();
      assertNotNull(context);
      assertEquals("bar", context.getJobExecutionContext().get("foo"));
    }
    finally {
      listener.afterTestMethod(testContext);
    }
    assertNull(JobSynchronizationManager.getContext());
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.scope.context.JobContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.