Skip to content

The Controller Endpoint

NoteFox edited this page Jul 9, 2020 · 2 revisions

The Controller Endpoint is the only way to controll the Service and it's specific Modules. The Communication happens over SFTP.

Here is a Sequencediagram, which shows a Standart "Controller Procedure".

Variables

Name Type Standard Value Description Authors Note
msgPath String null ( defined in Constructor ) Path where the Messages should appear
TAG String "ControllerAccessEndpoint" Tag for the Logger
STATUS_KEY String (static, final) "status" Key Word for the Status Request
STATUS_DONE_KEY String (static, final) "done" Key Word for the Status Request for the DONE_LIST specifially
STATUS_ERROR_KEY String (static, final) "error" Key Word for the Status Request for the ERROR_LIST specifially
STATUS_BUFFER_KEY String (static, final) "buffer" Key Word for the Status Request for the BUFFER_LIST specifially
ID_KEY String (static, final) "id" Key Word for the id Request
LOG_KEY String (static, final) "current log" Key Word for the log Request
DAEMON_KEY String (static, final) "daemon log" Key Word for the Daemon log Request
RELOAD_S_KEY String (static, final) "reload requestService" Key Word for the restart call for the RequestManager
RELOAD_LOG_KEY String (static, final) "reload log" Key Word for the restart call for the Logger
RELOAD_ID_KEY String (static, final) "reload id" Key Word for the reload call for the ID System
CLEAR_BUFFER_LIST String (static, final) "clean buffer" Key Word for the clean Buffer list Request
STOP_WORKER_LIST String (static, final) "stop wroker" Key Word for the stop Worker list Request
CLEAN_ERROR_LIST String (static, final) "clean error" Key Word for the cleaning of the Error list
CLEAN_DONE_LIST String (static, final) "clean done" Key Word for the cleaning of the Done list
RESTART_KEY String (static, final) "restart" Key Word for the restart call

Constructor

public ControllerEndpoint(String msgPath) {
    this.msgPath = msgPath;
}

The "run" Method

/**
 * runner method for the processing of incoming Controller Requests 
 */
@Override
public synchronized void run() {
    // endless Loop for the scanning, processing and sending of ControllerRequests and Answers
    // cannot be stopped until the Main Thread stops
    while (true) {
        File f = null;
        try {
            // fetches new File from the msg Directory
            f = fetchNewFile();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        ControllerRequest request = null;
        try {
            // reads the content of the received File and writes it into an Object
            request = readContent(f);

        } catch (IOException e) {
            e.printStackTrace();
        }
        assert request != null;

        try {
            // processes the given request 
            request.setReturnValue(processRequest(request.value));
        } catch (IOException e) {
            request.setReturnValue(e.getMessage());
        }

        f.delete();

        // creates the answer File
        File returnFile = new File(msgPath + request.id + ".ans");
        try {
            // writes the response into the Answer File and closes the OutputStream
            writeResponse(returnFile, request).close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

Public Methods

cannot be accessed from the outside, can only be started


Private Methods

Name Parameter List return Value Description Authors Note
fetchNewFile empty File Method that fetches a new request File from the msg Path
readContent file (File) ControllerRequest reads content from the specific File and gives it back in form of an Custom Object
writeResponse file (File), r (ControllerRequest) BufferedWriter writing the response to a ControllerRequest into a File
processRequest request (String) String processing the given Request String

Custom Controller Request Object

/**
 * Custom Controller Request Object
 */
private class ControllerRequest {
    String id;
    String value;
    String returnValue;

    public ControllerRequest(String id, String value) {
        this.id = id;
        this.value = value;
    }

    public void setReturnValue(String returnValue) {
        this.returnValue = returnValue;
    }

    public String getReturnValue() {
        return returnValue;
    }
}
Clone this wiki locally