Link to home
Start Free TrialLog in
Avatar of serrutom
serrutomFlag for Belgium

asked on

Error while deploying quartz InterruptableJob with a TriggerListener in JBoss

I created an InterruptableJob with a TriggerListener because i want to set a timeout for the job, and want to deploy it in JBoss. Everytime i deploy my application I get following error message:

java.lang.RuntimeException: An exception occurred initialising interceptors for class be.mycompany.incidentmanagement.connectors.IncidentManagementJob.triggerMisfired
        at org.jboss.ejb3.interceptor.EJB3InterceptorsFactory.createPerJoinpoint(EJB3InterceptorsFactory.java:108)
        at org.jboss.aop.advice.AspectFactoryDelegator.createPerJoinpoint(AspectFactoryDelegator.java:119)
        at org.jboss.aop.advice.ScopedInterceptorFactory.create(ScopedInterceptorFactory.java:113)
        at org.jboss.aop.Advisor.createInterceptorChain(Advisor.java:618)
        at org.jboss.aop.Advisor.pointcutResolved(Advisor.java:888)
        at org.jboss.aop.Advisor.resolveMethodPointcut(Advisor.java:650)
        at org.jboss.aop.ClassContainer.createInterceptorChains(ClassContainer.java:248)
        at org.jboss.aop.ClassContainer.rebuildInterceptors(ClassContainer.java:115)
        at org.jboss.aop.ClassContainer.initializeClassContainer(ClassContainer.java:58)
        at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:342)
        at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:292)
        at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:356)
        at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
        at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
        at $Proxy0.start(Unknown Source)
        at org.jboss.system.ServiceController.start(ServiceController.java:417)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy33.start(Unknown Source)
        at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:512)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
        at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
        at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
        at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
        at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
        at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy34.start(Unknown Source)
        at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
        at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
        at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
        at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy9.deploy(Unknown Source)
        at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
        at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
        at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
        at $Proxy0.start(Unknown Source)
        at org.jboss.system.ServiceController.start(ServiceController.java:417)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy4.start(Unknown Source)
        at org.jboss.deployment.SARDeployer.start(SARDeployer.java:304)
        at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy5.deploy(Unknown Source)
        at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
        at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
        at org.jboss.Main.boot(Main.java:200)
        at org.jboss.Main$1.run(Main.java:508)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.RuntimeException: unable to determine messagingType interface for MDB
        at org.jboss.ejb3.mdb.MDB.getMessagingType(MDB.java:88)
        at org.jboss.ejb3.interceptor.EJB3InterceptorsFactory.getBusinessInterfaces(EJB3InterceptorsFactory.java:167)
        at org.jboss.ejb3.interceptor.EJB3InterceptorsFactory.isBusinessMethod(EJB3InterceptorsFactory.java:122)
        at org.jboss.ejb3.interceptor.EJB3InterceptorsFactory.createPerJoinpoint(EJB3InterceptorsFactory.java:98)
        ... 124 more

I checked a lot of forums, wiki's, but with no result.
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.naming.InitialContext;
import javax.naming.NamingException;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.annotation.ejb.ResourceAdapter;
import org.quartz.InterruptableJob;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Trigger;
import org.quartz.TriggerListener;
import org.quartz.UnableToInterruptJobException;
 
@MessageDriven(activationConfig = { 
	@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0/5 * * * * ?"), 
	@ActivationConfigProperty(propertyName = "jobName", propertyValue = "JOBNAME"), 
	@ActivationConfigProperty(propertyName = "jobGroup", propertyValue = "JOBGROUP")
})
@ResourceAdapter("quartz-ra.rar")
public class IncidentJob implements InterruptableJob, TriggerListener {
	protected static Log log = LogFactory.getLog(IncidentJob.class);
 
	private Thread timer = new Timer();
	private JobExecutionContext context = null;
 
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		log.info("Execute my job...");
	}
 
	@Override
	public void interrupt() throws UnableToInterruptJobException {
		log.info("Job was killed due to timeout");
	}
 
	@Override
	public String getName() {
		return null;
	}
 
	@Override
	public void triggerComplete(Trigger trigger, JobExecutionContext context, int arg2) {
		log.info("Stopping job timer");
		this.timer.stop();
	}
 
	@Override
	public void triggerFired(Trigger trigger, JobExecutionContext context) {
		log.info("Starting job timer");
		this.context = context;
		this.timer.start();
	}
 
	@Override
	public void triggerMisfired(Trigger trigger) {
	}
 
	@Override
	public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
		return false;
	}
 
	private class Timer extends Thread {
		public void run() {
			try {
				sleep(1000);
				try {
					((InterruptableJob) context.getJobInstance()).interrupt();
				} catch (UnableToInterruptJobException e) {
					throw new RuntimeException("exception", e);
				}
			} catch (InterruptedException e) {
			}
		}
	}
}

Open in new window

Avatar of ramazanyich
ramazanyich
Flag of Belgium image

Hei Tom,
which version of JBOSS do you use ?
in JBoss 4.2 it worked well.

Check http://www.jboss.org/community/wiki/QuartzSchedulerIntegration

P.S: How is life ? ;)

It could be something due to fact that you re implementing TriggerListener.

Just for the test try to remove TriggerListener implementation from your class.
Avatar of serrutom

ASKER

I'm using JBoss-4.2.3.GA.

Without the TriggerListener everyting works just fine.

But i need the trigger listener to set a timeout on my job. If the job is running too long, it should be killed.


P.S: Life's great, we should get to gether some time and have a drink and talk up :o)
First of all don't use a internal fields in stateless EJB (MDB is a stateless). Your context initially always will be null.
Another thing from TriggerListener javadoc: "The interface to be implemented by classes that want to be informed when a Trigger fires. In general, applications that use a Scheduler will not have use for this mechanism. "
But if you use MessageDriven annotation with crontirigger it will use internal Scheduler of JBoss. So need to find some other mechanism for interrupting a job.


P.S: I'm always ready for a drink ;) so let's tak a date.
ASKER CERTIFIED SOLUTION
Avatar of ramazanyich
ramazanyich
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I got the standard Quartz installation of JBoss replaced by latest release from the OpenSymphony site (http://www.opensymphony.com/quartz/download.action).


I use following settings in my quartz-service.xml file:

org.quartz.scheduler.instanceName=DefaultQuartzScheduler
org.quartz.scheduler.rmi.export=false
org.quartz.scheduler.rmi.proxy=false
org.quartz.scheduler.xaTransacted=false

org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=5
org.quartz.threadPool.threadPriority=4

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.driverDelegateClass= org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource=QUARTZ
org.quartz.jobStore.nonManagedTXDataSource=QUARTZ_NO_TX
org.quartz.jobStore.tablePrefix=QRTZ_

org.quartz.dataSource.QUARTZ.jndiURL=java:/DSOneaQZ
org.quartz.dataSource.QUARTZ_NO_TX.jndiURL=java:/DSOneaQZ


I created the tables using the SQL script, and i added the datasource to my mysql-ds.xml config file:

<local-tx-datasource>
      <jndi-name>DSOneaQZ</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/oneaqz</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>
      <password>******</password>
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
      <metadata>
            <type-mapping>mySQL</type-mapping>
      </metadata>
</local-tx-datasource>

My JBoss starts without error messages, but when i try to start my job with the code below, i get following error message:

13:43:02,836 ERROR [STDERR] Caused by: java.sql.SQLException: Could not retrieve datasource via JNDI url 'java:/DSOneaQZ' org.jboss.util.NestedSQLException: Cou
ld not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist reso
urce, see the previous warnings. tx=TransactionImple < ac, BasicAction: -3f57561f:11cd:4a0025c6:49 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.
jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: j
ava.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: -3f57561f:11cd:4a0025c6:49 status: ActionStatu
s.ABORT_ONLY >))


Any idea?
try {
	InitialContext ctx = new InitialContext();
	StdScheduler scheduler = (StdScheduler) ctx.lookup("Quartz");
 
	JobDetail jd = new JobDetail("JobName", scheduler.DEFAULT_GROUP, Class.forName(tmp.getClassName()));
	CronTrigger ct = new CronTrigger("JobName"", scheduler.DEFAULT_GROUP, "0/5 * * * * ?");
	scheduler.scheduleJob(jd, ct);
} catch (Exception e) {
	e.printStackTrace();
}

Open in new window

What datasource should i use for the nonManagedTXDataSource?
Ok, i got it working:

I used my web application datasource as managed datasource, and created a separate datasource as non managed datasource.

Thx a lot.