Created
March 31, 2011 10:08
-
-
Save kimukou/896140 to your computer and use it in GitHub Desktop.
cron4j_test.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cron4j_test.groovy | |
// | |
// reference | |
// http://www.sauronsoftware.it/projects/cron4j/manual.php | |
// http://blog.zaq.ne.jp/oboe2uran/article/243/ | |
@GrabResolver (name='gridgainsystems', root='http://www.gridgainsystems.com/maven2') | |
@Grab(group = 'net.sf.cron4j', module='cron4j', version='*') | |
import it.sauronsoftware.cron4j.* | |
pattern="* * * * *" //equals "*/1 * * * *" is every 1 minutes | |
// Creates a Scheduler instance. | |
Scheduler s = new Scheduler() | |
// Schedule a once-a-minute task. | |
s.schedule(pattern, new Runnable() { | |
public void run() { | |
println "Another minute ticked away...${new Date()}" | |
} | |
}) | |
// Starts the scheduler. | |
s.start() | |
// Will run for ten minutes. | |
try { | |
Thread.sleep(1000L * 60L * 2L) | |
} catch (InterruptedException e) {} | |
// Stops the scheduler. | |
s.stop() | |
//validation check | |
long milisec=10243240L | |
SchedulingPattern sp = new SchedulingPattern(pattern) | |
boolean sts = sp.match(milisec) | |
println "Validate:$milisec /$pattern($sts)" | |
pattern="1 * * * *" //once call | |
WORKPATH="D:/Tooldev/groovyserv-0.6" | |
GROOVY_HOME="C:/opt/groovy-1.7.10" | |
JAVA_HOME="C:\\opt\\jdk"//"C:/opt/jdk" | |
//[TODO] case 1 groovyserv call | |
String[] command = [ "$WORKPATH/bin/groovyclient.exe","-e","\"groovy.ui.Console.main(args)\""] //, "%*" ] | |
String[] envs = [ "GROOVY_HOME=$GROOVY_HOME", | |
"JAVA_HOME=$JAVA_HOME", | |
"CLASSPATH=$GROOVY_HOME/lib/*;$GROOVY_HOME/lib/bootstrap;D:/workspace36_/_github/g100pon/libprocess/*" | |
] | |
File directory = new File("$WORKPATH/bin") | |
println command | |
println envs | |
//[TODO] case 2 groovyConsole DirectCall call | |
/* | |
String[] command = [ "$GROOVY_HOME/bin/groovyConsole.bat"]//, "%*" ] | |
String[] envs = [ "GROOVY_HOME=$GROOVY_HOME", | |
"JAVA_HOME=$JAVA_HOME", | |
"CLASSPATH=$GROOVY_HOME/lib/*;$GROOVY_HOME/lib/bootstrap;D:/workspace36_/_github/g100pon/libprocess/*" | |
] | |
File directory = new File("$GROOVY_HOME/bin") | |
println command | |
println envs | |
*/ | |
//========================================================================== | |
//call patartn [A] | |
// not running ProcessTask | |
ProcessTask task = new ProcessTask(command, envs)//, directory) | |
s = new Scheduler() | |
s.schedule(pattern, task) | |
s.start() | |
try { | |
Thread.sleep(1000L * 60L * 3L) | |
} catch (InterruptedException e) {} | |
// Stops the scheduler. | |
s.stop() | |
println "====EE=====" | |
//call patartn [B] | |
// running OK | |
// It is not significant. | |
/* | |
void printInputStream(InputStream is) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(is)); | |
try { | |
for (;;) { | |
String line = br.readLine(); | |
if (line == null) break; | |
System.out.println(line); | |
} | |
} finally { | |
br.close(); | |
} | |
} | |
ProcessBuilder builder = new ProcessBuilder(command as List) | |
Map<String, String> env = builder.environment() | |
envs.each{ | |
println it | |
arr = it.split("=") | |
println arr | |
env.put(arr[0], arr[1]) | |
} | |
println env | |
println directory | |
builder.directory(directory) | |
Process p = builder.start() | |
p.waitFor(); | |
is = p.getInputStream() | |
printInputStream(is) | |
es = p.getErrorStream() | |
printInputStream(es) | |
p.waitFor() | |
int ret = p.exitValue() | |
println "return :" + ret | |
*/ | |
println "====EE2=====" | |
/* | |
//Exception occuered groovy console not running? | |
pattern="1 * * * * OUT:C:/ping.txt ping 192.168.10.28" //once call | |
Scheduler scheduler2 = new Scheduler() | |
scheduler2.schedule(pattern) | |
scheduler2.start() | |
try { | |
Thread.sleep(1000L * 60L * 1L) | |
} catch (InterruptedException e) {} | |
new File("C:/ping.txt").eachLine{println it} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
call patartn [A] ProcessTask not running !!
Why it doesn't runnign is a questions.