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

org.bidib.wizard.api.model.connection.ConnectionState Maven / Gradle / Ivy

There is a newer version: 2.0.29
Show newest version
package org.bidib.wizard.api.model.connection;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.bidib.api.json.types.ConnectionPhase;
import org.bidib.wizard.api.annotation.PublishChange;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.reactivex.rxjava3.subjects.BehaviorSubject;

public class ConnectionState {

    private boolean isConnected;

    private String error;

    private ConnectionPhase requestedPhase;

    private ConnectionPhase actualPhase;

    private transient final BehaviorSubject subjectConnectionStateChanges;

    public ConnectionState() {
        this.requestedPhase = ConnectionPhase.DISCONNECTED;
        this.actualPhase = ConnectionPhase.DISCONNECTED;

        subjectConnectionStateChanges = BehaviorSubject.create();
    }

    /**
     * @return the subject that emits the connection state changes
     */
    @JsonIgnore
    public BehaviorSubject getSubjectConnectionStateChanges() {
        return subjectConnectionStateChanges;
    }

    @JsonProperty("isConnected")
    public boolean isConnected() {
        return isConnected;
    }

    @PublishChange
    public void setConnected(boolean isConnected) {
        this.isConnected = isConnected;
    }

    public String getError() {
        return error;
    }

    @PublishChange
    public void setError(String error) {
        this.error = error;
    }

    public ConnectionPhase getRequestedPhase() {
        return requestedPhase;
    }

    @PublishChange
    public void setRequestedPhase(ConnectionPhase requestedPhase) {
        this.requestedPhase = requestedPhase;
    }

    public ConnectionPhase getActualPhase() {
        return actualPhase;
    }

    @PublishChange
    public void setActualPhase(ConnectionPhase actualPhase) {
        this.actualPhase = actualPhase;

        subjectConnectionStateChanges.onNext(actualPhase);
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy