forked from phoedos/pmd
fleshing out Job, adding some utility code
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@781 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -12,4 +12,4 @@ set SPACENAME_ARG=-Dcom.sun.jini.outrigger.spacename=JavaSpaces
|
||||
set GROUP_ARG=-Dcom.sun.jini.lookup.groups=public
|
||||
set CODEBASE=-Djava.rmi.server.codebase=http://mordor:8081/dcpd.jar
|
||||
|
||||
java %MEMORY_ARG% %POLICY_ARG% %SPACENAME_ARG% %GROUP_ARG% -cp %CLASSPATH% %CODEBASE% %MAIN%
|
||||
java %MEMORY_ARG% %POLICY_ARG% %SPACENAME_ARG% %GROUP_ARG% -cp %CLASSPATH% %CODEBASE% %MAIN% %2
|
||||
|
@ -30,7 +30,7 @@ public class DCPD {
|
||||
public DCPD(String javaSpaceURL) {
|
||||
try {
|
||||
space = Util.findSpace("mordor");
|
||||
space.write(new Job("test"), null, Lease.FOREVER);
|
||||
space.write(new Job("test", new Integer((int)System.currentTimeMillis())), null, Lease.FOREVER);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Couldn't connect to the space on " + javaSpaceURL);
|
||||
|
@ -16,17 +16,26 @@ import java.rmi.MarshalledObject;
|
||||
|
||||
public class DCPDWorker {
|
||||
|
||||
private Job currentJob;
|
||||
|
||||
public DCPDWorker() {
|
||||
try {
|
||||
JavaSpace space = Util.findSpace("mordor");
|
||||
// register for future jobs
|
||||
space.notify(new Job(), null, new JobAddedListener(space, this), Lease.FOREVER, null);
|
||||
// get a job if there are any out there
|
||||
Job job = (Job)space.readIfExists(new Job(), null, 200);
|
||||
if (job != null) {
|
||||
jobAdded(job);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void jobAdded(Job job) {
|
||||
System.out.println("GOT A JOB NAMED " + job.name);
|
||||
System.out.println("GOT A JOB NAMED " + job.name + " , id is " + job.id.intValue());
|
||||
currentJob = job;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -9,10 +9,12 @@ import net.jini.core.entry.Entry;
|
||||
|
||||
public class Job implements Entry {
|
||||
public String name;
|
||||
public Integer id;
|
||||
|
||||
public Job() {}
|
||||
|
||||
public Job(String name) {
|
||||
public Job(String name, Integer id) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,20 @@ public class Util {
|
||||
ServiceMatches sm = registrar.lookup(new ServiceTemplate(null, new Class[] {JavaSpace.class}, new Entry[] {}), 1);
|
||||
return (JavaSpace)sm.items[0].service;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if (args[0].equals("clearjobs")) {
|
||||
JavaSpace space = Util.findSpace("mordor");
|
||||
while (space.take(new Job(), null, 100) != null) {
|
||||
System.out.println("take() succeeded");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Usage: clearjobs");
|
||||
}
|
||||
System.out.println("Done");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user