You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by Ondrej Shedee <on...@gmail.com> on 2017/04/11 18:14:57 UTC

Custom listener - Can't get reference to GUI instance

Hello,

I'm developing a plugin for custom network analysis which consist of:
- GUI class derived from AbstractVisualizer
- test element class derived from ResultsCollector

I've overriden a testStarted() method in test element class to do some 
initialization and then to start a separate thread which does the rest.

My problem is that I need to display some information on GUI of my 
plugin but I'm not able to get a reference to my GUI object to use it's 
methods. I need to do this  independently on events of receiving sample 
results thus I can't use method add(final SampleResult res).

In the beginnig I was sending GUI object reference to test element class 
in modifyTestElement method. This worked very well if I stored the 
reference in a static variable in the test element. But as I intend to 
add multiple instances of my new component to the test plan I had to 
make the variable non-static to have individual reference to each GUI 
class instance. And this is where the problem appears. I get 
NullPointerException if I do this.

I've done some investigation by using text interpretation of the test 
element objects and I found out that:
- when I create the test element in createTestElement it is one instance
- when it is passed to modifyTestElement where GUI reference is passed 
in it is still the same instance
- when I try to call a method of GUI from the test element it is 
different (new?) instance -> thus the non-static variable which should 
store the GUI reference is empty
- when modifyTestElement() is then called again it uses again the 
original instance


Could anyone please explain me where and why this new instance is 
created and how to get a reference to my GUI class object from test 
element object?

Thanks in advance
Shedee