Search in sources :

Example 1 with SEPANotExistsException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPANotExistsException 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)

Example 2 with SEPANotExistsException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPANotExistsException in project SEPA by arces-wot.

the class Subscriptions method notifySubscribers.

public static synchronized void notifySubscribers(Notification notify) {
    logger.log(Level.getLevel("subscriptions"), "@notifySubscribers");
    String spuid = notify.getSpuid();
    if (!spus.containsKey(spuid))
        return;
    HashSet<Subscriber> brokenSubscribers = new HashSet<Subscriber>();
    for (Subscriber client : handlers.get(spuid)) {
        // Dispatching events
        Notification event = new Notification(client.getSID(), notify.getARBindingsResults(), client.nextSequence());
        try {
            client.notifyEvent(event);
        } catch (SEPAProtocolException e) {
            logger.error(e.getMessage());
            if (logger.isTraceEnabled())
                e.printStackTrace();
            brokenSubscribers.add(client);
        }
    }
    for (Subscriber client : brokenSubscribers) {
        try {
            removeSubscriber(client.getSID());
        } catch (SEPANotExistsException e) {
            logger.error(e.getMessage());
            if (logger.isTraceEnabled())
                e.printStackTrace();
        }
    }
}
Also used : SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPANotExistsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPANotExistsException) Notification(it.unibo.arces.wot.sepa.commons.response.Notification) HashSet(java.util.HashSet)

Aggregations

SEPANotExistsException (it.unibo.arces.wot.sepa.commons.exceptions.SEPANotExistsException)2 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)1 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)1 Notification (it.unibo.arces.wot.sepa.commons.response.Notification)1 UnsubscribeResponse (it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse)1 HashSet (java.util.HashSet)1