Adds extra function to export harvesting time.
This commit is contained in:
parent
e4c70ba522
commit
ac5cf14be0
@ -2168,4 +2168,43 @@ public class Agent
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the harvesting time (in ms) for the harvester given in parameter.
|
||||
*
|
||||
* @param harvesterName The class name if the harvester.
|
||||
*
|
||||
* @return The harvesting time (in ms) for the harvester given in parameter.
|
||||
* -1 if this harvester does not exists, if the ICE agent is null, or if the
|
||||
* agent is not currently harvesting with this harvester.
|
||||
*/
|
||||
public long getHarvestingTime(String harvesterName)
|
||||
{
|
||||
if(this.hostCandidateHarvester.getClass().getName().endsWith(
|
||||
harvesterName))
|
||||
{
|
||||
return this.hostCandidateHarvester.getHarvestingTime();
|
||||
}
|
||||
|
||||
long harvestingTime = -1;
|
||||
CandidateHarvester tmpHarvester;
|
||||
Iterator<CandidateHarvester> itHarvesters = this.harvesters.iterator();
|
||||
while(itHarvesters.hasNext())
|
||||
{
|
||||
tmpHarvester = itHarvesters.next();
|
||||
if(tmpHarvester.getClass().getName().endsWith(harvesterName))
|
||||
{
|
||||
harvestingTime = tmpHarvester.getHarvestingTime();
|
||||
// Theremay be several harvester with the same class name. Thus,
|
||||
// returns only an active one.
|
||||
if(harvestingTime != -1)
|
||||
{
|
||||
return harvestingTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,8 +19,19 @@ import org.ice4j.ice.*;
|
||||
* @author Emil Ivov
|
||||
* @author Lyubomir Marinov
|
||||
*/
|
||||
public interface CandidateHarvester
|
||||
public abstract class CandidateHarvester
|
||||
{
|
||||
/**
|
||||
* The last harvest start time for this harvester. -1 if this harvester is
|
||||
* not currently harvesting.
|
||||
*/
|
||||
private long lastStartHarvestingTime = -1;
|
||||
|
||||
/**
|
||||
* The last ended harvesting time for this harvester. -1 if this harvester
|
||||
* has never harvested yet.
|
||||
*/
|
||||
private long lastHarvestingTime = -1;
|
||||
|
||||
/**
|
||||
* Gathers all candidate addresses of the type that this
|
||||
@ -38,5 +49,54 @@ public interface CandidateHarvester
|
||||
* as they are discovered, they should also be returned in order to make
|
||||
* sure that the gathering will be considered successful.
|
||||
*/
|
||||
public Collection<LocalCandidate> harvest(Component component);
|
||||
public abstract Collection<LocalCandidate> harvest(Component component);
|
||||
|
||||
/**
|
||||
* Starts the harvesting timer. Called when the harvest begins.
|
||||
*/
|
||||
public void startHarvesting()
|
||||
{
|
||||
// Remember the start date of this harvester.
|
||||
this.lastStartHarvestingTime = System.currentTimeMillis();
|
||||
// Reset the last harvesting time.
|
||||
this.lastHarvestingTime = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the harvesting timer. Called when the harvest ends.
|
||||
*/
|
||||
public void stopHarvesting()
|
||||
{
|
||||
// Remember the last harvesting time.
|
||||
this.lastHarvestingTime = this.getHarvestingTime();
|
||||
// Stops the current timer.
|
||||
this.lastStartHarvestingTime = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current harvesting time in ms. If this harvester is not
|
||||
* currently harvesting, then returns the value of the last harvesting time.
|
||||
* -1 if this harvester has nerver harvested.
|
||||
*
|
||||
* @return The current harvesting time in ms. If this harvester is not
|
||||
* currently harvesting, then returns the value of the last harvesting time.
|
||||
* -1 if this harvester has nerver harvested.
|
||||
*/
|
||||
public long getHarvestingTime()
|
||||
{
|
||||
if(this.lastStartHarvestingTime != -1)
|
||||
{
|
||||
long currentHarvestingTime
|
||||
= System.currentTimeMillis() - lastStartHarvestingTime;
|
||||
// Retest here, while the harvesting may be end while computing the
|
||||
// harvsting time.
|
||||
if(this.lastStartHarvestingTime != -1)
|
||||
{
|
||||
return currentHarvestingTime;
|
||||
}
|
||||
}
|
||||
// If we are ont currently harvesting, then returns the value of the
|
||||
// last harvesting time.
|
||||
return this.lastHarvestingTime;
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,17 +416,14 @@ public class CandidateHarvesterSet
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
long startCandidateHarvestTime = System.currentTimeMillis();
|
||||
|
||||
harvester.startHarvesting();
|
||||
Collection<LocalCandidate> candidates
|
||||
= harvester.harvest(component);
|
||||
harvester.stopHarvesting();
|
||||
|
||||
long stopCandidateHarvestTime = System.currentTimeMillis();
|
||||
long candidateHarvestTime
|
||||
= stopCandidateHarvestTime - startCandidateHarvestTime;
|
||||
logger.info(
|
||||
"End candidate harvest within "
|
||||
+ candidateHarvestTime
|
||||
+ harvester.getHarvestingTime()
|
||||
+ " ms, for "
|
||||
+ harvester.getClass().getName()
|
||||
+ ", component: " + component.getComponentID());
|
||||
|
||||
@ -33,6 +33,18 @@ public class HostCandidateHarvester
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(HostCandidateHarvester.class.getName());
|
||||
|
||||
/**
|
||||
* The last harvest start time for this harvester. -1 if this harvester is
|
||||
* not currently harvesting.
|
||||
*/
|
||||
private long lastStartHarvestingTime = -1;
|
||||
|
||||
/**
|
||||
* The last ended harvesting time for this harvester. -1 if this harvester
|
||||
* has never harvested yet.
|
||||
*/
|
||||
private long lastHarvestingTime = -1;
|
||||
|
||||
/**
|
||||
* Gathers all candidate addresses on the local machine, binds sockets on
|
||||
* them and creates {@link HostCandidate}s. The harvester would always
|
||||
@ -64,7 +76,7 @@ public class HostCandidateHarvester
|
||||
throws IllegalArgumentException,
|
||||
IOException
|
||||
{
|
||||
long startCandidateHarvestTime = System.currentTimeMillis();
|
||||
this.startHarvesting();
|
||||
|
||||
Enumeration<NetworkInterface> interfaces
|
||||
= NetworkInterface.getNetworkInterfaces();
|
||||
@ -172,12 +184,10 @@ public class HostCandidateHarvester
|
||||
+ " maxPort=" + maxPort);
|
||||
}
|
||||
|
||||
long stopCandidateHarvestTime = System.currentTimeMillis();
|
||||
long candidateHarvestTime
|
||||
= stopCandidateHarvestTime - startCandidateHarvestTime;
|
||||
this.stopHarvesting();
|
||||
logger.info(
|
||||
"End candidate harvest within "
|
||||
+ candidateHarvestTime
|
||||
+ this.getHarvestingTime()
|
||||
+ " ms, for "
|
||||
+ this.getClass().getName()
|
||||
+ ", component: " + component.getComponentID());
|
||||
@ -403,4 +413,51 @@ public class HostCandidateHarvester
|
||||
+ ") and maxPort (" + maxPort + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the harvesting timer. Called when the harvest begins.
|
||||
*/
|
||||
public void startHarvesting()
|
||||
{
|
||||
// Remember the start date of this harvester.
|
||||
this.lastStartHarvestingTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the harvesting timer. Called when the harvest ends.
|
||||
*/
|
||||
public void stopHarvesting()
|
||||
{
|
||||
// Remember the last harvesting time.
|
||||
this.lastHarvestingTime = this.getHarvestingTime();
|
||||
// Stops the current timer.
|
||||
this.lastStartHarvestingTime = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current harvesting time in ms. If this harvester is not
|
||||
* currently harvesting, then returns the value of the last harvesting time.
|
||||
* -1 if this harvester has nerver harvested.
|
||||
*
|
||||
* @return The current harvesting time in ms. If this harvester is not
|
||||
* currently harvesting, then returns the value of the last harvesting time.
|
||||
* -1 if this harvester has nerver harvested.
|
||||
*/
|
||||
public long getHarvestingTime()
|
||||
{
|
||||
if(this.lastStartHarvestingTime != -1)
|
||||
{
|
||||
long currentHarvestingTime
|
||||
= System.currentTimeMillis() - lastStartHarvestingTime;
|
||||
// Retest here, while the harvesting may be end while computing the
|
||||
// harvsting time.
|
||||
if(this.lastStartHarvestingTime != -1)
|
||||
{
|
||||
return currentHarvestingTime;
|
||||
}
|
||||
}
|
||||
// If we are ont currently harvesting, then returns the value of the
|
||||
// last harvesting time.
|
||||
return this.lastHarvestingTime;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ import org.ice4j.stack.*;
|
||||
* @author Lyubomir Marinov
|
||||
*/
|
||||
public class StunCandidateHarvester
|
||||
implements CandidateHarvester
|
||||
extends CandidateHarvester
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@ -24,7 +24,7 @@ import org.bitlet.weupnp.*;
|
||||
* @author Sebastien Vincent
|
||||
*/
|
||||
public class UPNPHarvester
|
||||
implements CandidateHarvester
|
||||
extends CandidateHarvester
|
||||
{
|
||||
/**
|
||||
* The logger.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user