use of org.motechproject.bundle.extender.MotechOsgiConfigurableApplicationContext in project motech by motech.
the class MdsScheduledJob method execute.
@Override
@SuppressWarnings("unchecked")
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
LOGGER.info("Executing Trash Clean Up");
try {
SchedulerContext schedulerContext;
try {
schedulerContext = jobExecutionContext.getScheduler().getContext();
} catch (SchedulerException e) {
LOGGER.error("Can not execute job. Can not get Scheduler Context", e);
return;
}
ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get("applicationContext");
BundleContext bundleContext = ((MotechOsgiConfigurableApplicationContext) applicationContext).getBundleContext();
TrashService trashService = OSGiServiceUtils.findService(bundleContext, TrashService.class);
EntityInfoReader entityInfoReader = OSGiServiceUtils.findService(bundleContext, EntityInfoReader.class);
if (trashService != null) {
if (entityInfoReader != null) {
Collection<String> entitiesClassNames = entityInfoReader.getEntitiesClassNames();
trashService.emptyTrash(entitiesClassNames);
} else {
LOGGER.warn("EntityInfoReader is unavailable, unable to empty trash");
}
} else {
LOGGER.warn("TrashService is unavailable, unable to empty trash");
}
} catch (Exception e) {
LOGGER.error("Job execution failed.", e);
}
}
Aggregations