Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 115 additions & 13 deletions Source/Core/src/ca/uqac/lif/labpal/Experiment.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract class Experiment implements Runnable, DataOwner
/**
* The status of the experiment
*/
public static enum Status {DUNNO, PREREQ_NOK, PREREQ_OK, PREREQ_F, RUNNING, DONE, DONE_WARNING, FAILED, TIMEOUT, INTERRUPTED, RUNNING_REMOTELY};
public static enum Status {DUNNO, PREREQ_NOK, PREREQ_RUNNING, PREREQ_OK, PREREQ_F, RUNNING, DONE, DONE_WARNING, FAILED, KILLED, TIMEOUT, INTERRUPTED, RUNNING_REMOTELY};

/**
* The queuing status of the experiment
Expand Down Expand Up @@ -97,6 +97,14 @@ public static enum QueueStatus {QUEUED, QUEUED_REMOTELY, NOT_QUEUED};
*/
private long m_maxDuration = -1;

/**
* The maximum duration for this experiment requirements (in milliseconds).
* If the requirements lasts longer than this duration, the lab assistant
* can interrupt experiment. A negative value indicates that no timeout
* applies.
*/
private long m_maxPrereqDuration = -1;

/**
* A list of exceptions that the experiment does not throw, but
* rather adds to a list
Expand All @@ -118,6 +126,16 @@ public static enum QueueStatus {QUEUED, QUEUED_REMOTELY, NOT_QUEUED};
*/
private long m_endTime = -1;

/**
* The start time of requirements
*/
private long m_startPrereqTime = -1;

/**
* The end time of requirements
*/
private long m_endPrereqTime = -1;

/**
* An approximate measurement of the experiment's progression
*/
Expand Down Expand Up @@ -217,7 +235,15 @@ public final QueueStatus getQueueStatus()
*/
public boolean prerequisitesFulfilled()
{
return true;
if (m_status == Status.PREREQ_F || m_status == Status.PREREQ_NOK || m_status == Status.PREREQ_OK)
{
return true;
}
else
{
return false;
}

}

/**
Expand All @@ -232,6 +258,7 @@ public boolean prerequisitesFulfilled()
*/
public void fulfillPrerequisites() throws ExperimentException
{
m_status = Status.PREREQ_OK;
return;
}

Expand Down Expand Up @@ -654,6 +681,29 @@ public final long getEndTime()
return m_endTime;
}

/**
* Gets the start time of requirement
* @return The difference, measured in milliseconds,
* between the start time and midnight, January 1, 1970 UTC. The
* value is -1 if requirement has not started yet.
*/
public final long getStartPrereqTime()
{
return m_startPrereqTime;
}

/**
* Gets the end time of requirement
* @return The difference, measured in milliseconds,
* between the end time and midnight, January 1, 1970 UTC. The
* value is -1 if requirement has not started yet or is still
* running.
*/
public final long getEndPrereqTime()
{
return m_endPrereqTime;
}

/**
* Gets the name of the lab assistant that ran the experiment
* @return The name, or the empty string if the experiment has not run yet
Expand Down Expand Up @@ -684,6 +734,8 @@ public synchronized final void reset()
m_outputParameters.clear();
m_startTime = -1;
m_endTime = -1;
m_startPrereqTime = -1;
m_endPrereqTime = -1;
m_runBy = "";
m_status = Status.DUNNO;
m_errorMessage = "";
Expand All @@ -707,7 +759,7 @@ public final void clean()
*/
public synchronized final Status getStatus()
{
if (m_status == Status.DUNNO || m_status == Status.PREREQ_NOK || m_status == Status.PREREQ_OK)
/*if (m_status == Status.DUNNO || m_status == Status.PREREQ_NOK || m_status == Status.PREREQ_OK)
{
if (prerequisitesFulfilled())
{
Expand All @@ -717,20 +769,27 @@ public synchronized final Status getStatus()
{
m_status = Status.PREREQ_NOK;
}
}
}*/
return m_status;
}

@Override
public final void run()
{
m_running = true;
m_startTime = System.currentTimeMillis();

//m_running = true;
//m_startTime = System.currentTimeMillis();

if (!prerequisitesFulfilled())
{
m_startPrereqTime = System.currentTimeMillis();
try
{
fulfillPrerequisites();
//if (m_status != Status.PREREQ_RUNNING)
//{
m_status = Status.PREREQ_RUNNING;
fulfillPrerequisites();
//}
}
catch (Exception e)
{
Expand All @@ -742,9 +801,11 @@ public final void run()
setErrorMessage(sw.toString());
return;
}
m_endPrereqTime = System.currentTimeMillis();
}
m_status = Status.PREREQ_OK;
//m_status = Status.PREREQ_OK;
m_status = Status.RUNNING;
m_startTime = System.currentTimeMillis();
try
{
execute();
Expand Down Expand Up @@ -967,8 +1028,18 @@ public final Experiment interrupt()
m_running = false;
m_status = Status.INTERRUPTED;
m_errorMessage = "The experiment was manually interrupted";
m_endTime = System.currentTimeMillis();
prepareToInterrupt();
if (m_startTime > -1)
{
m_endTime = System.currentTimeMillis();
}
if (m_endPrereqTime == -1)
{
m_endPrereqTime = System.currentTimeMillis();
}

//m_endTime = System.currentTimeMillis();
//prepareToInterrupt();

return this;
}

Expand Down Expand Up @@ -1039,14 +1110,36 @@ public final long getMaxDuration()
* If the experiment lasts longer than this duration, the lab assistant
* can interrupt it.
* @return The duration, in milliseconds. A negative value indicates
* that no timeout applies.
* that no timeout applies.
*/
public final Experiment setMaxDuration(long duration)
{
m_maxDuration = duration;
return this;
}

/**
* Gets the maximum duration for this experiment requirement
* @return The duration
*/
public final long getMaxPrereqDuration()
{
return m_maxPrereqDuration;
}

/**
* Sets the maximum duration for this experiment requirement.
* If the experiment lasts longer than this duration, the lab assistant
* can interrupt it.
* @return The duration, in milliseconds. A negative value indicates
* that no timeout applies. m_maxPrereqDuration
*/
public final Experiment setMaxPrereqDuration(long duration)
{
m_maxPrereqDuration = duration;
return this;
}

/**
* Interrupts the current experiment
* @return This experiment
Expand All @@ -1056,7 +1149,14 @@ public final Experiment kill()
m_running = false;
m_status = Status.TIMEOUT;
m_errorMessage = "The experiment was interrupted by the lab assistant because it was taking too long";
m_endTime = System.currentTimeMillis();
if (m_startTime > -1)
{
m_endTime = System.currentTimeMillis();
}
if (m_endPrereqTime == -1)
{
m_endPrereqTime = System.currentTimeMillis();
}
return this;
}

Expand Down Expand Up @@ -1141,7 +1241,7 @@ public Experiment getOwner()
*/
public synchronized boolean mergeWith(Experiment e, boolean is_remote)
{
if (m_status == Status.RUNNING)
if (m_status == Status.RUNNING || m_status == Status.PREREQ_RUNNING)
{
return false;
}
Expand All @@ -1168,6 +1268,8 @@ public synchronized boolean mergeWith(Experiment e, boolean is_remote)
m_errorMessage = e.m_errorMessage;
m_startTime = e.m_startTime;
m_endTime = e.m_endTime;
m_startPrereqTime = e.m_startPrereqTime;
m_endPrereqTime = e.m_endPrereqTime;
m_runBy = e.m_runBy;
return true;
}
Expand Down
74 changes: 61 additions & 13 deletions Source/Core/src/ca/uqac/lif/labpal/Laboratory.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ public abstract class Laboratory implements OwnershipManager
/**
* The default filename assumed for the HTML description
*/
private static transient final String s_descriptionDefaultFilename = "description.html";
private static transient final String s_descriptionDefaultFilename = "description.html";

/**
* shadow laboratory
*/
private static transient Laboratory shadow_laboratory = null;

/**
* Creates a new lab assistant
Expand Down Expand Up @@ -479,6 +484,16 @@ public Set<Integer> getTableIds(boolean including_invisible)
return ids;
}


/**
* Gets the title given to this assistant
* @return The
*/
public String getTitle()
{
return m_title;
}

/**
* Gets the plot with given ID
* @param id The ID
Expand All @@ -498,12 +513,12 @@ public Plot getPlot(int id)


/**
* Gets the title given to this assistant
* @return The title
* Gets the shadow_laboratory if the current lab has one
* @return The shadow_laboratory
*/
public String getTitle()
public Laboratory getShadowLaboratory()
{
return m_title;
return shadow_laboratory;
}

/**
Expand Down Expand Up @@ -818,6 +833,10 @@ protected static CliParser setupParser()
.withLongName("filter")
.withArgument("exp")
.withDescription("Filter experiments according to expression exp"));
parser.addArgument(new Argument()
.withLongName("shadow")
.withArgument("x")
.withDescription("Set shadow laboratory to x"));
return parser;
}

Expand Down Expand Up @@ -866,21 +885,49 @@ public static final void initialize(String[] args, Class<? extends Laboratory> c
{
new_lab = preloadLab(new_lab, stdout);
}
// are we a shadow lab?
if (argument_map.hasOption("shadow"))
{
String shadowLabFile = argument_map.getOptionValue("shadow");
try
{
shadow_laboratory = clazz.newInstance();
}
catch (InstantiationException e)
{
e.printStackTrace();
//System.exit(ERR_LAB);
}
catch (IllegalAccessException e)
{
e.printStackTrace();
//System.exit(ERR_LAB);
}
shadow_laboratory = loadFromFilename(shadow_laboratory, shadowLabFile);
shadow_laboratory.setAssistant(assistant);
shadow_laboratory.setupCli(parser);
shadow_laboratory.setup();
}
// Are we loading a lab file? If so, this overrides the
// lab loaded from an internal file (if any)
String filename = "";
List<String> names = argument_map.getOthers();
for (int i = 0; i < names.size(); i++)
{
filename = names.get(i);
if (i == 0)
{
new_lab = loadFromFilename(new_lab, filename);
}
else
int ii = 0;
if (names.get(i).toUpperCase().endsWith(".LABO"))
{
Laboratory lab_to_merge = loadFromFilename(new_lab, filename);
new_lab.mergeWith(lab_to_merge);
filename = names.get(i);
if (ii == 0)
{
new_lab = loadFromFilename(new_lab, filename);
}
else
{
Laboratory lab_to_merge = loadFromFilename(new_lab, filename);
new_lab.mergeWith(lab_to_merge);
}
ii++;
}
}
new_lab.setAssistant(assistant);
Expand Down Expand Up @@ -944,6 +991,7 @@ public void run()
String assistant_name = argument_map.getOptionValue("name").trim();
assistant.setName(assistant_name);
}

// Sets an experiment filter
String filter_params = "";
if (argument_map.hasOption("filter"))
Expand Down
Loading