Package org.apache.flink.runtime.io.network

Examples of org.apache.flink.runtime.io.network.Envelope


  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

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

      this.numExpectedEnvelopesPerSubtask = numExpectedEnvelopesPerSubtask;
    }

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

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

      if (seqNum == 0) {
        Integer previousSeqNum = this.received.putIfAbsent(channelId, seqNum);

        String msg = String.format("Received envelope from %s before, but current seq num is 0", channelId);
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

    if (buffer.size() == 0) {
      buffer.recycleBuffer();
      return;
    }

    Envelope envelope = createNextEnvelope();
    envelope.setBuffer(buffer);
    this.envelopeDispatcher.dispatchFromOutputChannel(envelope);
  }
View Full Code Here

  }

  public void sendEvent(AbstractEvent event) throws IOException, InterruptedException {
    checkStatus();

    Envelope envelope = createNextEnvelope();
    envelope.serializeEventList(Arrays.asList(event));
    this.envelopeDispatcher.dispatchFromOutputChannel(envelope);
  }
View Full Code Here

  }

  public void sendBufferAndEvent(Buffer buffer, AbstractEvent event) throws IOException, InterruptedException {
    checkStatus();

    Envelope envelope = createNextEnvelope();
    envelope.setBuffer(buffer);
    envelope.serializeEventList(Arrays.asList(event));
    this.envelopeDispatcher.dispatchFromOutputChannel(envelope);
  }
View Full Code Here

      return;
    }

    this.senderCloseRequested = true;

    Envelope envelope = createNextEnvelope();
    envelope.serializeEventList(Arrays.asList(new ChannelCloseEvent()));
    this.envelopeDispatcher.dispatchFromOutputChannel(envelope);
  }
View Full Code Here

      throw new ReceiverAlreadyClosedException();
    }
  }

  private Envelope createNextEnvelope() {
    return new Envelope(this.currentSeqNum++, getJobID(), getID());
  }
View Full Code Here

TOP

Related Classes of org.apache.flink.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.