Search in sources :

Example 1 with UnsubscribeResponse

use of it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse in project SEPA by arces-wot.

the class SPUManager method unsubscribe.

public Response unsubscribe(UnsubscribeRequest req) {
    logger.debug(req);
    SPUManagerBeans.unsubscribeRequest();
    String spuid = req.getSubscribeUUID();
    if (!spus.containsKey(spuid))
        return new ErrorResponse(req.getToken(), 404, "SPUID not found: " + spuid);
    synchronized (unsubscribeQueue) {
        unsubscribeQueue.offer(spus.get(spuid));
        unsubscribeQueue.notify();
    }
    return new UnsubscribeResponse(req.getToken(), spuid);
}
Also used : UnsubscribeResponse(it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 2 with UnsubscribeResponse

use of it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse in project SEPA by arces-wot.

the class SEPAWebsocketClient method onMessage.

@Override
public void onMessage(String message) {
    logger.debug("@onMessage " + message);
    // Parse message
    JsonObject notify = new JsonParser().parse(message).getAsJsonObject();
    if (notify.get("ping") != null) {
        if (handler != null)
            handler.onPing();
    } else if (notify.get("subscribed") != null) {
        response = new SubscribeResponse(notify);
        setResponse();
    } else if (notify.get("unsubscribed") != null) {
        response = new UnsubscribeResponse(notify);
        setResponse();
    } else if (notify.get("results") != null) {
        if (handler != null)
            handler.onSemanticEvent(new Notification(notify));
    } else if (notify.get("code") != null) {
        if (handler != null)
            handler.onError(new ErrorResponse(notify));
    } else
        logger.error("Unknown message: " + message);
}
Also used : JsonObject(com.google.gson.JsonObject) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) UnsubscribeResponse(it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse) Notification(it.unibo.arces.wot.sepa.commons.response.Notification) JsonParser(com.google.gson.JsonParser) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 3 with UnsubscribeResponse

use of it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse in project SEPA by arces-wot.

the class SPUManager method unsubscribe.

// public Response unsubscribe(String sid, String gid) {
// logger.log(Level.getLevel("SPUManager"), "@unsubscribe " + sid + " " + gid);
// return internalUnsubscribe(sid, gid, true);
// }
// public void killSubscription(String sid, String gid) {
// logger.log(Level.getLevel("SPUManager"), "@killSubscription " + sid + " " + gid);
// internalUnsubscribe(sid, gid, false);
// }
public Response unsubscribe(String sid, String gid) {
    // private Response internalUnsubscribe(String sid, String gid, boolean dep) {
    // + " " + dep);
    logger.log(Level.getLevel("SPUManager"), "@internalUnsubscribe " + sid + " " + gid);
    try {
        // Subscriber sub = Subscriptions.getSubscriber(sid);
        // 
        // endOfProcessing(sub.getSPU());
        // 
        // synchronized (activeSpus) {
        // activeSpus.remove(sub.getSPU());
        // }
        Subscriptions.removeSubscriber(sid);
    } catch (SEPANotExistsException e) {
        logger.warn("@internalUnsubscribe SID not found: " + sid);
        return new ErrorResponse(500, "sid_not_found", "Unregistering a not existing subscriber: " + sid);
    }
    // if (dep)
    Dependability.onUnsubscribe(gid, sid);
    return new UnsubscribeResponse(sid);
}
Also used : SEPANotExistsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPANotExistsException) UnsubscribeResponse(it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Aggregations

ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)3 UnsubscribeResponse (it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse)3 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 SEPANotExistsException (it.unibo.arces.wot.sepa.commons.exceptions.SEPANotExistsException)1 Notification (it.unibo.arces.wot.sepa.commons.response.Notification)1 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)1