From d6f509087c033967617855c2dd78ee339733bc7f Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Mon, 26 Aug 2002 19:43:32 +0000 Subject: [PATCH] fleshing out Job, adding some utility code git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@781 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-dcpd/etc/go.bat | 2 +- pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPD.java | 2 +- .../src/net/sourceforge/pmd/dcpd/DCPDWorker.java | 11 ++++++++++- pmd-dcpd/src/net/sourceforge/pmd/dcpd/Job.java | 4 +++- pmd-dcpd/src/net/sourceforge/pmd/dcpd/Util.java | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/pmd-dcpd/etc/go.bat b/pmd-dcpd/etc/go.bat index 880e1035a3..995da5f4bd 100755 --- a/pmd-dcpd/etc/go.bat +++ b/pmd-dcpd/etc/go.bat @@ -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 diff --git a/pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPD.java b/pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPD.java index 14ae0d5fee..0fc531fed1 100644 --- a/pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPD.java +++ b/pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPD.java @@ -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); diff --git a/pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPDWorker.java b/pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPDWorker.java index ddcd9267ac..33d6ffd435 100644 --- a/pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPDWorker.java +++ b/pmd-dcpd/src/net/sourceforge/pmd/dcpd/DCPDWorker.java @@ -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) { diff --git a/pmd-dcpd/src/net/sourceforge/pmd/dcpd/Job.java b/pmd-dcpd/src/net/sourceforge/pmd/dcpd/Job.java index 185f6055cf..052967440f 100644 --- a/pmd-dcpd/src/net/sourceforge/pmd/dcpd/Job.java +++ b/pmd-dcpd/src/net/sourceforge/pmd/dcpd/Job.java @@ -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; } } diff --git a/pmd-dcpd/src/net/sourceforge/pmd/dcpd/Util.java b/pmd-dcpd/src/net/sourceforge/pmd/dcpd/Util.java index fe26973843..68c2436f6e 100644 --- a/pmd-dcpd/src/net/sourceforge/pmd/dcpd/Util.java +++ b/pmd-dcpd/src/net/sourceforge/pmd/dcpd/Util.java @@ -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(); + } + } }