Exemplo n.º 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;
  }
Exemplo n.º 2
0
  private void handleResetRequest(
      ResetRequestTuple request, final AbstractLengthPrependerClient ctx) throws IOException {
    DataList dl;
    dl = publisherBuffers.remove(request.getIdentifier());

    byte[] message;
    if (dl == null) {
      message = ("Invalid identifier '" + request.getIdentifier() + "'").getBytes();
    } else {
      AbstractLengthPrependerClient channel = publisherChannels.remove(request.getIdentifier());
      if (channel != null) {
        eventloop.disconnect(channel);
      }
      dl.reset();
      message = ("Request sent for processing: " + request).getBytes();
    }

    final byte[] tuple = PayloadTuple.getSerializedTuple(0, message.length);
    System.arraycopy(message, 0, tuple, tuple.length - message.length, message.length);
    serverHelperExecutor.submit(
        new Runnable() {
          @Override
          public void run() {
            ctx.write(tuple);
            eventloop.disconnect(ctx);
          }
        });
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
0
    @Override
    public void handleException(Exception cce, EventLoop el) {
      teardown();

      if (cce instanceof RejectedExecutionException && serverHelperExecutor.isTerminated()) {
        logger.warn("Terminated Executor Exception for {}.", this, cce);
        el.disconnect(this);
      } else {
        super.handleException(cce, el);
      }
    }