Update of /var/cvs/applications/crontab/src/org/mmbase/applications/crontab
In directory
james.mmbase.org:/tmp/cvs-serv16867/src/org/mmbase/applications/crontab
Modified Files:
CronDaemon.java CronEntry.java CronEntryField.java
ProposedJobs.java
Log Message:
more MMB-1687
See also:
http://cvs.mmbase.org/viewcvs/applications/crontab/src/org/mmbase/applications/crontab
See also: http://www.mmbase.org/jira/browse/MMB-1687
Index: CronDaemon.java
===================================================================
RCS file:
/var/cvs/applications/crontab/src/org/mmbase/applications/crontab/CronDaemon.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- CronDaemon.java 29 Jul 2008 13:36:34 -0000 1.16
+++ CronDaemon.java 29 Jul 2008 15:21:45 -0000 1.17
@@ -20,7 +20,7 @@
*
* @author Kees Jongenburger
* @author Michiel Meeuwissen
- * @version $Id: CronDaemon.java,v 1.16 2008/07/29 13:36:34 michiel Exp $
+ * @version $Id: CronDaemon.java,v 1.17 2008/07/29 15:21:45 michiel Exp $
*/
public class CronDaemon implements ProposedJobs.Listener {
@@ -47,29 +47,49 @@
public void notify(ProposedJobs.Event event) {
+ log.debug("Received " + event);
+ if (proposedJobs != null) {
synchronized(proposedJobs) {
+ log.debug("" + proposedJobs.size());
Iterator<ProposedJobs.Event> i = proposedJobs.iterator();
while (i.hasNext()) {
ProposedJobs.Event proposed = i.next();
if (event.equals(proposed)) {
+ log.debug("Found job " + event + " already ");
if (proposed.getMachine().compareTo(event.getMachine()) >
0) {
+ log.debug("Will prefer " + proposed.getMachine());
event = proposed;
+ } else {
+ log.debug("Will prefer " + event.getMachine());
}
// remove any way, to readd later after the loop.
i.remove();
+ break; //can be only one
+ } else {
+ log.debug("" + event + " != " + proposed);
}
}
+ log.debug("Scheduling " + event);
proposedJobs.add(event);
+ log.debug("" + proposedJobs.size());
+ }
+ } else {
+ log.service("Ignored " + event + " because we don't have jobs of
type " + CronEntry.Type.BALANCE);
}
}
protected void consumeJobs() {
synchronized(proposedJobs) {
- ProposedJobs.Event event = proposedJobs.poll();
- while (event != null) {
+
+ for (ProposedJobs.Event event = proposedJobs.poll(); event !=
null; event = proposedJobs.poll()) {
+ log.service("Consuming " + event);
if (event.isLocal()) {
CronEntry proposed = event.getCronEntry();
CronEntry local = getById(cronEntries,
event.getCronEntry().getId());
+ if (local == null) {
+ log.service("Ignored " + event + " because we don't
have it.");
+ continue;
+ }
if (local.equals(proposed)) {
//local.setLastRun(event.getCronStart());
org.mmbase.util.ThreadPools.jobsExecutor.execute(local.getExecutable());
@@ -81,6 +101,13 @@
}
}
}
+ public List<ProposedJobs.Event> getQueue() {
+ if (proposedJobs != null) {
+ return new ArrayList<ProposedJobs.Event>(proposedJobs);
+ } else {
+ return Collections.emptyList();
+ }
+ }
/**
* Finds in given set the CronEntry with the given id.
@@ -113,18 +140,18 @@
} else {
addEntry(entry);
}
- if (entry.getType() == CronEntry.Type.BALANCE && proposedJobs == null)
{
- proposedJobs = new DelayQueue<ProposedJobs.Event>();
- cronTimer.scheduleAtFixedRate(new TimerTask() { public void run()
{CronDaemon.this.consumeJobs();} }, getFirst(), 60 * 1000);
}
- }
/**
* Actually adds, no checks for 'removedEntries' and so on.
*/
protected void addEntry(CronEntry entry) {
entry.init();
+ if (entry.getType() == CronEntry.Type.BALANCE && proposedJobs == null)
{
+ proposedJobs = new DelayQueue<ProposedJobs.Event>();
+ cronTimer.scheduleAtFixedRate(new TimerTask() { public void run()
{CronDaemon.this.consumeJobs();} }, getFirst(), 60 * 1000);
+ }
cronEntries.add(entry);
log.service("Added entry " + entry);
}
@@ -238,7 +265,7 @@
for (CronEntry entry : cronEntries) {
if (Thread.currentThread().isInterrupted()) return;
if (entry.mustRun(currentMinute)) {
- if (entry.kick()) {
+ if (entry.kick(currentMinute)) {
if (log.isDebugEnabled()) {
log.debug("Started " + entry);
}
Index: CronEntry.java
===================================================================
RCS file:
/var/cvs/applications/crontab/src/org/mmbase/applications/crontab/CronEntry.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- CronEntry.java 29 Jul 2008 13:36:34 -0000 1.13
+++ CronEntry.java 29 Jul 2008 15:21:45 -0000 1.14
@@ -19,7 +19,7 @@
*
* @author Kees Jongenburger
* @author Michiel Meeuwissen
- * @version $Id: CronEntry.java,v 1.13 2008/07/29 13:36:34 michiel Exp $
+ * @version $Id: CronEntry.java,v 1.14 2008/07/29 15:21:45 michiel Exp $
*/
public class CronEntry implements java.io.Serializable {
@@ -39,31 +39,32 @@
* Since we use a thread-pool for other types of jobs now any way, it
is doubtfull if it is
* ever usefull to opt for this type.
*/
- SHORT,
+ SHORT, //0
/**
* The default job type is the 'must be one' job. Such jobs are not
started if the same job is
* still running. They are wrapped in a seperate thread, so other jobs
can be started during the
* execution of this one.
*/
- MUSTBEONE,
+ MUSTBEONE, //1
/**
* The 'can be more' type job is like a 'must be one' job, but the
run() method of such jobs is even
* called (when scheduled) if it itself is still running.
*/
- CANBEMORE,
+ CANBEMORE, //2
/**
* A job of this type runs exactly once in the load balanced mmbase
cluster. Before the job
* is started, communication between mmbase's in the server will be
done, to negotiate who
* is going to do it.
*/
- BALANCE,
+ BALANCE; //3
+
/**
* NOT IMPLEMENTED. As BALANCED, but no job is started as the previous
was not yet finished.
*/
- BALANCE_MUSTBEONE;
+ //BALANCE_MUSTBEONE;
@@ -182,6 +183,9 @@
public boolean isAlive() {
return isAlive(0);
}
+ public boolean isMustBeOne() {
+ return type == Type.MUSTBEONE;
+ }
Interruptable getExecutable() {
final Date start = new Date();
@@ -196,7 +200,7 @@
return thread;
}
- public boolean kick() {
+ public boolean kick(Date currentTime) {
switch (type) {
case SHORT:
{
@@ -207,7 +211,8 @@
}
return true;
}
- case BALANCE_MUSTBEONE: {
+ case BALANCE: {
+
org.mmbase.core.event.EventManager.getInstance().propagateEvent(new
ProposedJobs.Event(this, currentTime));
return true;
}
case MUSTBEONE:
@@ -342,8 +347,9 @@
return false;
}
CronEntry other = (CronEntry)o;
+ //
return id.equals(other.id) && name.equals(other.name) &&
- className.equals(other.className) &&
cronTime.equals(other.cronTime) && servers.equals(other.servers)
+ className.equals(other.className) &&
cronTime.equals(other.cronTime) &&
servers.pattern().equals(other.servers.pattern())
&& (configuration == null ? other.configuration == null :
configuration.equals(other.configuration));
}
Index: CronEntryField.java
===================================================================
RCS file:
/var/cvs/applications/crontab/src/org/mmbase/applications/crontab/CronEntryField.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- CronEntryField.java 2 Jan 2006 22:01:39 -0000 1.2
+++ CronEntryField.java 29 Jul 2008 15:21:45 -0000 1.3
@@ -14,10 +14,10 @@
* One the fields of the 'crontab' syntax, which is something like '*' or '*
/5' or 5-23. See 'man 5 crontab'
*
* @author Kees Jongenburger
- * @version $Id: CronEntryField.java,v 1.2 2006/01/02 22:01:39 michiel Exp $
+ * @version $Id: CronEntryField.java,v 1.3 2008/07/29 15:21:45 michiel Exp $
*/
-public class CronEntryField {
+public class CronEntryField implements java.io.Serializable {
private String content;
boolean[] valid = new boolean[60];
Index: ProposedJobs.java
===================================================================
RCS file:
/var/cvs/applications/crontab/src/org/mmbase/applications/crontab/ProposedJobs.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ProposedJobs.java 29 Jul 2008 13:36:34 -0000 1.1
+++ ProposedJobs.java 29 Jul 2008 15:21:45 -0000 1.2
@@ -14,13 +14,17 @@
import java.util.Date;
import java.util.concurrent.*;
+import org.mmbase.util.logging.*;
+
/**
* @author Michiel Meeuwissen
- * @version $Id: ProposedJobs.java,v 1.1 2008/07/29 13:36:34 michiel Exp $
+ * @version $Id: ProposedJobs.java,v 1.2 2008/07/29 15:21:45 michiel Exp $
*/
public class ProposedJobs {
+ private static final Logger log =
Logging.getLoggerInstance(ProposedJobs.class);
+
public static int TYPE_PROPOSE = 100;
public static int TYPE_DONE = 101;
@@ -31,12 +35,12 @@
protected final CronEntry entry;
protected final Date cronStart;
- protected final long maxDuration;
+ //protected final long maxDuration;
- public Event(CronEntry entry, Date s, long duration) {
+ public Event(CronEntry entry, Date s) { //, long duration) {
this.entry = entry;
this.cronStart = s;
- this.maxDuration = duration;
+ //this.maxDuration = duration;
};
public CronEntry getCronEntry() {
return entry;
@@ -44,17 +48,20 @@
public Date getCronStart() {
return cronStart;
}
+ /*
public long getMaxDuration() {
return maxDuration;
}
+ */
public boolean equals(Object o) {
if (o instanceof Event) {
Event other = (Event) o;
return
other.getCronEntry().equals(entry) &&
- other.getCronStart() == cronStart;
+ other.getCronStart().equals(cronStart);
} else {
+ log.debug("no");
return false;
}
}
@@ -73,6 +80,10 @@
}
+ public String toString() {
+ return getMachine() + ":" + cronStart + ":" + entry;
+ }
+
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs