提交 93a7d49e 编写于 作者: K kutzi

[FIXED HUDSON-8033] Prevent AbstractMethodError if a plugin implements a...

[FIXED HUDSON-8033] Prevent AbstractMethodError if a plugin implements a Queue.Executor which does not extend AbstractBuild.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@36910 71c3de6d-444a-0410-be80-ed276b4c234a
上级 e41b55cd
......@@ -269,7 +269,7 @@ public class Executor extends Thread implements ModelObject {
public int getProgress() {
Queue.Executable e = executable;
if(e==null) return -1;
long d = e.getEstimatedDuration();
long d = getEstimatedDurationFor(e);
if(d<0) return -1;
int num = (int)(getElapsedTime()*100/d);
......@@ -290,7 +290,7 @@ public class Executor extends Thread implements ModelObject {
if(e==null) return false;
long elapsed = getElapsedTime();
long d = e.getEstimatedDuration();
long d = getEstimatedDurationFor(e);
if(d>=0) {
// if it's taking 10 times longer than ETA, consider it stuck
return d*10 < elapsed;
......@@ -322,7 +322,7 @@ public class Executor extends Thread implements ModelObject {
Queue.Executable e = executable;
if(e==null) return Messages.Executor_NotAvailable();
long d = e.getEstimatedDuration();
long d = getEstimatedDurationFor(e);
if(d<0) return Messages.Executor_NotAvailable();
long eta = d-getElapsedTime();
......@@ -339,7 +339,7 @@ public class Executor extends Thread implements ModelObject {
Queue.Executable e = executable;
if(e==null) return -1;
long d = e.getEstimatedDuration();
long d = getEstimatedDurationFor(e);
if(d<0) return -1;
long eta = d-getElapsedTime();
......@@ -379,7 +379,7 @@ public class Executor extends Thread implements ModelObject {
if (isIdle())
return Math.max(finishTime, owner.getConnectTime());
else {
return Math.max(startTime + Math.max(0, executable.getEstimatedDuration()),
return Math.max(startTime + Math.max(0, getEstimatedDurationFor(executable)),
System.currentTimeMillis() + 15000);
}
}
......@@ -417,6 +417,19 @@ public class Executor extends Thread implements ModelObject {
if (t instanceof Executor) return (Executor) t;
return IMPERSONATION.get();
}
/**
* Returns the estimated duration for the executable.
* Protects against {@link AbstractMethodError}s if the {@link Executable} implementation
* was compiled against Hudson < 1.383
*/
public static long getEstimatedDurationFor(Executable e) {
try {
return e.getEstimatedDuration();
} catch (AbstractMethodError error) {
return e.getParent().getEstimatedDuration();
}
}
/**
* Mechanism to allow threads (in particular the channel request handling threads) to
......
......@@ -1114,6 +1114,9 @@ public class Queue extends ResourceController implements Saveable {
/**
* Estimate of how long will it take to execute this executable.
* Measured in milliseconds.
*
* Please, consider using {@link Executor#getEstimatedDurationFor(Executable)}
* to protected against AbstractMethodErrors!
*
* @return -1 if it's impossible to estimate.
* @since 1.383
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册