Java Code Examples for javax.cache.event.EventType#UPDATED

The following examples show how to use javax.cache.event.EventType#UPDATED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCacheJSR107.java    From triava with Apache License 2.0 6 votes vote down vote up
@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;				
}
 
Example 2
Source File: TCacheJSR107.java    From triava with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: TCacheJSR107.java    From triava with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: BlazingCacheCacheEntryListenerWrapper.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
void onEntryUpdated(K key, V oldValue, V value) {
    if (onUpdate) {
        BlazingCacheCacheEntryEvent event = new BlazingCacheCacheEntryEvent(key, oldValue, value, parent, EventType.UPDATED, true);
        if (filter != null && !filter.evaluate(event)) {
            return;
        }
        ((CacheEntryUpdatedListener) listener).onUpdated(Arrays.asList(event));
    }
}
 
Example 5
Source File: IgniteCacheContinuousQueryImmutableEntryTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 *
 */
@Test
public void testCacheContinuousQueryEntrySerialization() {
    CacheContinuousQueryEntry e0 = new CacheContinuousQueryEntry(
        1,
        EventType.UPDATED,
        new KeyCacheObjectImpl(1, new byte[] {0, 0, 0, 1}, 1),
        new CacheObjectImpl(2, new byte[] {0, 0, 0, 2}),
        new CacheObjectImpl(2, new byte[] {0, 0, 0, 3}),
        true,
        1,
        1L,
        new AffinityTopologyVersion(1L),
        (byte)0);

    e0.markFiltered();

    ByteBuffer buf = ByteBuffer.allocate(4096);
    DirectMessageWriter writer = new DirectMessageWriter((byte)1);

    // Skip write class header.
    writer.onHeaderWritten();
    e0.writeTo(buf, writer);

    CacheContinuousQueryEntry e1 = new CacheContinuousQueryEntry();
    IgniteMessageFactoryImpl msgFactory =
            new IgniteMessageFactoryImpl(new MessageFactory[]{new GridIoMessageFactory()});
    e1.readFrom(ByteBuffer.wrap(buf.array()), new DirectMessageReader(msgFactory, (byte)1));

    assertEquals(e0.cacheId(), e1.cacheId());
    assertEquals(e0.eventType(), e1.eventType());
    assertEquals(e0.isFiltered(), e1.isFiltered());
    assertEquals(e0.isBackup(), e1.isBackup());
    assertEquals(e0.isKeepBinary(), e1.isKeepBinary());
    assertEquals(e0.partition(), e1.partition());
    assertEquals(e0.updateCounter(), e1.updateCounter());

    // Key and value shouldn't be serialized in case an event is filtered.
    assertNull(e1.key());
    assertNotNull(e0.key());
    assertNull(e1.oldValue());
    assertNotNull(e0.oldValue());
    assertNull(e1.value());
    assertNotNull(e0.value());
}
 
Example 6
Source File: CacheEntryListenerClientServerTest.java    From cache2k with Apache License 2.0 4 votes vote down vote up
/**
 * Ensure that values can be loaded from the {@link org.jsr107.tck.event.CacheEntryListenerClient} via
 * the {@link org.jsr107.tck.event.CacheEntryListenerServer}.
 */
@Test
public void shouldHandleCacheEntryEventFromServerWithClient() {

  CacheTestSupport.MyCacheEntryListener<String, String> listener = new CacheTestSupport.MyCacheEntryListener<>();


  CacheEntryListenerServer<String, String> serverListener =
    new CacheEntryListenerServer<>(10011, String.class, String.class);
  serverListener.addCacheEventListener(listener);

  try {
    serverListener.open();

    CacheEntryListenerClient<String, String> clientListener =
      new CacheEntryListenerClient<>(serverListener.getInetAddress(), serverListener.getPort());

    TestCacheEntryEvent<String, String> event = new TestCacheEntryEvent(null, EventType.CREATED);
    event.setKey("key");
    event.setValue("value");
    event.setOldValueAvailable(false);
    ArrayList events = new ArrayList();
    events.add(event);

    clientListener.onCreated(events);
    Assert.assertThat(listener.getCreated(), is(1));

    clientListener.onRemoved(events);
    Assert.assertThat(listener.getRemoved(), is(0));

    event = new TestCacheEntryEvent(null, EventType.UPDATED);
    event.setKey("key");
    event.setValue("value");
    event.setOldValue("oldValue");
    event.setOldValueAvailable(true);

    events.clear();
    events.add(event);
    clientListener.onUpdated(events);
    Assert.assertThat(listener.getUpdated(), is(1));
    Assert.assertThat(listener.getCreated(), is(1));

  } catch (Exception e) {

  } finally {
    serverListener.close();
  }
}
 
Example 7
Source File: Listener.java    From cache2k with Apache License 2.0 4 votes vote down vote up
@Override
public EventType getEventType() {
  return EventType.UPDATED;
}