RespSubscribeController add(String path, LocalNode node, int sid, int qos)

Source

RespSubscribeController add(String path, LocalNode node, int sid, int qos) {
  RespSubscribeController controller;
  if (subscriptions[path] != null) {
    controller = subscriptions[path];
    if (controller.sid != sid) {
      if (controller.sid >= 0) {
        subsriptionids.remove(controller.sid);
      }
      controller.sid = sid;
      if (sid >= 0) {
        subsriptionids[sid] = controller;
      }
    }
    controller.qosLevel = qos;
    if (sid > -1 && controller.lastValue != null) {
      subscriptionChanged(controller);
    }
  } else {
    int permission = responder.nodeProvider.permissions
        .getPermission(node.path, responder);
    controller = new RespSubscribeController(
        this, node, sid, permission >= Permission.READ, qos);
    subscriptions[path] = controller;

    if (sid >= 0) {
      subsriptionids[sid] = controller;
    }

    if (responder._traceCallbacks != null) {
      ResponseTrace update = new ResponseTrace(path, 'subscribe', 0, '+');
      for (ResponseTraceCallback callback in responder._traceCallbacks) {
        callback(update);
      }
    }
  }
  return controller;
}