001package org.apache.commons.jcs.auxiliary.disk;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.commons.jcs.engine.CacheElement;
023import org.apache.commons.jcs.engine.behavior.ICacheElement;
024import org.apache.commons.jcs.engine.behavior.IElementAttributes;
025
026/**
027 * Implementation of cache elements in purgatory.
028 * 
029 * Elements are stored in purgatory when they are spooled to the auxiliary cache, but have not yet
030 * been written to disk.
031 */
032public class PurgatoryElement<K, V>
033    extends CacheElement<K, V>
034{
035    /** Don't change */
036    private static final long serialVersionUID = -8152034342684135628L;
037
038    /** Is the element ready to be spooled? */
039    private boolean spoolable = false;
040
041    /** Wrapped cache Element */
042    private ICacheElement<K, V> cacheElement;
043
044    /**
045     * Constructor for the PurgatoryElement&lt;K, V&gt; object
046     * 
047     * @param cacheElement CacheElement
048     */
049    public PurgatoryElement( ICacheElement<K, V> cacheElement )
050    {
051        super(cacheElement.getCacheName(),
052                cacheElement.getKey(), cacheElement.getVal(),
053                cacheElement.getElementAttributes());
054        this.cacheElement = cacheElement;
055    }
056
057    /**
058     * Gets the spoolable property.
059     * 
060     * @return The spoolable value
061     */
062    public boolean isSpoolable()
063    {
064        return spoolable;
065    }
066
067    /**
068     * Sets the spoolable property.
069     * 
070     * @param spoolable The new spoolable value
071     */
072    public void setSpoolable( boolean spoolable )
073    {
074        this.spoolable = spoolable;
075    }
076
077    /**
078     * Get the wrapped cache element.
079     * 
080     * @return ICacheElement
081     */
082    public ICacheElement<K, V> getCacheElement()
083    {
084        return cacheElement;
085    }
086
087    // ------------------------------------------------ interface ICacheElement
088
089    /**
090     * @return cacheElement.getCacheName();
091     * @see ICacheElement#getCacheName
092     */
093    @Override
094    public String getCacheName()
095    {
096        return cacheElement.getCacheName();
097    }
098
099    /**
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}