EMMA Coverage Report (generated Tue May 06 07:28:24 PDT 2008)
[all classes][org.springframework.batch.retry.policy]

COVERAGE SUMMARY FOR SOURCE FILE [CompositeRetryPolicy.java]

nameclass, %method, %block, %line, %
CompositeRetryPolicy.java100% (2/2)100% (7/7)100% (141/141)100% (31/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CompositeRetryPolicy100% (1/1)100% (6/6)100% (122/122)100% (26/26)
CompositeRetryPolicy (): void 100% (1/1)100% (7/7)100% (3/3)
canRetry (RetryContext): boolean 100% (1/1)100% (28/28)100% (6/6)
close (RetryContext): void 100% (1/1)100% (24/24)100% (5/5)
open (RetryCallback, RetryContext): RetryContext 100% (1/1)100% (30/30)100% (4/4)
registerThrowable (RetryContext, Throwable): void 100% (1/1)100% (29/29)100% (6/6)
setPolicies (RetryPolicy []): void 100% (1/1)100% (4/4)100% (2/2)
     
class CompositeRetryPolicy$CompositeRetryContext100% (1/1)100% (1/1)100% (19/19)100% (5/5)
CompositeRetryPolicy$CompositeRetryContext (CompositeRetryPolicy, RetryContex... 100% (1/1)100% (19/19)100% (5/5)

1/*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package org.springframework.batch.retry.policy;
18 
19import java.util.ArrayList;
20import java.util.List;
21 
22import org.springframework.batch.retry.RetryCallback;
23import org.springframework.batch.retry.RetryContext;
24import org.springframework.batch.retry.RetryPolicy;
25import org.springframework.batch.retry.TerminatedRetryException;
26import org.springframework.batch.retry.context.RetryContextSupport;
27 
28/**
29 * A {@link RetryPolicy} that composes a list of other policies and delegates
30 * calls to them in order.
31 * 
32 * @author Dave Syer
33 * 
34 */
35public class CompositeRetryPolicy extends AbstractStatelessRetryPolicy {
36 
37        RetryPolicy[] policies = new RetryPolicy[0];
38 
39        /**
40         * Setter for policies.
41         * 
42         * @param policies
43         */
44        public void setPolicies(RetryPolicy[] policies) {
45                this.policies = policies;
46        }
47 
48        /**
49         * Delegate to the policies that were in operation when the context was
50         * created. If any of them cannot retry then return false, oetherwise return
51         * true.
52         * 
53         * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext)
54         */
55        public boolean canRetry(RetryContext context) {
56                RetryContext[] contexts = ((CompositeRetryContext) context).contexts;
57                RetryPolicy[] policies = ((CompositeRetryContext) context).policies;
58                for (int i = 0; i < contexts.length; i++) {
59                        if (!policies[i].canRetry(contexts[i])) {
60                                return false;
61                        }
62                }
63                return true;
64        }
65 
66        /**
67         * Delegate to the policies that were in operation when the context was
68         * created.
69         * 
70         * @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext)
71         */
72        public void close(RetryContext context) {
73                RetryContext[] contexts = ((CompositeRetryContext) context).contexts;
74                RetryPolicy[] policies = ((CompositeRetryContext) context).policies;
75                // TODO: throw some sort of composite exception if any of the close
76                // methods fail?
77                for (int i = 0; i < contexts.length; i++) {
78                        policies[i].close(contexts[i]);
79                }
80        }
81 
82        /**
83         * Creates a new context that copies the existing policies and keeps a list
84         * of the contexts from each one.
85         * 
86         * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext)
87         */
88        public RetryContext open(RetryCallback callback, RetryContext parent) {
89                List list = new ArrayList();
90                for (int i = 0; i < policies.length; i++) {
91                        list.add(policies[i].open(callback, parent));
92                }
93                return new CompositeRetryContext(parent, list);
94        }
95 
96        /**
97         * Delegate to the policies that were in operation when the context was
98         * created.
99         * 
100         * @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext)
101         */
102        public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException {
103                RetryContext[] contexts = ((CompositeRetryContext) context).contexts;
104                RetryPolicy[] policies = ((CompositeRetryContext) context).policies;
105                for (int i = 0; i < contexts.length; i++) {
106                        policies[i].registerThrowable(contexts[i], throwable);
107                }
108                ((RetryContextSupport) context).registerThrowable(throwable);
109        }
110 
111        private class CompositeRetryContext extends RetryContextSupport {
112                RetryContext[] contexts;
113 
114                RetryPolicy[] policies;
115 
116                public CompositeRetryContext(RetryContext parent, List contexts) {
117                        super(parent);
118                        this.contexts = (RetryContext[]) contexts.toArray(new RetryContext[0]);
119                        this.policies = CompositeRetryPolicy.this.policies;
120                }
121 
122        }
123 
124}

[all classes][org.springframework.batch.retry.policy]
EMMA 2.0.5312 (C) Vladimir Roubtsov