Skip to content
Snippets Groups Projects
Commit 4159ef5b authored by Bjoern Weissenfels's avatar Bjoern Weissenfels
Browse files

server side control of the execution of JMeter

parent 54b55cfd
No related branches found
No related tags found
No related merge requests found
...@@ -2,9 +2,14 @@ package livedemo.managedbeans; ...@@ -2,9 +2,14 @@ package livedemo.managedbeans;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Observable;
import java.util.Observer;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.bean.ApplicationScoped; import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
/** /**
* @author Bjoern Weissenfels * @author Bjoern Weissenfels
...@@ -13,25 +18,55 @@ import javax.faces.bean.ManagedBean; ...@@ -13,25 +18,55 @@ import javax.faces.bean.ManagedBean;
*/ */
@ManagedBean(name = "jMeterBean") @ManagedBean(name = "jMeterBean")
@ApplicationScoped @ApplicationScoped
public class JMeterBean { public class JMeterBean implements Observer{
private final long TIMEOUT_IN_MILLIS = 120000;
private final String DEFAULT_BUTTON_TEXT = "Generate Load";
@ManagedProperty(value = "#{analysisBean}")
private AnalysisBean analysisBean;
private boolean disabled; private boolean disabled;
private long timestamp;
private String buttonText;
public JMeterBean(){ public JMeterBean(){
this.disabled = false; this.disabled = false;
this.timestamp = System.currentTimeMillis();
this.buttonText = this.DEFAULT_BUTTON_TEXT;
}
@PostConstruct
public void init() {
this.analysisBean.getUpdateThread().addObserver(this);
}
@PreDestroy
public void terminate() {
this.analysisBean.getUpdateThread().deleteObserver(this);
}
public void setAnalysisBean(final AnalysisBean analysisBean) {
this.analysisBean = analysisBean;
}
public String getButtonText(){
return this.buttonText;
} }
public boolean getDisabled(){ public boolean getDisabled(){
return this.disabled; return this.disabled;
} }
public void change(){ public void runJMeter(){
this.disabled = !this.disabled; synchronized(this){
long actualtime = System.currentTimeMillis();
if(actualtime < this.timestamp){
return;
}else{
this.timestamp = actualtime + this.TIMEOUT_IN_MILLIS;
}
} }
public synchronized void runJMeter(){
this.disabled = true;
System.out.println("---disabled=true---");
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
File dir = new File(new File("").getAbsolutePath()+"/jmeter/bin"); File dir = new File(new File("").getAbsolutePath()+"/jmeter/bin");
try { try {
...@@ -40,8 +75,18 @@ public class JMeterBean { ...@@ -40,8 +75,18 @@ public class JMeterBean {
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
}
@Override
public void update(Observable arg0, Object arg1) {
long actualtime = System.currentTimeMillis();
if(actualtime > this.timestamp){
this.buttonText = this.DEFAULT_BUTTON_TEXT;
this.disabled = false; this.disabled = false;
System.out.println("---disabled=false---" + runtime.availableProcessors()); }else{
this.buttonText = "Generate Load in " + String.valueOf((int)((this.timestamp - actualtime)/1000)) + " s";
this.disabled = true;
}
} }
} }
...@@ -157,6 +157,7 @@ public class MethodResponsetimeBean implements Observer { ...@@ -157,6 +157,7 @@ public class MethodResponsetimeBean implements Observer {
} }
private synchronized void updateModels() { private synchronized void updateModels() {
this.maxY = 4;
for (final String shortSignature : this.getSelectedMethods()) { for (final String shortSignature : this.getSelectedMethods()) {
final String signature = this.shortToLongSignatures.get(shortSignature); final String signature = this.shortToLongSignatures.get(shortSignature);
...@@ -169,7 +170,11 @@ public class MethodResponsetimeBean implements Observer { ...@@ -169,7 +170,11 @@ public class MethodResponsetimeBean implements Observer {
final ChartSeries countings = new ChartSeries(); final ChartSeries countings = new ChartSeries();
countings.setLabel(shortSignature); countings.setLabel(shortSignature);
final Map<Object, Number> countMap = this.methodCallsXYplot.getEntries(signature); final Map<Object, Number> countMap = this.methodCallsXYplot.getEntries(signature);
this.maxY = this.calculateMaxY(countMap.values());
int max = this.calculateMaxY(countMap.values());
if(max > this.maxY){
this.maxY = max;
}
countings.setData(countMap); countings.setData(countMap);
this.countingModel.addSeries(countings); this.countingModel.addSeries(countings);
} }
......
No preview for this file type
No preview for this file type
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
offLabel="Select One" valueChangeListener="#{methodResponsetimeBean.onChange}"> offLabel="Select One" valueChangeListener="#{methodResponsetimeBean.onChange}">
<p:ajax update="dialog"/> <p:ajax update="dialog"/>
</p:selectBooleanButton> </p:selectBooleanButton>
<p:commandButton async="true" id="loadButton" value="Generate Load" disabled="#{jMeterBean.disabled}" actionListener="#{jMeterBean.runJMeter}" /> <p:commandButton async="true" id="loadButton" value="#{jMeterBean.buttonText}" disabled="#{jMeterBean.disabled}" actionListener="#{jMeterBean.runJMeter}" />
</h:panelGrid> </h:panelGrid>
<p:dialog id="dialog" header="Select Methods" widgetVar="dlg2" onShow="poll.stop()" onHide="poll.start()" > <p:dialog id="dialog" header="Select Methods" widgetVar="dlg2" onShow="poll.stop()" onHide="poll.start()" >
......
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
<ul class="menu"> <ul class="menu">
<li class="menu-item"><a href="http://kieker-monitoring.net/contact/">Contact</a></li> <li class="menu-item"><a href="http://kieker-monitoring.net/contact/">Contact</a></li>
<li class="menu-item"><a href="http://kieker-monitoring.net/legal-notice/">Legal Notice</a></li> <li class="menu-item"><a href="http://kieker-monitoring.net/legal-notice/">Legal Notice</a></li>
<li class="menu-item">v08122013</li> <li class="menu-item" style="font-size:x-small">v17122013</li>
</ul> </ul>
</div> </div>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment