Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed dependency on classes from repeat package

  • Loading branch information...
commit c1c16d3e23b579a688e44467ff0777832b69792d 1 parent 9dd0346
Thomas Risberg authored
Showing with 2 additions and 7,454 deletions.
  1. +0 −80 src/main/java/org/springframework/repeat/CompletionPolicy.java
  2. +0 −44 src/main/java/org/springframework/repeat/RepeatCallback.java
  3. +0 −91 src/main/java/org/springframework/repeat/RepeatContext.java
  4. +0 −31 src/main/java/org/springframework/repeat/RepeatException.java
  5. +0 −80 src/main/java/org/springframework/repeat/RepeatListener.java
  6. +0 −47 src/main/java/org/springframework/repeat/RepeatOperations.java
  7. +0 −48 src/main/java/org/springframework/repeat/RepeatStatus.java
  8. +0 −61 src/main/java/org/springframework/repeat/callback/NestedRepeatCallback.java
  9. +0 −7 src/main/java/org/springframework/repeat/callback/package.html
  10. +0 −115 src/main/java/org/springframework/repeat/context/RepeatContextCounter.java
  11. +0 −178 src/main/java/org/springframework/repeat/context/RepeatContextSupport.java
  12. +0 −161 src/main/java/org/springframework/repeat/context/SynchronizedAttributeAccessor.java
  13. +0 −7 src/main/java/org/springframework/repeat/context/package.html
  14. +0 −49 src/main/java/org/springframework/repeat/exception/CompositeExceptionHandler.java
  15. +0 −39 src/main/java/org/springframework/repeat/exception/DefaultExceptionHandler.java
  16. +0 −48 src/main/java/org/springframework/repeat/exception/ExceptionHandler.java
  17. +0 −111 src/main/java/org/springframework/repeat/exception/LogOrRethrowExceptionHandler.java
  18. +0 −150 src/main/java/org/springframework/repeat/exception/RethrowOnThresholdExceptionHandler.java
  19. +0 −147 src/main/java/org/springframework/repeat/exception/SimpleLimitExceptionHandler.java
  20. +0 −7 src/main/java/org/springframework/repeat/exception/package.html
  21. +0 −203 src/main/java/org/springframework/repeat/interceptor/RepeatOperationsInterceptor.java
  22. +0 −7 src/main/java/org/springframework/repeat/interceptor/package.html
  23. +0 −99 src/main/java/org/springframework/repeat/listener/CompositeRepeatListener.java
  24. +0 −46 src/main/java/org/springframework/repeat/listener/RepeatListenerSupport.java
  25. +0 −7 src/main/java/org/springframework/repeat/listener/package.html
  26. +0 −7 src/main/java/org/springframework/repeat/package.html
  27. +0 −77 src/main/java/org/springframework/repeat/policy/CompletionPolicySupport.java
  28. +0 −133 src/main/java/org/springframework/repeat/policy/CompositeCompletionPolicy.java
  29. +0 −132 src/main/java/org/springframework/repeat/policy/CountingCompletionPolicy.java
  30. +0 −53 src/main/java/org/springframework/repeat/policy/DefaultResultCompletionPolicy.java
  31. +0 −115 src/main/java/org/springframework/repeat/policy/SimpleCompletionPolicy.java
  32. +0 −98 src/main/java/org/springframework/repeat/policy/TimeoutTerminationPolicy.java
  33. +0 −7 src/main/java/org/springframework/repeat/policy/package.html
  34. +0 −37 src/main/java/org/springframework/repeat/support/RepeatInternalState.java
  35. +0 −35 src/main/java/org/springframework/repeat/support/RepeatInternalStateSupport.java
  36. +0 −104 src/main/java/org/springframework/repeat/support/RepeatSynchronizationManager.java
  37. +0 −476 src/main/java/org/springframework/repeat/support/RepeatTemplate.java
  38. +0 −52 src/main/java/org/springframework/repeat/support/ResultHolder.java
  39. +0 −176 src/main/java/org/springframework/repeat/support/ResultHolderResultQueue.java
  40. +0 −91 src/main/java/org/springframework/repeat/support/ResultQueue.java
  41. +0 −324 src/main/java/org/springframework/repeat/support/TaskExecutorRepeatTemplate.java
  42. +0 −105 src/main/java/org/springframework/repeat/support/ThrottleLimitResultQueue.java
  43. +0 −7 src/main/java/org/springframework/repeat/support/package.html
  44. +1 −2  src/main/java/org/springframework/retry/support/RetrySynchronizationManager.java
  45. +1 −2  src/main/java/org/springframework/retry/support/RetryTemplate.java
  46. +0 −36 src/test/java/org/springframework/repeat/AbstractExceptionTests.java
  47. +0 −34 src/test/java/org/springframework/repeat/RepeatExceptionTests.java
  48. +0 −41 src/test/java/org/springframework/repeat/callback/NestedRepeatCallbackTests.java
  49. +0 −64 src/test/java/org/springframework/repeat/context/RepeatContextCounterTests.java
  50. +0 −93 src/test/java/org/springframework/repeat/context/RepeatContextSupportTests.java
  51. +0 −113 src/test/java/org/springframework/repeat/context/SynchronizedAttributeAccessorTests.java
  52. +0 −60 src/test/java/org/springframework/repeat/exception/CompositeExceptionHandlerTests.java
  53. +0 −45 src/test/java/org/springframework/repeat/exception/DefaultExceptionHandlerTests.java
  54. +0 −101 src/test/java/org/springframework/repeat/exception/LogOrRethrowExceptionHandlerTests.java
  55. +0 −116 src/test/java/org/springframework/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java
  56. +0 −267 src/test/java/org/springframework/repeat/exception/SimpleLimitExceptionHandlerTests.java
  57. +0 −270 src/test/java/org/springframework/repeat/interceptor/RepeatOperationsInterceptorTests.java
  58. +0 −89 src/test/java/org/springframework/repeat/listener/CompositeRepeatListenerTests.java
  59. +0 −263 src/test/java/org/springframework/repeat/listener/RepeatListenerTests.java
  60. +0 −69 src/test/java/org/springframework/repeat/policy/CompositeCompletionPolicyTests.java
  61. +0 −138 src/test/java/org/springframework/repeat/policy/CountingCompletionPolicyTests.java
  62. +0 −27 src/test/java/org/springframework/repeat/policy/MockCompletionPolicySupport.java
  63. +0 −74 src/test/java/org/springframework/repeat/policy/SimpleCompletionPolicyTests.java
  64. +0 −63 src/test/java/org/springframework/repeat/policy/TimeoutCompletionPolicyTests.java
  65. +0 −73 src/test/java/org/springframework/repeat/support/AbstractTradeBatchTests.java
  66. +0 −210 src/test/java/org/springframework/repeat/support/ChunkedRepeatTests.java
  67. +0 −66 src/test/java/org/springframework/repeat/support/RepeatSynchronizationManagerTests.java
  68. +0 −61 src/test/java/org/springframework/repeat/support/ResultHolderResultQueueTests.java
  69. +0 −514 src/test/java/org/springframework/repeat/support/SimpleRepeatTemplateTests.java
  70. +0 −270 src/test/java/org/springframework/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java
  71. +0 −201 src/test/java/org/springframework/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java
  72. +0 −43 src/test/java/org/springframework/repeat/support/TaskExecutorRepeatTemplateTests.java
  73. +0 −92 src/test/java/org/springframework/repeat/support/ThrottleLimitResultQueueTests.java
  74. +0 −53 src/test/java/org/springframework/repeat/support/Trade.java
  75. +0 −12 src/test/java/org/springframework/retry/support/StatefulRecoveryRetryTests.java
View
80 src/main/java/org/springframework/repeat/CompletionPolicy.java
@@ -1,80 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat;
-
-
-/**
- * Interface for batch completion policies, to enable batch operations to
- * strategise normal completion conditions. Stateful implementations of batch
- * iterators should <em>only</em> update state using the update method. If you
- * need custom behaviour consider extending an existing implementation or using
- * the composite provided.
- *
- * @author Dave Syer
- *
- */
-public interface CompletionPolicy {
-
- /**
- * Determine whether a batch is complete given the latest result from the
- * callback. If this method returns true then
- * {@link #isComplete(RepeatContext)} should also (but not necessarily vice
- * versa, since the answer here depends on the result).
- *
- * @param context the current batch context.
- * @param result the result of the latest batch item processing.
- *
- * @return true if the batch should terminate.
- *
- * @see #isComplete(RepeatContext)
- */
- boolean isComplete(RepeatContext context, RepeatStatus result);
-
- /**
- * Allow policy to signal completion according to internal state, without
- * having to wait for the callback to complete.
- *
- * @param context the current batch context.
- *
- * @return true if the batch should terminate.
- */
- boolean isComplete(RepeatContext context);
-
- /**
- * Create a new context for the execution of a batch. N.B. implementations
- * should <em>not</em> return the parent from this method - they must
- * create a new context to meet the specific needs of the policy. The best
- * way to do this might be to override an existing implementation and use
- * the {@link RepeatContext} to store state in its attributes.
- *
- * @param parent the current context if one is already in progress.
- * @return a context object that can be used by the implementation to store
- * internal state for a batch.
- */
- RepeatContext start(RepeatContext parent);
-
- /**
- * Give implementations the opportunity to update the state of the current
- * batch. Will be called <em>once</em> per callback, after it has been
- * launched, but not necessarily after it completes (if the batch is
- * asynchronous).
- *
- * @param context the value returned by start.
- */
- void update(RepeatContext context);
-
-}
View
44 src/main/java/org/springframework/repeat/RepeatCallback.java
@@ -1,44 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat;
-
-
-/**
- * Callback interface for batch operations. Many simple processes will be able
- * to use off-the-shelf implementations of this interface, enabling the
- * application developer to concentrate on business logic.
- *
- * @see RepeatOperations
- *
- * @author Dave Syer
- *
- */
-public interface RepeatCallback {
-
- /**
- * Implementations return true if they can continue processing - e.g. there
- * is a data source that is not yet exhausted. Exceptions are not necessarily
- * fatal - processing might continue depending on the Exception type and the
- * implementation of the caller.
- *
- * @param context the current context passed in by the caller.
- * @return an {@link RepeatStatus} which is continuable if there is (or may
- * be) more data to process.
- * @throws Exception if there is a problem with the processing.
- */
- RepeatStatus doInIteration(RepeatContext context) throws Exception;
-}
View
91 src/main/java/org/springframework/repeat/RepeatContext.java
@@ -1,91 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat;
-
-import org.springframework.core.AttributeAccessor;
-
-/**
- * Base interface for context which controls the state and completion /
- * termination of a batch step. A new context is created for each call to the
- * {@link RepeatOperations}. Within a batch callback code can communicate via
- * the {@link AttributeAccessor} interface.
- *
- * @author Dave Syer
- *
- * @see RepeatOperations#iterate(RepeatCallback)
- *
- */
-public interface RepeatContext extends AttributeAccessor {
-
- /**
- * If batches are nested, then the inner batch will be created with the
- * outer one as a parent. This is an accessor for the parent if it exists.
- *
- * @return the parent context or null if there is none
- */
- RepeatContext getParent();
-
- /**
- * Public access to a counter for the number of operations attempted.
- *
- * @return the number of batch operations started.
- */
- int getStartedCount();
-
- /**
- * Signal to the framework that the current batch should complete normally,
- * independent of the current {@link CompletionPolicy}.
- */
- void setCompleteOnly();
-
- /**
- * Public accessor for the complete flag.
- */
- boolean isCompleteOnly();
-
- /**
- * Signal to the framework that the current batch should complete
- * abnormally, independent of the current {@link CompletionPolicy}.
- */
- void setTerminateOnly();
-
- /**
- * Public accessor for the termination flag. If this flag is set then the
- * complete flag will also be.
- */
- boolean isTerminateOnly();
-
- /**
- * Register a callback to be executed on close, associated with the
- * attribute having the given name. The {@link Runnable} callback should not
- * throw any exceptions.
- *
- * @param name the name of the attribute to associated this callback with.
- * If this attribute is removed the callback should never be called.
- * @param callback a {@link Runnable} to execute when the context is closed.
- */
- void registerDestructionCallback(String name, Runnable callback);
-
- /**
- * Allow resources to be cleared, especially in destruction callbacks.
- * Implementations should ensure that any registered destruction callbacks
- * are executed here, as long as the corresponding attribute is still
- * available.
- */
- void close();
-
-}
View
31 src/main/java/org/springframework/repeat/RepeatException.java
@@ -1,31 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat;
-
-import org.springframework.core.NestedRuntimeException;
-
-public class RepeatException extends NestedRuntimeException {
-
- public RepeatException(String msg) {
- super(msg);
- }
-
- public RepeatException(String msg, Throwable t) {
- super(msg, t);
- }
-
-}
View
80 src/main/java/org/springframework/repeat/RepeatListener.java
@@ -1,80 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat;
-
-
-/**
- * Interface for listeners to the batch process. Implementers can provide
- * enhance the behaviour of a batch in small cross-cutting modules. The
- * framework provides callbacks at key points in the processing.
- *
- * @author Dave Syer
- *
- */
-public interface RepeatListener {
- /**
- * Called by the framework before each batch item. Implementers can halt a
- * batch by setting the complete flag on the context.
- *
- * @param context the current batch context.
- */
- void before(RepeatContext context);
-
- /**
- * Called by the framework after each item has been processed, unless the
- * item processing results in an exception. This method is called as soon as
- * the result is known.
- *
- * @param context the current batch context
- * @param result the result of the callback
- */
- void after(RepeatContext context, RepeatStatus result);
-
- /**
- * Called once at the start of a complete batch, before any items are
- * processed. Implementers can use this method to acquire any resources that
- * might be needed during processing. Implementers can halt the current
- * operation by setting the complete flag on the context. To halt all
- * enclosing batches (the whole job), the would need to use the parent
- * context (recursively).
- *
- * @param context the current batch context
- */
- void open(RepeatContext context);
-
- /**
- * Called when a repeat callback fails by throwing an exception. There will
- * be one call to this method for each exception thrown during a repeat
- * operation (e.g. a chunk).<br/>
- *
- * There is no need to re-throw the exception here - that will be done by
- * the enclosing framework.
- *
- * @param context the current batch context
- * @param e the error that was encountered in an item callback.
- */
- void onError(RepeatContext context, Throwable e);
-
- /**
- * Called once at the end of a complete batch, after normal or abnormal
- * completion (i.e. even after an exception). Implementers can use this
- * method to clean up any resources.
- *
- * @param context the current batch context.
- */
- void close(RepeatContext context);
-}
View
47 src/main/java/org/springframework/repeat/RepeatOperations.java
@@ -1,47 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat;
-
-
-/**
- * The main interface providing access to batch operations. The batch client is
- * the {@link RepeatCallback}, where a single item or record is processed. The
- * batch behaviour, boundary conditions, transactions etc, are dealt with by the
- * {@link RepeatOperations} in such as way that the client does not need to know
- * about them. The client may have access to framework abstractions, like
- * template data sources, but these should work the same whether they are in a
- * batch or not.
- *
- * @author Dave Syer
- *
- */
-public interface RepeatOperations {
-
- /**
- * Execute the callback repeatedly, until a decision can be made to
- * complete. The decision about how many times to execute or when to
- * complete, and what to do in the case of an error is delegated to a
- * {@link CompletionPolicy}.
- *
- * @param callback the batch callback.
- * @return the aggregate of the result of all the callback operations. An
- * indication of whether the {@link RepeatOperations} can continue
- * processing if this method is called again.
- */
- RepeatStatus iterate(RepeatCallback callback) throws RepeatException;
-
-}
View
48 src/main/java/org/springframework/repeat/RepeatStatus.java
@@ -1,48 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat;
-
-public enum RepeatStatus {
-
- /**
- * Indicates that processing can continue.
- */
- CONTINUABLE(true),
- /**
- * Indicates that processing is finished (either successful or unsuccessful)
- */
- FINISHED(false);
-
- private final boolean continuable;
-
- private RepeatStatus(boolean continuable) {
- this.continuable = continuable;
- }
-
- public static RepeatStatus continueIf(boolean continuable) {
- return continuable ? CONTINUABLE : FINISHED;
- }
-
- public boolean isContinuable() {
- return this == CONTINUABLE;
- }
-
- public RepeatStatus and(boolean value) {
- return value && continuable ? CONTINUABLE : FINISHED;
- }
-
-}
View
61 src/main/java/org/springframework/repeat/callback/NestedRepeatCallback.java
@@ -1,61 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.callback;
-
-import org.springframework.repeat.RepeatCallback;
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.RepeatOperations;
-import org.springframework.repeat.RepeatStatus;
-
-/**
- * Callback that delegates to another callback, via a {@link RepeatOperations}
- * instance. Useful when nesting or composing batches in one another, e.g. for
- * breaking a batch down into chunks.
- *
- * @author Dave Syer
- *
- */
-public class NestedRepeatCallback implements RepeatCallback {
-
- private RepeatOperations template;
-
- private RepeatCallback callback;
-
- /**
- * Constructor setting mandatory fields.
- *
- * @param template the {@link RepeatOperations} to use when calling the
- * delegate callback
- * @param callback the {@link RepeatCallback} delegate
- */
- public NestedRepeatCallback(RepeatOperations template, RepeatCallback callback) {
- super();
- this.template = template;
- this.callback = callback;
- }
-
- /**
- * Simply calls template.execute(callback). Clients can use this to repeat a
- * batch process, or to break a process up into smaller chunks (e.g. to
- * change the transaction boundaries).
- *
- * @see org.springframework.repeat.RepeatCallback#doInIteration(RepeatContext)
- */
- public RepeatStatus doInIteration(RepeatContext context) throws Exception {
- return template.iterate(callback);
- }
-}
View
7 src/main/java/org/springframework/repeat/callback/package.html
@@ -1,7 +0,0 @@
-<html>
-<body>
-<p>
-Infrastructure implementations of repeat callback concerns.
-</p>
-</body>
-</html>
View
115 src/main/java/org/springframework/repeat/context/RepeatContextCounter.java
@@ -1,115 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.context;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.springframework.repeat.RepeatContext;
-import org.springframework.util.Assert;
-
-/**
- * Helper class for policies that need to count the number of occurrences of
- * some event (e.g. an exception type in the context) in the scope of a batch.
- * The value of the counter can be stored between batches in a nested context,
- * so that the termination decision is based on the aggregate of a number of
- * sibling batches.
- *
- * @author Dave Syer
- *
- */
-public class RepeatContextCounter {
-
- final private String countKey;
-
- /**
- * Flag to indicate whether the count is stored at the level of the parent
- * context, or just local to the current context. Default value is false.
- */
- final private boolean useParent;
-
- final private RepeatContext context;
-
- /**
- * Increment the counter.
- *
- * @param delta the amount by which to increment the counter.
- */
- final public void increment(int delta) {
- AtomicInteger count = getCounter();
- count.addAndGet(delta);
- }
-
- /**
- * Increment by 1.
- */
- final public void increment() {
- increment(1);
- }
-
- /**
- * Convenience constructor with useParent=false.
- * @param context the current context.
- * @param countKey the key to use to store the counter in the context.
- */
- public RepeatContextCounter(RepeatContext context, String countKey) {
- this(context, countKey, false);
- }
-
- /**
- * Construct a new {@link RepeatContextCounter}.
- *
- * @param context the current context.
- * @param countKey the key to use to store the counter in the context.
- * @param useParent true if the counter is to be shared between siblings.
- * The state will be stored in the parent of the context (if it exists)
- * instead of the context itself.
- */
- public RepeatContextCounter(RepeatContext context, String countKey, boolean useParent) {
-
- super();
-
- Assert.notNull(context, "The context must be provided to initialize a counter");
-
- this.countKey = countKey;
- this.useParent = useParent;
-
- RepeatContext parent = context.getParent();
-
- if (this.useParent && parent != null) {
- this.context = parent;
- }
- else {
- this.context = context;
- }
- if (!this.context.hasAttribute(countKey)) {
- this.context.setAttribute(countKey, new AtomicInteger());
- }
-
- }
-
- /**
- * @return the current value of the counter
- */
- public int getCount() {
- return getCounter().intValue();
- }
-
- private AtomicInteger getCounter() {
- return ((AtomicInteger) context.getAttribute(countKey));
- }
-
-}
View
178 src/main/java/org/springframework/repeat/context/RepeatContextSupport.java
@@ -1,178 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.context;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.springframework.repeat.RepeatContext;
-
-public class RepeatContextSupport extends SynchronizedAttributeAccessor implements RepeatContext {
-
- private RepeatContext parent;
-
- private int count;
-
- private volatile boolean completeOnly;
-
- private volatile boolean terminateOnly;
-
- private Map<String, Set<Runnable>> callbacks = new HashMap<String, Set<Runnable>>();
-
- /**
- * Constructor for {@link RepeatContextSupport}. The parent can be null, but
- * should be set to the enclosing repeat context if there is one, e.g. if
- * this context is an inner loop.
- * @param parent
- */
- public RepeatContextSupport(RepeatContext parent) {
- super();
- this.parent = parent;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.batch.repeat.RepeatContext#isCompleteOnly()
- */
- public boolean isCompleteOnly() {
- return completeOnly;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.batch.repeat.RepeatContext#setCompleteOnly()
- */
- public void setCompleteOnly() {
- completeOnly = true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.batch.repeat.RepeatContext#isTerminateOnly()
- */
- public boolean isTerminateOnly() {
- return terminateOnly;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.batch.repeat.RepeatContext#setTerminateOnly()
- */
- public void setTerminateOnly() {
- terminateOnly = true;
- setCompleteOnly();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.batch.repeat.RepeatContext#getParent()
- */
- public RepeatContext getParent() {
- return parent;
- }
-
- /**
- * Used by clients to increment the started count.
- */
- public synchronized void increment() {
- count++;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.batch.repeat.RepeatContext#getStartedCount()
- */
- public synchronized int getStartedCount() {
- return count;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.batch.repeat.RepeatContext#registerDestructionCallback
- * (java.lang.String, java.lang.Runnable)
- */
- public void registerDestructionCallback(String name, Runnable callback) {
- synchronized (callbacks) {
- Set<Runnable> set = callbacks.get(name);
- if (set == null) {
- set = new HashSet<Runnable>();
- callbacks.put(name, set);
- }
- set.add(callback);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.batch.repeat.RepeatContext#close()
- */
- public void close() {
-
- List<RuntimeException> errors = new ArrayList<RuntimeException>();
-
- Set<Map.Entry<String, Set<Runnable>>> copy;
-
- synchronized (callbacks) {
- copy = new HashSet<Map.Entry<String, Set<Runnable>>>(callbacks.entrySet());
- }
-
- for (Map.Entry<String, Set<Runnable>> entry : copy) {
-
- for (Runnable callback : entry.getValue()) {
- /*
- * Potentially we could check here if there is an attribute with
- * the given name - if it has been removed, maybe the callback
- * is invalid. On the other hand it is less surprising for the
- * callback register if it is always executed.
- */
- if (callback != null) {
- /*
- * The documentation of the interface says that these
- * callbacks must not throw exceptions, but we don't trust
- * them necessarily...
- */
- try {
- callback.run();
- }
- catch (RuntimeException t) {
- errors.add(t);
- }
- }
- }
- }
-
- if (errors.isEmpty()) {
- return;
- }
-
- throw (RuntimeException) errors.get(0);
- }
-
-}
View
161 src/main/java/org/springframework/repeat/context/SynchronizedAttributeAccessor.java
@@ -1,161 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.context;
-
-import org.springframework.core.AttributeAccessor;
-import org.springframework.core.AttributeAccessorSupport;
-
-/**
- * An {@link AttributeAccessor} that synchronizes on a mutex (not this) before
- * modifying or accessing the underlying attributes.
- *
- * @author Dave Syer
- *
- */
-public class SynchronizedAttributeAccessor implements AttributeAccessor {
-
- /**
- * All methods are delegated to this support object.
- */
- AttributeAccessorSupport support = new AttributeAccessorSupport() {
- /**
- * Generated serial UID.
- */
- private static final long serialVersionUID = -7664290016506582290L;
- };
-
- /*
- * (non-Javadoc)
- * @see org.springframework.core.AttributeAccessor#attributeNames()
- */
- public String[] attributeNames() {
- synchronized (support) {
- return support.attributeNames();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- AttributeAccessorSupport that;
- if (other instanceof SynchronizedAttributeAccessor) {
- that = ((SynchronizedAttributeAccessor) other).support;
- }
- else if (other instanceof AttributeAccessorSupport) {
- that = (AttributeAccessorSupport) other;
- }
- else {
- return false;
- }
- synchronized (support) {
- return support.equals(that);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.core.AttributeAccessor#getAttribute(java.lang.String)
- */
- public Object getAttribute(String name) {
- synchronized (support) {
- return support.getAttribute(name);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.core.AttributeAccessor#hasAttribute(java.lang.String)
- */
- public boolean hasAttribute(String name) {
- synchronized (support) {
- return support.hasAttribute(name);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return support.hashCode();
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.core.AttributeAccessor#removeAttribute(java.lang.String)
- */
- public Object removeAttribute(String name) {
- synchronized (support) {
- return support.removeAttribute(name);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.core.AttributeAccessor#setAttribute(java.lang.String,
- * java.lang.Object)
- */
- public void setAttribute(String name, Object value) {
- synchronized (support) {
- support.setAttribute(name, value);
- }
- }
-
- /**
- * Additional support for atomic put if absent.
- * @param name the key for the attribute name
- * @param value the value of the attribute
- * @return null if the attribute was not already set, the existing value
- * otherwise.
- */
- public Object setAttributeIfAbsent(String name, Object value) {
- synchronized (support) {
- Object old = getAttribute(name);
- if (old != null) {
- return old;
- }
- setAttribute(name, value);
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer("SynchronizedAttributeAccessor: [");
- synchronized (support) {
- String[] names = attributeNames();
- for (int i = 0; i < names.length; i++) {
- String name = names[i];
- buffer.append(names[i]).append("=").append(getAttribute(name));
- if (i < names.length - 1) {
- buffer.append(", ");
- }
- }
- buffer.append("]");
- return buffer.toString();
- }
- }
-
-}
View
7 src/main/java/org/springframework/repeat/context/package.html
@@ -1,7 +0,0 @@
-<html>
-<body>
-<p>
-Infrastructure implementations of repeat context concerns.
-</p>
-</body>
-</html>
View
49 src/main/java/org/springframework/repeat/exception/CompositeExceptionHandler.java
@@ -1,49 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.exception;
-
-import java.util.Arrays;
-
-import org.springframework.repeat.RepeatContext;
-
-/**
- * Composiste {@link ExceptionHandler} that loops though a list of delegates.
- *
- * @author Dave Syer
- *
- */
-public class CompositeExceptionHandler implements ExceptionHandler {
-
- private ExceptionHandler[] handlers = new ExceptionHandler[0];
-
- public void setHandlers(ExceptionHandler[] handlers) {
- this.handlers = Arrays.asList(handlers).toArray(new ExceptionHandler[handlers.length]);
- }
-
- /**
- * Iterate over the handlers delegating the call to each in turn. The chain
- * ends if an exception is thrown.
- *
- * @see ExceptionHandler#handleException(RepeatContext, Throwable)
- */
- public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
- for (int i = 0; i < handlers.length; i++) {
- ExceptionHandler handler = handlers[i];
- handler.handleException(context, throwable);
- }
- }
-}
View
39 src/main/java/org/springframework/repeat/exception/DefaultExceptionHandler.java
@@ -1,39 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.exception;
-
-import org.springframework.repeat.RepeatContext;
-
-/**
- * Default implementation of {@link ExceptionHandler} - just re-throws the exception it encounters.
- *
- * @author Dave Syer
- *
- */
-public class DefaultExceptionHandler implements ExceptionHandler {
-
- /**
- * Re-throw the throwable.
- *
- * @see org.springframework.repeat.exception.ExceptionHandler#handleException(RepeatContext,
- * Throwable)
- */
- public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
- throw throwable;
- }
-
-}
View
48 src/main/java/org/springframework/repeat/exception/ExceptionHandler.java
@@ -1,48 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.exception;
-
-import org.springframework.repeat.CompletionPolicy;
-import org.springframework.repeat.RepeatContext;
-
-/**
- * Handler to allow strategies for re-throwing exceptions. Normally a
- * {@link CompletionPolicy} will be used to decide whether to end a batch when
- * there is no exception, and the {@link ExceptionHandler} is used to signal an
- * abnormal ending - an abnormal ending would result in an
- * {@link ExceptionHandler} throwing an exception. The caller will catch and
- * re-throw it if necessary.
- *
- * @author Dave Syer
- * @author Robert Kasanicky
- *
- */
-public interface ExceptionHandler {
-
- /**
- * Deal with a Throwable during a batch - decide whether it should be
- * re-thrown in the first place.
- *
- * @param context the current {@link RepeatContext}. Can be used to store
- * state (via attributes), for example to count the number of occurrences of
- * a particular exception type and implement a threshold policy.
- * @param throwable an exception.
- * @throws Throwable implementations are free to re-throw the exception
- */
- void handleException(RepeatContext context, Throwable throwable) throws Throwable;
-
-}
View
111 src/main/java/org/springframework/repeat/exception/LogOrRethrowExceptionHandler.java
@@ -1,111 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.exception;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.classify.Classifier;
-import org.springframework.classify.ClassifierSupport;
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.RepeatException;
-
-/**
- * Implementation of {@link ExceptionHandler} based on an {@link Classifier}.
- * The classifier determines whether to log the exception or rethrow it. The
- * keys in the classifier must be the same as the static enum in this class.
- *
- * @author Dave Syer
- *
- */
-public class LogOrRethrowExceptionHandler implements ExceptionHandler {
-
- /**
- * Logging levels for the handler.
- *
- * @author Dave Syer
- *
- */
- public static enum Level {
-
- /**
- * Key for {@link Classifier} signalling that the throwable should be
- * rethrown. If the throwable is not a RuntimeException it is wrapped in
- * a {@link RepeatException}.
- */
- RETHROW,
-
- /**
- * Key for {@link Classifier} signalling that the throwable should be
- * logged at debug level.
- */
- DEBUG,
-
- /**
- * Key for {@link Classifier} signalling that the throwable should be
- * logged at warn level.
- */
- WARN,
-
- /**
- * Key for {@link Classifier} signalling that the throwable should be
- * logged at error level.
- */
- ERROR
-
- }
-
- protected final Log logger = LogFactory.getLog(LogOrRethrowExceptionHandler.class);
-
- private Classifier<Throwable, Level> exceptionClassifier = new ClassifierSupport<Throwable, Level>(Level.RETHROW);
-
- /**
- * Setter for the {@link Classifier} used by this handler. The default is to
- * map all throwable instances to {@link Level#RETHROW}.
- *
- * @param exceptionClassifier the ExceptionClassifier to use
- */
- public void setExceptionClassifier(Classifier<Throwable, Level> exceptionClassifier) {
- this.exceptionClassifier = exceptionClassifier;
- }
-
- /**
- * Classify the throwables and decide whether to rethrow based on the
- * result. The context is not used.
- *
- * @throws Throwable
- *
- * @see ExceptionHandler#handleException(RepeatContext, Throwable)
- */
- public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
-
- Level key = exceptionClassifier.classify(throwable);
- if (Level.ERROR.equals(key)) {
- logger.error("Exception encountered in batch repeat.", throwable);
- }
- else if (Level.WARN.equals(key)) {
- logger.warn("Exception encountered in batch repeat.", throwable);
- }
- else if (Level.DEBUG.equals(key) && logger.isDebugEnabled()) {
- logger.debug("Exception encountered in batch repeat.", throwable);
- }
- else if (Level.RETHROW.equals(key)) {
- throw throwable;
- }
-
- }
-
-}
View
150 src/main/java/org/springframework/repeat/exception/RethrowOnThresholdExceptionHandler.java
@@ -1,150 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.exception;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.classify.Classifier;
-import org.springframework.classify.SubclassClassifier;
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.context.RepeatContextCounter;
-import org.springframework.util.ObjectUtils;
-
-/**
- * Implementation of {@link ExceptionHandler} that rethrows when exceptions of a
- * given type reach a threshold. Requires an {@link Classifier} that maps
- * exception types to unique keys, and also a map from those keys to threshold
- * values (Integer type).
- *
- * @author Dave Syer
- *
- */
-public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
-
- protected static final IntegerHolder ZERO = new IntegerHolder(0);
-
- protected final Log logger = LogFactory.getLog(RethrowOnThresholdExceptionHandler.class);
-
- private Classifier<? super Throwable, IntegerHolder> exceptionClassifier = new Classifier<Throwable, IntegerHolder>() {
- public RethrowOnThresholdExceptionHandler.IntegerHolder classify(Throwable classifiable) {
- return ZERO;
- }
- };
-
- private boolean useParent = false;
-
- /**
- * Flag to indicate the the exception counters should be shared between
- * sibling contexts in a nested batch. Default is false.
- *
- * @param useParent true if the parent context should be used to store the
- * counters.
- */
- public void setUseParent(boolean useParent) {
- this.useParent = useParent;
- }
-
- /**
- * Set up the exception handler. Creates a default exception handler and
- * threshold that maps all exceptions to a threshold of 0 - all exceptions
- * are rethrown by default.
- */
- public RethrowOnThresholdExceptionHandler() {
- super();
- }
-
- /**
- * A map from exception classes to a threshold value of type Integer.
- *
- * @param thresholds the threshold value map.
- */
- public void setThresholds(Map<Class<? extends Throwable>, Integer> thresholds) {
- Map<Class<? extends Throwable>, IntegerHolder> typeMap = new HashMap<Class<? extends Throwable>, IntegerHolder>();
- for (Entry<Class<? extends Throwable>, Integer> entry : thresholds.entrySet()) {
- typeMap.put(entry.getKey(), new IntegerHolder(entry.getValue()));
- }
- exceptionClassifier = new SubclassClassifier<Throwable, IntegerHolder>(typeMap, ZERO);
- }
-
- /**
- * Classify the throwables and decide whether to re-throw based on the
- * result. The context is used to accumulate the number of exceptions of the
- * same type according to the classifier.
- *
- * @throws Throwable
- * @see ExceptionHandler#handleException(RepeatContext, Throwable)
- */
- public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
-
- IntegerHolder key = exceptionClassifier.classify(throwable);
-
- RepeatContextCounter counter = getCounter(context, key);
- counter.increment();
- int count = counter.getCount();
- int threshold = key.getValue();
- if (count > threshold) {
- throw throwable;
- }
-
- }
-
- private RepeatContextCounter getCounter(RepeatContext context, IntegerHolder key) {
- String attribute = RethrowOnThresholdExceptionHandler.class.getName() + "." + key;
- // Creates a new counter and stores it in the correct context:
- return new RepeatContextCounter(context, attribute, useParent);
- }
-
- /**
- * @author Dave Syer
- *
- */
- private static class IntegerHolder {
-
- private final int value;
-
- /**
- * @param value
- */
- public IntegerHolder(int value) {
- this.value = value;
- }
-
- /**
- * Public getter for the value.
- * @return the value
- */
- public int getValue() {
- return value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return ObjectUtils.getIdentityHexString(this) + "." + value;
- }
-
- }
-
-}
View
147 src/main/java/org/springframework/repeat/exception/SimpleLimitExceptionHandler.java
@@ -1,147 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.exception;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.repeat.RepeatContext;
-
-/**
- * Simple implementation of exception handler which looks for given exception
- * types. If one of the types is found then a counter is incremented and the
- * limit is checked to determine if it has been exceeded and the Throwable
- * should be re-thrown. Also allows to specify list of 'fatal' exceptions that
- * are never subject to counting, but are immediately re-thrown. The fatal list
- * has higher priority so the two lists needn't be exclusive.
- *
- * @author Dave Syer
- * @author Robert Kasanicky
- */
-public class SimpleLimitExceptionHandler implements ExceptionHandler, InitializingBean {
-
- private RethrowOnThresholdExceptionHandler delegate = new RethrowOnThresholdExceptionHandler();
-
- private Collection<Class<? extends Throwable>> exceptionClasses = Collections
- .<Class<? extends Throwable>> singleton(Exception.class);
-
- private Collection<Class<? extends Throwable>> fatalExceptionClasses = Collections
- .<Class<? extends Throwable>> singleton(Error.class);
-
- private int limit = 0;
-
- /**
- * Apply the provided properties to create a delegate handler.
- *
- * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
- */
- public void afterPropertiesSet() throws Exception {
- if (limit <= 0) {
- return;
- }
- Map<Class<? extends Throwable>, Integer> thresholds = new HashMap<Class<? extends Throwable>, Integer>();
- for (Class<? extends Throwable> type : exceptionClasses) {
- thresholds.put(type, limit);
- }
- // do the fatalExceptionClasses last so they override the others
- for (Class<? extends Throwable> type : fatalExceptionClasses) {
- thresholds.put(type, 0);
- }
- delegate.setThresholds(thresholds);
- }
-
- /**
- * Flag to indicate the the exception counters should be shared between
- * sibling contexts in a nested batch (i.e. inner loop). Default is false.
- * Set this flag to true if you want to count exceptions for the whole
- * (outer) loop in a typical container.
- *
- * @param useParent true if the parent context should be used to store the
- * counters.
- */
- public void setUseParent(boolean useParent) {
- delegate.setUseParent(useParent);
- }
-
- /**
- * Convenience constructor for the {@link SimpleLimitExceptionHandler} to
- * set the limit.
- *
- * @param limit the limit
- */
- public SimpleLimitExceptionHandler(int limit) {
- this();
- this.limit = limit;
- }
-
- /**
- * Default constructor for the {@link SimpleLimitExceptionHandler}.
- */
- public SimpleLimitExceptionHandler() {
- super();
- }
-
- /**
- * Rethrows only if the limit is breached for this context on the exception
- * type specified.
- *
- * @see #setExceptionClasses(Collection)
- * @see #setLimit(int)
- *
- * @see org.springframework.repeat.exception.ExceptionHandler#handleException(org.springframework.repeat.RepeatContext,
- * Throwable)
- */
- public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
- delegate.handleException(context, throwable);
- }
-
- /**
- * The limit on the given exception type within a single context before it
- * is rethrown.
- *
- * @param limit the limit
- */
- public void setLimit(final int limit) {
- this.limit = limit;
- }
-
- /**
- * Setter for the exception classes that this handler counts. Defaults to
- * {@link Exception}. If more exceptionClasses are specified handler uses
- * single counter that is incremented when one of the recognized exception
- * exceptionClasses is handled.
- * @param classes exceptionClasses
- */
- public void setExceptionClasses(Collection<Class<? extends Throwable>> classes) {
- this.exceptionClasses = classes;
- }
-
- /**
- * Setter for the exception classes that shouldn't be counted, but rethrown
- * immediately. This list has higher priority than
- * {@link #setExceptionClasses(Collection)}.
- *
- * @param fatalExceptionClasses defaults to {@link Error}
- */
- public void setFatalExceptionClasses(Collection<Class<? extends Throwable>> fatalExceptionClasses) {
- this.fatalExceptionClasses = fatalExceptionClasses;
- }
-
-}
View
7 src/main/java/org/springframework/repeat/exception/package.html
@@ -1,7 +0,0 @@
-<html>
-<body>
-<p>
-Infrastructure implementations of repeat exception handler concerns.
-</p>
-</body>
-</html>
View
203 src/main/java/org/springframework/repeat/interceptor/RepeatOperationsInterceptor.java
@@ -1,203 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.interceptor;
-
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-import org.springframework.aop.ProxyMethodInvocation;
-import org.springframework.repeat.RepeatCallback;
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.RepeatException;
-import org.springframework.repeat.RepeatOperations;
-import org.springframework.repeat.RepeatStatus;
-import org.springframework.repeat.support.RepeatTemplate;
-import org.springframework.util.Assert;
-
-/**
- * A {@link MethodInterceptor} that can be used to automatically repeat calls to
- * a method on a service. The injected {@link RepeatOperations} is used to
- * control the completion of the loop. Independent of the completion policy in
- * the {@link RepeatOperations} the loop will repeat until the target method
- * returns null or false. Be careful when injecting a bespoke
- * {@link RepeatOperations} that the loop will actually terminate, because the
- * default policy for a vanilla {@link RepeatTemplate} will never complete if
- * the return type of the target method is void (the value returned is always
- * not-null, representing the {@link Void#TYPE}).
- *
- * @author Dave Syer
- */
-public class RepeatOperationsInterceptor implements MethodInterceptor {
-
- private RepeatOperations repeatOperations = new RepeatTemplate();
-
- /**
- * Setter for the {@link RepeatOperations}.
- *
- * @param batchTempate
- * @throws IllegalArgumentException if the argument is null.
- */
- public void setRepeatOperations(RepeatOperations batchTempate) {
- Assert.notNull(batchTempate, "'repeatOperations' cannot be null.");
- this.repeatOperations = batchTempate;
- }
-
- /**
- * Invoke the proceeding method call repeatedly, according to the properties
- * of the injected {@link RepeatOperations}.
- *
- * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
- */
- public Object invoke(final MethodInvocation invocation) throws Throwable {
-
- final ResultHolder result = new ResultHolder();
- // Cache void return value if intercepted method returns void
- final boolean voidReturnType = Void.TYPE.equals(invocation.getMethod().getReturnType());
- if (voidReturnType) {
- // This will be ignored anyway, but we want it to be non-null for
- // convenience of checking that there is a result.
- result.setValue(new Object());
- }
-
- try {
- repeatOperations.iterate(new RepeatCallback() {
-
- public RepeatStatus doInIteration(RepeatContext context) throws Exception {
- try {
-
- MethodInvocation clone = invocation;
- if (invocation instanceof ProxyMethodInvocation) {
- clone = ((ProxyMethodInvocation) invocation).invocableClone();
- }
- else {
- throw new IllegalStateException(
- "MethodInvocation of the wrong type detected - this should not happen with Spring AOP, so please raise an issue if you see this exception");
- }
-
- Object value = clone.proceed();
- if (voidReturnType) {
- return RepeatStatus.CONTINUABLE;
- }
- if (!isComplete(value)) {
- // Save the last result
- result.setValue(value);
- return RepeatStatus.CONTINUABLE;
- }
- else {
- result.setFinalValue(value);
- return RepeatStatus.FINISHED;
- }
- }
- catch (Throwable e) {
- if (e instanceof Exception) {
- throw (Exception) e;
- }
- else {
- throw new RepeatOperationsInterceptorException("Unexpected error in batch interceptor", e);
- }
- }
- }
-
- });
- }
- catch (Throwable t) {
- // The repeat exception should be unwrapped by the template
- throw t;
- }
-
- if (result.isReady()) {
- return result.getValue();
- }
-
- // No result means something weird happened
- throw new IllegalStateException("No result available for attempted repeat call to " + invocation
- + ". The invocation was never called, so maybe there is a problem with the completion policy?");
- }
-
- /**
- * @param result
- * @return
- */
- private boolean isComplete(Object result) {
- return result == null || (result instanceof Boolean) && !((Boolean) result).booleanValue();
- }
-
- /**
- * Simple wrapper exception class to enable nasty errors to be passed out of
- * the scope of the repeat operations and handled by the caller.
- *
- * @author Dave Syer
- *
- */
- private static class RepeatOperationsInterceptorException extends RepeatException {
- /**
- * @param message
- * @param e
- */
- public RepeatOperationsInterceptorException(String message, Throwable e) {
- super(message, e);
- }
- }
-
- /**
- * Simple wrapper object for the result from a method invocation.
- *
- * @author Dave Syer
- *
- */
- private static class ResultHolder {
- private Object value = null;
-
- private boolean ready = false;
-
- /**
- * Public setter for the Object.
- * @param value the value to set
- */
- public void setValue(Object value) {
- this.ready = true;
- this.value = value;
- }
-
- /**
- * @param value
- */
- public void setFinalValue(Object value) {
- if (ready) {
- // Only set the value the last time if the last time was also
- // the first time
- return;
- }
- setValue(value);
- }
-
- /**
- * Public getter for the Object.
- * @return the value
- */
- public Object getValue() {
- return value;
- }
-
- /**
- * @return true if a value has been set
- */
- public boolean isReady() {
- return ready;
- }
- }
-
-}
View
7 src/main/java/org/springframework/repeat/interceptor/package.html
@@ -1,7 +0,0 @@
-<html>
-<body>
-<p>
-Infrastructure implementations of repeat aop concerns.
-</p>
-</body>
-</html>
View
99 src/main/java/org/springframework/repeat/listener/CompositeRepeatListener.java
@@ -1,99 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.listener;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.RepeatListener;
-import org.springframework.repeat.RepeatStatus;
-
-/**
- * @author Dave Syer
- *
- */
-public class CompositeRepeatListener implements RepeatListener {
-
- private List<RepeatListener> listeners = new ArrayList<RepeatListener>();
-
- /**
- * Public setter for the listeners.
- *
- * @param listeners
- */
- public void setListeners(RepeatListener[] listeners) {
- this.listeners = Arrays.asList(listeners);
- }
-
- /**
- * Register additional listener.
- *
- * @param listener
- */
- public void register(RepeatListener listener) {
- if (!listeners.contains(listener)) {
- listeners.add(listener);
- }
- }
-
- /* (non-Javadoc)
- * @see org.springframework.batch.repeat.RepeatListener#after(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.ExitStatus)
- */
- public void after(RepeatContext context, RepeatStatus result) {
- for (RepeatListener listener : listeners) {
- listener.after(context, result);
- }
- }
-
- /* (non-Javadoc)
- * @see org.springframework.batch.repeat.RepeatListener#before(org.springframework.batch.repeat.RepeatContext)
- */
- public void before(RepeatContext context) {
- for (RepeatListener listener : listeners) {
- listener.before(context);
- }
- }
-
- /* (non-Javadoc)
- * @see org.springframework.batch.repeat.RepeatListener#close(org.springframework.batch.repeat.RepeatContext)
- */
- public void close(RepeatContext context) {
- for (RepeatListener listener : listeners) {
- listener.close(context);
- }
- }
-
- /* (non-Javadoc)
- * @see org.springframework.batch.repeat.RepeatListener#onError(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)
- */
- public void onError(RepeatContext context, Throwable e) {
- for (RepeatListener listener : listeners) {
- listener.onError(context, e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.springframework.batch.repeat.RepeatListener#open(org.springframework.batch.repeat.RepeatContext)
- */
- public void open(RepeatContext context) {
- for (RepeatListener listener : listeners) {
- listener.open(context);
- }
- }
-
-}
View
46 src/main/java/org/springframework/repeat/listener/RepeatListenerSupport.java
@@ -1,46 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.listener;
-
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.RepeatListener;
-import org.springframework.repeat.RepeatStatus;
-
-/**
- * Empty method implementation of {@link RepeatListener}.
- *
- * @author Dave Syer
- *
- */
-public class RepeatListenerSupport implements RepeatListener {
-
- public void before(RepeatContext context) {
- }
-
- public void after(RepeatContext context, RepeatStatus result) {
- }
-
- public void close(RepeatContext context) {
- }
-
- public void onError(RepeatContext context, Throwable e) {
- }
-
- public void open(RepeatContext context) {
- }
-
-}
View
7 src/main/java/org/springframework/repeat/listener/package.html
@@ -1,7 +0,0 @@
-<html>
-<body>
-<p>
-Infrastructure implementations of repeat interceptor concerns.
-</p>
-</body>
-</html>
View
7 src/main/java/org/springframework/repeat/package.html
@@ -1,7 +0,0 @@
-<html>
-<body>
-<p>
-Infrastructure implementations of repeat concerns.
-</p>
-</body>
-</html>
View
77 src/main/java/org/springframework/repeat/policy/CompletionPolicySupport.java
@@ -1,77 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.policy;
-
-import org.springframework.repeat.CompletionPolicy;
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.RepeatStatus;
-import org.springframework.repeat.context.RepeatContextSupport;
-
-/**
- * Very simple base class for {@link CompletionPolicy} implementations.
- *
- * @author Dave Syer
- *
- */
-public class CompletionPolicySupport implements CompletionPolicy {
-
- /**
- * If exit status is not continuable return <code>true</code>, otherwise
- * delegate to {@link #isComplete(RepeatContext)}.
- *
- * @see org.springframework.repeat.CompletionPolicy#isComplete(org.springframework.repeat.RepeatContext,
- * RepeatStatus)
- */
- public boolean isComplete(RepeatContext context, RepeatStatus result) {
- if (result != null && !result.isContinuable()) {
- return true;
- }
- else {
- return isComplete(context);
- }
- }
-
- /**
- * Always true.
- *
- * @see org.springframework.repeat.CompletionPolicy#isComplete(org.springframework.repeat.RepeatContext)
- */
- public boolean isComplete(RepeatContext context) {
- return true;
- }
-
- /**
- * Build a new {@link RepeatContextSupport} and return it.
- *
- * @see org.springframework.repeat.CompletionPolicy#start(RepeatContext)
- */
- public RepeatContext start(RepeatContext context) {
- return new RepeatContextSupport(context);
- }
-
- /**
- * Increment the context so the counter is up to date. Do nothing else.
- *
- * @see org.springframework.repeat.CompletionPolicy#update(org.springframework.repeat.RepeatContext)
- */
- public void update(RepeatContext context) {
- if (context instanceof RepeatContextSupport) {
- ((RepeatContextSupport) context).increment();
- }
- }
-
-}
View
133 src/main/java/org/springframework/repeat/policy/CompositeCompletionPolicy.java
@@ -1,133 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.policy;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.springframework.repeat.CompletionPolicy;
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.RepeatStatus;
-import org.springframework.repeat.context.RepeatContextSupport;
-
-/**
- * Composite policy that loops through a list of delegate policies and answers
- * calls by a concensus.
- *
- * @author Dave Syer
- *
- */
-public class CompositeCompletionPolicy implements CompletionPolicy {
-
- CompletionPolicy[] policies = new CompletionPolicy[0];
-
- /**
- * Setter for the policies.
- *
- * @param policies
- */
- public void setPolicies(CompletionPolicy[] policies) {
- this.policies = Arrays.asList(policies).toArray(new CompletionPolicy[policies.length]);
- }
-
- /**
- * This policy is complete if any of the composed policies is complete.
- *
- * @see org.springframework.repeat.CompletionPolicy#isComplete(org.springframework.repeat.RepeatContext,
- * RepeatStatus)
- */
- public boolean isComplete(RepeatContext context, RepeatStatus result) {
- RepeatContext[] contexts = ((CompositeBatchContext) context).contexts;
- CompletionPolicy[] policies = ((CompositeBatchContext) context).policies;
- for (int i = 0; i < policies.length; i++) {
- if (policies[i].isComplete(contexts[i], result)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * This policy is complete if any of the composed policies is complete.
- *
- * @see org.springframework.repeat.CompletionPolicy#isComplete(org.springframework.repeat.RepeatContext)
- */
- public boolean isComplete(RepeatContext context) {
- RepeatContext[] contexts = ((CompositeBatchContext) context).contexts;
- CompletionPolicy[] policies = ((CompositeBatchContext) context).policies;
- for (int i = 0; i < policies.length; i++) {
- if (policies[i].isComplete(contexts[i])) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Create a new composite context from all the available policies.
- *
- * @see org.springframework.repeat.CompletionPolicy#start(RepeatContext)
- */
- public RepeatContext start(RepeatContext context) {
- List<RepeatContext> list = new ArrayList<RepeatContext>();
- for (int i = 0; i < policies.length; i++) {
- list.add(policies[i].start(context));
- }
- return new CompositeBatchContext(context, list);
-
- }
-
- /**
- * Update all the composed contexts, and also increment the parent context.
- *
- * @see org.springframework.repeat.CompletionPolicy#update(org.springframework.repeat.RepeatContext)
- */
- public void update(RepeatContext context) {
- RepeatContext[] contexts = ((CompositeBatchContext) context).contexts;
- CompletionPolicy[] policies = ((CompositeBatchContext) context).policies;
- for (int i = 0; i < policies.length; i++) {
- policies[i].update(contexts[i]);
- }
- ((RepeatContextSupport) context).increment();
- }
-
- /**
- * Composite context that knows about the policies and contexts is was
- * created with.
- *
- * @author Dave Syer
- *
- */
- protected class CompositeBatchContext extends RepeatContextSupport {
-
- private RepeatContext[] contexts;
-
- // Save a reference to the policies when we were created - gives some
- // protection against reference changes (e.g. if the number of policies
- // change).
- private CompletionPolicy[] policies;
-
- public CompositeBatchContext(RepeatContext context, List<RepeatContext> contexts) {
- super(context);
- this.contexts = contexts.toArray(new RepeatContext[contexts.size()]);
- this.policies = CompositeCompletionPolicy.this.policies;
- }
-
- }
-
-}
View
132 src/main/java/org/springframework/repeat/policy/CountingCompletionPolicy.java
@@ -1,132 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.policy;
-
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.context.RepeatContextCounter;
-import org.springframework.repeat.context.RepeatContextSupport;
-
-/**
- * Abstract base class for policies that need to count the number of occurrences
- * of some event (e.g. an exception type in the context), and terminate based on
- * a limit for the counter. The value of the counter can be stored between
- * batches in a nested context, so that the termination decision is based on the
- * aggregate of a number of sibling batches.
- *
- * @author Dave Syer
- *
- */
-public abstract class CountingCompletionPolicy extends DefaultResultCompletionPolicy {
-
- /**
- * Session key for global counter.
- */
- public static final String COUNT = CountingCompletionPolicy.class.getName() + ".COUNT";
-
- private boolean useParent = false;
-
- private int maxCount = 0;
-
- /**
- * Flag to indicate whether the count is at the level of the parent context,
- * or just local to the context. If true then the count is aggregated among
- * siblings in a nested batch.
- *
- * @param useParent whether to use the parent context to cache the total
- * count. Default value is false.
- */
- public void setUseParent(boolean useParent) {
- this.useParent = useParent;
- }
-
- /**
- * Setter for maximum value of count before termination.
- *
- * @param maxCount the maximum number of counts before termination. Default
- * 0 so termination is immediate.
- */
- public void setMaxCount(int maxCount) {
- this.maxCount = maxCount;
- }
-
- /**
- * Extension point for subclasses. Obtain the value of the count in the
- * current context. Subclasses can count the number of attempts or
- * violations and store the result in their context. This policy base class
- * will take care of the termination contract and aggregating at the level
- * of the session if required.
- *
- * @param context the current context, specific to the subclass.
- * @return the value of the counter in the context.
- */
- protected abstract int getCount(RepeatContext context);
-
- /**
- * Extension point for subclasses. Inspect the context and update the state
- * of a counter in whatever way is appropriate. This will be added to the
- * session-level counter if {@link #setUseParent(boolean)} is true.
- *
- * @param context the current context.
- *
- * @return the change in the value of the counter (default 0).
- */
- protected int doUpdate(RepeatContext context) {
- return 0;
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.batch.repeat.policy.CompletionPolicySupport#isComplete(org.springframework.batch.repeat.BatchContext)
- */
- final public boolean isComplete(RepeatContext context) {
- int count = ((CountingBatchContext) context).getCounter().getCount();
- return count >= maxCount;
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.batch.repeat.policy.CompletionPolicySupport#start(org.springframework.batch.repeat.BatchContext)
- */
- public RepeatContext start(RepeatContext parent) {
- return new CountingBatchContext(parent);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.batch.repeat.policy.CompletionPolicySupport#update(org.springframework.batch.repeat.BatchContext)
- */
- final public void update(RepeatContext context) {
- super.update(context);
- int delta = doUpdate(context);
- ((CountingBatchContext) context).getCounter().increment(delta);
- }
-
- protected class CountingBatchContext extends RepeatContextSupport {
-
- RepeatContextCounter counter;
-
- public CountingBatchContext(RepeatContext parent) {
- super(parent);
- counter = new RepeatContextCounter(this, COUNT, useParent);
- }
-
- public RepeatContextCounter getCounter() {
- return counter;
- }
-
- }
-}
View
53 src/main/java/org/springframework/repeat/policy/DefaultResultCompletionPolicy.java
@@ -1,53 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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.springframework.repeat.policy;
-
-import org.springframework.repeat.CompletionPolicy;
-import org.springframework.repeat.RepeatContext;
-import org.springframework.repeat.RepeatStatus;
-
-/**
- * Very simple {@link CompletionPolicy} that bases its decision on the result of
- * a batch operation. If the result is null or not continuable according to the
- * {@link RepeatStatus} the batch is complete, otherwise not.
- *
- * @author Dave Syer
- *
- */
-public class DefaultResultCompletionPolicy extends CompletionPolicySupport {
-
- /**
- * True if the result is null, or a {@link RepeatStatus} indicating
- * completion.
- *
- * @see org.springframework.repeat.CompletionPolicy#isComplete(org.springframework.repeat.RepeatContext,
- * RepeatStatus)
- */
- public boolean isComplete(RepeatContext context, RepeatStatus result) {
- return (result == null || !result.isContinuable());
- }
-
- /**
- * Always false.
- *
- * @see org.springframework.repeat.CompletionPolicy#isComplete(org.springframework.repeat.RepeatContext)
- */
- public boolean isComplete(RepeatContext context) {
- return false;
- }
-
-}
View
115 src/main/java/org/springframework/repeat/policy/SimpleCompletionPolicy.java
@@ -1,115 +0,0 @@
-/*
- * Copyright 2006-2007 the original author or authors.
- *
- * 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 req