001 package toolbus.atom.tool;
002
003 import toolbus.TBTermFactory;
004 import toolbus.TBTermVar;
005 import toolbus.atom.Atom;
006 import toolbus.atom.Ref;
007 import toolbus.exceptions.ToolBusException;
008 import toolbus.parsercup.PositionInformation;
009 import toolbus.process.ProcessExpression;
010 import toolbus.tool.ToolInstance;
011 import aterm.ATerm;
012
013 public class GetPerfStats extends Atom{
014 private final Ref toolId;
015 private ToolInstance toolInstance;
016
017 public GetPerfStats(ATerm toolId, TBTermFactory tbfactory, PositionInformation posInfo){
018 super(tbfactory, posInfo);
019
020 this.toolId = new Ref(toolId);
021 setAtomArgs(new Ref[]{this.toolId});
022 externalNameAsReceivedByTool = "snd-perf-stats";
023 }
024
025 public ProcessExpression copy(){
026 Atom a = new GetPerfStats(toolId.value, tbfactory, getPosInfo());
027 a.copyAtomAttributes(this);
028
029 return a;
030 }
031
032 public void activate(){
033 toolInstance = null;
034 super.activate();
035 }
036
037 public boolean execute() throws ToolBusException{
038 if(!isEnabled()) return false;
039
040 if(toolInstance == null){
041 ATerm tid = getEnv().getValue((TBTermVar) toolId.value);
042 toolInstance = getToolBus().getToolInstanceManager().get(tid);
043 if(toolInstance == null) return false;
044 }
045
046 if(toolInstance.tryDoEval()){
047 toolInstance.sendPerformanceStatsRequest(tbfactory.makeList());
048 //LoggerFactory.log(this.getProcess().getProcessName(), "Sending performace statistics request to tool: " + toolInstance.getToolKey(), IToolBusLoggerConstants.TOOLCOM);
049 return true;
050 }
051 return false;
052 }
053 }