001package org.apache.commons.jcs3.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(final String key, final boolean eternal, final String createTime,
056                        final long maxLifeSeconds, final long expiresInSeconds)
057    {
058                this.key = key;
059                this.eternal = eternal;
060                this.createTime = createTime;
061                this.maxLifeSeconds = maxLifeSeconds;
062                this.expiresInSeconds = expiresInSeconds;
063        }
064
065        /**
066     * @return a string representation of the key
067     */
068    public String getKey()
069    {
070        return this.key;
071    }
072
073    /**
074     * @return true if the item does not expire
075     */
076    public boolean isEternal()
077    {
078        return this.eternal;
079    }
080
081    /**
082     * @return the time the object was created
083     */
084    public String getCreateTime()
085    {
086        return this.createTime;
087    }
088
089    /**
090     * Ignored if isEternal
091     * @return the longest this object can live.
092     */
093    public long getMaxLifeSeconds()
094    {
095        return this.maxLifeSeconds;
096    }
097
098    /**
099     * Ignored if isEternal
100     * @return how many seconds until this object expires.
101     */
102    public long getExpiresInSeconds()
103    {
104        return this.expiresInSeconds;
105    }
106
107    /**
108     * @return string info on the item
109     */
110    @Override
111    public String toString()
112    {
113        final StringBuilder buf = new StringBuilder();
114        buf.append( "\nCacheElementInfo " );
115        buf.append( "\n Key [" ).append( getKey() ).append( "]" );
116        buf.append( "\n Eternal [" ).append( isEternal() ).append( "]" );
117        buf.append( "\n CreateTime [" ).append( getCreateTime() ).append( "]" );
118        buf.append( "\n MaxLifeSeconds [" ).append( getMaxLifeSeconds() ).append( "]" );
119        buf.append( "\n ExpiresInSeconds [" ).append( getExpiresInSeconds() ).append( "]" );
120
121        return buf.toString();
122    }
123}