You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by rm...@apache.org on 2013/11/05 08:39:03 UTC
[26/62] importing batchee from github - a fork from the IBm RI
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/ListenerFactory.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/ListenerFactory.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/ListenerFactory.java
new file mode 100755
index 0000000..f568205
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/ListenerFactory.java
@@ -0,0 +1,358 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.impl.StepContextImpl;
+import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
+import org.apache.batchee.container.services.ServicesManager;
+import org.apache.batchee.jaxb.JSLJob;
+import org.apache.batchee.jaxb.Listener;
+import org.apache.batchee.jaxb.Listeners;
+import org.apache.batchee.jaxb.Property;
+import org.apache.batchee.jaxb.Step;
+
+import javax.batch.api.chunk.listener.ChunkListener;
+import javax.batch.api.chunk.listener.ItemProcessListener;
+import javax.batch.api.chunk.listener.ItemReadListener;
+import javax.batch.api.chunk.listener.ItemWriteListener;
+import javax.batch.api.chunk.listener.RetryProcessListener;
+import javax.batch.api.chunk.listener.RetryReadListener;
+import javax.batch.api.chunk.listener.RetryWriteListener;
+import javax.batch.api.chunk.listener.SkipProcessListener;
+import javax.batch.api.chunk.listener.SkipReadListener;
+import javax.batch.api.chunk.listener.SkipWriteListener;
+import javax.batch.api.listener.JobListener;
+import javax.batch.api.listener.StepListener;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+public class ListenerFactory {
+ private List<ListenerInfo> jobLevelListenerInfo = null;
+
+ private Map<String, List<ListenerInfo>> stepLevelListenerInfo = new ConcurrentHashMap<String, List<ListenerInfo>>();
+
+ /*
+ * Build job-level ListenerInfo(s) up-front, but build step-level ones
+ * lazily.
+ */
+ public ListenerFactory(final JSLJob jobModel, final InjectionReferences injectionRefs, final RuntimeJobExecution execution) {
+ jobLevelListenerInfo = new ArrayList<ListenerInfo>();
+
+ Listeners jobLevelListeners = jobModel.getListeners();
+
+ jobLevelListenerInfo.addAll(globalListeners("org.apache.batchee.job.listeners.before", injectionRefs, execution));
+ if (jobLevelListeners != null) {
+ for (final Listener listener : jobLevelListeners.getListenerList()) {
+ jobLevelListenerInfo.add(buildListenerInfo(listener, injectionRefs, execution));
+ }
+ }
+ jobLevelListenerInfo.addAll(globalListeners("org.apache.batchee.job.listeners.after", injectionRefs, execution));
+ }
+
+ private static Collection<ListenerInfo> globalListeners(final String key, final InjectionReferences injectionRefs, final RuntimeJobExecution execution) {
+ final String globalListeners = ServicesManager.value(key, null);
+ if (globalListeners != null) {
+ final String[] refs = globalListeners.split(",");
+
+ final Collection<ListenerInfo> list = new ArrayList<ListenerInfo>(refs.length);
+ for (final String ref : refs) {
+ final Listener listener = new Listener();
+ listener.setRef(ref);
+
+ list.add(buildListenerInfo(listener, injectionRefs, execution));
+ }
+
+ return list;
+ }
+ return Collections.emptyList();
+ }
+
+ /*
+ * Does NOT throw an exception if a step-level listener is annotated with
+ *
+ * @JobListener, even if that is the only type of listener annotation found.
+ */
+ private List<ListenerInfo> getStepListenerInfo(final Step step, final InjectionReferences injectionRefs, final RuntimeJobExecution execution) {
+ List<ListenerInfo> stepListenerInfoList = stepLevelListenerInfo.get(step.getId());
+ if (stepListenerInfoList == null) {
+ synchronized (this) {
+ stepListenerInfoList = stepLevelListenerInfo.get(step.getId());
+ if (stepListenerInfoList == null) {
+ stepListenerInfoList = new ArrayList<ListenerInfo>();
+ stepLevelListenerInfo.put(step.getId(), stepListenerInfoList);
+
+ stepListenerInfoList.addAll(globalListeners("org.apache.batchee.step.listeners.before", injectionRefs, execution));
+
+ final Listeners stepLevelListeners = step.getListeners();
+ if (stepLevelListeners != null) {
+ for (final Listener listener : stepLevelListeners.getListenerList()) {
+ stepListenerInfoList.add(buildListenerInfo(listener, injectionRefs, execution));
+ }
+ }
+
+ stepListenerInfoList.addAll(globalListeners("org.apache.batchee.step.listeners.after", injectionRefs, execution));
+ }
+ }
+ }
+ return stepListenerInfoList;
+ }
+
+ private static ListenerInfo buildListenerInfo(final Listener listener, final InjectionReferences injectionRefs, final RuntimeJobExecution execution) {
+ final String id = listener.getRef();
+ final List<Property> propList = (listener.getProperties() == null) ? null : listener.getProperties().getPropertyList();
+
+ injectionRefs.setProps(propList);
+ final Object listenerArtifact = ProxyFactory.loadArtifact(id, injectionRefs, execution);
+ if (listenerArtifact == null) {
+ throw new IllegalArgumentException("Load of artifact id: " + id + " returned <null>.");
+ }
+ return new ListenerInfo(listenerArtifact);
+
+ }
+
+ public List<JobListenerProxy> getJobListeners() {
+ final List<JobListenerProxy> retVal = new ArrayList<JobListenerProxy>();
+ for (final ListenerInfo li : jobLevelListenerInfo) {
+ if (li.isJobListener()) {
+ retVal.add(new JobListenerProxy((JobListener) li.getArtifact()));
+ }
+ }
+ return retVal;
+ }
+
+ public List<ChunkListenerProxy> getChunkListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<ChunkListenerProxy> retVal = new ArrayList<ChunkListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isChunkListener()) {
+ final ChunkListenerProxy proxy = new ChunkListenerProxy((ChunkListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<ItemProcessListenerProxy> getItemProcessListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<ItemProcessListenerProxy> retVal = new ArrayList<ItemProcessListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isItemProcessListener()) {
+ ItemProcessListenerProxy proxy = new ItemProcessListenerProxy((ItemProcessListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<ItemReadListenerProxy> getItemReadListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<ItemReadListenerProxy> retVal = new ArrayList<ItemReadListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isItemReadListener()) {
+ final ItemReadListenerProxy proxy = new ItemReadListenerProxy((ItemReadListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<ItemWriteListenerProxy> getItemWriteListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<ItemWriteListenerProxy> retVal = new ArrayList<ItemWriteListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isItemWriteListener()) {
+ final ItemWriteListenerProxy proxy = new ItemWriteListenerProxy((ItemWriteListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<RetryProcessListenerProxy> getRetryProcessListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<RetryProcessListenerProxy> retVal = new ArrayList<RetryProcessListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isRetryProcessListener()) {
+ final RetryProcessListenerProxy proxy = new RetryProcessListenerProxy((RetryProcessListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<RetryReadListenerProxy> getRetryReadListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<RetryReadListenerProxy> retVal = new ArrayList<RetryReadListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isRetryReadListener()) {
+ final RetryReadListenerProxy proxy = new RetryReadListenerProxy((RetryReadListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<RetryWriteListenerProxy> getRetryWriteListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<RetryWriteListenerProxy> retVal = new ArrayList<RetryWriteListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isRetryWriteListener()) {
+ final RetryWriteListenerProxy proxy = new RetryWriteListenerProxy((RetryWriteListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<SkipProcessListenerProxy> getSkipProcessListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<SkipProcessListenerProxy> retVal = new ArrayList<SkipProcessListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isSkipProcessListener()) {
+ final SkipProcessListenerProxy proxy = new SkipProcessListenerProxy((SkipProcessListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<SkipReadListenerProxy> getSkipReadListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<SkipReadListenerProxy> retVal = new ArrayList<SkipReadListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isSkipReadListener()) {
+ final SkipReadListenerProxy proxy = new SkipReadListenerProxy((SkipReadListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<SkipWriteListenerProxy> getSkipWriteListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<SkipWriteListenerProxy> retVal = new ArrayList<SkipWriteListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isSkipWriteListener()) {
+ final SkipWriteListenerProxy proxy = new SkipWriteListenerProxy((SkipWriteListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ public List<StepListenerProxy> getStepListeners(final Step step, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final List<ListenerInfo> stepListenerInfo = getStepListenerInfo(step, injectionRefs, execution);
+ final List<StepListenerProxy> retVal = new ArrayList<StepListenerProxy>();
+ for (final ListenerInfo li : stepListenerInfo) {
+ if (li.isStepListener()) {
+ final StepListenerProxy proxy = new StepListenerProxy((StepListener) li.getArtifact());
+ proxy.setStepContext(stepContext);
+ retVal.add(proxy);
+ }
+ }
+
+ return retVal;
+ }
+
+ private static class ListenerInfo {
+ private Object listenerArtifact = null;
+ private Class listenerArtifactClass = null;
+
+ private ListenerInfo(final Object listenerArtifact) {
+ this.listenerArtifact = listenerArtifact;
+ this.listenerArtifactClass = listenerArtifact.getClass();
+ }
+
+ Object getArtifact() {
+ return listenerArtifact;
+ }
+
+ boolean isJobListener() {
+ return JobListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isStepListener() {
+ return StepListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isChunkListener() {
+ return ChunkListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isItemProcessListener() {
+ return ItemProcessListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isItemReadListener() {
+ return ItemReadListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isItemWriteListener() {
+ return ItemWriteListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isRetryReadListener() {
+ return RetryReadListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isRetryWriteListener() {
+ return RetryWriteListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isRetryProcessListener() {
+ return RetryProcessListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isSkipProcessListener() {
+ return SkipProcessListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isSkipReadListener() {
+ return SkipReadListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+
+ boolean isSkipWriteListener() {
+ return SkipWriteListener.class.isAssignableFrom(listenerArtifactClass);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionAnalyzerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionAnalyzerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionAnalyzerProxy.java
new file mode 100755
index 0000000..305f971
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionAnalyzerProxy.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.partition.PartitionAnalyzer;
+import javax.batch.runtime.BatchStatus;
+import java.io.Serializable;
+
+public class PartitionAnalyzerProxy extends AbstractProxy<PartitionAnalyzer> implements PartitionAnalyzer {
+ PartitionAnalyzerProxy(final PartitionAnalyzer delegate) {
+ super(delegate);
+
+ }
+
+ @Override
+ public synchronized void analyzeCollectorData(final Serializable data) {
+ try {
+ this.delegate.analyzeCollectorData(data);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+
+ @Override
+ public synchronized void analyzeStatus(final BatchStatus batchStatus, final String exitStatus) {
+ try {
+ this.delegate.analyzeStatus(batchStatus, exitStatus);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionCollectorProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionCollectorProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionCollectorProxy.java
new file mode 100755
index 0000000..c3fcde2
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionCollectorProxy.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.partition.PartitionCollector;
+import java.io.Serializable;
+
+public class PartitionCollectorProxy extends AbstractProxy<PartitionCollector> implements PartitionCollector {
+ PartitionCollectorProxy(final PartitionCollector delegate) {
+ super(delegate);
+
+ }
+
+ @Override
+ public Serializable collectPartitionData() {
+ try {
+ return this.delegate.collectPartitionData();
+ } catch (Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionMapperProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionMapperProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionMapperProxy.java
new file mode 100755
index 0000000..05e5b54
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionMapperProxy.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.partition.PartitionMapper;
+import javax.batch.api.partition.PartitionPlan;
+
+public class PartitionMapperProxy extends AbstractProxy<PartitionMapper> implements PartitionMapper {
+ PartitionMapperProxy(final PartitionMapper delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public PartitionPlan mapPartitions() {
+ try {
+ return this.delegate.mapPartitions();
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionReducerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionReducerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionReducerProxy.java
new file mode 100755
index 0000000..b4b5e64
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/PartitionReducerProxy.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.partition.PartitionReducer;
+
+public class PartitionReducerProxy extends AbstractProxy<PartitionReducer> implements PartitionReducer {
+ PartitionReducerProxy(final PartitionReducer delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public void afterPartitionedStepCompletion(final PartitionStatus status) {
+ try {
+ this.delegate.afterPartitionedStepCompletion(status);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+
+ @Override
+ public void beforePartitionedStepCompletion() {
+ try {
+ this.delegate.beforePartitionedStepCompletion();
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+
+ @Override
+ public void beginPartitionedStep() {
+ try {
+ this.delegate.beginPartitionedStep();
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+
+ @Override
+ public void rollbackPartitionedStep() {
+ try {
+ this.delegate.rollbackPartitionedStep();
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/ProxyFactory.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/ProxyFactory.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/ProxyFactory.java
new file mode 100755
index 0000000..de27560
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/ProxyFactory.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.impl.StepContextImpl;
+import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
+import org.apache.batchee.container.services.ServicesManager;
+import org.apache.batchee.spi.BatchArtifactFactory;
+
+import javax.batch.api.Batchlet;
+import javax.batch.api.Decider;
+import javax.batch.api.chunk.CheckpointAlgorithm;
+import javax.batch.api.chunk.ItemProcessor;
+import javax.batch.api.chunk.ItemReader;
+import javax.batch.api.chunk.ItemWriter;
+import javax.batch.api.partition.PartitionAnalyzer;
+import javax.batch.api.partition.PartitionCollector;
+import javax.batch.api.partition.PartitionMapper;
+import javax.batch.api.partition.PartitionReducer;
+
+/*
+ * Introduce a level of indirection so proxies are not instantiated directly by newing them up.
+ */
+public class ProxyFactory {
+ private static final BatchArtifactFactory ARTIFACT_FACTORY = ServicesManager.service(BatchArtifactFactory.class);
+ private static final ThreadLocal<InjectionReferences> INJECTION_CONTEXT = new ThreadLocal<InjectionReferences>();
+
+ protected static Object loadArtifact(final String id, final InjectionReferences injectionReferences, final RuntimeJobExecution execution) {
+ INJECTION_CONTEXT.set(injectionReferences);
+ try {
+ final BatchArtifactFactory.Instance instance = ARTIFACT_FACTORY.load(id);
+ if (instance == null) {
+ return null;
+ }
+
+ if (instance.getReleasable() != null && execution != null) {
+ execution.addReleasable(instance.getReleasable());
+ }
+ return instance.getValue();
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ INJECTION_CONTEXT.remove();
+ }
+ }
+
+ public static InjectionReferences getInjectionReferences() {
+ return INJECTION_CONTEXT.get();
+ }
+
+ /*
+ * Decider
+ */
+ public static DeciderProxy createDeciderProxy(final String id, final InjectionReferences injectionRefs, final RuntimeJobExecution execution) {
+ return new DeciderProxy(Decider.class.cast(loadArtifact(id, injectionRefs, execution)));
+ }
+
+ /*
+ * Batchlet artifact
+ */
+ public static BatchletProxy createBatchletProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final Batchlet loadedArtifact = (Batchlet) loadArtifact(id, injectionRefs, execution);
+ final BatchletProxy proxy = new BatchletProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+
+ /*
+ * The four main chunk-related artifacts
+ */
+
+ public static CheckpointAlgorithmProxy createCheckpointAlgorithmProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final CheckpointAlgorithm loadedArtifact = (CheckpointAlgorithm) loadArtifact(id, injectionRefs, execution);
+ final CheckpointAlgorithmProxy proxy = new CheckpointAlgorithmProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+
+ public static ItemReaderProxy createItemReaderProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final ItemReader loadedArtifact = (ItemReader) loadArtifact(id, injectionRefs, execution);
+ final ItemReaderProxy proxy = new ItemReaderProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+
+ public static ItemProcessorProxy createItemProcessorProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final ItemProcessor loadedArtifact = (ItemProcessor) loadArtifact(id, injectionRefs, execution);
+ final ItemProcessorProxy proxy = new ItemProcessorProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+
+ public static ItemWriterProxy createItemWriterProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final ItemWriter loadedArtifact = (ItemWriter) loadArtifact(id, injectionRefs, execution);
+ final ItemWriterProxy proxy = new ItemWriterProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+
+ /*
+ * The four partition-related artifacts
+ */
+
+ public static PartitionReducerProxy createPartitionReducerProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final PartitionReducer loadedArtifact = (PartitionReducer) loadArtifact(id, injectionRefs, execution);
+ final PartitionReducerProxy proxy = new PartitionReducerProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+
+ public static PartitionMapperProxy createPartitionMapperProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final PartitionMapper loadedArtifact = (PartitionMapper) loadArtifact(id, injectionRefs, execution);
+ final PartitionMapperProxy proxy = new PartitionMapperProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+
+ public static PartitionAnalyzerProxy createPartitionAnalyzerProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final PartitionAnalyzer loadedArtifact = (PartitionAnalyzer) loadArtifact(id, injectionRefs, execution);
+ final PartitionAnalyzerProxy proxy = new PartitionAnalyzerProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+
+ public static PartitionCollectorProxy createPartitionCollectorProxy(final String id, final InjectionReferences injectionRefs, final StepContextImpl stepContext, final RuntimeJobExecution execution) {
+ final PartitionCollector loadedArtifact = (PartitionCollector) loadArtifact(id, injectionRefs, execution);
+ final PartitionCollectorProxy proxy = new PartitionCollectorProxy(loadedArtifact);
+ proxy.setStepContext(stepContext);
+ return proxy;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryProcessListenerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryProcessListenerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryProcessListenerProxy.java
new file mode 100755
index 0000000..70f818d
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryProcessListenerProxy.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.chunk.listener.RetryProcessListener;
+
+public class RetryProcessListenerProxy extends AbstractProxy<RetryProcessListener> implements RetryProcessListener {
+ RetryProcessListenerProxy(final RetryProcessListener delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public void onRetryProcessException(final Object item, final Exception ex) {
+ try {
+ this.delegate.onRetryProcessException(item, ex);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryReadListenerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryReadListenerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryReadListenerProxy.java
new file mode 100755
index 0000000..75537fb
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryReadListenerProxy.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.chunk.listener.RetryReadListener;
+
+public class RetryReadListenerProxy extends AbstractProxy<RetryReadListener> implements RetryReadListener {
+ RetryReadListenerProxy(final RetryReadListener delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public void onRetryReadException(final Exception ex) {
+ try {
+ this.delegate.onRetryReadException(ex);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryWriteListenerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryWriteListenerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryWriteListenerProxy.java
new file mode 100755
index 0000000..084b29d
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/RetryWriteListenerProxy.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.chunk.listener.RetryWriteListener;
+import java.util.List;
+
+public class RetryWriteListenerProxy extends AbstractProxy<RetryWriteListener> implements RetryWriteListener {
+ RetryWriteListenerProxy(final RetryWriteListener delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public void onRetryWriteException(final List<Object> items, final Exception ex) {
+ try {
+ this.delegate.onRetryWriteException(items, ex);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipProcessListenerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipProcessListenerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipProcessListenerProxy.java
new file mode 100755
index 0000000..ec305fd
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipProcessListenerProxy.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.chunk.listener.SkipProcessListener;
+
+public class SkipProcessListenerProxy extends AbstractProxy<SkipProcessListener> implements SkipProcessListener {
+ SkipProcessListenerProxy(final SkipProcessListener delegate) {
+ super(delegate);
+
+ }
+
+ @Override
+ public void onSkipProcessItem(final Object item, final Exception ex) {
+ try {
+ this.delegate.onSkipProcessItem(item, ex);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipReadListenerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipReadListenerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipReadListenerProxy.java
new file mode 100755
index 0000000..190c467
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipReadListenerProxy.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.chunk.listener.SkipReadListener;
+
+public class SkipReadListenerProxy extends AbstractProxy<SkipReadListener> implements SkipReadListener {
+ SkipReadListenerProxy(final SkipReadListener delegate) {
+ super(delegate);
+
+ }
+
+ @Override
+ public void onSkipReadItem(final Exception ex) {
+ try {
+ this.delegate.onSkipReadItem(ex);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipWriteListenerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipWriteListenerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipWriteListenerProxy.java
new file mode 100755
index 0000000..1b3a0b7
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/SkipWriteListenerProxy.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.chunk.listener.SkipWriteListener;
+import java.util.List;
+
+public class SkipWriteListenerProxy extends AbstractProxy<SkipWriteListener> implements SkipWriteListener {
+ SkipWriteListenerProxy(final SkipWriteListener delegate) {
+ super(delegate);
+
+ }
+
+ @Override
+ public void onSkipWriteItem(final List<Object> items, final Exception ex) {
+ try {
+ this.delegate.onSkipWriteItem(items, ex);
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/proxy/StepListenerProxy.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/proxy/StepListenerProxy.java b/jbatch/src/main/java/org/apache/batchee/container/proxy/StepListenerProxy.java
new file mode 100755
index 0000000..1f00693
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/proxy/StepListenerProxy.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.container.proxy;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+
+import javax.batch.api.listener.StepListener;
+
+public class StepListenerProxy extends AbstractProxy<StepListener> implements StepListener {
+ StepListenerProxy(final StepListener delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public void afterStep() {
+ try {
+ this.delegate.afterStep();
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+
+ }
+
+ @Override
+ public void beforeStep() {
+ try {
+ this.delegate.beforeStep();
+ } catch (final Exception e) {
+ this.stepContext.setException(e);
+ throw new BatchContainerRuntimeException(e);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java b/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java
new file mode 100755
index 0000000..e423c18
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.container.services;
+
+import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
+import org.apache.batchee.container.util.BatchFlowInSplitWorkUnit;
+import org.apache.batchee.container.util.BatchPartitionWorkUnit;
+import org.apache.batchee.container.util.BatchWorkUnit;
+import org.apache.batchee.container.util.FlowInSplitBuilderConfig;
+import org.apache.batchee.container.util.PartitionsBuilderConfig;
+import org.apache.batchee.spi.BatchService;
+
+import javax.batch.operations.JobExecutionAlreadyCompleteException;
+import javax.batch.operations.JobExecutionNotMostRecentException;
+import javax.batch.operations.JobExecutionNotRunningException;
+import javax.batch.operations.JobRestartException;
+import javax.batch.operations.JobStartException;
+import javax.batch.operations.NoSuchJobExecutionException;
+import javax.batch.runtime.JobInstance;
+import java.util.List;
+import java.util.Properties;
+
+public interface BatchKernelService extends BatchService {
+ InternalJobExecution getJobExecution(long executionId) throws NoSuchJobExecutionException;
+
+ InternalJobExecution restartJob(long executionID, Properties overrideJobParameters) throws JobRestartException, JobExecutionAlreadyCompleteException, JobExecutionNotMostRecentException, NoSuchJobExecutionException;
+
+ InternalJobExecution startJob(String jobXML, Properties jobParameters) throws JobStartException;
+
+ void stopJob(long executionID) throws NoSuchJobExecutionException, JobExecutionNotRunningException;
+
+ void jobExecutionDone(RuntimeJobExecution jobExecution);
+
+ int getJobInstanceCount(String jobName);
+
+ JobInstance getJobInstance(long instanceId);
+
+ List<BatchPartitionWorkUnit> buildNewParallelPartitions(PartitionsBuilderConfig config) throws JobRestartException, JobStartException;
+
+ List<BatchPartitionWorkUnit> buildOnRestartParallelPartitions(PartitionsBuilderConfig config) throws JobRestartException, JobExecutionAlreadyCompleteException, JobExecutionNotMostRecentException;
+
+ void startGeneratedJob(BatchWorkUnit batchWork);
+
+ void restartGeneratedJob(BatchWorkUnit batchWork) throws JobRestartException;
+
+ boolean isExecutionRunning(long executionId);
+
+ BatchFlowInSplitWorkUnit buildNewFlowInSplitWorkUnit(
+ FlowInSplitBuilderConfig config);
+
+ BatchFlowInSplitWorkUnit buildOnRestartFlowInSplitWorkUnit(
+ FlowInSplitBuilderConfig config);
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/InternalJobExecution.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/InternalJobExecution.java b/jbatch/src/main/java/org/apache/batchee/container/services/InternalJobExecution.java
new file mode 100755
index 0000000..32e6676
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/InternalJobExecution.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2013 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.container.services;
+
+import org.apache.batchee.container.impl.JobContextImpl;
+
+import javax.batch.runtime.JobExecution;
+import java.sql.Timestamp;
+import java.util.Properties;
+
+public interface InternalJobExecution extends JobExecution {
+ void setBatchStatus(String status);
+ void setCreateTime(Timestamp ts);
+ void setEndTime(Timestamp ts);
+ void setExitStatus(String status);
+ void setLastUpdateTime(Timestamp ts);
+ void setStartTime(Timestamp ts);
+ void setJobParameters(Properties jProps);
+ long getInstanceId();
+ void setJobContext(JobContextImpl jobContext);
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/JobStatusManagerService.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/JobStatusManagerService.java b/jbatch/src/main/java/org/apache/batchee/container/services/JobStatusManagerService.java
new file mode 100755
index 0000000..ebda1b5
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/JobStatusManagerService.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.services;
+
+import org.apache.batchee.container.exception.BatchContainerServiceException;
+import org.apache.batchee.container.status.JobStatus;
+import org.apache.batchee.container.status.StepStatus;
+import org.apache.batchee.spi.BatchService;
+
+import javax.batch.runtime.BatchStatus;
+
+public interface JobStatusManagerService extends BatchService {
+
+ /**
+ * This method creates an entry for a new job instance
+ */
+ JobStatus createJobStatus(long jobInstanceId) throws BatchContainerServiceException;
+
+ void updateJobStatus(JobStatus jobStatus);
+
+ /**
+ * Returns the JobStatus for a given jobInstance id
+ *
+ * @param jobInstanceId
+ * @return
+ * @throws BatchContainerServiceException
+ */
+ JobStatus getJobStatus(long jobInstanceId) throws BatchContainerServiceException;
+
+ JobStatus getJobStatusFromExecutionId(long executionId) throws BatchContainerServiceException;
+
+ void updateJobBatchStatus(long jobInstanceId, BatchStatus batchStatus) throws BatchContainerServiceException;
+
+ void updateJobExecutionStatus(long jobInstanceId, BatchStatus batchStatus, String exitStatus) throws BatchContainerServiceException;
+
+ void updateJobStatusFromJSLStop(long jobInstanceId, String restartOn) throws BatchContainerServiceException;
+
+ /*
+ * A side effect of this method is that it nulls out the 'restartOn' value from the previous execution gets zeroed out.
+ *
+ * Also sets BatchStatus to STARTING
+ */
+ void updateJobStatusWithNewExecution(long jobInstanceId, long newExecutionId) throws BatchContainerServiceException;
+
+
+ void updateJobCurrentStep(long jobInstanceId, String currentStepName) throws BatchContainerServiceException;
+
+ /**
+ * Creates an entry for the step in the stepstatus table during jobsetup
+ *
+ * @param stepExecutionId
+ * @throws BatchContainerServiceException
+ */
+ StepStatus createStepStatus(long stepExecutionId) throws BatchContainerServiceException;
+
+ void updateStepStatus(long stepExecutionId, StepStatus newStepStatus) throws BatchContainerServiceException;
+
+ StepStatus getStepStatus(long jobInstanceId, String stepId) throws BatchContainerServiceException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java b/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java
new file mode 100755
index 0000000..46cfaac
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java
@@ -0,0 +1,225 @@
+/*
+ *
+ * Copyright 2012,2013 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.container.services;
+
+import org.apache.batchee.container.exception.BatchContainerRuntimeException;
+import org.apache.batchee.container.exception.BatchContainerServiceException;
+import org.apache.batchee.container.services.executor.DefaultThreadPoolService;
+import org.apache.batchee.container.services.factory.CDIBatchArtifactFactory;
+import org.apache.batchee.container.services.factory.DefaultBatchArtifactFactory;
+import org.apache.batchee.container.services.kernel.DefaultBatchKernel;
+import org.apache.batchee.container.services.loader.DefaultJobXMLLoaderService;
+import org.apache.batchee.container.services.locator.SingletonLocator;
+import org.apache.batchee.container.services.persistence.MemoryPersistenceManager;
+import org.apache.batchee.container.services.security.DefaultSecurityService;
+import org.apache.batchee.container.services.status.DefaultJobStatusManager;
+import org.apache.batchee.container.services.transaction.DefaultBatchTransactionService;
+import org.apache.batchee.container.util.BatchContainerConstants;
+import org.apache.batchee.spi.BatchArtifactFactory;
+import org.apache.batchee.spi.BatchService;
+import org.apache.batchee.spi.BatchThreadPoolService;
+import org.apache.batchee.spi.JobXMLLoaderService;
+import org.apache.batchee.spi.PersistenceManagerService;
+import org.apache.batchee.spi.SecurityService;
+import org.apache.batchee.spi.TransactionManagementService;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+
+public class ServicesManager implements BatchContainerConstants {
+ private final static Logger LOGGER = Logger.getLogger(ServicesManager.class.getName());
+
+ private static final String SERVICES_CONFIGURATION_FILE = "/batchee.properties";
+
+ // Use class names instead of Class objects to not drag in any dependencies and to easily interact with properties
+ private static final Map<String, String> SERVICE_IMPL_CLASS_NAMES = new ConcurrentHashMap<String, String>();
+ static {
+ SERVICE_IMPL_CLASS_NAMES.put(TransactionManagementService.class.getName(), DefaultBatchTransactionService.class.getName());
+ // SERVICE_IMPL_CLASS_NAMES.put(PersistenceManagerService.class.getName(), JDBCPersistenceManager.class.getName()); // too slow in embedded mode to be usable because of init step
+ SERVICE_IMPL_CLASS_NAMES.put(PersistenceManagerService.class.getName(), MemoryPersistenceManager.class.getName());
+ SERVICE_IMPL_CLASS_NAMES.put(JobStatusManagerService.class.getName(), DefaultJobStatusManager.class.getName());
+ SERVICE_IMPL_CLASS_NAMES.put(BatchThreadPoolService.class.getName(), DefaultThreadPoolService.class.getName());
+ SERVICE_IMPL_CLASS_NAMES.put(BatchKernelService.class.getName(), DefaultBatchKernel.class.getName());
+ SERVICE_IMPL_CLASS_NAMES.put(JobXMLLoaderService.class.getName(), DefaultJobXMLLoaderService.class.getName());
+ SERVICE_IMPL_CLASS_NAMES.put(SecurityService.class.getName(), DefaultSecurityService.class.getName());
+ try {
+ Thread.currentThread().getContextClassLoader().loadClass("javax.enterprise.inject.spi.BeanManager");
+ SERVICE_IMPL_CLASS_NAMES.put(BatchArtifactFactory.class.getName(), CDIBatchArtifactFactory.class.getName());
+ } catch (final Throwable th) {
+ SERVICE_IMPL_CLASS_NAMES.put(BatchArtifactFactory.class.getName(), DefaultBatchArtifactFactory.class.getName());
+ }
+
+ setServicesManagerLocator(SingletonLocator.INSTANCE); // default init
+ }
+
+ private static ServicesManagerLocator servicesManagerLocator;
+
+ // designed to be used from app or a server
+ public static void setServicesManagerLocator(final ServicesManagerLocator locator) {
+ servicesManagerLocator = locator;
+ }
+
+ public static <T extends BatchService> T service(final Class<T> api) {
+ return api.cast(Proxy.newProxyInstance(ServicesManager.class.getClassLoader(), new Class<?>[]{ api }, new ServiceHandler<T>(api)));
+ }
+
+ public static String value(final String key, final String defaultValue) {
+ return servicesManagerLocator.find().batchRuntimeConfig.getProperty(key, defaultValue);
+ }
+
+ // Declared 'volatile' to allow use in double-checked locking. This 'isInited'
+ // refers to whether the configuration has been hardened and possibly the
+ // first service impl loaded, not whether the instance has merely been instantiated.
+ private final byte[] isInitedLock = new byte[0];
+ private volatile boolean isInited = false;
+
+ private Properties batchRuntimeConfig;
+ private boolean logServices;
+
+ // Registry of all current services
+ private final ConcurrentHashMap<String, BatchService> serviceRegistry = new ConcurrentHashMap<String, BatchService>();
+
+ /**
+ * Init doesn't actually load the service impls, which are still loaded lazily. What it does is it
+ * hardens the config. This is necessary since the batch runtime by and large is not dynamically
+ * configurable, (e.g. via MBeans). Things like the database config used by the batch runtime's
+ * persistent store are hardened then, as are the names of the service impls to use.
+ */
+ public void init(final Properties props) {
+ // Use double-checked locking with volatile.
+ if (!isInited) {
+ synchronized (isInitedLock) {
+ if (!isInited) {
+ batchRuntimeConfig = new Properties();
+
+ batchRuntimeConfig.putAll(SERVICE_IMPL_CLASS_NAMES); // defaults
+
+ // file in the classloader
+ final InputStream batchServicesListInputStream = getClass().getResourceAsStream(SERVICES_CONFIGURATION_FILE);
+ if (batchServicesListInputStream != null) {
+ try {
+ batchRuntimeConfig.load(batchServicesListInputStream);
+ } catch (final Exception e) {
+ LOGGER.config("Error loading " + SERVICES_CONFIGURATION_FILE + " Exception=" + e.toString());
+ } finally {
+ try {
+ batchServicesListInputStream.close();
+ } catch (final IOException e) {
+ // no-op
+ }
+ }
+ }
+
+ // API overriding
+ if (props != null) {
+ batchRuntimeConfig.putAll(props);
+ }
+
+ // JVM instance overriding
+ batchRuntimeConfig.putAll(System.getProperties());
+
+ logServices = Boolean.parseBoolean(batchRuntimeConfig.getProperty("batchee.service-manager.log", "false"));
+
+ isInited = Boolean.TRUE;
+ }
+ }
+ }
+ }
+
+ private <T extends BatchService> T getService(final Class<T> clazz) throws BatchContainerServiceException {
+ T service = clazz.cast(serviceRegistry.get(clazz.getName()));
+ if (service == null) {
+ // Probably don't want to be loading two on two different threads so lock the whole table.
+ synchronized (serviceRegistry) {
+ service = clazz.cast(serviceRegistry.get(clazz.getName()));
+ if (service == null) {
+ service = loadService(clazz);
+ service.init(batchRuntimeConfig);
+ serviceRegistry.putIfAbsent(clazz.getName(), service);
+ }
+ }
+ }
+ return service;
+ }
+
+ private <T extends BatchService> T loadService(final Class<T> serviceType) {
+ T service = null;
+ String className = batchRuntimeConfig.getProperty(serviceType.getSimpleName());
+ try {
+ if (className != null) {
+ service = load(serviceType, className);
+ } else {
+ className = batchRuntimeConfig.getProperty(serviceType.getName());
+ if (className != null) {
+ service = load(serviceType, className);
+ }
+ }
+ } catch (final Throwable e1) {
+ throw new IllegalArgumentException("Could not instantiate service " + className + " due to exception: " + e1);
+ }
+
+ if (service == null) {
+ throw new BatchContainerRuntimeException("Instantiate of service=: " + className + " returned null. Aborting...");
+ }
+
+ if (logServices) {
+ LOGGER.info("Using " + service + " (" + className + ") as " + serviceType.getName());
+ }
+
+ return service;
+ }
+
+ private static <T> T load(final Class<T> expected, final String className) throws Exception {
+ final Class<?> cls = Class.forName(className);
+ if (cls != null) {
+ if (cls.getConstructor() != null) {
+ return expected.cast(cls.newInstance());
+ }
+ throw new BatchContainerRuntimeException("Service class " + className + " should have a default constructor defined");
+ }
+ throw new Exception("Exception loading Service class " + className + " make sure it exists");
+ }
+
+ // just an handler getting the right service instance using the ServicesManagerLocator
+ private static class ServiceHandler<T extends BatchService> implements InvocationHandler {
+ private final Class<T> service;
+
+ public ServiceHandler(final Class<T> api) {
+ this.service = api;
+ }
+
+ @Override
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
+ final T instance = servicesManagerLocator.find().getService(service);
+ try {
+ return method.invoke(instance, args);
+ } catch (final InvocationTargetException ite) {
+ throw ite.getCause();
+ }
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManagerLocator.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManagerLocator.java b/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManagerLocator.java
new file mode 100644
index 0000000..3897ac0
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManagerLocator.java
@@ -0,0 +1,22 @@
+/*
+ *
+ * Copyright 2012,2013 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.container.services;
+
+public interface ServicesManagerLocator {
+ ServicesManager find();
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/executor/AbstractThreadPoolService.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/executor/AbstractThreadPoolService.java b/jbatch/src/main/java/org/apache/batchee/container/services/executor/AbstractThreadPoolService.java
new file mode 100755
index 0000000..ff704dd
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/executor/AbstractThreadPoolService.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2013 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.services.executor;
+
+import org.apache.batchee.container.exception.BatchContainerServiceException;
+import org.apache.batchee.spi.BatchThreadPoolService;
+
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+
+import static org.apache.batchee.container.util.ClassLoaderAwareHandler.runnableLoaderAware;
+
+public abstract class AbstractThreadPoolService implements BatchThreadPoolService {
+ protected ExecutorService executorService;
+
+ protected abstract ExecutorService newExecutorService(Properties batchConfig);
+
+ @Override
+ public void init(final Properties batchConfig) throws BatchContainerServiceException {
+ executorService = newExecutorService(batchConfig);
+ }
+
+ @Override
+ public void shutdown() throws BatchContainerServiceException {
+ executorService.shutdownNow();
+ executorService = null;
+ }
+
+ @Override
+ public void executeTask(final Runnable work, final Object config) {
+ executorService.execute(runnableLoaderAware(work));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/executor/BatcheeThreadFactory.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/executor/BatcheeThreadFactory.java b/jbatch/src/main/java/org/apache/batchee/container/services/executor/BatcheeThreadFactory.java
new file mode 100644
index 0000000..2affe9a
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/executor/BatcheeThreadFactory.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.services.executor;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class BatcheeThreadFactory implements ThreadFactory {
+ public static final ThreadFactory INSTANCE = new BatcheeThreadFactory();
+
+ private static final ThreadGroup GROUP = System.getSecurityManager() != null ? System.getSecurityManager().getThreadGroup() : Thread.currentThread().getThreadGroup();
+ private static final String PREFIX = "batchee-thread-";
+ private static final AtomicInteger THREAD_NUMBER = new AtomicInteger(1);
+
+ @Override
+ public Thread newThread(final Runnable r) {
+ final ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ // avoid leaks when BatchEE is in the container
+ Thread.currentThread().setContextClassLoader(BatcheeThreadFactory.class.getClassLoader());
+ try {
+ final Thread t = new Thread(GROUP, r, PREFIX + THREAD_NUMBER.getAndIncrement(), 0);
+ if (!t.isDaemon()) {
+ t.setDaemon(true);
+ }
+ if (t.getPriority() != Thread.NORM_PRIORITY) {
+ t.setPriority(Thread.NORM_PRIORITY);
+ }
+ return t;
+ } finally {
+ Thread.currentThread().setContextClassLoader(loader);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/executor/BoundedThreadPoolService.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/executor/BoundedThreadPoolService.java b/jbatch/src/main/java/org/apache/batchee/container/services/executor/BoundedThreadPoolService.java
new file mode 100755
index 0000000..f6d6c8a
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/executor/BoundedThreadPoolService.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2013 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.services.executor;
+
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class BoundedThreadPoolService extends AbstractThreadPoolService {
+ public static final String BOUNDED_THREADPOOL_MAX_POOL_SIZE = "BOUNDED_THREADPOOL_MAX_POOL_SIZE";
+ public static final String BOUNDED_THREADPOOL_MIN_POOL_SIZE = "BOUNDED_THREADPOOL_MIN_POOL_SIZE";
+ public static final String BOUNDED_THREADPOOL_KEEP_ALIVE_TIME = "BOUNDED_THREADPOOL_KEEP_ALIVE_TIME";
+ public static final String BOUNDED_THREADPOOL_QUEUE_SIZE = "BOUNDED_THREADPOOL_QUEUE_SIZE";
+
+ @Override
+ protected ExecutorService newExecutorService(Properties batchConfig) {
+ return new ThreadPoolExecutor(
+ getInt(batchConfig, BOUNDED_THREADPOOL_MIN_POOL_SIZE, "3"),
+ getInt(batchConfig, BOUNDED_THREADPOOL_MAX_POOL_SIZE, "10"),
+ getInt(batchConfig, BOUNDED_THREADPOOL_KEEP_ALIVE_TIME, "900"), TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(getInt(batchConfig, BOUNDED_THREADPOOL_QUEUE_SIZE, "4096")),
+ BatcheeThreadFactory.INSTANCE);
+ }
+
+ private static int getInt(final Properties batchConfig, final String key, final String defaultValue) {
+ return Integer.parseInt(batchConfig.getProperty(key, defaultValue));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/executor/DefaultThreadPoolService.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/executor/DefaultThreadPoolService.java b/jbatch/src/main/java/org/apache/batchee/container/services/executor/DefaultThreadPoolService.java
new file mode 100755
index 0000000..3d92e15
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/executor/DefaultThreadPoolService.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2012,2013 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.batchee.container.services.executor;
+
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class DefaultThreadPoolService extends AbstractThreadPoolService {
+ @Override
+ protected ExecutorService newExecutorService(Properties batchConfig) {
+ return Executors.newCachedThreadPool(BatcheeThreadFactory.INSTANCE);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/efa64877/jbatch/src/main/java/org/apache/batchee/container/services/executor/JNDIThreadPoolService.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/executor/JNDIThreadPoolService.java b/jbatch/src/main/java/org/apache/batchee/container/services/executor/JNDIThreadPoolService.java
new file mode 100755
index 0000000..35d3e5f
--- /dev/null
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/executor/JNDIThreadPoolService.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2013 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.container.services.executor;
+
+import org.apache.batchee.container.exception.BatchContainerServiceException;
+import org.apache.batchee.spi.BatchThreadPoolService;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+
+import static org.apache.batchee.container.util.ClassLoaderAwareHandler.runnableLoaderAware;
+
+public class JNDIThreadPoolService implements BatchThreadPoolService {
+ public static final String THREADPOOL_JNDI_LOCATION = "thread-pool.jndi";
+
+ public final String DEFAULT_JNDI_LOCATION = "java:comp/DefaultManagedExecutorService";
+
+ private String jndiLocation = null;
+
+ @Override
+ public void init(final Properties batchConfig) {
+ // Don't want to get/cache the actual threadpool here since we want to do a JNDI lookup each time.
+ jndiLocation = batchConfig.getProperty(THREADPOOL_JNDI_LOCATION, DEFAULT_JNDI_LOCATION);
+ }
+
+ public void executeTask(Runnable work, Object config) {
+ try {
+ final Context ctx = new InitialContext();
+ final ExecutorService delegateService = (ExecutorService) ctx.lookup(jndiLocation);
+ delegateService.execute(runnableLoaderAware(work));
+ } catch (final NamingException e) {
+ throw new BatchContainerServiceException(e);
+ }
+ }
+
+ @Override
+ public void shutdown() {
+ // no-op
+ }
+}