package de.XXXXX.j2ee.infrastructure; import java.util.Iterator; import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.ServiceImplementationFactory; import org.apache.hivemind.ServiceImplementationFactoryParameters; import org.apache.hivemind.ShutdownCoordinator; import org.apache.hivemind.events.RegistryShutdownListener; import org.apache.hivemind.internal.RegistryInfrastructure; import org.apache.hivemind.internal.ser.ServiceSerializationHelper; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.SchedulerFactory; public class HivemindSchedulerFactory implements ServiceImplementationFactory, RegistryShutdownListener { private SchedulerFactory schedulerFactory; private ShutdownCoordinator shutdownCoord; public HivemindSchedulerFactory(SchedulerFactory sf) { schedulerFactory = sf; } public Object createCoreServiceImplementation( ServiceImplementationFactoryParameters factoryParameters) { System.out.println("Registry Start"); try { if (!factoryParameters.getServiceInterface() .equals(Scheduler.class)) throw new ApplicationRuntimeException( "this factory can't make " + factoryParameters.getServiceInterface()); String name = (String) factoryParameters.getFirstParameter(); Scheduler s = name == null ? schedulerFactory.getScheduler() : schedulerFactory.getScheduler(name); s.start(); return s; } catch (SchedulerException e) { throw new ApplicationRuntimeException(e); } } public void registryDidShutdown() { System.out.println("Registry Shutdown"); try { for (Iterator it = schedulerFactory.getAllSchedulers().iterator(); it .hasNext();) { Scheduler s = (Scheduler) it.next(); s.shutdown(); } } catch (SchedulerException e) { throw new ApplicationRuntimeException(e); } } public ShutdownCoordinator getShutdownCoord() { return shutdownCoord; } public void setShutdownCoord(ShutdownCoordinator shutdownCoord) { this.shutdownCoord = shutdownCoord; shutdownCoord.addRegistryShutdownListener(this); } }