package core.service;

import core.broker.MessageBrokerWrapper;
import core.entity.NodeExtension;
import core.heartbeat.HeartbeatReq;
import core.heartbeat.HeartbeatRes;
import core.message.AtomisException;

/**
 * Created by siberis on 11/8/2016.
 */
public abstract class NodeExtensionService<D extends NodeExtension> implements Service {
    public <T> boolean receiveNodeExtensionMessage(T payload, String targetTopic, int stateId) {
        if (payload instanceof HeartbeatReq) {
            MessageBrokerWrapper.sendMessage(new HeartbeatRes(getServiceId()));
        } else {
            return false;
        }
        return true;
    }

    public void receiveUnknownMessage(Long typeId, String rawPayload, String targetTopic, int stateId) {
        System.out.println("Unknown message received : (id:" + typeId + ",value:" + rawPayload + ")");
    }

    @Override
    public void handleException(AtomisException e, String targetTopic, int stateId) {

    }
}
