Question

I am working on refactoring an existing application written in PowerBuilder and Java and which runs on Sybase EA Server (Jaguar). I am building a small framework to wrap around Jaguar API functions that are available in EA Server. One of the classes is to get runtime statistics from EA Server using the Monitoring class.

Without going into too much detail, Monitoring is a class in EA Server API that provides Jaguar Runtime Monitoring statistics (actual classes are in C++; EA Server provides a wrapper for these in Java, so they can be accessed through CORBA).

Below is the simplified version of my class. (I made a superclass which I inherit from for getting stats for components, conn. caches, HTTP etc).

public class JagMonCompStats {
...
    public void dumpStats(String type, String entity) {

    private String type = "Component";
        private String entity = "web_business_rules";
        private String[] header = {"Active", "Pooled", "invoke"};
        // This has a lot more keys, simplified for this discussion
        private static short[] compKeys = {
            (short) (MONITOR_COMPONENT_ACTIVE.value),
            (short) (MONITOR_COMPONENT_POOLED.value),
            (short) (MONITOR_COMPONENT_INVOKE.value)
        };
        private double[] data = null;

    ...
        /* Call to Jaguar API */
        Monitoring jm = MonitoringHelper.narrow(session.create("Jaguar/Monitoring"));
        data = jm.monitor(type, entity, keys);

    ...

        printStats(entity, header, data);
        ...
    }

    protected void printStats(String entityName, String[] header, double[] data) {

    /* print the header and print data in a formatted way */

    }
}

The line data = jm.monitor is the call to Jaguar API. It takes the type of the entity, the name of the entity, and the keys of the stats we want. This method returns a double array. I go on to print the header and data in a formatted output.

The program works, but I would like to get experts' opinion on OO design aspect. For one, I want to be able to customize printStats to be able to print in different formats (for e.g., full blown report or a one-liner). Apart from this, I am also thinking of showing the stats on a web page or PowerBuilder screen, in which case printStats may not even be relevant. How would you do this in a real OO way?

Was it helpful?

Solution

Well, it's quite simple. Don't print stats from this class. Return them. And let the caller decide how the returned stats should be displayed.

Now that you can get stats, you can create a OneLinerStatsPrinter, a DetailedStatsPrinter, an HtmlStatsFormatter, or whatever you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top