Hi, I want to write a JMX service that upon the activation of its "test" method, a perioudic job will begin.
I added the following lines to the jboss-service.xml:
I then wrote the interface of the service:
@Local
@Remote
public interface TestTimer
{
public void test();
}
And then I implemented the service itself:
@Service (objectName="trail:service=TestTimer")
@Management(TestTimer.class)
@Depends ("acme:service=Scheduler")
public class TestTimerMBean implements TestTimer, Schedulable {
private SchedulerMBean schedulerMBean;
public void test()
{
try
{
System.out.println("Hello time " + System.currentTimeMillis());
MBeanServer server = MBeanServerLocator.locate();
schedulerMBean = (SchedulerMBean) MBeanProxyExt.create(
SchedulerMBean.class,
"acme:service=Scheduler",
server);
if (schedulerMBean != null)
System.out.println("succeeded in looking up scheduler");
System.out.println("@@@@@My class name is " + getClass().getName());
schedulerMBean.setSchedulableClass(getClass().getName());
schedulerMBean.setInitialRepetitions(20);
schedulerMBean.setInitialStartDate("NOW");
schedulerMBean.setSchedulePeriod(2000);
schedulerMBean.start();
schedulerMBean.startSchedule();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void perform(Date arg0, long arg1) {
// TODO Auto-generated method stub
try
{
File f = new File("c:\\sched.txt");
FileOutputStream fos = new FileOutputStream(f,f.exists());
fos.write(("date is " + arg0 + "arg is " + arg1).getBytes());
fos.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
When I deploy, I can see that there is a perioudic job that runs, but I dont see that the method "perform" is executed (the file c:\sched.txt is not created and i do have permissions - i also tried using system.out.println - and nothing - the jboss application server runs on my machine )
What am I doing wrong here?
Thanks
Yair