karouani / javasimon

Automatically exported from code.google.com/p/javasimon
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Extend StopwatchMXBeanImpl #126

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by Vladimir...@gmail.com on 12 Jul 2014 at 12:12

GoogleCodeExporter commented 8 years ago
I don't understand this one :-) can you elaborate?

Original comment by virgo47 on 24 Jul 2014 at 9:44

GoogleCodeExporter commented 8 years ago
Sorry for my delayed answer. 
For generic JMX access to simon attributes I'm using the next classes

public class MonitorStopwatchMXBeanImpl extends StopwatchMXBeanImpl implements 
MonitorStopwatchMXBean {

    public MonitorStopwatchMXBeanImpl(Stopwatch stopwatch) {
        super(stopwatch);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<String[]> getAttributes() {
        List<String[]> attributes = new ArrayList<String[]>();
        Iterator<String> iterator = simon().getAttributeNames();
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object attr = simon().getAttribute(key);
            String value = attr != null ? String.valueOf(attr) : null;
            String[] attrib = new String[2];
            attrib[0] = key;
            attrib[1] = value;
            attributes.add(attrib);
        }
        return attributes;
    }
}

public class MonitorCounterMXBeanImpl extends CounterMXBeanImpl implements 
MonitorCounterMXBean {

    public MonitorCounterMXBeanImpl(Counter counter) {
        super(counter);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<String[]> getAttributes() {
        List<String[]> attributes = new ArrayList<String[]>();
        Iterator<String> iterator = simon().getAttributeNames();
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object attr = simon().getAttribute(key);
            String value = attr != null ? String.valueOf(attr) : null;
            String[] attrib = new String[2];
            attrib[0] = key;
            attrib[1] = value;
            attributes.add(attrib);
        }
        return attributes;
    }

As a side effect I must extend also MonitorJmxRegisterCallback. Much convenient 
sollution is to have these methods in StopwatchMXBeanImpl and CounterMXBeanImpl

Original comment by Vladimir...@gmail.com on 7 Aug 2014 at 4:59

GoogleCodeExporter commented 8 years ago
Hi Vlado, please feel free to add them there, you're still commiter after all. 
:-) That way you can do it exactly as you like and test it. If I understand 
there should added classes, right? Feel free to push it to master.

If it is a problem for you I can do it, but I can't test your usecase.

Original comment by virgo47 on 8 Aug 2014 at 7:15

GoogleCodeExporter commented 8 years ago
Closed here - open as https://github.com/virgo47/javasimon/issues/3

Original comment by virgo47 on 29 Oct 2014 at 10:03