Search in sources :

Example 11 with SubscribeResponse

use of it.unibo.arces.wot.sepa.commons.response.SubscribeResponse 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 12 with SubscribeResponse

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

the class SPUManager method subscribe.

public Response subscribe(InternalSubscribeRequest req) {
    logger.log(Level.getLevel("SPUManager"), "@subscribe");
    SPUManagerBeans.subscribeRequest();
    // Create or link to an existing SPU
    SPU spu;
    if (Subscriptions.containsSubscribe(req)) {
        spu = Subscriptions.getSPU(req);
    } else {
        spu = Subscriptions.createSPU(req, this);
        // Initialize SPU
        Response init;
        try {
            logger.log(Level.getLevel("SPUManager"), "init SPU");
            init = spu.init();
        } catch (SEPASecurityException | IOException e) {
            logger.error(e.getMessage());
            if (logger.isTraceEnabled())
                e.printStackTrace();
            init = new ErrorResponse(401, "SEPASecurityException", e.getMessage());
        }
        if (init.isError()) {
            logger.error("@subscribe SPU initialization failed: " + init);
            if (req.getAlias() != null) {
                ((ErrorResponse) init).setAlias(req.getAlias());
            }
            return init;
        }
        // Register request
        logger.log(Level.getLevel("SPUManager"), "Register SPU");
        Subscriptions.registerSubscribe(req, spu);
        // Start the SPU thread
        spu.setName(spu.getSPUID());
        logger.log(Level.getLevel("SPUManager"), "Start SPU");
        spu.start();
    }
    Subscriber sub = Subscriptions.addSubscriber(req, spu);
    return new SubscribeResponse(sub.getSID(), req.getAlias(), sub.getSPU().getLastBindings());
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) UnsubscribeResponse(it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Aggregations

SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)12 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)11 Response (it.unibo.arces.wot.sepa.commons.response.Response)10 Bindings (it.unibo.arces.wot.sepa.commons.sparql.Bindings)5 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)3 IOException (java.io.IOException)3 JsonObject (com.google.gson.JsonObject)2 SubscribeRequest (it.unibo.arces.wot.sepa.commons.request.SubscribeRequest)2 UnsubscribeResponse (it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)1 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 SSLSecurityManager (it.unibo.arces.wot.sepa.commons.protocol.SSLSecurityManager)1 Notification (it.unibo.arces.wot.sepa.commons.response.Notification)1 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)1 ARBindingsResults (it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults)1 BindingsResults (it.unibo.arces.wot.sepa.commons.sparql.BindingsResults)1 RDFTermLiteral (it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)1