1 package org.apache.commons.jcs.auxiliary.disk;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.commons.jcs.engine.CacheElement;
23 import org.apache.commons.jcs.engine.behavior.ICacheElement;
24 import org.apache.commons.jcs.engine.behavior.IElementAttributes;
25
26 /**
27 * Implementation of cache elements in purgatory.
28 *
29 * Elements are stored in purgatory when they are spooled to the auxiliary cache, but have not yet
30 * been written to disk.
31 */
32 public class PurgatoryElement<K, V>
33 extends CacheElement<K, V>
34 {
35 /** Don't change */
36 private static final long serialVersionUID = -8152034342684135628L;
37
38 /** Is the element ready to be spooled? */
39 private boolean spoolable = false;
40
41 /** Wrapped cache Element */
42 private ICacheElement<K, V> cacheElement;
43
44 /**
45 * Constructor for the PurgatoryElement<K, V> object
46 *
47 * @param cacheElement CacheElement
48 */
49 public PurgatoryElement( ICacheElement<K, V> cacheElement )
50 {
51 super(cacheElement.getCacheName(),
52 cacheElement.getKey(), cacheElement.getVal(),
53 cacheElement.getElementAttributes());
54 this.cacheElement = cacheElement;
55 }
56
57 /**
58 * Gets the spoolable property.
59 *
60 * @return The spoolable value
61 */
62 public boolean isSpoolable()
63 {
64 return spoolable;
65 }
66
67 /**
68 * Sets the spoolable property.
69 *
70 * @param spoolable The new spoolable value
71 */
72 public void setSpoolable( boolean spoolable )
73 {
74 this.spoolable = spoolable;
75 }
76
77 /**
78 * Get the wrapped cache element.
79 *
80 * @return ICacheElement
81 */
82 public ICacheElement<K, V> getCacheElement()
83 {
84 return cacheElement;
85 }
86
87 // ------------------------------------------------ interface ICacheElement
88
89 /**
90 * @return cacheElement.getCacheName();
91 * @see ICacheElement#getCacheName
92 */
93 @Override
94 public String getCacheName()
95 {
96 return cacheElement.getCacheName();
97 }
98
99 /**
100 * @return cacheElement.getKey();
101 * @see ICacheElement#getKey
102 */
103 @Override
104 public K getKey()
105 {
106 return cacheElement.getKey();
107 }
108
109 /**
110 * @return cacheElement.getVal();
111 * @see ICacheElement#getVal
112 */
113 @Override
114 public V getVal()
115 {
116 return cacheElement.getVal();
117 }
118
119 /**
120 * @return cacheElement.getElementAttributes();
121 * @see ICacheElement#getElementAttributes
122 */
123 @Override
124 public IElementAttributes getElementAttributes()
125 {
126 return cacheElement.getElementAttributes();
127 }
128
129 /**
130 * @param attr
131 * @see ICacheElement#setElementAttributes
132 */
133 @Override
134 public void setElementAttributes( IElementAttributes attr )
135 {
136 cacheElement.setElementAttributes( attr );
137 }
138
139 /**
140 * @return debug string
141 */
142 @Override
143 public String toString()
144 {
145 StringBuilder buf = new StringBuilder();
146 buf.append( "[PurgatoryElement: " );
147 buf.append( " isSpoolable = " + isSpoolable() );
148 buf.append( " CacheElement = " + getCacheElement() );
149 buf.append( " CacheName = " + getCacheName() );
150 buf.append( " Key = " + getKey() );
151 buf.append( " Value = " + getVal() );
152 buf.append( " ElementAttributes = " + getElementAttributes() );
153 buf.append( "]" );
154 return buf.toString();
155 }
156 }