

package io.trivium.extension;

import io.trivium.anystore.AnyClient;
import io.trivium.extension.fact.TriviumObject;

import java.util.logging.Logger;

public abstract class Binding implements Typed {
    protected Logger logger = Logger.getLogger(getClass().getName());
    private BindingState state = BindingState.stopped;

    public void startBinding(){
        start();
        setState(BindingState.running);
    }

    protected abstract void start();

    public void stopBinding(){
        stop();
        setState(BindingState.stopped);
    }

    protected abstract void stop();

    public void check() throws Exception{}

    public BindingState getState(){
        return state;
    }

    protected void setState(BindingState newState){
        state=newState;
    }

    public String getName(){
        return this.getClass().getSimpleName();
    }

    protected void emit(Fact object){
        TriviumObject obj = object.toTriviumObject();
        AnyClient.INSTANCE.storeObject(obj);
    }
}
