com.alachisoft.ncache.client.internal.caching.CacheEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
/*
* @(#)CacheEvent.java
*
* Created on September 14, 2006, 11:53 AM
*
* Copyright 2005 Alachisoft, Inc. All rights reserved.
* ALACHISOFT PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package com.alachisoft.ncache.client.internal.caching;
import java.util.EventObject;
import com.alachisoft.ncache.client.internal.caching.CacheItemRemovedReason;
//~--- classes ----------------------------------------------------------------
/**
* CacheEvent is used to notify interested parties that
* something has happened with respect to a cache.
*
* @author Arif Iftikhar
* @version 0.1
*/
public class CacheEvent extends EventObject {
private EventType type;
private String key;
private Object value;
private CacheItemRemovedReason reason;
/**
* Creates a new object representing a cache event.
*
* @param source the cache object responsible for the event
* @param type the event type
* @param key the key of the item added.
*/
public CacheEvent(Object source, EventType type, String key) {
super(source);
this.type = type;
this.key = key;
}
/**
* Creates a new object representing a cache event.
*
* @param source the cache object responsible for the event
* @param type the event type
* @param key the key of the item added.
* @param value the value of the item added.
*/
public CacheEvent(Object source, EventType type, String key, Object value) {
super(source);
this.type = type;
this.key = key;
this.value = value;
}
/**
* Creates a new object representing a cache event.
*
* @param source the cache object responsible for the event
* @param type the event type
* @param key the key of the item added.
* @param value the value of the item added.
* @param reason the reason for the removal of the item from
* the cache.
* @see CacheItemRemovedReason
*/
public CacheEvent(Object source, EventType type, String key, Object value,
CacheItemRemovedReason reason) {
super(source);
this.type = type;
this.key = key;
this.value = value;
this.reason = reason;
}
/**
* Gets the type of event.
*
* @return the type
*/
public EventType getEventType() {
return type;
}
/**
* Returns the Key of the item for which this event occured.
*
* @return Returns the Key of the item for which this event occured.
*/
public String getKey() {
return key;
}
/**
* Returns the Value of the item for which this event occured.
*
* @return Returns the Value of the item for which this event occured.
*/
public Object getValue() {
return value;
}
/**
* Returns the remove reason for the Reamve Event.
*
* @return Returns the remove reason for the Reamve Event.
*/
public CacheItemRemovedReason getRemoveReason() {
return reason;
}
/**
* Defines the ADDED, UPDATED, REMOVED and CLEARED event types, along
* with their string representations, returned by toString().
*/
public static final class EventType {
/**
* Added type.
*/
public static final EventType ADDED = new EventType("ADDED");
/**
* Updated type.
*/
public static final EventType UPDATED = new EventType("UPDATED");
/**
* Removed type.
*/
public static final EventType REMOVED = new EventType("REMOVED");
/**
* Cleared type.
*/
public static final EventType CLEARED = new EventType("CLEARED");
private String typeString;
/**
* @param s
*/
private EventType(String s) {
typeString = s;
}
/**
* Converts the type to a string.
*
* @return the string
*/
public String toString() {
return typeString;
}
}
}