@Test public void testSimpleCaseProgrammatic() { CacheManager manager = new CacheManager(); manager.removalAll(); manager.addCache(new Cache(new CacheConfiguration().name("test").eternal(true).maxEntriesLocalHeap(5000))); Ehcache cache = manager.getEhcache("test"); cache.registerCacheLoader(stupidCacheLoaderEvens); cache.registerCacheLoader(stupidCacheLoaderOdds); int second = (new GregorianCalendar().get(Calendar.SECOND) + 5) % 60; ScheduledRefreshConfiguration config = new ScheduledRefreshConfiguration().batchSize(100).quartzThreadCount (4).cronExpression(second + "/5 * * * * ?").build(); ScheduledRefreshCacheExtension cacheExtension = new ScheduledRefreshCacheExtension(config, cache); cache.registerCacheExtension(cacheExtension); cacheExtension.init(); for (int i = 0; i < 10; i++) { cache.put(new Element(new Integer(i), i + "")); } sleepySeconds(8); for (Object key : cache.getKeys()) { Element val = cache.get(key); int iVal = ((Number) key).intValue(); if ((iVal & 0x01) == 0) { Assert.assertEquals(iVal + 20000, Long.parseLong((String) val.getObjectValue())); } else { Assert.assertEquals(iVal + 10000, Long.parseLong((String) val.getObjectValue())); } } manager.removalAll(); manager.shutdown(); }
@Override public void init() { if (config.getScheduledRefreshName() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getScheduledRefreshName(); } 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.getScheduledRefreshName() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getScheduledRefreshName(); } 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.getScheduledRefreshName() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getScheduledRefreshName(); } 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.getScheduledRefreshName() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getScheduledRefreshName(); } 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.getScheduledRefreshName() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getScheduledRefreshName(); } 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();  }