congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
StepListenerFactoryBean
Code IndexAdd Tabnine to your IDE (free)

How to use
StepListenerFactoryBean
in
org.springframework.batch.core.listener

Best Java code snippets using org.springframework.batch.core.listener.StepListenerFactoryBean (Showing top 20 results out of 315)

origin: spring-projects/spring-batch

/**
 * Convenience method to wrap any object and expose the appropriate
 * {@link StepListener} interfaces.
 *
 * @param delegate a delegate object
 * @return a StepListener instance constructed from the delegate
 */
public static StepListener getListener(Object delegate) {
  StepListenerFactoryBean factory = new StepListenerFactoryBean();
  factory.setDelegate(delegate);
  return (StepListener) factory.getObject();
}
origin: spring-projects/spring-batch

/**
 * Register explicitly set item listeners and auto-register reader, processor and writer if applicable
 */
private void registerSkipListeners() {
  // auto-register reader, processor and writer
  for (Object itemHandler : new Object[] { getReader(), getWriter(), getProcessor() }) {
    if (StepListenerFactoryBean.isListener(itemHandler)) {
      StepListener listener = StepListenerFactoryBean.getListener(itemHandler);
      if (listener instanceof SkipListener<?, ?>) {
        @SuppressWarnings("unchecked")
        SkipListener<? super I, ? super O> skipListener = (SkipListener<? super I, ? super O>) listener;
        skipListeners.add(skipListener);
      }
    }
  }
}
origin: spring-projects/spring-batch

@Test(expected = IllegalArgumentException.class)
public void testWrongSignatureNamedMethod() {
  AbstractTestComponent delegate = new AbstractTestComponent() {
    @SuppressWarnings("unused")
    public void aMethod(Integer item) {
      executed = true;
    }
  };
  factoryBean.setDelegate(delegate);
  Map<String, String> metaDataMap = new HashMap<>();
  metaDataMap.put(AFTER_WRITE.getPropertyName(), "aMethod");
  factoryBean.setMetaDataMap(metaDataMap);
  factoryBean.getObject();
}
origin: spring-projects/spring-batch

@Test(expected = IllegalArgumentException.class)
public void testWrongSignatureAnnotation() {
  AbstractTestComponent delegate = new AbstractTestComponent() {
    @AfterWrite
    public void aMethod(Integer item) {
      executed = true;
    }
  };
  factoryBean.setDelegate(delegate);
  factoryBean.getObject();
}
origin: spring-projects/spring-batch

@Test
public void testProxiedAnnotationsFactoryMethod() throws Exception {
  Object delegate = new InitializingBean() {
    @BeforeStep
    public void foo(StepExecution execution) {
    }
    @Override
    public void afterPropertiesSet() throws Exception {
    }
  };
  ProxyFactory factory = new ProxyFactory(delegate);
  assertTrue("Listener is not of correct type",
      StepListenerFactoryBean.getListener(factory.getProxy()) instanceof StepExecutionListener);
}
origin: spring-projects/spring-batch

@Test
public void testAnnotationsIsListener() throws Exception {
  assertTrue(StepListenerFactoryBean.isListener(new Object() {
    @BeforeStep
    public void foo(StepExecution execution) {
    }
  }));
}
origin: spring-projects/spring-batch

@Before
public void setUp() {
  factoryBean = new StepListenerFactoryBean();
}
origin: spring-projects/spring-batch

@Test
public void testNonListener() throws Exception {
  Object delegate = new Object();
  factoryBean.setDelegate(delegate);
  assertTrue(factoryBean.getObject() instanceof StepListener);
}
origin: spring-projects/spring-batch

@Test
public void testAnnotationsWithOrdered() throws Exception {
  Object delegate = new Ordered() {
    @BeforeStep
    public void foo(StepExecution execution) {
    }
    @Override
    public int getOrder() {
      return 3;
    }
  };
  StepListener listener = StepListenerFactoryBean.getListener(delegate);
  assertTrue("Listener is not of correct type", listener instanceof Ordered);
  assertEquals(3, ((Ordered) listener).getOrder());
}
origin: spring-projects/spring-batch

@Test
public void testInterfaceIsListener() throws Exception {
  assertTrue(StepListenerFactoryBean.isListener(new ThreeStepExecutionListener()));
}
origin: spring-projects/spring-batch

/**
 * Registers objects using the annotation based listener configuration.
 *
 * @param listener the object that has a method configured with listener annotation
 * @return this for fluent chaining
 */
public B listener(Object listener) {
  Set<Method> stepExecutionListenerMethods = new HashSet<>();
  stepExecutionListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), BeforeStep.class));
  stepExecutionListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), AfterStep.class));
  if(stepExecutionListenerMethods.size() > 0) {
    StepListenerFactoryBean factory = new StepListenerFactoryBean();
    factory.setDelegate(listener);
    properties.addStepExecutionListener((StepExecutionListener) factory.getObject());
  }
  @SuppressWarnings("unchecked")
  B result = (B) this;
  return result;
}
origin: spring-projects/spring-batch

protected void registerAsStreamsAndListeners(ItemReader<? extends I> itemReader,
    ItemProcessor<? super I, ? extends O> itemProcessor, ItemWriter<? super O> itemWriter) {
  for (Object itemHandler : new Object[] { itemReader, itemWriter, itemProcessor }) {
    if (itemHandler instanceof ItemStream) {
      stream((ItemStream) itemHandler);
    }
    if (StepListenerFactoryBean.isListener(itemHandler)) {
      StepListener listener = StepListenerFactoryBean.getListener(itemHandler);
      if (listener instanceof StepExecutionListener) {
        listener((StepExecutionListener) listener);
      }
      if (listener instanceof ChunkListener) {
        listener((ChunkListener) listener);
      }
      if (listener instanceof ItemReadListener<?> || listener instanceof ItemProcessListener<?, ?>
      || listener instanceof ItemWriteListener<?>) {
        itemListeners.add(listener);
      }
    }
  }
}
origin: spring-projects/spring-batch

@Test
public void testEmptySignatureAnnotation() {
  AbstractTestComponent delegate = new AbstractTestComponent() {
    @AfterWrite
    public void aMethod() {
      executed = true;
    }
  };
  factoryBean.setDelegate(delegate);
  @SuppressWarnings("unchecked")
  ItemWriteListener<String> listener = (ItemWriteListener<String>) factoryBean.getObject();
  listener.afterWrite(Arrays.asList("foo", "bar"));
  assertTrue(delegate.isExecuted());
}
origin: spring-projects/spring-batch

@Test
public void testAnnotatingInterfaceResultsInOneCall() throws Exception {
  MultipleAfterStep delegate = new MultipleAfterStep();
  factoryBean.setDelegate(delegate);
  Map<String, String> metaDataMap = new HashMap<>();
  metaDataMap.put(AFTER_STEP.getPropertyName(), "afterStep");
  factoryBean.setMetaDataMap(metaDataMap);
  StepListener listener = (StepListener) factoryBean.getObject();
  ((StepExecutionListener) listener).afterStep(stepExecution);
  assertEquals(1, delegate.callcount);
}
origin: spring-projects/spring-batch

@Test
public void testFactoryMethod() throws Exception {
  MultipleAfterStep delegate = new MultipleAfterStep();
  Object listener = StepListenerFactoryBean.getListener(delegate);
  assertTrue(listener instanceof StepExecutionListener);
  assertFalse(listener instanceof ChunkListener);
  ((StepExecutionListener) listener).beforeStep(stepExecution);
  assertEquals(1, delegate.callcount);
}
origin: spring-projects/spring-batch

@Test
public void testMixedIsListener() throws Exception {
  assertTrue(StepListenerFactoryBean.isListener(new MultipleAfterStep()));
}
origin: spring-projects/spring-batch

/**
 * Registers objects using the annotation based listener configuration.
 *
 * @param listener the object that has a method configured with listener annotation
 * @return this for fluent chaining
 */
@Override
@SuppressWarnings("unchecked")
public SimpleStepBuilder<I, O> listener(Object listener) {
  super.listener(listener);
  Set<Method> skipListenerMethods = new HashSet<>();
  skipListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), OnSkipInRead.class));
  skipListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), OnSkipInProcess.class));
  skipListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), OnSkipInWrite.class));
  if(skipListenerMethods.size() > 0) {
    StepListenerFactoryBean factory = new StepListenerFactoryBean();
    factory.setDelegate(listener);
    skipListeners.add((SkipListener) factory.getObject());
  }
  @SuppressWarnings("unchecked")
  SimpleStepBuilder<I, O> result = this;
  return result;
}
origin: spring-projects/spring-batch

@Test
public void testProxiedAnnotationsIsListener() throws Exception {
  Object delegate = new InitializingBean() {
    @BeforeStep
    public void foo(StepExecution execution) {
    }
    @Override
    public void afterPropertiesSet() throws Exception {
    }
  };
  ProxyFactory factory = new ProxyFactory(delegate);
  Object proxy = factory.getProxy();
  assertTrue(StepListenerFactoryBean.isListener(proxy));
  ((StepExecutionListener) StepListenerFactoryBean.getListener(proxy)).beforeStep(null);
}
origin: spring-projects/spring-batch

@Test
public void testRightSignatureAnnotation() {
  AbstractTestComponent delegate = new AbstractTestComponent() {
    @AfterWrite
    public void aMethod(List<String> items) {
      executed = true;
      assertEquals("foo", items.get(0));
      assertEquals("bar", items.get(1));
    }
  };
  factoryBean.setDelegate(delegate);
  @SuppressWarnings("unchecked")
  ItemWriteListener<String> listener = (ItemWriteListener<String>) factoryBean.getObject();
  listener.afterWrite(Arrays.asList("foo", "bar"));
  assertTrue(delegate.isExecuted());
}
origin: spring-projects/spring-batch

@Test
public void testAllThreeTypes() throws Exception {
  // Test to make sure if someone has annotated a method, implemented the
  // interface, and given a string
  // method name, that all three will be called
  ThreeStepExecutionListener delegate = new ThreeStepExecutionListener();
  factoryBean.setDelegate(delegate);
  Map<String, String> metaDataMap = new HashMap<>();
  metaDataMap.put(AFTER_STEP.getPropertyName(), "destroy");
  factoryBean.setMetaDataMap(metaDataMap);
  StepListener listener = (StepListener) factoryBean.getObject();
  ((StepExecutionListener) listener).afterStep(stepExecution);
  assertEquals(3, delegate.callcount);
}
org.springframework.batch.core.listenerStepListenerFactoryBean

Javadoc

This AbstractListenerFactoryBean implementation is used to create a StepListener.

Most used methods

  • <init>
  • getListener
    Convenience method to wrap any object and expose the appropriate StepListener interfaces.
  • getObject
  • isListener
    Convenience method to check whether the given object is or can be made into a StepListener.
  • setDelegate
  • setMetaDataMap

Popular in Java

  • Parsing JSON documents to java classes using gson
  • compareTo (BigDecimal)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getSupportFragmentManager (FragmentActivity)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • JFileChooser (javax.swing)
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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