@Test public void testGenerateSamples() { System.out.println("generateSamples"); JMXMonSampleGenerator collector = new JMXMonSampleGeneratorEmul(); Map<String, Double> queryResults = new HashMap<String, Double>(); queryResults.put("attribute",1.0); JMXMonSampler instance = new JMXMonSampler(new MBeanServerConnectionEmul(queryResults), null, new JMeterPropertyEmul("service:jmx:rmi: "name", "Something:name=objectName", "attribute", "", true); instance.generateSamples(collector); }
public void generateSamples(JMXMonSampleGenerator collector) { try { if (hasFailed && !canRetry){ return; } ObjectName beanName = new ObjectName(objectName); MBeanServerConnection activeRemote = null; if (remote == null) { activeRemote = pool.getConnection(url.getStringValue(), connectionAttributes); if (activeRemote == null){ hasFailed = true; } } else { activeRemote = remote; } final double val; if (activeRemote != null) { Object o = activeRemote.getAttribute(beanName, attribute); if (o instanceof CompositeDataSupport) { if (key == null || "".equals(key)) { log.error("Got composite object from JMX, but no key specified "); return; } CompositeDataSupport cds = (CompositeDataSupport)o; val = Double.parseDouble(cds.get(key).toString()); } else { if (key != null && !key.equals("")) { log.error("key specified, but didnt get composite object from JMX. Will continue anyway."); } val = Double.parseDouble(o.toString()); } } else { val = 0; } if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(val - oldValue, metricName); } oldValue = val; } else { collector.generateSample(val, metricName); } } catch (MalformedURLException ex) { log.error(ex.getMessage()); } catch (ConnectException ex) { log.warn("Connection lost", ex); pool.notifyConnectionDirty(url.getStringValue()); if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(0 - oldValue, metricName); } oldValue = 0; } else { collector.generateSample(0, metricName); } } catch (IOException ex) { log.error(ex.getMessage()); } catch (ReflectionException ex) { log.error(ex.getMessage()); } catch (MalformedObjectNameException ex) { log.error(ex.getMessage()); } catch (NullPointerException ex) { log.error(ex.getMessage()); } catch (MBeanException ex) { log.error(ex.getMessage()); } catch (AttributeNotFoundException ex) { log.error(ex.getMessage()); } catch (InstanceNotFoundException ex) { log.error(ex.getMessage()); } }
JMXMonSampler { public void generateSamples(JMXMonSampleGenerator collector) { try { if (hasFailed && !canRetry){ return; } ObjectName beanName = new ObjectName(objectName); MBeanServerConnection activeRemote = null; if (remote == null) { activeRemote = pool.getConnection(url.getStringValue(), connectionAttributes); if (activeRemote == null){ hasFailed = true; } } else { activeRemote = remote; } final double val; if (activeRemote != null) { Object o = activeRemote.getAttribute(beanName, attribute); if (o instanceof CompositeDataSupport) { if (key == null || "".equals(key)) { log.error("Got composite object from JMX, but no key specified "); return; } CompositeDataSupport cds = (CompositeDataSupport)o; val = Double.parseDouble(cds.get(key).toString()); } else { if (key != null && !key.equals("")) { log.error("key specified, but didnt get composite object from JMX. Will continue anyway."); } val = Double.parseDouble(o.toString()); } } else { val = 0; } if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(val - oldValue, metricName); } oldValue = val; } else { collector.generateSample(val, metricName); } } catch (MalformedURLException ex) { log.error(ex.getMessage()); } catch (ConnectException ex) { log.warn("Connection lost", ex); pool.notifyConnectionDirty(url.getStringValue()); if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(0 - oldValue, metricName); } oldValue = 0; } else { collector.generateSample(0, metricName); } } catch (IOException ex) { log.error(ex.getMessage()); } catch (ReflectionException ex) { log.error(ex.getMessage()); } catch (MalformedObjectNameException ex) { log.error(ex.getMessage()); } catch (NullPointerException ex) { log.error(ex.getMessage()); } catch (MBeanException ex) { log.error(ex.getMessage()); } catch (AttributeNotFoundException ex) { log.error(ex.getMessage()); } catch (InstanceNotFoundException ex) { log.error(ex.getMessage()); } } }
JMXMonSampler { public void generateSamples(JMXMonSampleGenerator collector) { try { if (hasFailed && !canRetry){ return; } ObjectName beanName = new ObjectName(objectName); MBeanServerConnection activeRemote = null; if (remote == null) { activeRemote = pool.getConnection(url.getStringValue(), connectionAttributes); if (activeRemote == null){ hasFailed = true; } } else { activeRemote = remote; } final double val; if (activeRemote != null) { Object o = activeRemote.getAttribute(beanName, attribute); if (o instanceof CompositeDataSupport) { if (key == null || "".equals(key)) { log.error("Got composite object from JMX, but no key specified "); return; } CompositeDataSupport cds = (CompositeDataSupport)o; val = Double.parseDouble(cds.get(key).toString()); } else { if (key != null && !key.equals("")) { log.error("key specified, but didnt get composite object from JMX. Will continue anyway."); } val = Double.parseDouble(o.toString()); } } else { val = 0; } if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(val - oldValue, metricName); } oldValue = val; } else { collector.generateSample(val, metricName); } } catch (MalformedURLException ex) { log.error(ex.getMessage()); } catch (ConnectException ex) { log.warn("Connection lost", ex); pool.notifyConnectionDirty(url.getStringValue()); if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(0 - oldValue, metricName); } oldValue = 0; } else { collector.generateSample(0, metricName); } } catch (IOException ex) { log.error(ex.getMessage()); } catch (ReflectionException ex) { log.error(ex.getMessage()); } catch (MalformedObjectNameException ex) { log.error(ex.getMessage()); } catch (NullPointerException ex) { log.error(ex.getMessage()); } catch (MBeanException ex) { log.error(ex.getMessage()); } catch (AttributeNotFoundException ex) { log.error(ex.getMessage()); } catch (InstanceNotFoundException ex) { log.error(ex.getMessage()); } } JMXMonSampler(MBeanServerConnection remote, JMXConnector jmxConnector, JMeterProperty url, String name, String objectName, String attribute, String key, boolean sampleDeltaValue);  JMXMonSampler(JMXMonCollector jmxMonCollector, JMXMonConnectionPool pool, Hashtable attributes, JMeterProperty url, String name, String objectName, String attribute, String key, boolean sampleDeltaValue, boolean canRetry); }
JMXMonSampler { public void generateSamples(JMXMonSampleGenerator collector) { try { if (hasFailed && !canRetry){ return; } ObjectName beanName = new ObjectName(objectName); MBeanServerConnection activeRemote = null; if (remote == null) { activeRemote = pool.getConnection(url.getStringValue(), connectionAttributes); if (activeRemote == null){ hasFailed = true; } } else { activeRemote = remote; } final double val; if (activeRemote != null) { Object o = activeRemote.getAttribute(beanName, attribute); if (o instanceof CompositeDataSupport) { if (key == null || "".equals(key)) { log.error("Got composite object from JMX, but no key specified "); return; } CompositeDataSupport cds = (CompositeDataSupport)o; val = Double.parseDouble(cds.get(key).toString()); } else { if (key != null && !key.equals("")) { log.error("key specified, but didnt get composite object from JMX. Will continue anyway."); } val = Double.parseDouble(o.toString()); } } else { val = 0; } if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(val - oldValue, metricName); } oldValue = val; } else { collector.generateSample(val, metricName); } } catch (MalformedURLException ex) { log.error(ex.getMessage()); } catch (ConnectException ex) { log.warn("Connection lost", ex); pool.notifyConnectionDirty(url.getStringValue()); if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(0 - oldValue, metricName); } oldValue = 0; } else { collector.generateSample(0, metricName); } } catch (IOException ex) { log.error(ex.getMessage()); } catch (ReflectionException ex) { log.error(ex.getMessage()); } catch (MalformedObjectNameException ex) { log.error(ex.getMessage()); } catch (NullPointerException ex) { log.error(ex.getMessage()); } catch (MBeanException ex) { log.error(ex.getMessage()); } catch (AttributeNotFoundException ex) { log.error(ex.getMessage()); } catch (InstanceNotFoundException ex) { log.error(ex.getMessage()); } } JMXMonSampler(MBeanServerConnection remote, JMXConnector jmxConnector, JMeterProperty url, String name, String objectName, String attribute, String key, boolean sampleDeltaValue);  JMXMonSampler(JMXMonCollector jmxMonCollector, JMXMonConnectionPool pool, Hashtable attributes, JMeterProperty url, String name, String objectName, String attribute, String key, boolean sampleDeltaValue, boolean canRetry); void generateSamples(JMXMonSampleGenerator collector); String getMetricName(); void setMetricName(String metricName); String getObjectName(); void setObjectName(String objectName); String getAttribute(); void setAttribute(String attribute); String getKey(); void setKey(String key); JMeterProperty getUrl(); void setUrl(JMeterProperty url); boolean isSampleDeltaValue(); void setSampleDeltaValue(boolean sampleDeltaValue); double getOldValue(); void setOldValue(double oldValue); }
JMXMonSampler { public void generateSamples(JMXMonSampleGenerator collector) { try { if (hasFailed && !canRetry){ return; } ObjectName beanName = new ObjectName(objectName); MBeanServerConnection activeRemote = null; if (remote == null) { activeRemote = pool.getConnection(url.getStringValue(), connectionAttributes); if (activeRemote == null){ hasFailed = true; } } else { activeRemote = remote; } final double val; if (activeRemote != null) { Object o = activeRemote.getAttribute(beanName, attribute); if (o instanceof CompositeDataSupport) { if (key == null || "".equals(key)) { log.error("Got composite object from JMX, but no key specified "); return; } CompositeDataSupport cds = (CompositeDataSupport)o; val = Double.parseDouble(cds.get(key).toString()); } else { if (key != null && !key.equals("")) { log.error("key specified, but didnt get composite object from JMX. Will continue anyway."); } val = Double.parseDouble(o.toString()); } } else { val = 0; } if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(val - oldValue, metricName); } oldValue = val; } else { collector.generateSample(val, metricName); } } catch (MalformedURLException ex) { log.error(ex.getMessage()); } catch (ConnectException ex) { log.warn("Connection lost", ex); pool.notifyConnectionDirty(url.getStringValue()); if (sampleDeltaValue) { if (!Double.isNaN(oldValue)) { collector.generateSample(0 - oldValue, metricName); } oldValue = 0; } else { collector.generateSample(0, metricName); } } catch (IOException ex) { log.error(ex.getMessage()); } catch (ReflectionException ex) { log.error(ex.getMessage()); } catch (MalformedObjectNameException ex) { log.error(ex.getMessage()); } catch (NullPointerException ex) { log.error(ex.getMessage()); } catch (MBeanException ex) { log.error(ex.getMessage()); } catch (AttributeNotFoundException ex) { log.error(ex.getMessage()); } catch (InstanceNotFoundException ex) { log.error(ex.getMessage()); } } JMXMonSampler(MBeanServerConnection remote, JMXConnector jmxConnector, JMeterProperty url, String name, String objectName, String attribute, String key, boolean sampleDeltaValue);  JMXMonSampler(JMXMonCollector jmxMonCollector, JMXMonConnectionPool pool, Hashtable attributes, JMeterProperty url, String name, String objectName, String attribute, String key, boolean sampleDeltaValue, boolean canRetry); void generateSamples(JMXMonSampleGenerator collector); String getMetricName(); void setMetricName(String metricName); String getObjectName(); void setObjectName(String objectName); String getAttribute(); void setAttribute(String attribute); String getKey(); void setKey(String key); JMeterProperty getUrl(); void setUrl(JMeterProperty url); boolean isSampleDeltaValue(); void setSampleDeltaValue(boolean sampleDeltaValue); double getOldValue(); void setOldValue(double oldValue);  }