void onEvent(Object event) { messages.offer(event); if (event instanceof ContextualNotification) { notifs.add(((ContextualNotification) event).getType()); } num.countDown(); } });
@Override public void cacheRemoved(String alias, Cache<?, ?> cache) { collector.onNotification( new ContextualNotification( configuration.getContext().with("cacheName", alias), EhcacheNotification.CACHE_REMOVED.name())); }
private void waitFor(String notifType) throws InterruptedException { while (!Thread.currentThread().isInterrupted()) { Message message = nmsService.waitForMessage(); if (message.getType().equals("NOTIFICATION")) { ContextualNotification notification = message.unwrap(ContextualNotification.class).get(0); if (notification.getType().equals(notifType)) { break; } } } assertFalse(Thread.currentThread().isInterrupted()); }
private void cacheCleared(String alias) { collector.onNotification( new ContextualNotification( configuration.getContext().with("cacheName", alias), EhcacheNotification.CACHE_CLEARED.name())); }
@Override public synchronized void stop() { // do not call deregisterListener here because the stateTransition event for UNINITIALIZED won't be caught. // so deregisterListener is done in the stateTransition listener //cacheManager.deregisterListener(this); collector.onNotification( new ContextualNotification( configuration.getContext(), EhcacheNotification.CACHE_MANAGER_CLOSED.name())); statisticCollector.stopStatisticCollector(); shutdownNow(scheduledExecutorService); }
@Override public void cacheAdded(String alias, Cache<?, ?> cache) { registerClearNotification(alias, cache); collector.onNotification( new ContextualNotification( configuration.getContext().with("cacheName", alias), EhcacheNotification.CACHE_ADDED.name())); }
@Override public void stateTransition(Status from, Status to) { switch (to) { case AVAILABLE: // .register() call should be there when CM is AVAILABLE // this is to expose the stats collector for management calls managementRegistry.register(statisticCollector); collector.onNotification( new ContextualNotification( configuration.getContext(), EhcacheNotification.CACHE_MANAGER_AVAILABLE.name())); break; case MAINTENANCE: collector.onNotification( new ContextualNotification( configuration.getContext(), EhcacheNotification.CACHE_MANAGER_MAINTENANCE.name())); break; case UNINITIALIZED: // deregister me - should not be in stop() - see other comments cacheManager.deregisterListener(this); break; default: throw new AssertionError("Unsupported state: " + to); } }