// Path: cdiqi-core/src/main/java/cz/symbiont_it/cdiqi/api/AsyncEvent.java
// public final class AsyncEvent {
// 
// 	private final Object targetEvent;
// 
// 	private final Annotation[] qualifiers;
// 
// 	public AsyncEvent(Object targetEvent, Annotation... qualifiers) {
// 		super();
// 		
// 		if(targetEvent == null)
// 			throw new IllegalArgumentException("Target event must not be null");
// 		
// 		this.targetEvent = targetEvent;
// 		this.qualifiers = qualifiers;
// 	}
// 
// 	public Object getTargetEvent() {
// 		return targetEvent;
// 	}
// 
// 	public Annotation[] getQualifiers() {
// 		return qualifiers;
// 	}
// 	
// }
// 
// Path: cdiqi-core/src/main/java/cz/symbiont_it/cdiqi/api/QuartzSchedulerManager.java
// public interface QuartzSchedulerManager {
// 
// 	public static final String QUARTZ_PROPERTY_FILE_NAME = "cdiqi-quartz.properties";
// 	
// 	/**
// 	 * Perform init.
// 	 * 
// 	 * @throws SchedulerException
// 	 */
// 	public void init() throws SchedulerException;
// 
// 	/**
// 	 * @return <code>true</code> if initialized, <code>false</code> otherwise
// 	 */
// 	public boolean isInitialized();
// 
// 	/**
// 	 * Start underlying quartz scheduler. If not initialized perform init first.
// 	 * 
// 	 * @throws SchedulerException
// 	 */
// 	public void start() throws SchedulerException;
// 
// 	/**
// 	 * Pause underlying quartz scheduler.
// 	 * 
// 	 * @throws SchedulerException
// 	 */
// 	public void standby() throws SchedulerException;
// 
// 	/**
// 	 * Deletes all scheduling data.
// 	 * 
// 	 * @throws SchedulerException
// 	 */
// 	public void clear() throws SchedulerException;
// 
// 	/**
// 	 * Schedule new job.
// 	 * 
// 	 * @param jobDetail
// 	 * @param trigger
// 	 * @throws SchedulerException
// 	 */
// 	public void schedule(JobDetail jobDetail, Trigger trigger)
// 			throws SchedulerException;
// 
// }
// 
// Path: cdiqi-core/src/main/java/cz/symbiont_it/cdiqi/spi/BoundRequestJobListener.java
// public abstract class BoundRequestJobListener implements JobListener {
// 
// 	protected static final String REQUEST_DATA_STORE_KEY = BoundRequestJobListener.class
// 			.getName() + "_REQUEST_DATA_STORE_KEY";
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.quartz.JobListener#getName()
// 	 */
// 	public String getName() {
// 		return getClass().getName();
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
// 	 */
// 	public void jobToBeExecuted(JobExecutionContext context) {
// 		startRequest(context);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
// 	 */
// 	public void jobExecutionVetoed(JobExecutionContext context) {
// 		endRequest(context);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext,
// 	 * org.quartz.JobExecutionException)
// 	 */
// 	public void jobWasExecuted(JobExecutionContext context,
// 			JobExecutionException jobException) {
// 		endRequest(context);
// 	}
// 
// 	/**
// 	 * @param context
// 	 */
// 	protected abstract void startRequest(JobExecutionContext context);
// 
// 	/**
// 	 * @param context
// 	 */
// 	protected abstract void endRequest(JobExecutionContext context);
// 
// }


import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;
import java.util.UUID;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.EverythingMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.symbiont_it.cdiqi.api.AsyncEvent;
import cz.symbiont_it.cdiqi.api.QuartzSchedulerManager;
import cz.symbiont_it.cdiqi.spi.BoundRequestJobListener;
/*
 * Copyright 2011, Symbiont v.o.s
 *	
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.symbiont_it.cdiqi.impl;






/**
 * Quartz scheduler manager implementation.
 * 
 * @author Martin Kouba
 */
@ApplicationScoped
public class QuartzSchedulerManagerImpl implements QuartzSchedulerManager {

	private static final Logger logger = LoggerFactory
			.getLogger(QuartzSchedulerManagerImpl.class);

	private static final String ASYNC_GROUP = "CdiqiAsync";

	@Inject
// Path: cdiqi-core/src/main/java/cz/symbiont_it/cdiqi/api/AsyncEvent.java
// public final class AsyncEvent {
// 
// 	private final Object targetEvent;
// 
// 	private final Annotation[] qualifiers;
// 
// 	public AsyncEvent(Object targetEvent, Annotation... qualifiers) {
// 		super();
// 		
// 		if(targetEvent == null)
// 			throw new IllegalArgumentException("Target event must not be null");
// 		
// 		this.targetEvent = targetEvent;
// 		this.qualifiers = qualifiers;
// 	}
// 
// 	public Object getTargetEvent() {
// 		return targetEvent;
// 	}
// 
// 	public Annotation[] getQualifiers() {
// 		return qualifiers;
// 	}
// 	
// }
// 
// Path: cdiqi-core/src/main/java/cz/symbiont_it/cdiqi/api/QuartzSchedulerManager.java
// public interface QuartzSchedulerManager {
// 
// 	public static final String QUARTZ_PROPERTY_FILE_NAME = "cdiqi-quartz.properties";
// 	
// 	/**
// 	 * Perform init.
// 	 * 
// 	 * @throws SchedulerException
// 	 */
// 	public void init() throws SchedulerException;
// 
// 	/**
// 	 * @return <code>true</code> if initialized, <code>false</code> otherwise
// 	 */
// 	public boolean isInitialized();
// 
// 	/**
// 	 * Start underlying quartz scheduler. If not initialized perform init first.
// 	 * 
// 	 * @throws SchedulerException
// 	 */
// 	public void start() throws SchedulerException;
// 
// 	/**
// 	 * Pause underlying quartz scheduler.
// 	 * 
// 	 * @throws SchedulerException
// 	 */
// 	public void standby() throws SchedulerException;
// 
// 	/**
// 	 * Deletes all scheduling data.
// 	 * 
// 	 * @throws SchedulerException
// 	 */
// 	public void clear() throws SchedulerException;
// 
// 	/**
// 	 * Schedule new job.
// 	 * 
// 	 * @param jobDetail
// 	 * @param trigger
// 	 * @throws SchedulerException
// 	 */
// 	public void schedule(JobDetail jobDetail, Trigger trigger)
// 			throws SchedulerException;
// 
// }
// 
// Path: cdiqi-core/src/main/java/cz/symbiont_it/cdiqi/spi/BoundRequestJobListener.java
// public abstract class BoundRequestJobListener implements JobListener {
// 
// 	protected static final String REQUEST_DATA_STORE_KEY = BoundRequestJobListener.class
// 			.getName() + "_REQUEST_DATA_STORE_KEY";
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.quartz.JobListener#getName()
// 	 */
// 	public String getName() {
// 		return getClass().getName();
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
// 	 */
// 	public void jobToBeExecuted(JobExecutionContext context) {
// 		startRequest(context);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
// 	 */
// 	public void jobExecutionVetoed(JobExecutionContext context) {
// 		endRequest(context);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext,
// 	 * org.quartz.JobExecutionException)
// 	 */
// 	public void jobWasExecuted(JobExecutionContext context,
// 			JobExecutionException jobException) {
// 		endRequest(context);
// 	}
// 
// 	/**
// 	 * @param context
// 	 */
// 	protected abstract void startRequest(JobExecutionContext context);
// 
// 	/**
// 	 * @param context
// 	 */
// 	protected abstract void endRequest(JobExecutionContext context);
// 
// }


// Path: cdiqi-core/src/main/java/cz/symbiont_it/cdiqi/impl/QuartzSchedulerManagerImpl.java
import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;
import java.util.UUID;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.EverythingMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.symbiont_it.cdiqi.api.AsyncEvent;
import cz.symbiont_it.cdiqi.api.QuartzSchedulerManager;
import cz.symbiont_it.cdiqi.spi.BoundRequestJobListener;

/*
 * Copyright 2011, Symbiont v.o.s
 *	
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.symbiont_it.cdiqi.impl;






/**
 * Quartz scheduler manager implementation.
 * 
 * @author Martin Kouba
 */
@ApplicationScoped
public class QuartzSchedulerManagerImpl implements QuartzSchedulerManager {

	private static final Logger logger = LoggerFactory
			.getLogger(QuartzSchedulerManagerImpl.class);

	private static final String ASYNC_GROUP = "CdiqiAsync";

	@Inject
	private BoundRequestJobListener jobListener;