Tabnine Logo
JobContext.setAttribute
Code IndexAdd Tabnine to your IDE (free)

How to use
setAttribute
method
in
org.springframework.batch.core.scope.context.JobContext

Best Java code snippets using org.springframework.batch.core.scope.context.JobContext.setAttribute (Showing top 12 results out of 315)

origin: spring-projects/spring-batch

private void setContextFromCollaborator() {
  if (context != null) {
    context.setAttribute("collaborator", collaborator.getName());
    context.setAttribute("collaborator.class", collaborator.getClass().toString());
    if (collaborator.getParent()!=null) {
      context.setAttribute("parent", collaborator.getParent().getName());
      context.setAttribute("parent.class", collaborator.getParent().getClass().toString());
    }
  }
}
origin: spring-projects/spring-batch

/**
 * @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;
}
origin: spring-projects/spring-batch

  @Override
  public JobContext call() throws Exception {
    try {
      JobSynchronizationManager.register(jobExecution);
      JobContext context = JobSynchronizationManager.getContext();
      context.setAttribute("foo", "bar");
      return context;
    }
    finally {
      JobSynchronizationManager.close();
    }
  }
});
origin: spring-projects/spring-batch

@Test
public void testRegisterDestructionCallback() {
  final List<String> list = new ArrayList<>();
  context.setAttribute("foo", "bar");
  scope.registerDestructionCallback("foo", new Runnable() {
    @Override
    public void run() {
      list.add("foo");
    }
  });
  assertEquals(0, list.size());
  // When the context is closed, provided the attribute exists the
  // callback is called...
  context.close();
  assertEquals(1, list.size());
}
origin: spring-projects/spring-batch

@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));
}
origin: spring-projects/spring-batch

@Test
public void testRemove() {
  context.setAttribute("foo", "bar");
  scope.remove("foo");
  assertFalse(context.hasAttribute("foo"));
}
origin: spring-projects/spring-batch

@Test
public void testRegisterAnotherDestructionCallback() {
  final List<String> list = new ArrayList<>();
  context.setAttribute("foo", "bar");
  scope.registerDestructionCallback("foo", new Runnable() {
    @Override
    public void run() {
      list.add("foo");
    }
  });
  scope.registerDestructionCallback("foo", new Runnable() {
    @Override
    public void run() {
      list.add("bar");
    }
  });
  assertEquals(0, list.size());
  // When the context is closed, provided the attribute exists the
  // callback is called...
  context.close();
  assertEquals(2, list.size());
}
origin: spring-projects/spring-batch

@Test
public void testDestructionCallbackWithException() throws Exception {
  context.setAttribute("foo", "FOO");
  context.setAttribute("bar", "BAR");
  context.registerDestructionCallback("bar", new Runnable() {
    @Override
origin: spring-projects/spring-batch

@Test
public void testGetWithSomethingAlreadyThere() {
  context.setAttribute("foo", "bar");
  Object value = scope.get("foo", new ObjectFactory<String>() {
    @Override
    public String getObject() throws BeansException {
      return null;
    }
  });
  assertEquals("bar", value);
  assertTrue(context.hasAttribute("foo"));
}
origin: org.springframework.batch/spring-batch-core

/**
 * @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;
}
origin: apache/servicemix-bundles

/**
 * @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;
}
origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

/**
 * @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;
}
org.springframework.batch.core.scope.contextJobContextsetAttribute

Popular methods of JobContext

  • getJobExecutionContext
  • getJobParameters
  • <init>
  • close
    Clean up the context at the end of a step execution. Must be called once at the end of a step execut
  • getAttribute
  • getId
  • registerDestructionCallback
    Allow clients to register callbacks for clean up on close.
  • removeAttribute
    Override base class behaviour to ensure destruction callbacks are unregistered as well as the defaul
  • unregisterDestructionCallbacks
  • attributeNames
  • equals
    Extend the base class method to include the job execution itself as a key (i.e. two contexts are onl
  • getJobExecution
    The current JobExecution that is active in this context.
  • equals,
  • getJobExecution,
  • getJobName,
  • getSystemProperties,
  • hasAttribute

Popular in Java

  • Making http requests using okhttp
  • compareTo (BigDecimal)
  • startActivity (Activity)
  • onCreateOptionsMenu (Activity)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now