当前位置: 首页>>代码示例>>Java>>正文


Java EventType类代码示例

本文整理汇总了Java中org.ehcache.event.EventType的典型用法代码示例。如果您正苦于以下问题:Java EventType类的具体用法?Java EventType怎么用?Java EventType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EventType类属于org.ehcache.event包,在下文中一共展示了EventType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEventOrderForUpdateThatTriggersEviction

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testEventOrderForUpdateThatTriggersEviction () {
  CacheConfiguration<Long, SerializableObject> cacheConfiguration = newCacheConfigurationBuilder(Long.class, SerializableObject.class,
      newResourcePoolsBuilder()
          .heap(1L, EntryUnit.ENTRIES).offheap(1l, MemoryUnit.MB).build()).build();

  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
      .build(true);
  Cache<Long, SerializableObject> cache = cacheManager.getCache("cache", Long.class, SerializableObject.class);
  cache.getRuntimeConfiguration().registerCacheEventListener(listener1, EventOrdering.ORDERED, EventFiring.SYNCHRONOUS, EnumSet
      .of(EventType.EVICTED, EventType.CREATED, EventType.UPDATED, EventType.REMOVED));
  SerializableObject object1 = new SerializableObject(0xAAE60);     // 700 KB
  SerializableObject object2 = new SerializableObject(0xDBBA0);     // 900 KB

  cache.put(1L, object1);
  cache.put(1L, object2);
  assertThat(listener1.eventTypeHashMap.get(EventType.EVICTED), lessThan(listener1.eventTypeHashMap.get(EventType.CREATED)));

  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:EventNotificationTest.java

示例2: onEvent

import org.ehcache.event.EventType; //导入依赖的package包/类
@Override
public void onEvent(CacheEvent<? extends Object, ? extends Object> event) {
  Logger logger = LoggerFactory.getLogger(EhcacheWithLoaderWriter.class + "-" + "EventNotificationTest");
  logger.info(event.getType().toString());
  eventTypeHashMap.put(event.getType(), eventCounter.get());
  eventCounter.getAndIncrement();
  if(event.getType() == EventType.EVICTED){
    evicted.getAndIncrement();
  }
  if(event.getType() == EventType.CREATED){
    created.getAndIncrement();
  }
  if(event.getType() == EventType.UPDATED){
    updated.getAndIncrement();
  }
  if(event.getType() == EventType.REMOVED){
    removed.getAndIncrement();
  }
  if(event.getType() == EventType.EXPIRED){
    expired.getAndIncrement();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:EventNotificationTest.java

示例3: testCacheEventListener

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testCacheEventListener() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/ehcache-cacheEventListener.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  cache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.CREATED));
  cache.put(10, "cat");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
  cache.remove(10);
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.REMOVED));
  cache.put(10, "dog");
  resetValues();
  assertThat(configuration.getCacheConfigurations().containsKey("template1"), is(true));
  final Cache<Number, String> templateCache = cacheManager.getCache("template1", Number.class, String.class);
  templateCache.put(10,"cat");
  assertThat(TestCacheEventListener.FIRED_EVENT, nullValue());
  templateCache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:IntegrationConfigurationTest.java

示例4: testCacheEventListenerWithMultipleListener

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testCacheEventListenerWithMultipleListener() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/ehcache-multipleCacheEventListener.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  resetValues();
  cache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.CREATED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT, is(nullValue()));
  resetValues();
  cache.put(10, "cat");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT.getType(), is(EventType.UPDATED));
  resetValues();
  cache.remove(10);
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.REMOVED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT.getType(), is(EventType.REMOVED));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例5: userManagedListenerCache

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void userManagedListenerCache() throws Exception {
  // tag::userManagedListenerCache[]

  UserManagedCache<Long, String> cache = UserManagedCacheBuilder.newUserManagedCacheBuilder(Long.class, String.class)
      .withEventExecutors(Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(5)) // <1>
      .withEventListeners(CacheEventListenerConfigurationBuilder
          .newEventListenerConfiguration(ListenerObject.class, EventType.CREATED, EventType.UPDATED)
          .asynchronous()
          .unordered()) // <2>
      .withResourcePools(ResourcePoolsBuilder.newResourcePoolsBuilder()
          .heap(3, EntryUnit.ENTRIES))
      .build(true);

  cache.put(1L, "Put it");
  cache.put(1L, "Update it");

  cache.close();
  // end::userManagedListenerCache[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:UserManagedCaches.java

示例6: testCacheEventListener

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testCacheEventListener() {
  // tag::cacheEventListener[]
  CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
      .newEventListenerConfiguration(new ListenerObject(), EventType.CREATED, EventType.UPDATED) // <1>
      .unordered().asynchronous(); // <2>

  final CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
      .withCache("foo",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.heap(10))
              .add(cacheEventListenerConfiguration) // <3>
      ).build(true);

  final Cache<String, String> cache = manager.getCache("foo", String.class, String.class);
  cache.put("Hello", "World"); // <4>
  cache.put("Hello", "Everyone"); // <5>
  cache.remove("Hello"); // <6>
  // end::cacheEventListener[]

  manager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:22,代码来源:GettingStarted.java

示例7: testInvalidListenerConfig

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testInvalidListenerConfig() {
  try {
    UserManagedCacheBuilder.newUserManagedCacheBuilder(String.class, String.class)
      .withEventListeners(CacheEventListenerConfigurationBuilder
          .newEventListenerConfiguration(DefaultCacheEventListenerProviderTest.ListenerObject.class,
              EventType.CREATED,
              EventType.UPDATED)
              .synchronous()
              .unordered()
              .build())
      .build();
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e.getMessage(), equalTo("Listeners will not work unless Executors or EventDispatcher is configured."));
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:18,代码来源:UserManagedCacheBuilderTest.java

示例8: testCacheConfigUsage

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testCacheConfigUsage() {
  Set<EventType> eventTypeSet = new HashSet<>();
  eventTypeSet.add(EventType.CREATED);
  eventTypeSet.add(EventType.UPDATED);

  CacheEventListenerConfigurationBuilder listenerBuilder = CacheEventListenerConfigurationBuilder
      .newEventListenerConfiguration(ListenerObject.class, eventTypeSet).unordered().asynchronous();
  final CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
      .withCache("foo",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class, heap(10))
              .add(listenerBuilder)
              .build()).build(true);
  final Collection<?> bar = manager.getCache("foo", Object.class, Object.class).getRuntimeConfiguration().getServiceConfigurations();
  assertThat(bar.iterator().next().getClass().toString(), is(ListenerObject.object.toString()));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:17,代码来源:DefaultCacheEventListenerProviderTest.java

示例9: testReset

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testReset() {
  eventSink.created("k1", "v1");
  eventSink.evicted("k1", () -> "v2");
  eventSink.reset();
  eventSink.created("k1", "v1");
  eventSink.updated("k1", () -> "v1", "v2");
  eventSink.evicted("k1", () -> "v2");
  eventSink.close();

  InOrder inOrder = inOrder(listener);
  Matcher<StoreEvent<String, String>> createdMatcher = eventType(EventType.CREATED);
  inOrder.verify(listener).onEvent(argThat(createdMatcher));
  Matcher<StoreEvent<String, String>> updatedMatcher = eventType(EventType.UPDATED);
  inOrder.verify(listener).onEvent(argThat(updatedMatcher));
  Matcher<StoreEvent<String, String>> evictedMatcher = eventType(EventType.EVICTED);
  inOrder.verify(listener).onEvent(argThat(evictedMatcher));
  verifyNoMoreInteractions(listener);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:20,代码来源:InvocationScopedEventSinkTest.java

示例10: testEventFiltering

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testEventFiltering() {
  ScopedStoreEventDispatcher<String, String> dispatcher = new ScopedStoreEventDispatcher<>(1);
  @SuppressWarnings("unchecked")
  StoreEventListener<String, String> listener = mock(StoreEventListener.class, withSettings().verboseLogging());
  dispatcher.addEventListener(listener);

  @SuppressWarnings("unchecked")
  StoreEventFilter<String, String> filter = mock(StoreEventFilter.class);
  when(filter.acceptEvent(eq(EventType.CREATED), anyString(), ArgumentMatchers.<String>isNull(), anyString())).thenReturn(true);
  when(filter.acceptEvent(eq(EventType.REMOVED), anyString(), anyString(), anyString())).thenReturn(false);
  dispatcher.addEventFilter(filter);

  StoreEventSink<String, String> sink = dispatcher.eventSink();
  sink.removed("gone", () -> "really gone");
  sink.created("new", "and shiny");
  dispatcher.releaseEventSink(sink);

  Matcher<StoreEvent<String, String>> matcher = eventOfType(EventType.CREATED);
  verify(listener).onEvent(argThat(matcher));
  verifyNoMoreInteractions(listener);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:ScopedStoreEventDispatcherTest.java

示例11: testEvictionCandidateLimits

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testEvictionCandidateLimits() throws Exception {
  TestTimeSource timeSource = new TestTimeSource();
  StoreConfigurationImpl<String, String> configuration = new StoreConfigurationImpl<>(
    String.class, String.class, noAdvice(),
    getClass().getClassLoader(), ExpiryPolicyBuilder.noExpiration(), heap(1).build(), 1, null, null);
  TestStoreEventDispatcher<String, String> eventDispatcher = new TestStoreEventDispatcher<>();
  final String firstKey = "daFirst";
  eventDispatcher.addEventListener(event -> {
    if (event.getType().equals(EventType.EVICTED)) {
      assertThat(event.getKey(), is(firstKey));
    }
  });
  OnHeapStore<String, String> store = new OnHeapStore<>(configuration, timeSource,
    new IdentityCopier<>(), new IdentityCopier<>(), new NoopSizeOfEngine(), eventDispatcher);
  timeSource.advanceTime(10000L);
  store.put(firstKey, "daValue");
  timeSource.advanceTime(10000L);
  store.put("other", "otherValue");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:OnHeapStoreEvictionTest.java

示例12: testExpiryEventFiredOnExpiredCachedEntry

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testExpiryEventFiredOnExpiredCachedEntry() throws StoreAccessException {
  offHeapStore = createAndInitStore(timeSource, ExpiryPolicyBuilder.timeToIdleExpiration(Duration.ofMillis(10L)));

  final List<String> expiredKeys = new ArrayList<>();
  offHeapStore.getStoreEventSource().addEventListener(event -> {
    if (event.getType() == EventType.EXPIRED) {
      expiredKeys.add(event.getKey());
    }
  });

  offHeapStore.put("key1", "value1");
  offHeapStore.put("key2", "value2");

  offHeapStore.get("key1");   // Bring the entry to the caching tier

  timeSource.advanceTime(11);   // Expire the elements

  offHeapStore.get("key1");
  offHeapStore.get("key2");
  assertThat(expiredKeys, containsInAnyOrder("key1", "key2"));
  assertThat(getExpirationStatistic(offHeapStore).count(StoreOperationOutcomes.ExpirationOutcome.SUCCESS), is(2L));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:AbstractOffHeapStoreTest.java

示例13: performEvictionTest

import org.ehcache.event.EventType; //导入依赖的package包/类
private void performEvictionTest(TestTimeSource timeSource, ExpiryPolicy<Object, Object> expiry, EvictionAdvisor<String, byte[]> evictionAdvisor) throws StoreAccessException {
  AbstractOffHeapStore<String, byte[]> offHeapStore = createAndInitStore(timeSource, expiry, evictionAdvisor);
  try {
    @SuppressWarnings("unchecked")
    StoreEventListener<String, byte[]> listener = mock(StoreEventListener.class);
    offHeapStore.getStoreEventSource().addEventListener(listener);

    byte[] value = getBytes(MemoryUnit.KB.toBytes(200));
    offHeapStore.put("key1", value);
    offHeapStore.put("key2", value);
    offHeapStore.put("key3", value);
    offHeapStore.put("key4", value);
    offHeapStore.put("key5", value);
    offHeapStore.put("key6", value);

    Matcher<StoreEvent<String, byte[]>> matcher = eventType(EventType.EVICTED);
    verify(listener, atLeast(1)).onEvent(argThat(matcher));
  } finally {
    destroyStore(offHeapStore);
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:22,代码来源:AbstractOffHeapStoreTest.java

示例14: testAsyncEventFiring

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testAsyncEventFiring() throws Exception {
  eventService = new CacheEventDispatcherImpl<>(Executors.newCachedThreadPool(), orderedExecutor);
  eventService.setStoreEventSource(storeEventDispatcher);
  final CountDownLatch signal = new CountDownLatch(1);
  final CountDownLatch signal2 = new CountDownLatch(1);
  doAnswer(invocation -> {
    if (!signal.await(2, TimeUnit.SECONDS)) {
      return null;
    } else {
      signal2.countDown();
      return null;
    }
  }).when(listener).onEvent(any(CacheEvent.class));
  eventService.registerCacheEventListener(listener, EventOrdering.UNORDERED, EventFiring.ASYNCHRONOUS, EnumSet.of(EventType.CREATED));
  final CacheEvent<Number, String> create = eventOfType(EventType.CREATED);

  eventService.onEvent(create);

  signal.countDown();
  if (!signal2.await(2, TimeUnit.SECONDS)) {
    fail("event handler never triggered latch - are we synchronous?");
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:CacheEventDispatcherImplTest.java

示例15: testShutdownDisableStoreEventsAndShutsDownOrderedExecutor

import org.ehcache.event.EventType; //导入依赖的package包/类
@Test
public void testShutdownDisableStoreEventsAndShutsDownOrderedExecutor() {
  eventService.registerCacheEventListener(listener,
      EventOrdering.UNORDERED, EventFiring.SYNCHRONOUS, EnumSet.of(EventType.CREATED));
  CacheEventListener<Number, String> otherLsnr = mock(CacheEventListener.class);
  eventService.registerCacheEventListener(otherLsnr,
      EventOrdering.ORDERED, EventFiring.SYNCHRONOUS, EnumSet.of(EventType.REMOVED));

  eventService.shutdown();

  InOrder inOrder = inOrder(storeEventDispatcher, orderedExecutor);
  inOrder.verify(storeEventDispatcher).removeEventListener(any(StoreEventListener.class));
  inOrder.verify(storeEventDispatcher).setEventOrdering(false);
  inOrder.verify(orderedExecutor).shutdown();
  inOrder.verifyNoMoreInteractions();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:17,代码来源:CacheEventDispatcherImplTest.java


注:本文中的org.ehcache.event.EventType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。