001package org.apache.commons.jcs3.engine.logging; 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.util.Date; 023 024import org.apache.commons.jcs3.engine.logging.behavior.ICacheEvent; 025 026/** It's returned from create and passed into log. */ 027public class CacheEvent<K> 028 implements ICacheEvent<K> 029{ 030 /** Don't change. */ 031 private static final long serialVersionUID = -5913139566421714330L; 032 033 /** The time at which this object was created. */ 034 private final long createTime = System.currentTimeMillis(); 035 036 /** The auxiliary or other source of the event. */ 037 private String source; 038 039 /** The cache region */ 040 private String region; 041 042 /** The event name: update, get, remove, etc. */ 043 private String eventName; 044 045 /** disk location, ip, etc. */ 046 private String optionalDetails; 047 048 /** The key that was put or retrieved. */ 049 private K key; 050 051 /** 052 * @param source the source to set 053 */ 054 @Override 055 public void setSource( final String source ) 056 { 057 this.source = source; 058 } 059 060 /** 061 * @return the source 062 */ 063 @Override 064 public String getSource() 065 { 066 return source; 067 } 068 069 /** 070 * @param region the region to set 071 */ 072 @Override 073 public void setRegion( final String region ) 074 { 075 this.region = region; 076 } 077 078 /** 079 * @return the region 080 */ 081 @Override 082 public String getRegion() 083 { 084 return region; 085 } 086 087 /** 088 * @param eventName the eventName to set 089 */ 090 @Override 091 public void setEventName( final String eventName ) 092 { 093 this.eventName = eventName; 094 } 095 096 /** 097 * @return the eventName 098 */ 099 @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( final 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( final 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 final 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}