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

COVERAGE SUMMARY FOR SOURCE FILE [MapRetryContextCache.java]

nameclass, %method, %block, %line, %
MapRetryContextCache.java100% (1/1)86%  (6/7)93%  (51/55)88%  (14/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapRetryContextCache100% (1/1)86%  (6/7)93%  (51/55)88%  (14/16)
setCapacity (int): void 0%   (0/1)0%   (0/4)0%   (0/2)
MapRetryContextCache (): void 100% (1/1)100% (4/4)100% (2/2)
MapRetryContextCache (int): void 100% (1/1)100% (12/12)100% (4/4)
containsKey (Object): boolean 100% (1/1)100% (5/5)100% (1/1)
get (Object): RetryContext 100% (1/1)100% (6/6)100% (1/1)
put (Object, RetryContext): void 100% (1/1)100% (18/18)100% (4/4)
remove (Object): void 100% (1/1)100% (6/6)100% (2/2)

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.Collections;
20import java.util.HashMap;
21import java.util.Map;
22 
23import org.springframework.batch.retry.RetryContext;
24 
25/**
26 * Map-based implementation of {@link RetryContextCache}. The map backing the
27 * cache of contexts is synchronized.
28 * 
29 * @author Dave Syer
30 * 
31 */
32public class MapRetryContextCache implements RetryContextCache {
33 
34        /**
35         * Default value for maximum capacity of the cache. This is set to a
36         * reasonably low value (4096) to avoid users inadvertently filling the
37         * cache with item keys that are inconsistent.
38         */
39        public static final int DEFAULT_CAPACITY = 4096;
40 
41        private Map map = Collections.synchronizedMap(new HashMap());
42 
43        private int capacity;
44 
45        /**
46         * Create a {@link MapRetryContextCache} with default capacity.
47         */
48        public MapRetryContextCache() {
49                this(DEFAULT_CAPACITY);
50        }
51 
52        /**
53         * @param defaultCapacity
54         */
55        public MapRetryContextCache(int defaultCapacity) {
56                super();
57                this.capacity = defaultCapacity;
58        }
59 
60        /**
61         * Public setter for the capacity. Prevents the cache from growing
62         * unboundedly if items that fail are misidentified and two references to an
63         * identical item actually do not have the same key. This can happen when
64         * users implement equals and hashCode based on mutable fields, for
65         * instance.
66         * 
67         * @param capacity the capacity to set
68         */
69        public void setCapacity(int capacity) {
70                this.capacity = capacity;
71        }
72 
73        public boolean containsKey(Object key) {
74                return map.containsKey(key);
75        }
76 
77        public RetryContext get(Object key) {
78                return (RetryContext) map.get(key);
79        }
80 
81        public void put(Object key, RetryContext context) {
82                if (map.size() >= capacity) {
83                        throw new RetryCacheCapacityExceededException("Retry cache capacity limit breached. " +
84                                        "Do you need to re-consider the implementation of the key generator, " +
85                                        "or the equals and hashCode of the items that failed?");
86                }
87                map.put(key, context);
88        }
89 
90        public void remove(Object key) {
91                map.remove(key);
92        }
93 
94}

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