All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ajjpj.asysmon.datasink.log.ALoggingDataSink Maven / Gradle / Ivy

There is a newer version: 1.0-pre28
Show newest version
package com.ajjpj.asysmon.datasink.log;

import com.ajjpj.asysmon.data.AHierarchicalData;
import com.ajjpj.asysmon.data.AHierarchicalDataRoot;
import com.ajjpj.asysmon.datasink.ADataSink;


public abstract class ALoggingDataSink implements ADataSink {
    @Override public void onStartedHierarchicalMeasurement(String identifier) {
    }

    @Override public void onFinishedHierarchicalMeasurement(AHierarchicalDataRoot data) {
        if(isLoggingEnabled()) {
            logDataRec(data.getRootNode(), 0);
        }
    }

    @Override public void shutdown() {
    }

    protected boolean isLoggingEnabled() {
        return true;
    }

    private String indent(int level) {
        return "                                                                                                                                                                                                                                                                                    ".substring(0, 2*level);
    }

    private void logDataRec(AHierarchicalData data, int level) {
        String s = indent(level) + (data.isSerial() ? "+" : "-") + data.getIdentifier() + "@" + data.getStartTimeMillis() + ": " + data.getDurationNanos() + " " + data.getParameters();
        log(s);

        for(AHierarchicalData child: data.getChildren()) {
            logDataRec(child, level + 1);
        }
    }

    protected abstract void log(String s);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy