From: villberg Date: Tue, 9 Sep 2014 05:08:57 +0000 (+0000) Subject: Performance optimization X-Git-Tag: v1.29.0~184 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=e248e010c4709783fa5ae973a5fdcba8bde0a87b;p=simantics%2Fsysdyn.git Performance optimization refs #5261 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30236 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java index 0b03a5b4..bf71e39f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java @@ -38,6 +38,7 @@ public abstract class IndexVariable extends AbstractPropertyVariable { protected HashMap rvis; protected String indexes; protected VariableSubscriptionManager subscriptionManager; + protected Pair,ArrayList> variableNameArrays; public IndexVariable(ReadGraph graph, Variable parent, String indexes) throws DatabaseException { this.parent = parent; @@ -164,68 +165,83 @@ public abstract class IndexVariable extends AbstractPropertyVariable { } protected void ensureInformationAvailable(ReadGraph graph) throws DatabaseException { - SimulationResource SIMU = SimulationResource.getInstance(graph); - ModelingResources MOD = ModelingResources.getInstance(graph); if(model == null) { + SimulationResource SIMU = SimulationResource.getInstance(graph); Resource modelResource = Variables.getModel(graph, parent); Resource configuration = graph.getPossibleObject(modelResource, SIMU.HasConfiguration); model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration); } - - Variable var = parent.getParent(graph); - Resource represents = var.getRepresents(graph); - - Resource activeRun = null; - if(represents != null) { - do { - if(graph.isInstanceOf(represents, SIMU.Run)) { - activeRun = represents; - break; - } - var = var.getParent(graph); - represents = var.getRepresents(graph); - } while(represents != null && !graph.isInstanceOf(represents, MOD.StructuralModel)); - } - IProject project = Simantics.peekProject(); - if(activeRun != null && project != null) { - IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); - IExperiment e = expMan.getExperiment(NameUtils.getSafeName(graph, activeRun)); - if(e instanceof SysdynExperiment) - this.experiment = (SysdynExperiment)e; + if(this.experiment == null || this.subscriptionManager == null) { + SimulationResource SIMU = SimulationResource.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + Variable var = parent.getParent(graph); + Resource represents = var.getRepresents(graph); + Resource activeRun = null; + if(represents != null) { + do { + if(graph.isInstanceOf(represents, SIMU.Run)) { + activeRun = represents; + break; + } + var = var.getParent(graph); + represents = var.getRepresents(graph); + } while(represents != null && !graph.isInstanceOf(represents, MOD.StructuralModel)); + } + + IProject project = Simantics.peekProject(); + if(activeRun != null && project != null) { + IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment e = expMan.getExperiment(NameUtils.getSafeName(graph, activeRun)); + if(e instanceof SysdynExperiment) + this.experiment = (SysdynExperiment)e; + } + this.subscriptionManager = getSubscriptionManager(); } - this.subscriptionManager = getSubscriptionManager(); - rvi = Variables.getPossibleRVI(graph, this); + if(rvi == null) + rvi = Variables.getPossibleRVI(graph, this); + if(rvi != null) - rvis = graph.syncRequest(new VariableRVIUtils.GetActiveRVIs(parent.getParent(graph))); //VariableRVIUtils.getActiveRVIs(graph, parent.getParent(graph)); + rvis = graph.syncRequest(new VariableRVIUtils.GetActiveRVIs(parent.getParent(graph))); //VariableRVIUtils.getActiveRVIs(graph, parent.getParent(graph)); + } private Pair,ArrayList> getVariableNameArrays() { - Pair,ArrayList> result = new Pair,ArrayList>(new ArrayList(), new ArrayList()); - if(rvi == null || rvis == null) - return result; - if(rvi.indexOf('#') > 0) - rvi = rvi.substring(0, rvi.indexOf('#')); - - String test = rvi; - if(indexes != null && !indexes.isEmpty()) { - String regexIndexes = indexes.trim().replaceAll(":", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012 - test = rvi + "\\[" + regexIndexes + "\\]"; - } else { - test = rvi + "(\\[.*\\])?"; - } - for(String k : rvis.keySet()) { - String value = rvis.get(k); - if(k.matches(test) || value.matches(test)) { - result.first.add(k.substring(1).replace("/", ".").replace("%20", "_")); - result.second.add(value.substring(1).replace("/", ".").replace("%20", " ")); - } - } - - return result; + if(variableNameArrays == null) { + + Pair,ArrayList> result = new Pair,ArrayList>(new ArrayList(), new ArrayList()); + if(rvi != null && rvis != null) { + + if(rvi.indexOf('#') > 0) + rvi = rvi.substring(0, rvi.indexOf('#')); + + String test = rvi; + if(indexes != null && !indexes.isEmpty()) { + String regexIndexes = indexes.trim().replaceAll(":", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012 + test = rvi + "\\[" + regexIndexes + "\\]"; + } else { + test = rvi + "(\\[.*\\])?"; + } + for(String k : rvis.keySet()) { + String value = rvis.get(k); + if(k.matches(test) || value.matches(test)) { + result.first.add(k.substring(1).replace("/", ".").replace("%20", "_")); + result.second.add(value.substring(1).replace("/", ".").replace("%20", " ")); + } + } + + variableNameArrays = result; + + } + + } + + if(variableNameArrays == null) return new Pair,ArrayList>(new ArrayList(), new ArrayList()); + + return variableNameArrays; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynConsole.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynConsole.java index 3d20128c..6a79068f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynConsole.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynConsole.java @@ -127,20 +127,26 @@ public class SysdynConsole implements ISolverMonitor { } } + final static private SimpleDateFormat hhmmss = new SimpleDateFormat("hh:mm:ss"); + @Override public void message(String message) { - message(message, "hh:mm:ss"); + message(message, hhmmss); + } + + public void message(String message, String timeStampFormat) { + message(message, new SimpleDateFormat(timeStampFormat)); } + final static Calendar cal = Calendar.getInstance(); + /** * Print message to a console with a specified time stamp format * * @param message the message to be printed * @param timeStampFormat simpledateformat timestamp format. null if no timestamp wanted */ - public void message(String message, String timeStampFormat) { - Calendar cal = Calendar.getInstance(); - SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat); + public void message(String message, SimpleDateFormat sdf) { String time = sdf.format(cal.getTime()); MessageConsoleStream out = this.console.newMessageStream();