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

io.infinicast.client.impl.objectState.Endpoint Maven / Gradle / Ivy

There is a newer version: 3.0.9
Show newest version
package io.infinicast.client.impl.objectState;
import io.infinicast.*;
import org.joda.time.DateTime;
import java.util.*;
import java.util.function.*;
import java.util.concurrent.*;
import io.infinicast.client.api.*;
import io.infinicast.client.impl.*;
import io.infinicast.client.utils.*;
import io.infinicast.client.protocol.*;
import io.infinicast.client.api.paths.*;
import io.infinicast.client.api.query.*;
import io.infinicast.client.api.paths.handler.*;
import io.infinicast.client.api.paths.options.*;
import io.infinicast.client.api.paths.taskObjects.*;
import io.infinicast.client.api.paths.handler.messages.*;
import io.infinicast.client.api.paths.handler.reminders.*;
import io.infinicast.client.api.paths.handler.lists.*;
import io.infinicast.client.api.paths.handler.objects.*;
import io.infinicast.client.api.paths.handler.requests.*;
import io.infinicast.client.impl.contexts.*;
import io.infinicast.client.impl.helper.*;
import io.infinicast.client.impl.query.*;
import io.infinicast.client.impl.messaging.*;
import io.infinicast.client.impl.pathAccess.*;
import io.infinicast.client.impl.responder.*;
import io.infinicast.client.impl.objectState.*;
import io.infinicast.client.impl.messaging.receiver.*;
import io.infinicast.client.impl.messaging.handlers.*;
import io.infinicast.client.impl.messaging.sender.*;
import io.infinicast.client.protocol.messages.*;
/**
 * Everything in Infinicast is using paths. Paths are the way to share anything:
 * paths can be used to store data, send requests and send messages.
 * all data, requests, messages can be listened on and live updates can be received.
*/
public class Endpoint extends PathImpl  implements IEndpoint {
    String _endpointId;
    public Endpoint(String path, String targetAddress, PathImpl root) {
        super(path);
        super.setRoot(root);
        this.setEndpointId(targetAddress);
    }
    /**
     * adds a role to the given {@code pathString}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * @param pathString
     * @param role
    */
    public void addRoleToStringPath(String pathString, String role) {
        this.addRoleToStringPath(pathString, role, (CompleteCallback) null);
    }
    /**
     * adds a role to the given {@code pathString}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * @param pathString
     * @param role
     * @param onComplete
    */
    public void addRoleToStringPath(String pathString, String role, CompleteCallback onComplete) {
        this.sendModifyRole("add", pathString, role, onComplete);
    }
    /**
     * adds a role to the given {@code path}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter.
     * note: path wildcards are valid paths for roles
     * @param path
     * @param role
    */
    public void addRole(IPath path, String role) {
        this.addRole(path, role, (CompleteCallback) null);
    }
    /**
     * adds a role to the given {@code path}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * @param path
     * @param role
    */
    public CompletableFuture addRoleAsync(IPath path, String role) {
        Endpoint self = this;
        final CompletableFuture tcs = new CompletableFuture();
        this.addRole(path, role, new CompleteCallback() {
            public void accept(ErrorInfo error) {
                if ((error != null)) {
                    tcs.completeExceptionally(new AfinityException(error));
                }
                else {
                    tcs.complete(null);
                }
                ;
            }
        }
        );
        return tcs;
    }
    /**
     * adds a role to the given {@code pathString}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * @param pathString
     * @param role
    */
    public CompletableFuture addRoleToStringPathAsync(String pathString, String role) {
        Endpoint self = this;
        final CompletableFuture tcs = new CompletableFuture();
        this.addRoleToStringPath(pathString, role, new CompleteCallback() {
            public void accept(ErrorInfo error) {
                if ((error != null)) {
                    tcs.completeExceptionally(new AfinityException(error));
                }
                else {
                    tcs.complete(null);
                }
                ;
            }
        }
        );
        return tcs;
    }
    /**
     * adds a role to the given {@code path}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter.
     * note: path wildcards are valid paths for roles
     * @param path
     * @param role
     * @param onComplete
    */
    public void addRole(IPath path, String role, CompleteCallback onComplete) {
        this.addRoleToStringPath(path.toString(), role, onComplete);
    }
    public void introduce(IPath objekt) {
        this.introduce(objekt, (JObject) null);
    }
    /**
     * removes a role to the given {@code path}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * note: for removing roles wildcards can be used. for example RemoveRole(...,"*",...)
     * @param path
     * @param role
    */
    public CompletableFuture removeRoleAsync(IPath path, String role) {
        Endpoint self = this;
        final CompletableFuture tcs = new CompletableFuture();
        this.removeRole(path, role, new CompleteCallback() {
            public void accept(ErrorInfo error) {
                if ((error != null)) {
                    tcs.completeExceptionally(new AfinityException(error));
                }
                else {
                    tcs.complete(null);
                }
                ;
            }
        }
        );
        return tcs;
    }
    /**
     * removes a role to the given {@code pathString}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * note: for removing roles wildcards can be used. for example RemoveRole(...,"*",...)
     * @param pathString
     * @param role
    */
    public CompletableFuture removeRoleFromStringPathAsync(String pathString, String role) {
        Endpoint self = this;
        final CompletableFuture tcs = new CompletableFuture();
        this.removeRoleFromStringPath(pathString, role, new CompleteCallback() {
            public void accept(ErrorInfo error) {
                if ((error != null)) {
                    tcs.completeExceptionally(new AfinityException(error));
                }
                else {
                    tcs.complete(null);
                }
                ;
            }
        }
        );
        return tcs;
    }
    public void getRoles(IPath rolePath, DRoleListHandler roleListHandler) {
        this.getRolesForStringPath(rolePath.toString(), roleListHandler);
    }
    /**
     * returns a list of the roles the endpoint fullfills for the given {@code pathString}
     * @param pathString
     * @param roleListHandler
    */
    public void getRolesForStringPath(String pathString, final DRoleListHandler roleListHandler) {
        Endpoint self = this;
        JObject message = new JObject();
        message.set("target", this.getEndpointId());
        super.messageManager.sendMessageWithResponseString(Connector2EpsMessageType.GetRoleForPath, pathString, message, new DMessageResponseHandler() {
            public void accept(JObject json, IPathAndEndpointContext context) {
                if (!(checkIfHasErrorsAndCallHandlersNew(json, new CompleteCallback() {
                    public void accept(ErrorInfo error) {
                        roleListHandler.accept(error, null);
                        ;
                    }
                }
                ))) {
                    ArrayList list = json.getStringArray("list");
                    roleListHandler.accept(null, list);
                    ;
                }
                ;
            }
        }
        );
    }
    /**
     * returns a list of the roles the endpoint fullfills for the given {@code path}
     * @param path
    */
    public CompletableFuture> getRolesAsync(IPath path) {
        return this.getRolesForStringPathAsync(path.toString());
    }
    /**
     * returns a list of the roles the endpoint fullfills for the given {@code pathString}
     * @param pathString
    */
    public CompletableFuture> getRolesForStringPathAsync(String pathString) {
        Endpoint self = this;
        final CompletableFuture> tcs = new CompletableFuture>();
        this.getRolesForStringPath(pathString, new DRoleListHandler() {
            public void accept(ErrorInfo error, ArrayList roles) {
                if ((error != null)) {
                    tcs.completeExceptionally(new AfinityException(error));
                }
                else {
                    tcs.complete(roles);
                }
                ;
            }
        }
        );
        return tcs;
    }
    public void setDebugName(String name) {
        JObject data = new JObject();
        data.set("target", this.getEndpointId());
        data.set("name", name);
        super.messageManager.sendMessageString(Connector2EpsMessageType.SetDebugName, "", data);
    }
    /**
     * returns the endpointconnectinfo of the given endpoint.
     * The IPAdress is an example of the information available.
     * @param result
    */
    public void getEndpointConnectionInfo(final BiConsumer result) {
        Endpoint self = this;
        JObject message = new JObject();
        message.set("target", this.getEndpointId());
        super.messageManager.sendMessageWithResponseString(Connector2EpsMessageType.GetEndpointConnectionInfo, "", message, new DMessageResponseHandler() {
            public void accept(JObject json, IPathAndEndpointContext context) {
                onGetEndpointConnectionInfoResponse(result, json);
            }
        }
        );
    }
    void onGetEndpointConnectionInfoResponse(final BiConsumer result, JObject json) {
        Endpoint self = this;
        if (!(super.checkIfHasErrorsAndCallHandlersNew(json, new CompleteCallback() {
            public void accept(ErrorInfo error) {
                result.accept(error, null);
                ;
            }
        }
        ))) {
            EndpointConnectionInfo info = new EndpointConnectionInfo();
            info.ipAddress = json.getString("ipAddress");
            result.accept(null, info);
            ;
        }
    }
    /**
     * returns the endpointconnectinfo of the given endpoint.
     * The IPAdress is an example of the information available.
    */
    public CompletableFuture getEndpointConnectionInfoAsync() {
        Endpoint self = this;
        final CompletableFuture tcs = new CompletableFuture();
        this.getEndpointConnectionInfo(new BiConsumer() {
            public void accept(ErrorInfo error, EndpointConnectionInfo info) {
                if ((error != null)) {
                    tcs.completeExceptionally(new AfinityException(error));
                }
                else {
                    tcs.complete(info);
                }
                ;
            }
        }
        );
        return tcs;
    }
    public void introduce(IPath objekt, JObject infoJson) {
        JObject data = new JObject();
        data.set("target", this.getEndpointId());
        super.messageManager.sendMessage(Connector2EpsMessageType.IntroduceObject, objekt, data);
    }
    /**
     * endpoint Id of this endpoint
    */
    public String getEndpointId() {
        return this._endpointId;
    }
    public void setEndpointId(String value) {
        this._endpointId = value;
    }
    /**
     * removes a role to the given {@code path}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * note: for removing roles wildcards can be used. for example RemoveRole(...,"*",...)
     * @param path
     * @param role
     * @param onComplete
    */
    public void removeRole(IPath path, String role, CompleteCallback onComplete) {
        this.removeRoleFromStringPath(path.toString(), role, onComplete);
    }
    /**
     * removes a role to the given {@code path}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * note: for removing roles wildcards can be used. for example RemoveRole(...,"*",...)
     * @param path
     * @param role
    */
    public void removeRole(IPath path, String role) {
        this.removeRole(path, role, (CompleteCallback) null);
    }
    /**
     * removes a role to the given {@code pathString}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * note: for removing roles wildcards can be used. for example RemoveRole(...,"*",...)
     * @param pathString
     * @param role
     * @param onComplete
    */
    public void removeRoleFromStringPath(String pathString, String role, CompleteCallback onComplete) {
        this.sendModifyRole("remove", pathString, role, onComplete);
    }
    /**
     * removes a role to the given {@code pathString}.
     * multiple roles cann be passed by a comma seperated list in the {@code role} parameter
     * note: path wildcards are valid paths for roles
     * note: for removing roles wildcards can be used. for example RemoveRole(...,"*",...)
     * @param pathString
     * @param role
    */
    public void removeRoleFromStringPath(String pathString, String role) {
        this.removeRoleFromStringPath(pathString, role, (CompleteCallback) null);
    }
    void sendModifyRole(String modifier, String pathString, String role, final CompleteCallback onComplete) {
        Endpoint self = this;
        JObject data = new JObject();
        data.set("modifier", modifier);
        data.set("role", role);
        data.set("target", this.getEndpointId());
        super.messageManager.sendMessageWithResponseString(Connector2EpsMessageType.ModifyRoleForPath, pathString, data, new DMessageResponseHandler() {
            public void accept(JObject json, IPathAndEndpointContext context) {
                if (!(checkIfHasErrorsAndCallHandlersNew(json, onComplete))) {
                    if ((onComplete != null)) {
                        onComplete.accept(null);
                        ;
                    }
                }
                ;
            }
        }
        );
    }
    void sendModifyRole(String modifier, String pathString, String role) {
        this.sendModifyRole(modifier, pathString, role, (CompleteCallback) null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy