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

xyz.thepathfinder.android.SubscribableModel Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package xyz.thepathfinder.android;

import com.google.gson.JsonObject;

/**
 * @param  Listener type
 * @author David Robinson
 */
public abstract class SubscribableModel> extends Model {

    public SubscribableModel(String path, PathfinderServices services) {
        super(path, services);
    }

    public JsonObject getMessageHeader(String type) {
        JsonObject json = new JsonObject();

        json.addProperty("message", type);
        json.addProperty("path", this.getPath());
        json.addProperty("model", this.getModel());

        return json;
    }

    public void subscribe() {
        if (!this.isConnected()) {
            throw new IllegalStateException("Not connected to object on Pathfinder server");
        }

        JsonObject json = this.getMessageHeader("subscribe");
        this.getServices().getConnection().sendMessage(json.toString());
    }

    public void unsubscribe() {
        //TODO implement
        //Not implemented on server
    }

    public void routeSubscribe() {
        if (!this.isConnected()) {
            throw new IllegalStateException("Not connected to object on Pathfinder server");
        }

        JsonObject json = this.getMessageHeader("routeSubscribe");
        this.getServices().getConnection().sendMessage(json.toString());
    }

    public void routeUnsubscribe() {
        //TODO implement
        //Not implemented on server
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy