Package eu.stratosphere.runtime.io.network

Examples of eu.stratosphere.runtime.io.network.Envelope


    return this.channel;
  }

  private void writeAndFlushNextEnvelopeIfPossible() {
    if (this.channel.isWritable() && !this.queuedEnvelopes.isEmpty()) {
      Envelope nextEnvelope = this.queuedEnvelopes.pollFirst();
      this.numQueued.decrementAndGet();

      this.channel.writeAndFlush(nextEnvelope).addListener(this);
    }
  }
View Full Code Here


    this.channelManager = channelManager;
  }

  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    Envelope envelope = (Envelope) msg;
//    LOG.debug(String.format("Decoded envelope with seq num %d from source channel %s",
//        envelope.getSequenceNumber(),
//        envelope.getSource()));
    this.channelManager.dispatchFromNetwork(envelope);
  }
View Full Code Here

    final EmbeddedChannel channel = new EmbeddedChannel(new OutboundEnvelopeEncoder());

    int numBuffers = 0;
    for (int i = 0; i < NUM_RANDOM_ENVELOPES; i++) {
      Envelope env = new Envelope(i, new JobID(), new ChannelID());
      int expectedEncodedMsgSize = OutboundEnvelopeEncoder.HEADER_SIZE;

      if (random.nextBoolean()) {
        int eventsSize = random.nextInt(MAX_EVENTS_SIZE + 1);
        expectedEncodedMsgSize += eventsSize;

        events.clear();
        events.limit(eventsSize);

        env.setEventsSerialized(events);
      }

      if (random.nextBoolean()) {
        numBuffers++;

        int bufferSize = random.nextInt(MAX_BUFFER_SIZE + 1);
        when(buffer.size()).thenReturn(bufferSize);
        env.setBuffer(buffer);

        expectedEncodedMsgSize += bufferSize;
      }

      Assert.assertTrue(channel.writeOutbound(env));
View Full Code Here

  private Envelope nextEnvelope(boolean withBuffer) {
    return nextEnvelope(withBuffer, false);
  }

  private Envelope nextEnvelope(int bufferSize, AbstractEvent... events) {
    Envelope env = new Envelope(random.nextInt(), new JobID(), new ChannelID());
    if (bufferSize > 0) {
      byte[] data = new byte[bufferSize];
      random.nextBytes(data);

      env.setBuffer(spy(new Buffer(new MemorySegment(data), bufferSize, RECYCLER)));
    }

    if (events != null && events.length > 0) {
      env.serializeEventList(Arrays.asList(events));
    }

    return env;
  }
View Full Code Here

    if (expectedEnvelopes == null) {
      Assert.assertNull(ch.readInbound());
    }
    else {
      for (Envelope expected : expectedEnvelopes) {
        Envelope actual = (Envelope) ch.readInbound();

        if (actual == null) {
          Assert.fail("No inbound envelope available, but expected one");
        }
View Full Code Here

      this.latch = latch;
    }

    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
      Envelope env = (Envelope) invocation.getArguments()[0];

      ChannelID channelId = env.getSource();
      int seqNum = env.getSequenceNumber();

      if (seqNum == 0) {
        Assert.assertNull(
            String.format("Received envelope from %s before, but current seq num is 0", channelId),
            this.received.putIfAbsent(channelId, seqNum));
View Full Code Here

    @Override
    public void run() {
      // enqueue envelopes with ascending seq nums
      while (this.seqNum < numToSendPerSubtask) {
        try {
          Envelope env = new Envelope(this.seqNum++, this.jobId, this.channelId);
          this.connectionManager.enqueue(env, receiver);
        } catch (IOException e) {
          throw new RuntimeException("Unexpected exception while enqueing envelope");
        }
      }
View Full Code Here

TOP

Related Classes of eu.stratosphere.runtime.io.network.Envelope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.