Skip to content
Permalink
Browse files
BATCHEE-29 remove StepContext where not needed
most time it's simple redundant
  • Loading branch information
struberg committed Apr 24, 2014
1 parent b5a9760 commit 2f73d835878dccff03ec04b0c6b0afc5fa2736e5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
@@ -136,7 +136,7 @@ private PartitionPlan generatePartitionPlan() {
// Some of them may be null
final InjectionReferences injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, propertyList);
final PartitionMapper partitionMapperProxy =
ProxyFactory.createPartitionMapperProxy(factory, partitionMapper.getRef(), injectionRef, stepContext, jobExecutionImpl);
ProxyFactory.createPartitionMapperProxy(factory, partitionMapper.getRef(), injectionRef, jobExecutionImpl);


PartitionPlan mapperPlan = null;
@@ -431,14 +431,14 @@ protected void setupStepArtifacts() {
if (analyzer != null) {
final List<Property> propList = analyzer.getProperties() == null ? null : analyzer.getProperties().getPropertyList();
injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, propList);
analyzerProxy = ProxyFactory.createPartitionAnalyzerProxy(factory, analyzer.getRef(), injectionRef, stepContext, jobExecutionImpl);
analyzerProxy = ProxyFactory.createPartitionAnalyzerProxy(factory, analyzer.getRef(), injectionRef, jobExecutionImpl);
}

final org.apache.batchee.jaxb.PartitionReducer partitionReducer = step.getPartition().getReducer();
if (partitionReducer != null) {
final List<Property> propList = partitionReducer.getProperties() == null ? null : partitionReducer.getProperties().getPropertyList();
injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, propList);
partitionReducerProxy = ProxyFactory.createPartitionReducerProxy(factory, partitionReducer.getRef(), injectionRef, stepContext, jobExecutionImpl);
partitionReducerProxy = ProxyFactory.createPartitionReducerProxy(factory, partitionReducer.getRef(), injectionRef, jobExecutionImpl);
}

}
@@ -77,7 +77,7 @@ protected void setupStepArtifacts() {
* contexts may be null
*/
injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, propList);
this.collectorProxy = ProxyFactory.createPartitionCollectorProxy(factory, collector.getRef(), injectionRef, this.stepContext, jobExecutionImpl);
this.collectorProxy = ProxyFactory.createPartitionCollectorProxy(factory, collector.getRef(), injectionRef, jobExecutionImpl);
}
}
}
@@ -50,7 +50,7 @@ private void invokeBatchlet(final org.apache.batchee.jaxb.Batchlet batchlet) thr
final String batchletId = batchlet.getRef();
final List<Property> propList = (batchlet.getProperties() == null) ? null : batchlet.getProperties().getPropertyList();
final InjectionReferences injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, propList);
batchletProxy = ProxyFactory.createBatchletProxy(factory, batchletId, injectionRef, stepContext, jobExecutionImpl);
batchletProxy = ProxyFactory.createBatchletProxy(factory, batchletId, injectionRef, jobExecutionImpl);

if (!wasStopIssued()) {
String processRetVal = null;
@@ -17,7 +17,6 @@
package org.apache.batchee.container.impl.controller.chunk;


import org.apache.batchee.container.impl.StepContextImpl;
import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
import org.apache.batchee.container.proxy.CheckpointAlgorithmProxy;
import org.apache.batchee.container.proxy.InjectionReferences;
@@ -28,12 +27,12 @@

public final class CheckpointAlgorithmFactory {
public static CheckpointAlgorithmProxy getCheckpointAlgorithmProxy(final BatchArtifactFactory factory, final Step step, final InjectionReferences injectionReferences,
final StepContextImpl stepContext, final RuntimeJobExecution jobExecution) {
final RuntimeJobExecution jobExecution) {
final Chunk chunk = step.getChunk();
final String checkpointType = chunk.getCheckpointPolicy();
final CheckpointAlgorithmProxy proxy;
if ("custom".equalsIgnoreCase(checkpointType)) {
proxy = ProxyFactory.createCheckpointAlgorithmProxy(factory, chunk.getCheckpointAlgorithm().getRef(), injectionReferences, stepContext, jobExecution);
proxy = ProxyFactory.createCheckpointAlgorithmProxy(factory, chunk.getCheckpointAlgorithm().getRef(), injectionReferences, jobExecution);
} else /* "item" */ {
proxy = new CheckpointAlgorithmProxy(new ItemCheckpointAlgorithm());
}
@@ -674,23 +674,23 @@ private void initializeChunkArtifacts() {
final org.apache.batchee.jaxb.ItemReader itemReader = chunk.getReader();
final List<Property> itemReaderProps = itemReader.getProperties() == null ? null : itemReader.getProperties().getPropertyList();
final InjectionReferences injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, itemReaderProps);
readerProxy = ProxyFactory.createItemReaderProxy(artifactFactory, itemReader.getRef(), injectionRef, stepContext, jobExecutionImpl);
readerProxy = ProxyFactory.createItemReaderProxy(artifactFactory, itemReader.getRef(), injectionRef, jobExecutionImpl);
}

{
final org.apache.batchee.jaxb.ItemProcessor itemProcessor = chunk.getProcessor();
if (itemProcessor != null) {
final List<Property> itemProcessorProps = itemProcessor.getProperties() == null ? null : itemProcessor.getProperties().getPropertyList();
final InjectionReferences injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, itemProcessorProps);
processorProxy = ProxyFactory.createItemProcessorProxy(artifactFactory, itemProcessor.getRef(), injectionRef, stepContext, jobExecutionImpl);
processorProxy = ProxyFactory.createItemProcessorProxy(artifactFactory, itemProcessor.getRef(), injectionRef, jobExecutionImpl);
}
}

{
final org.apache.batchee.jaxb.ItemWriter itemWriter = chunk.getWriter();
final List<Property> itemWriterProps = itemWriter.getProperties() == null ? null : itemWriter.getProperties().getPropertyList();
final InjectionReferences injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, itemWriterProps);
writerProxy = ProxyFactory.createItemWriterProxy(artifactFactory, itemWriter.getRef(), injectionRef, stepContext, jobExecutionImpl);
writerProxy = ProxyFactory.createItemWriterProxy(artifactFactory, itemWriter.getRef(), injectionRef, jobExecutionImpl);
}

{
@@ -702,7 +702,7 @@ private void initializeChunkArtifacts() {
}

final InjectionReferences injectionRef = new InjectionReferences(jobExecutionImpl.getJobContext(), stepContext, propList);
checkpointProxy = CheckpointAlgorithmFactory.getCheckpointAlgorithmProxy(artifactFactory, step, injectionRef, stepContext, jobExecutionImpl);
checkpointProxy = CheckpointAlgorithmFactory.getCheckpointAlgorithmProxy(artifactFactory, step, injectionRef, jobExecutionImpl);
}

{
@@ -24,7 +24,6 @@
public class CheckpointAlgorithmProxy extends AbstractProxy<CheckpointAlgorithm> implements CheckpointAlgorithm {

private String checkpointType = null;
private String checkpointName = null;

/*
* Allow this to be public as a special case so we can easily treat the built-in algorithms
@@ -35,10 +34,8 @@ public CheckpointAlgorithmProxy(final CheckpointAlgorithm delegate) {

if (delegate instanceof ItemCheckpointAlgorithm) {
checkpointType = "item";
checkpointName = ItemCheckpointAlgorithm.class.getName();
} else {
checkpointType = "custom";
checkpointName = delegate.getClass().getName();
}

}
@@ -48,9 +45,6 @@ public String getCheckpointType() {
return checkpointType;
}

public String getCheckpointAlgorithmClassName() {
return checkpointName;
}

@Override
public void beginCheckpoint() {
@@ -20,7 +20,6 @@
import java.util.HashSet;
import java.util.Set;

import org.apache.batchee.container.impl.StepContextImpl;
import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
import org.apache.batchee.spi.BatchArtifactFactory;

@@ -68,6 +67,18 @@ public static InjectionReferences getInjectionReferences() {
return INJECTION_CONTEXT.get();
}

/**
* set the InjectionReferences into the ThreadLocal and return the previously stored value
*/
public static InjectionReferences setInjectionReferences(InjectionReferences injectionReferences) {
InjectionReferences oldRef = INJECTION_CONTEXT.get();
INJECTION_CONTEXT.set(injectionReferences);
if (injectionReferences == null) {
INJECTION_CONTEXT.remove();
}
return oldRef;
}

public static <T> T createProxy(T delegate, InjectionReferences injectionRefs, String... nonExceptionHandlingMethods) {
return (T) Proxy.newProxyInstance(delegate.getClass().getClassLoader(), getInterfaces(delegate.getClass()),
new BatchProxyInvocationHandler(delegate, injectionRefs, nonExceptionHandlingMethods));
@@ -87,7 +98,7 @@ public static Decider createDeciderProxy(final BatchArtifactFactory factory, fin
* Batchlet artifact
*/
public static Batchlet createBatchletProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final Batchlet loadedArtifact = (Batchlet) loadArtifact(factory, id, injectionRefs, execution);
return createProxy(loadedArtifact, injectionRefs);
}
@@ -97,27 +108,27 @@ public static Batchlet createBatchletProxy(final BatchArtifactFactory factory, f
*/

public static CheckpointAlgorithmProxy createCheckpointAlgorithmProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final CheckpointAlgorithm loadedArtifact = (CheckpointAlgorithm) loadArtifact(factory, id, injectionRefs, execution);
final CheckpointAlgorithmProxy proxy = new CheckpointAlgorithmProxy(loadedArtifact);
proxy.setStepContext(stepContext);
proxy.setStepContext(injectionRefs.getStepContext());
return proxy;
}

public static ItemReader createItemReaderProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final ItemReader loadedArtifact = (ItemReader) loadArtifact(factory, id, injectionRefs, execution);
return createProxy(loadedArtifact, injectionRefs, "readItem");
}

public static ItemProcessor createItemProcessorProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final ItemProcessor loadedArtifact = (ItemProcessor) loadArtifact(factory, id, injectionRefs, execution);
return createProxy(loadedArtifact, injectionRefs, "processItem");
}

public static ItemWriter createItemWriterProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final ItemWriter loadedArtifact = (ItemWriter) loadArtifact(factory, id, injectionRefs, execution);
return createProxy(loadedArtifact, injectionRefs, "writeItems");
}
@@ -127,25 +138,25 @@ public static ItemWriter createItemWriterProxy(final BatchArtifactFactory factor
*/

public static PartitionReducer createPartitionReducerProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final PartitionReducer loadedArtifact = (PartitionReducer) loadArtifact(factory, id, injectionRefs, execution);
return createProxy(loadedArtifact, injectionRefs);
}

public static PartitionMapper createPartitionMapperProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final PartitionMapper loadedArtifact = (PartitionMapper) loadArtifact(factory, id, injectionRefs, execution);
return createProxy(loadedArtifact, injectionRefs);
}

public static PartitionAnalyzer createPartitionAnalyzerProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final PartitionAnalyzer loadedArtifact = (PartitionAnalyzer) loadArtifact(factory, id, injectionRefs, execution);
return createProxy(loadedArtifact, injectionRefs);
}

public static PartitionCollector createPartitionCollectorProxy(final BatchArtifactFactory factory, final String id, final InjectionReferences injectionRefs,
final StepContextImpl stepContext, final RuntimeJobExecution execution) {
final RuntimeJobExecution execution) {
final PartitionCollector loadedArtifact = (PartitionCollector) loadArtifact(factory, id, injectionRefs, execution);
return createProxy(loadedArtifact, injectionRefs);
}

0 comments on commit 2f73d83

Please sign in to comment.