Skip to content

Commit 700313f

Browse files
committed
Fix JMX configuration
1 parent 9de771b commit 700313f

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

core/src/main/java/com/microsoft/applicationinsights/internal/config/JmxXmlElement.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@
2121

2222
package com.microsoft.applicationinsights.internal.config;
2323

24-
import com.thoughtworks.xstream.annotations.XStreamAlias;
24+
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
2525

2626
/**
2727
* Created by gupele on 3/15/2015.
2828
*/
29-
@XStreamAlias("Add")
3029
public class JmxXmlElement {
3130

31+
@XStreamAsAttribute
3232
private String displayName;
33+
34+
@XStreamAsAttribute
3335
private String objectName;
36+
37+
@XStreamAsAttribute
3438
private String attribute;
39+
40+
@XStreamAsAttribute
3541
private String type;
3642

3743
public String getDisplayName() {

core/src/main/java/com/microsoft/applicationinsights/internal/config/PerformanceCountersXmlElement.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.thoughtworks.xstream.annotations.XStreamAlias;
2727
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
28+
import com.thoughtworks.xstream.annotations.XStreamImplicit;
2829

2930
/**
3031
* Created by gupele on 3/15/2015.
@@ -44,17 +45,17 @@ public class PerformanceCountersXmlElement {
4445
private String plugin;
4546

4647
@XStreamAlias("Jmx")
47-
private ArrayList<JmxXmlElement> jmxXmlElements;
48+
private JmxWrapperXmlElement jmxWrapper = new JmxWrapperXmlElement();
4849

4950
@XStreamAlias("Windows")
50-
private ArrayList<WindowsPerformanceCounterXmlElement> windowsPCs;
51+
private WindowsPCWrapperXmlElement windowsPCWrapper = new WindowsPCWrapperXmlElement();
5152

5253
public ArrayList<JmxXmlElement> getJmxXmlElements() {
53-
return jmxXmlElements;
54+
return jmxWrapper.jmxXmlElements;
5455
}
5556

5657
public void setJmxXmlElements(ArrayList<JmxXmlElement> jmxXmlElements) {
57-
this.jmxXmlElements = jmxXmlElements;
58+
jmxWrapper.jmxXmlElements = jmxXmlElements;
5859
}
5960

6061
public boolean isUseBuiltIn() {
@@ -66,11 +67,11 @@ public void setUseBuiltIn(boolean useBuiltIn) {
6667
}
6768

6869
public ArrayList<WindowsPerformanceCounterXmlElement> getWindowsPCs() {
69-
return windowsPCs;
70+
return windowsPCWrapper.windowsPCs;
7071
}
7172

7273
public void setWindowsPCs(ArrayList<WindowsPerformanceCounterXmlElement> windowsPCs) {
73-
this.windowsPCs = windowsPCs;
74+
windowsPCWrapper.windowsPCs = windowsPCs;
7475
}
7576

7677
public long getCollectionFrequencyInSec() {
@@ -96,4 +97,16 @@ public String getPlugin() {
9697
public void setPlugin(String plugin) {
9798
this.plugin = plugin;
9899
}
100+
101+
public static class JmxWrapperXmlElement {
102+
103+
@XStreamImplicit(itemFieldName = "Add")
104+
private ArrayList<JmxXmlElement> jmxXmlElements;
105+
}
106+
107+
public static class WindowsPCWrapperXmlElement {
108+
109+
@XStreamImplicit(itemFieldName = "Add")
110+
private ArrayList<WindowsPerformanceCounterXmlElement> windowsPCs;
111+
}
99112
}

core/src/main/java/com/microsoft/applicationinsights/internal/config/WindowsPerformanceCounterXmlElement.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121

2222
package com.microsoft.applicationinsights.internal.config;
2323

24-
import com.thoughtworks.xstream.annotations.XStreamAlias;
2524
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
2625

2726
/**
2827
* Created by gupele on 3/30/2015.
2928
*/
30-
@XStreamAlias("Add")
3129
public class WindowsPerformanceCounterXmlElement {
3230

3331
@XStreamAsAttribute

core/src/test/java/com/microsoft/applicationinsights/internal/config/JaxbAppInsightsConfigurationBuilderTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.IOException;
2727
import java.io.InputStream;
28+
import java.util.ArrayList;
2829

2930
public final class JaxbAppInsightsConfigurationBuilderTest {
3031
private final static String EXISTING_CONF_TEST_FILE = "ApplicationInsights2.xml";
@@ -56,6 +57,10 @@ public void testBuilderProducesCorrectConfig() throws IOException {
5657
Assert.assertEquals("myrole", config.getRoleName());
5758
Assert.assertFalse(config.getChannel().getDeveloperMode());
5859
Assert.assertEquals("mypackage.MyCustomContextInitializer", config.getContextInitializers().getAdds().get(0).getType());
60+
61+
WindowsPerformanceCounterXmlElement windowsPC = config.getPerformance().getWindowsPCs().get(0);
62+
Assert.assertEquals("System Threads", windowsPC.getDisplayName());
63+
JmxXmlElement jmxXmlElement = config.getPerformance().getJmxXmlElements().get(0);
64+
Assert.assertEquals("Thread Count", jmxXmlElement.getDisplayName());
5965
}
6066
}
61-

core/src/test/resources/ApplicationInsights2.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@
266266
The structure is the same as BuiltInProcessors.
267267
See comments above for more information on implementation and configuration.
268268
-->
269+
<Processor type="Test">
270+
<Add name="Test" value="Test" />
271+
</Processor>
269272
</CustomProcessors>
270273
</TelemetryProcessors>
271274

0 commit comments

Comments
 (0)