All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.client.CacheEventDescriptor Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
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  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() {
    }

    //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;

    }

    public EventDataFilter getDataFilter() {
        return _datafilter;
    }

    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
     */
    public boolean getIsRegistered() {
        synchronized (_syncblk) {
            return _isRegistered;
        }
    }

    public void setIsRegistered(boolean value) {
        synchronized (_syncblk) {
            _isRegistered = value;
        }
    }

    /**
     * Name of the cache registered against
     */
    public String getCacheName() {
        return _cacheName;
    }

    public void setCacheName(String value) {
        _cacheName = value;
    }

    /**
     * Event Types registered against. Can be ORed to check registeration types
     */
    public EnumSet getRegisteredAgainst() {
        return _eventTypes;
    }

    public void setRegisteredAgainst(EnumSet value) {
        _eventTypes = value;
    }

//#if !EXPRESS
    public CacheDataModificationListener getCacheDataNotificationListener() {
        return _cacheDataNotificationListener;
    }

    public void settCacheDataNotificationListener(CacheDataModificationListener listener) {
        _cacheDataNotificationListener = listener;
    }
//#endif

    /**
     * Cannot reset once created
     */
    public EventHandle getHandle() {
        return _handle;
    }

    public void setHandle(EventHandle value) {
        if (_handle == null) {
            setIsRegistered(true);
            _handle = value;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy