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

org.nakedobjects.nof.boot.system.SocketServerMonitor Maven / Gradle / Ivy

There is a newer version: 3.0.3
Show newest version
package org.nakedobjects.nof.boot.system;

import org.nakedobjects.nof.core.conf.Configuration;
import org.nakedobjects.nof.core.context.NakedObjectsContext;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;


public class SocketServerMonitor extends AbstractServerMonitor {
    private static final int DEFAULT_PORT = 8009;
    private static final String PORT = Configuration.ROOT + "monitor.telnet.port";

    private final Monitor monitor = new Monitor();
    private NakedObjectsSystem system;

    protected int getPort() {
        return NakedObjectsContext.getConfiguration().getInteger(PORT, DEFAULT_PORT);
    }

    protected void handleRequest(PrintWriter writer, String request) throws IOException {
        String query = URLDecoder.decode(request, "UTF-8");

        if (query.equalsIgnoreCase("shutdown")) {
            system.shutdown();
            System.exit(0);
            return;
        }
        
        if (query.startsWith("/monitor")) {
            query = query.substring("/monitor".length());

            if (query.startsWith("?")) {
                query = query.substring(1);
            }

            monitor.writePage(query, writer);
        } else {
            writer.println("ERROR Failed to find " + query);
        }
    }

    public void setTarget(NakedObjectsSystem system) {
        this.system = system;
        monitor.setTarget(system);
    }
}

// Copyright (c) Naked Objects Group Ltd.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy