本文整理汇总了Java中javax.cache.event.EventType类的典型用法代码示例。如果您正苦于以下问题:Java EventType类的具体用法?Java EventType怎么用?Java EventType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventType类属于javax.cache.event包,在下文中一共展示了EventType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRemoval
import javax.cache.event.EventType; //导入依赖的package包/类
@Override
public void onRemoval(RemovalNotification<K, V> notification)
{
switch (notification.getCause())
{
case EXPIRED:
notifyListeners(new GuavaCacheEntryEvent<>(this, EventType.EXPIRED, notification));
break;
case EXPLICIT:
notifyListeners(new GuavaCacheEntryEvent<>(this, EventType.REMOVED, notification));
break;
case REPLACED:
notifyListeners(new GuavaCacheEntryEvent<>(this, EventType.UPDATED, notification));
break;
}
}
示例2: createRegistry
import javax.cache.event.EventType; //导入依赖的package包/类
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
registry.bind("myFilter", new CacheEntryEventFilter<Object, Object>() {
@Override
public boolean evaluate(CacheEntryEvent<?, ?> event) throws CacheEntryListenerException {
if (event.getEventType() == EventType.REMOVED) {
return false;
}
return !event.getValue().toString().startsWith("to-filter-");
}
});
return registry;
}
示例3: testContinuousQueryDoNotFireExistingEntries
import javax.cache.event.EventType; //导入依赖的package包/类
@Test
public void testContinuousQueryDoNotFireExistingEntries() throws Exception {
context.startRoute("continuousQuery");
getMockEndpoint("mock:test1").expectedMessageCount(100);
Map<Integer, Person> persons = createPersons(1, 100);
IgniteCache<Integer, Person> cache = ignite().getOrCreateCache("testcontinuous1");
cache.putAll(persons);
assertMockEndpointsSatisfied();
for (Exchange exchange : getMockEndpoint("mock:test1").getExchanges()) {
assert_().that(exchange.getIn().getHeader(IgniteConstants.IGNITE_CACHE_NAME)).isEqualTo("testcontinuous1");
assert_().that(exchange.getIn().getHeader(IgniteConstants.IGNITE_CACHE_EVENT_TYPE)).isEqualTo(EventType.CREATED);
assert_().that(exchange.getIn().getHeader(IgniteConstants.IGNITE_CACHE_KEY)).isIn(persons.keySet());
assert_().that(exchange.getIn().getBody()).isIn(persons.values());
}
}
示例4: getAndReplace
import javax.cache.event.EventType; //导入依赖的package包/类
@Override
public V getAndReplace(K key, V value)
{
throwISEwhenClosed();
Action<K, V, Object> action = new ReplaceAction<K, V, Object>(key, value, EventType.UPDATED);
V oldValue = null;
if (actionRunnerWriteBehind.preMutate(action))
{
oldValue = tcache.getAndReplace(key, value);
boolean replaced = oldValue != null;
ChangeStatus changeStatus = replaced ? ChangeStatus.CHANGED : ChangeStatus.UNCHANGED;
actionRunnerWriteBehind.postMutate(action, changeStatus);
}
action.close();
return oldValue;
}
示例5: put0
import javax.cache.event.EventType; //导入依赖的package包/类
void put0(K key, V value, boolean writeThrough)
{
throwISEwhenClosed();
kvUtil.verifyKeyAndValueNotNull(key, value);
Action<K,V,Object> action = new PutAction<>(key, value, EventType.CREATED, false, writeThrough);
if (actionRunner.preMutate(action))
{
Holders<V> holders = tcache.putToMapI(key, value, tcache.cacheTimeSpread(), false);
final EventType eventType;
if (holders == null)
eventType = null;
else
{
if (holders.newHolder == null || holders.newHolder.isInvalid())
eventType = null; // new is invalid
else
eventType = holders.oldHolder == null ? EventType.CREATED : EventType.UPDATED;
}
action.setEventType(eventType);
actionRunner.postMutate(action);
}
action.close();
}
示例6: putIfAbsent
import javax.cache.event.EventType; //导入依赖的package包/类
@Override
public boolean putIfAbsent(K key, V value)
{
throwISEwhenClosed();
PutAction<K,V,Object> action = new PutAction<>(key, value, EventType.CREATED, false);
boolean added = false;
if (actionRunnerWriteBehind.preMutate(action))
{
Holders<V> holders = tcache.putIfAbsentH(key, value);
// For JSR107 putIfAbsent() should return whether a value was set.
// It is set when the old holder was null AND the new holder is not null.
// The latter case (new holder == null) can happen if it immediately expires.
added = holders.oldHolder == null && holders.newHolder != null;
if (added)
actionRunnerWriteBehind.postMutate(action);
}
return added;
}
示例7: replace
import javax.cache.event.EventType; //导入依赖的package包/类
@Override
public boolean replace(K key, V oldValue, V newValue)
{
throwISEwhenClosed();
kvUtil.verifyKeyAndValueNotNull(key, newValue);
kvUtil.verifyValueNotNull(oldValue);
boolean replaced = false;
Action<K, V, Object> action = new ReplaceAction<K, V, Object>(key, newValue, EventType.UPDATED);
if (actionRunnerWriteBehind.preMutate(action))
{
ChangeStatus changeStatus = tcache.replace(key, oldValue, newValue);
actionRunnerWriteBehind.postMutate(action, changeStatus);
replaced = changeStatus == ChangeStatus.CHANGED;
}
return replaced;
}
示例8: isListeningFor
import javax.cache.event.EventType; //导入依赖的package包/类
/**
* Returns whether this {@link ListenerEntry} is listening to the given eventType
* @param eventType The event Type
* @return true, if the listener is listening to the given eventType
*/
boolean isListeningFor(EventType eventType)
{
switch (eventType)
{
case CREATED:
return listener instanceof CacheEntryCreatedListener;
case EXPIRED:
return listener instanceof CacheEntryExpiredListener;
case REMOVED:
return listener instanceof CacheEntryRemovedListener;
case UPDATED:
return listener instanceof CacheEntryUpdatedListener;
}
return false;
}
示例9: rebuildListenerPresent
import javax.cache.event.EventType; //导入依赖的package包/类
/**
* Rebuild the listenerPresent lookup array
*/
private void rebuildListenerPresent()
{
short listenerPresentXnew = 0;
for (ListenerEntry<K, V> listener : listeners)
{
for (EventType eventType : EventType.values())
{
if (listener.isListeningFor(eventType))
{
listenerPresentXnew |= (1 << eventType.ordinal());
}
}
}
listenerPresentMask = listenerPresentXnew;
}
示例10: enableCacheEntryListener
import javax.cache.event.EventType; //导入依赖的package包/类
/**
* Enables a listener, without adding it to the Configuration. An enabled listener can send events after this method returns.
* The caller must make sure that the
* corresponding Configuration object reflects the change.
*
* @param listenerConfiguration
* @return
*/
private synchronized boolean enableCacheEntryListener(CacheEntryListenerConfiguration<K, V> listenerConfiguration)
{
DispatchMode dispatchMode = listenerConfiguration.isSynchronous() ? DispatchMode.SYNC : DispatchMode.ASYNC_TIMED;
ListenerEntry<K, V> newListener = new ListenerEntry<K, V>(listenerConfiguration, tcache, dispatchMode);
boolean added = listeners.add(newListener);
for (EventType eventType : EventType.values())
{
if (newListener.isListeningFor(eventType))
{
listenerPresentMask |= (1 << eventType.ordinal());
}
}
return added;
}
示例11: dispatchEvents
import javax.cache.event.EventType; //导入依赖的package包/类
/**
* Notifies all listeners that a given EventType has happened for all the given entries.
* You can force all listeners to Async mode, but should only do this if it is compliant with JSR107.
* <p>
* <b>IMPORTANT PERFORMANCE NOTE</b>: To avoid unnecessary object creation (TCacheEntryEvent and the event
* Iterable), you SHOULD check with {@link #hasListenerFor(EventType)} whether there is any Listener
* interested in the given eventType. If not, do you can spare to create the TCacheEntryEvent events.
*
* @param entries The key-value pairs for which to send events
* @param eventType The event Type
* @param forceAsync Force async mode
*/
public void dispatchEvents(Map<K, V> entries, EventType eventType, boolean forceAsync)
{
if (!hasListenerFor(eventType))
{
return;
}
List<TCacheEntryEvent<K,V>> events = new ArrayList<>(entries.size());
for (Entry<K, V> entry : entries.entrySet())
{
K key = entry.getKey();
V value = entry.getValue();
TCacheEntryEvent<K,V> event = new TCacheEntryEvent<>(jsr107cache, eventType, key, value);
events.add(event);
}
dispatchEventsToListeners(events, eventType, forceAsync);
}
示例12: CacheContinuousQueryEntry
import javax.cache.event.EventType; //导入依赖的package包/类
/**
* @param cacheId Cache ID.
* @param evtType Event type.
* @param key Key.
* @param newVal New value.
* @param oldVal Old value.
* @param keepBinary Keep binary flag.
* @param part Partition.
* @param updateCntr Update partition counter.
* @param topVer Topology version if applicable.
* @param flags Flags.
*/
CacheContinuousQueryEntry(
int cacheId,
EventType evtType,
KeyCacheObject key,
@Nullable CacheObject newVal,
@Nullable CacheObject oldVal,
boolean keepBinary,
int part,
long updateCntr,
@Nullable AffinityTopologyVersion topVer,
byte flags) {
this.cacheId = cacheId;
this.evtType = evtType;
this.key = key;
this.newVal = newVal;
this.oldVal = oldVal;
this.part = part;
this.updateCntr = updateCntr;
this.topVer = topVer;
this.flags = flags;
if (keepBinary)
this.flags |= KEEP_BINARY;
}
示例13: flag
import javax.cache.event.EventType; //导入依赖的package包/类
/**
* @param evtType Type.
* @return Flag value.
*/
private byte flag(EventType evtType) {
switch (evtType) {
case CREATED:
return CREATED_FLAG;
case UPDATED:
return UPDATED_FLAG;
case REMOVED:
return REMOVED_FLAG;
case EXPIRED:
return EXPIRED_FLAG;
default:
throw new IllegalStateException("Unknown type: " + evtType);
}
}
示例14: checkEvents
import javax.cache.event.EventType; //导入依赖的package包/类
/**
* @param evts Events.
* @param evtType Event type.
*/
private void checkEvents(List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts,
EventType evtType) {
for (int key = 0; key < KEYS; key++) {
QueryTestKey keyVal = new QueryTestKey(key);
for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : evts) {
if (e.getKey().equals(keyVal)) {
checkSingleEvent(e,
evtType,
evtType == CREATED ? new QueryTestValue(key) : null,
evtType == REMOVED ? new QueryTestValue(key) : null);
keyVal = null;
break;
}
}
assertNull("Event for key not found.", keyVal);
}
}
示例15: removeAll
import javax.cache.event.EventType; //导入依赖的package包/类
@Override
public void removeAll() {
checkOpen();
long start = configuration.isStatisticsEnabled() ? System.nanoTime() : 0;
final AtomicLong removedCount = new AtomicLong(0L);
internalClear(new Action1<SerializableDocument>() {
@Override
public void call(SerializableDocument serializableDocument) {
K key = fromInternalKey(serializableDocument.id());
V value = (V) serializableDocument.content();
eventManager.queueEvent(new CouchbaseCacheEntryEvent<K, V>(EventType.REMOVED, key, value,
CouchbaseCache.this));
}
});
eventManager.dispatch();
if (configuration.isStatisticsEnabled() && removedCount.get() > 0L) {
statisticsMxBean.increaseCacheRemovals(removedCount.get());
//approximate remove time as an average
statisticsMxBean.addRemoveTimeNano((System.nanoTime() - start) / removedCount.get());
}
}