Tabnine Logo
ChunkMonitor
Code IndexAdd Tabnine to your IDE (free)

How to use
ChunkMonitor
in
org.springframework.batch.core.step.item

Best Java code snippets using org.springframework.batch.core.step.item.ChunkMonitor (Showing top 20 results out of 315)

origin: spring-projects/spring-batch

  @Test
  public void testUpdateWithNoStream() throws Exception {
    monitor = new ChunkMonitor();
    monitor.setItemReader(new ItemReader<String>() {
      @Override
      public String read() throws Exception, UnexpectedInputException, ParseException {
        return "" + (count++);
      }
    });
    monitor.setChunkSize(CHUNK_SIZE);
    monitor.incrementOffset();
    ExecutionContext executionContext = new ExecutionContext();
    monitor.update(executionContext);
    assertEquals(0, executionContext.size());
  }
}
origin: spring-projects/spring-batch

@Before
public void setUp() {
  monitor.setItemReader(new ItemReader<String>() {
    @Override
    public String read() throws Exception, UnexpectedInputException, ParseException {
      return "" + (count++);
    }
  });
  monitor.registerItemStream(new ItemStreamSupport() {
    @Override
    public void close() {
      super.close();
      closed = true;
    }
  });
  monitor.setChunkSize(CHUNK_SIZE);
}
origin: spring-projects/spring-batch

public void incrementOffset() {
  ChunkMonitorData data = getData();
  data.offset ++;
  if (data.offset >= data.chunkSize) {
    resetOffset();
  }
}
origin: spring-projects/spring-batch

@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
  super.update(executionContext);
  if (streamsRegistered) {
    ChunkMonitorData data = getData();
    if (data.offset == 0) {
      // Only call the underlying update method if we are on a chunk
      // boundary
      stream.update(executionContext);
      executionContext.remove(getExecutionContextKey(OFFSET));
    }
    else {
      executionContext.putInt(getExecutionContextKey(OFFSET), data.offset);
    }
  }
}
origin: spring-projects/spring-batch

  data.scanning(false);
  inputs.setBusy(false);
  chunkMonitor.resetOffset();
  return;
chunkMonitor.incrementOffset();
if (outputs.isEmpty()) {
  data.scanning(false);
  inputs.setBusy(false);
  chunkMonitor.resetOffset();
origin: spring-projects/spring-batch

@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
  super.open(executionContext);
  if (streamsRegistered) {
    stream.open(executionContext);
    ChunkMonitorData data = new ChunkMonitorData(executionContext.getInt(getExecutionContextKey(OFFSET), 0), 0);
    holder.set(data);
    if (reader == null) {
      logger.warn("No ItemReader set (must be concurrent step), so ignoring offset data.");
      return;
    }
    for (int i = 0; i < data.offset; i++) {
      try {
        reader.read();
      }
      catch (Exception e) {
        throw new ItemStreamException("Could not position reader with offset: " + data.offset, e);
      }
    }
    resetOffset();
  }
}
origin: spring-projects/spring-batch

  @Override
  public Object doWithRetry(RetryContext context) throws Exception {
    contextHolder.set(context);
    if (!data.scanning()) {
      chunkMonitor.setChunkSize(inputs.size());
      try {
        doWrite(outputs.getItems());
      }
      catch (Exception e) {
        if (rollbackClassifier.classify(e)) {
          throw e;
        }
        /*
         * If the exception is marked as no-rollback, we need to
         * override that, otherwise there's no way to write the
         * rest of the chunk or to honour the skip listener
         * contract.
         */
        throw new ForceRollbackForWriteSkipException(
            "Force rollback on skippable exception so that skipped item can be located.", e);
      }
      contribution.incrementWriteCount(outputs.size());
    }
    else {
      scan(contribution, inputs, outputs, chunkMonitor, false);
    }
    return null;
  }
};
origin: spring-projects/spring-batch

@Test
public void testResetOffsetManually() {
  monitor.incrementOffset();
  monitor.resetOffset();
  assertEquals(0, monitor.getOffset());
}
origin: spring-projects/spring-batch

public void resetOffset() {
  getData().offset = 0;
}
origin: spring-projects/spring-batch

protected void detectStreamInReader() {
  if (streamIsReader) {
    if (!concurrent()) {
      chunkMonitor.setItemReader(getReader());
    }
    else {
      logger.warn("Asynchronous TaskExecutor detected with ItemStream reader.  This is probably an error, "
          + "and may lead to incorrect restart data being stored.");
    }
  }
}
origin: spring-projects/spring-batch

@Override
public AbstractTaskletStepBuilder<SimpleStepBuilder<I, O>> stream(ItemStream stream) {
  if (stream instanceof ItemReader<?>) {
    if (!streamIsReader) {
      streamIsReader = true;
      super.stream(chunkMonitor);
    }
    // In cases where multiple nested item readers are registered,
    // they all want to get the open() and close() callbacks.
    chunkMonitor.registerItemStream(stream);
  }
  else {
    super.stream(stream);
  }
  return this;
}
origin: org.springframework.batch/org.springframework.batch.core

if (stream instanceof ItemReader<?>) {
  streamIsReader = true;
  chunkMonitor.registerItemStream(stream);
boolean concurrent = taskExecutor != null && !(taskExecutor instanceof SyncTaskExecutor);
if (!concurrent) {
  chunkMonitor.setItemReader(itemReader);
origin: spring-projects/spring-batch

@Test
public void testOpenWithNullReader() {
  monitor.setItemReader(null);
  ExecutionContext executionContext = new ExecutionContext();
  monitor.open(executionContext);
  assertEquals(0, monitor.getOffset());
}
origin: spring-projects/spring-batch

@Test
public void testClose() {
  monitor.incrementOffset();
  monitor.close();
  assertTrue(closed);
  assertEquals(0, monitor.getOffset());
}
origin: spring-projects/spring-batch

@Test
public void testIncrementOffset() {
  assertEquals(0, monitor.getOffset());
  monitor.incrementOffset();
  assertEquals(1, monitor.getOffset());
}
origin: spring-projects/spring-batch

@Test(expected = ItemStreamException.class)
public void testOpenWithErrorInReader() {
  monitor.setItemReader(new ItemReader<String>() {
    @Override
    public String read() throws Exception, UnexpectedInputException, ParseException {
      throw new IllegalStateException("Expected");
    }
  });
  ExecutionContext executionContext = new ExecutionContext();
  executionContext.putInt(ChunkMonitor.class.getName() + ".OFFSET", 2);
  monitor.open(executionContext);
}
origin: spring-projects/spring-batch

@Test
public void testUpdateVanilla() {
  monitor.incrementOffset();
  ExecutionContext executionContext = new ExecutionContext();
  monitor.update(executionContext);
  assertEquals(1, executionContext.size());
}
origin: spring-projects/spring-batch

@Test
public void testUpdateOnBoundary() {
  monitor.resetOffset();
  ExecutionContext executionContext = new ExecutionContext();
  monitor.update(executionContext);
  assertEquals(0, executionContext.size());
  executionContext.put(ChunkMonitor.class.getName() + ".OFFSET", 3);
  monitor.update(executionContext);
  assertEquals(0, executionContext.size());
}
origin: spring-projects/spring-batch

public ChunkMonitor() {
  this.setExecutionContextName(ChunkMonitor.class.getName());
}
origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

  data.scanning(false);
  inputs.setBusy(false);
  chunkMonitor.resetOffset();
  return;
chunkMonitor.incrementOffset();
if (outputs.isEmpty()) {
  data.scanning(false);
  inputs.setBusy(false);
  chunkMonitor.resetOffset();
org.springframework.batch.core.step.itemChunkMonitor

Javadoc

Manage the offset data between the last successful commit and updates made to an input chunk. Only works with single threaded steps because it has to use a ThreadLocal to manage the state and coordinate between the caller and the wrapped ItemStream.

Most used methods

  • incrementOffset
  • registerItemStream
  • resetOffset
  • setChunkSize
  • setItemReader
  • getData
  • getExecutionContextKey
  • setExecutionContextName
  • <init>
  • close
  • getOffset
  • open
  • getOffset,
  • open,
  • update

Popular in Java

  • Making http requests using okhttp
  • runOnUiThread (Activity)
  • putExtra (Intent)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • From CI to AI: The AI layer in your organization
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