
com.alachisoft.ncache.client.CacheEventDescriptor Maven / Gradle / Ivy
package com.alachisoft.ncache.client;
import com.alachisoft.ncache.runtime.events.EventDataFilter;
import com.alachisoft.ncache.runtime.events.EventType;
import java.util.EnumSet;
/**
* Instance of this class holds the link to the registered delegate
* Keep it safe and use it to unregister the registered delegate when required.
* The bool isRegistered returns false when the discriptor has been consumed to unregister the delegate.
* Then this instance can then be disposed of. Upon re-registering for the interested event, a new discriptor will be created.
*/
public final class CacheEventDescriptor {
// private EventType _eventType;
private EnumSet _eventTypes;
private EventHandle _handle = null;
private String _cacheName;
private boolean _isRegistered;
private CacheDataModificationListener _cacheDataNotificationListener;
private EventDataFilter _datafilter;
private Object _syncblk = new Object();
private CacheEventDescriptor() {
}
/**
* @hidden
* @param eventTypes
* @param cacheName
* @param listener
* @param datafilter
* @return
*/
//Creation is CacheDesriptor's responsiblity
public static CacheEventDescriptor createCacheDiscriptor(EnumSet eventTypes, String cacheName, CacheDataModificationListener listener, EventDataFilter datafilter) {
CacheEventDescriptor descriptor = new CacheEventDescriptor();
descriptor.setRegisteredAgainst(eventTypes);
descriptor.setCacheName(cacheName);
descriptor.settCacheDataNotificationListener(listener);
descriptor.setIsRegistered(true);
descriptor.setDataFilter(datafilter);
return descriptor;
}
/**
* Gets the datafilter of the descriptor.
* @return EventDataFilter value of the descriptor.
*/
public EventDataFilter getDataFilter() {
return _datafilter;
}
/**
* Sets the value of the EventDataFilter.
* @param value EventDataFilter value.
*/
public void setDataFilter(EventDataFilter value) {
_datafilter = value;
}
/**
* Returns true if the linked event delegate is registered, returns false when the descriptor has been consumed
* This property is ThreadSafe.
* @return If descriptor is registered or not.
*/
public boolean getIsRegistered() {
synchronized (_syncblk) {
return _isRegistered;
}
}
/**
* This method is intended to be called internally.
* @param value
*/
public void setIsRegistered(boolean value) {
synchronized (_syncblk) {
_isRegistered = value;
}
}
/**
* Name of the cache registered against
*/
public String getCacheName() {
return _cacheName;
}
/**
* This method is intended to be called internally.
* @param value
*/
public void setCacheName(String value) {
_cacheName = value;
}
/**
* Gets the Event Types against which the descriptor is registered.
* @return The enumset containing all the registered event types.
*/
public EnumSet getRegisteredAgainst() {
return _eventTypes;
}
/**
* Sets the Event Types against which the descriptor is registered.
* @param value The enumset containing all the registered event types.
*/
public void setRegisteredAgainst(EnumSet value) {
_eventTypes = value;
}
/**
* Gets the Listener that triggers when any data changes in cache.
* @return The instance of data modification listener.
*/
public CacheDataModificationListener getCacheDataNotificationListener() {
return _cacheDataNotificationListener;
}
/**
* Sets the Listener that triggers when any data changes in cache.
* @param listener The instance of data modification listener.
*/
public void settCacheDataNotificationListener(CacheDataModificationListener listener) {
_cacheDataNotificationListener = listener;
}
/**
* Cannot reset once created
* @hidden
* @return
*/
public EventHandle getHandle() {
return _handle;
}
/**
* @hidden
* @param value
*/
public void setHandle(EventHandle value) {
if (_handle == null) {
setIsRegistered(true);
_handle = value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy