001package org.apache.commons.jcs.admin;
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 java.beans.ConstructorProperties;
023
024
025/**
026 * Stores info on a cache element for the template
027 */
028public class CacheElementInfo
029{
030    /** element key */
031    private final String key;
032
033    /** is it eternal */
034    private final boolean eternal;
035
036    /** when it was created */
037    private final String createTime;
038
039    /** max life */
040    private final long maxLifeSeconds;
041
042    /** when it will expire */
043    private final long expiresInSeconds;
044
045    /**
046     * Parameterized constructor
047     *
048         * @param key element key
049         * @param eternal is it eternal
050         * @param createTime when it was created
051         * @param maxLifeSeconds max life
052         * @param expiresInSeconds when it will expire
053         */
054    @ConstructorProperties({"key", "eternal", "createTime", "maxLifeSeconds", "expiresInSeconds"})
055    public CacheElementInfo(String key, boolean eternal, String createTime,
056                        long maxLifeSeconds, long expiresInSeconds)
057    {
058                super();
059                this.key = key;
060                this.eternal = eternal;
061                this.createTime = createTime;
062                this.maxLifeSeconds = maxLifeSeconds;
063                this.expiresInSeconds = expiresInSeconds;
064        }
065
066        /**
067     * @return a string representation of the key
068     */
069    public String getKey()
070    {
071        return this.key;
072    }
073
074    /**
075     * @return true if the item does not expire
076     */
077    public boolean isEternal()
078    {
079        return this.eternal;
080    }
081
082    /**
083     * @return the time the object was created
084     */
085    public String getCreateTime()
086    {
087        return this.createTime;
088    }
089
090    /**
091     * Ignored if isEternal
092     * @return the longest this object can live.
093     */
094    public long getMaxLifeSeconds()
095    {
096        return this.maxLifeSeconds;
097    }
098
099    /**
100     * Ignored if isEternal
101     * @return how many seconds until this object expires.
102     */
103    public long getExpiresInSeconds()
104    {
105        return this.expiresInSeconds;
106    }
107
108    /**
109     * @return string info on the item
110     */
111    @Override
112    public String toString()
113    {
114        StringBuilder buf = new StringBuilder();
115        buf.append( "\nCacheElementInfo " );
116        buf.append( "\n Key [" ).append( getKey() ).append( "]" );
117        buf.append( "\n Eternal [" ).append( isEternal() ).append( "]" );
118        buf.append( "\n CreateTime [" ).append( getCreateTime() ).append( "]" );
119        buf.append( "\n MaxLifeSeconds [" ).append( getMaxLifeSeconds() ).append( "]" );
120        buf.append( "\n ExpiresInSeconds [" ).append( getExpiresInSeconds() ).append( "]" );
121
122        return buf.toString();
123    }
124}