-
1. Re: Setting up a timer?
frito Jul 27, 2003 5:24 AM (in response to ucftcys)Depends on how you want to perform the backup. JBoss can't help you with this task but JBoss has a scheduler service to realize a timer. Look at the configuration and examples to see how it works.
Greetings,
Frito -
2. Re: Setting up a timer?
davem Jul 28, 2003 1:10 PM (in response to ucftcys)which jboss version are you using?
-
3. Re: Setting up a timer?
ucftcys Jul 31, 2003 4:38 AM (in response to ucftcys)sorry for replying so late...I am using 3.0.6 bundle with Tomcat...
-
4. Re: Setting up a timer?
davem Jul 31, 2003 9:28 AM (in response to ucftcys)I'm using Jboss 3.2.1 and here's what I did. I create a SAR file that includes all of the class files that are used by my timer. A SAR (super archive) file is similar to a JAR file (in fact I create it in ant using the JAR tool) and I put that file in my deploy directory.
The first thing you need is an XML file called jboss-service.xml. Here's what mine looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<!-- $Id: user-service.xml,v 1.4 2002/06/01 02:10:53 starksm Exp $ -->
<!-- ===================================================================== -->
<!-- -->
<!-- User Service Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!--
| Add custom MBeans here. MBeans should be registered under the
| 'user' JMX domain, or a domain specific to the component application.
|
| Do not place user components in the 'jboss' domain or any sub-domain.
-->
true
com.incentivation.eval.util.PrefsLoader
PrefsLoader,-1
java.lang.String,long
NOW
1
1
The important things to note are: the class file I'm using is located in the mbean name and the SchedulableClass attribute.
SchedulePeriod is the number of seconds between repetitions. 3600000 is one day. InitialRepetitions is how many times this timer is going to run. You'll set yours to -1 so it runs indefinitely. Your last two attributes will probably look like this:
3600000
-1
Almost ready but you still have to modify whatever class you're sending the notifications to, in this example, com.incentivation.eval.util.PrefsLoader.
My class looks like this:
import org.jboss.varia.scheduler.Schedulable;
import org.apache.log4j.Logger;
public class PrefsLoader implements Schedulable
{
private static final Logger log = Logger.getLogger(PrefsLoader.class);
private String name;
private long value;
public PrefsLoader(String name, long value)
{
this.name = name;
this.value = value;
}
public void perform(Date now, long remainingRepetitions)
{
// your database backup code
}
}
You need scheduler-plugin.jar for the class org.jboss.varia.scheduler.Schedulable so it'll compile. I have that jar in my [jboss-home]/server/incentivation/lib directory and ant knows to look there for the jars.
So now you have your class files ready to go in your SAR file with that XML file. Put the SAR file in the [jboss-home]/server/incentivation/deploy directory and you should be set to go!
Let me know if this works and I hope this helps everyone else trying to get a timer to work. -
5. Re: Setting up a timer?
ucftcys Jul 31, 2003 10:40 AM (in response to ucftcys)Thanks for the detailed instruction..I will give it a try. when mine works..I will let you know...
-
6. Re: Setting up a timer?
ucftcys Sep 12, 2003 1:21 PM (in response to ucftcys)Do I need to add a timer mbaen first? after add the following line in jboss-service.xml:
What should I do next?
The JBoss 3 document writes:
Date lNext = new Date( new Date().getTime() + Timer.ONE_MINUTE );
Integer lOneMinuteTimer = (Integer) lServer.invoke(
lTimer.getObjectName(),
"addNotification",
new Object[] {
"IDoNotKnowWhatTypeIs",
"I call you with this timer once",
// No user object
null,
// In one minute from now
lNext,
},
new String[] {
"".getClass().getName(),
"".getClass().getName(),
"java.lang.Object",
Date.class.getName()
}
);
Where should I put the code???
The document indicates that before using a scheduler we should set up a timer MBean. Is it right?
I've tried your solution, but it doesn't work. The console said the scheduler is not registered..why?? -
7. Re: Setting up a timer?
ucftcys Sep 13, 2003 1:03 AM (in response to ucftcys)It works now....I tried your solution again carefully...thanks a lot...