View Javadoc
1   package org.apache.commons.jcs.engine.logging;
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.logging.behavior.ICacheEvent;
23  
24  import java.util.Date;
25  
26  /** It's returned from create and passed into log. */
27  public class CacheEvent<K>
28      implements ICacheEvent<K>
29  {
30      /** Don't change. */
31      private static final long serialVersionUID = -5913139566421714330L;
32  
33      /** The time at which this object was created. */
34      private final long createTime = System.currentTimeMillis();
35  
36      /** The auxiliary or other source of the event. */
37      private String source;
38  
39      /** The cache region */
40      private String region;
41  
42      /** The event name: update, get, remove, etc. */
43      private String eventName;
44  
45      /** disk location, ip, etc. */
46      private String optionalDetails;
47  
48      /** The key that was put or retrieved. */
49      private K key;
50  
51      /**
52       * @param source the source to set
53       */
54      @Override
55  	public void setSource( String source )
56      {
57          this.source = source;
58      }
59  
60      /**
61       * @return the source
62       */
63      @Override
64  	public String getSource()
65      {
66          return source;
67      }
68  
69      /**
70       * @param region the region to set
71       */
72      @Override
73  	public void setRegion( String region )
74      {
75          this.region = region;
76      }
77  
78      /**
79       * @return the region
80       */
81      @Override
82  	public String getRegion()
83      {
84          return region;
85      }
86  
87      /**
88       * @param eventName the eventName to set
89       */
90      @Override
91  	public void setEventName( String eventName )
92      {
93          this.eventName = eventName;
94      }
95  
96      /**
97       * @return the eventName
98       */
99      @Override
100 	public String getEventName()
101     {
102         return eventName;
103     }
104 
105     /**
106      * @param optionalDetails the optionalDetails to set
107      */
108     @Override
109 	public void setOptionalDetails( String optionalDetails )
110     {
111         this.optionalDetails = optionalDetails;
112     }
113 
114     /**
115      * @return the optionalDetails
116      */
117     @Override
118 	public String getOptionalDetails()
119     {
120         return optionalDetails;
121     }
122 
123     /**
124      * @param key the key to set
125      */
126     @Override
127 	public void setKey( K key )
128     {
129         this.key = key;
130     }
131 
132     /**
133      * @return the key
134      */
135     @Override
136 	public K getKey()
137     {
138         return key;
139     }
140 
141     /**
142      * The time at which this object was created.
143      * <p>
144      * @return the createTime
145      */
146     public long getCreateTime()
147     {
148         return createTime;
149     }
150 
151     /**
152      * @return reflection toString
153      */
154     @Override
155     public String toString()
156     {
157     	StringBuilder sb = new StringBuilder();
158     	sb.append("CacheEvent: ").append(eventName).append(" Created: ").append(new Date(createTime));
159     	if (source != null)
160     	{
161         	sb.append(" Source: ").append(source);
162     	}
163     	if (region != null)
164     	{
165         	sb.append(" Region: ").append(region);
166     	}
167     	if (key != null)
168     	{
169         	sb.append(" Key: ").append(key);
170     	}
171     	if (optionalDetails != null)
172     	{
173         	sb.append(" Details: ").append(optionalDetails);
174     	}
175         return sb.toString();
176     }
177 }