package com.idlegandalf.ledd.components; import org.json.JSONException; import org.json.JSONObject; import java.util.UUID; import lombok.Getter; @Getter public class Sendable { private Host recipient; private JSONObject message; private String ref; private AnswerTask onAnswer; public Sendable(JSONObject msg, AnswerTask task, Host host) throws JSONException { this(msg, UUID.randomUUID().toString(), task, host); } public Sendable(JSONObject msg, String ref, AnswerTask task, Host recipient) throws JSONException { this.message = msg; this.ref = ref; this.message.put("ref", ref); this.onAnswer = task; this.recipient = recipient; } public void onResponse(JSONObject object) { if (onAnswer != null) { onAnswer.response = object; onAnswer.run(); } } }