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

org.nakedobjects.nos.remote.command.pipe.PipeContext Maven / Gradle / Ivy

There is a newer version: 3.0.3
Show newest version
package org.nakedobjects.nos.remote.command.pipe;

import org.nakedobjects.nof.core.context.ContextDebug;
import org.nakedobjects.nof.core.context.MultiUserContext;
import org.nakedobjects.nof.core.context.NakedObjectsContext;
import org.nakedobjects.nof.core.context.NakedObjectsData;
import org.nakedobjects.nof.core.util.DebugString;


/**
 * A specialised NakedObjectsContext implementation that provides two sets of components: one for the server;
 * and one for the client. This simply determines the current thread and if that thread is the server thread
 * then it provides server data. For any other thread the client data is used.
 */
public class PipeContext extends MultiUserContext {
    public static NakedObjectsContext createInstance() {
        return new PipeContext();
    }

    private NakedObjectsData clientData = new NakedObjectsData();
    private Thread server;
    private NakedObjectsData serverData = new NakedObjectsData();

    private PipeContext() {}

    public String debugTitle() {
        return "Naked Objects (pipe) " + Thread.currentThread().getName();
    }

    public void debugData(DebugString debug) {
        super.debugData(debug);
        debug.appendln("Server thread", server);
    }

    protected NakedObjectsData getLocal() {
        Thread thread = Thread.currentThread();
        if (thread == server) {
            return serverData;
        } else {
            return clientData;
        }
    }

    protected void terminateSession() {}

    public void setServer(final Thread server) {
        this.server = server;
    }

    protected String[] allExecutionContextIds() {
        return null;
    }

    protected ContextDebug debugContext(String executionContextId) {
        return null;
    }

    public void shutdownSession() {

    }
}
// Copyright (c) Naked Objects Group Ltd.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy