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);
}
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());
}
Aggregations