@Test public void testPolling() { CacheManager manager = new CacheManager(); manager.removalAll(); manager.addCache(new Cache(new CacheConfiguration().name("tt").eternal(true).maxEntriesLocalHeap(5000).overflowToDisk(false))); Ehcache cache = manager.getEhcache("tt"); stupidCacheLoaderEvens.setMsDelay(100); cache.registerCacheLoader(stupidCacheLoaderEvens); cache.registerCacheLoader(stupidCacheLoaderOdds); int second = (new GregorianCalendar().get(Calendar.SECOND) + 5) % 60; ScheduledRefreshConfiguration config = new ScheduledRefreshConfiguration().batchSize(2).quartzThreadCount (2).pollTimeMs(100).cronExpression(second + "/1 * * * * ?").build(); ScheduledRefreshCacheExtension cacheExtension = new ScheduledRefreshCacheExtension(config, cache); cache.registerCacheExtension(cacheExtension); cacheExtension.init(); final int ELEMENT_COUNT=50; long[] orig=new long[ELEMENT_COUNT]; for (int i = 0; i < ELEMENT_COUNT; i++) { Element elem = new Element(new Integer(i), i + ""); orig[i]=elem.getCreationTime(); cache.put(elem); } sleepySeconds(20); manager.removalAll(); manager.shutdown(); }
@Override public void init() { if (config.getUniqueNamePart() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getUniqueNamePart(); } else { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName(); } this.groupName = name + "_grp"; try { makeAndStartQuartzScheduler(); try { JobDetail seed = addOverseerJob(); try { scheduleOverseerJob(seed); status = Status.STATUS_ALIVE; } catch (SchedulerException e) { LOG.error("Unable to schedule control job for Scheduled Refresh", e); } } catch (SchedulerException e) { LOG.error("Unable to add Scheduled Refresh control job to Quartz Job Scheduler", e); } } catch (SchedulerException e) { LOG.error("Unable to instantiate Quartz Job Scheduler for Scheduled Refresh", e); } }
ScheduledRefreshCacheExtension implements CacheExtension { @Override public void init() { if (config.getUniqueNamePart() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getUniqueNamePart(); } else { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName(); } this.groupName = name + "_grp"; try { makeAndStartQuartzScheduler(); try { JobDetail seed = addOverseerJob(); try { scheduleOverseerJob(seed); status = Status.STATUS_ALIVE; } catch (SchedulerException e) { LOG.error("Unable to schedule control job for Scheduled Refresh", e); } } catch (SchedulerException e) { LOG.error("Unable to add Scheduled Refresh control job to Quartz Job Scheduler", e); } } catch (SchedulerException e) { LOG.error("Unable to instantiate Quartz Job Scheduler for Scheduled Refresh", e); } } }
ScheduledRefreshCacheExtension implements CacheExtension { @Override public void init() { if (config.getUniqueNamePart() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getUniqueNamePart(); } else { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName(); } this.groupName = name + "_grp"; try { makeAndStartQuartzScheduler(); try { JobDetail seed = addOverseerJob(); try { scheduleOverseerJob(seed); status = Status.STATUS_ALIVE; } catch (SchedulerException e) { LOG.error("Unable to schedule control job for Scheduled Refresh", e); } } catch (SchedulerException e) { LOG.error("Unable to add Scheduled Refresh control job to Quartz Job Scheduler", e); } } catch (SchedulerException e) { LOG.error("Unable to instantiate Quartz Job Scheduler for Scheduled Refresh", e); } } ScheduledRefreshCacheExtension(ScheduledRefreshConfiguration config,
                                          Ehcache cache); }
ScheduledRefreshCacheExtension implements CacheExtension { @Override public void init() { if (config.getUniqueNamePart() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getUniqueNamePart(); } else { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName(); } this.groupName = name + "_grp"; try { makeAndStartQuartzScheduler(); try { JobDetail seed = addOverseerJob(); try { scheduleOverseerJob(seed); status = Status.STATUS_ALIVE; } catch (SchedulerException e) { LOG.error("Unable to schedule control job for Scheduled Refresh", e); } } catch (SchedulerException e) { LOG.error("Unable to add Scheduled Refresh control job to Quartz Job Scheduler", e); } } catch (SchedulerException e) { LOG.error("Unable to instantiate Quartz Job Scheduler for Scheduled Refresh", e); } } ScheduledRefreshCacheExtension(ScheduledRefreshConfiguration config,
                                          Ehcache cache); @Override void init(); @Override void dispose(); @Override CacheExtension clone(Ehcache cache); @Override Status getStatus(); }
ScheduledRefreshCacheExtension implements CacheExtension { @Override public void init() { if (config.getUniqueNamePart() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getUniqueNamePart(); } else { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName(); } this.groupName = name + "_grp"; try { makeAndStartQuartzScheduler(); try { JobDetail seed = addOverseerJob(); try { scheduleOverseerJob(seed); status = Status.STATUS_ALIVE; } catch (SchedulerException e) { LOG.error("Unable to schedule control job for Scheduled Refresh", e); } } catch (SchedulerException e) { LOG.error("Unable to add Scheduled Refresh control job to Quartz Job Scheduler", e); } } catch (SchedulerException e) { LOG.error("Unable to instantiate Quartz Job Scheduler for Scheduled Refresh", e); } } ScheduledRefreshCacheExtension(ScheduledRefreshConfiguration config,
                                          Ehcache cache); @Override void init(); @Override void dispose(); @Override CacheExtension clone(Ehcache cache); @Override Status getStatus();  }