Exemple #1
0
  /**
   * @param request
   * @param connection
   * @return
   */
  public DataList handlePublisherRequest(
      PublishRequestTuple request, AbstractLengthPrependerClient connection) {
    String identifier = request.getIdentifier();

    DataList dl;

    if (publisherBuffers.containsKey(identifier)) {
      /*
       * close previous connection with the same identifier which is guaranteed to be unique.
       */
      AbstractLengthPrependerClient previous = publisherChannels.put(identifier, connection);
      if (previous != null) {
        eventloop.disconnect(previous);
      }

      dl = publisherBuffers.get(identifier);
      try {
        dl.rewind(request.getBaseSeconds(), request.getWindowId());
      } catch (IOException ie) {
        throw new RuntimeException(ie);
      }
    } else {
      dl =
          Tuple.FAST_VERSION.equals(request.getVersion())
              ? new FastDataList(identifier, blockSize, numberOfCacheBlocks)
              : new DataList(identifier, blockSize, numberOfCacheBlocks);
      publisherBuffers.put(identifier, dl);
    }
    dl.setSecondaryStorage(storage, storageHelperExecutor);

    return dl;
  }
Exemple #2
0
  /**
   * @param request
   * @param connection
   * @return
   */
  public LogicalNode handleSubscriberRequest(
      SubscribeRequestTuple request, AbstractLengthPrependerClient connection) {
    String identifier = request.getIdentifier();
    String type = request.getStreamType();
    String upstream_identifier = request.getUpstreamIdentifier();

    // Check if there is a logical node of this type, if not create it.
    LogicalNode ln;
    if (subscriberGroups.containsKey(type)) {
      // logger.debug("adding to exiting group = {}", subscriberGroups.get(type));
      /*
       * close previous connection with the same identifier which is guaranteed to be unique.
       */
      AbstractLengthPrependerClient previous = subscriberChannels.put(identifier, connection);
      if (previous != null) {
        eventloop.disconnect(previous);
      }

      ln = subscriberGroups.get(type);
      ln.boot(eventloop);
      ln.addConnection(connection);
    } else {
      /*
       * if there is already a datalist registered for the type in which this client is interested,
       * then get a iterator on the data items of that data list. If the datalist is not registered,
       * then create one and register it. Hopefully this one would be used by future upstream nodes.
       */
      DataList dl;
      if (publisherBuffers.containsKey(upstream_identifier)) {
        dl = publisherBuffers.get(upstream_identifier);
        // logger.debug("old list = {}", dl);
      } else {
        dl =
            Tuple.FAST_VERSION.equals(request.getVersion())
                ? new FastDataList(upstream_identifier, blockSize, numberOfCacheBlocks)
                : new DataList(upstream_identifier, blockSize, numberOfCacheBlocks);
        publisherBuffers.put(upstream_identifier, dl);
        // logger.debug("new list = {}", dl);
      }

      long skipWindowId = (long) request.getBaseSeconds() << 32 | request.getWindowId();
      ln =
          new LogicalNode(
              upstream_identifier, type, dl.newIterator(identifier, skipWindowId), skipWindowId);

      int mask = request.getMask();
      if (mask != 0) {
        for (Integer bs : request.getPartitions()) {
          ln.addPartition(bs, mask);
        }
      }

      subscriberGroups.put(type, ln);
      ln.addConnection(connection);
      dl.addDataListener(ln);
    }

    return ln;
  }