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

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


    final int sequenceNumber = envelope.getSequenceNumber();

    synchronized (this.queuedEnvelopes) {

      if (this.destroyCalled) {
        final Buffer buffer = envelope.getBuffer();
        if (buffer != null) {
          buffer.recycleBuffer();
        }
        return;
      }

      final int expectedSequenceNumber = this.lastReceivedEnvelope + 1;
      if (sequenceNumber != expectedSequenceNumber) {
        // This is a problem, now we are actually missing some data
        reportIOException(new IOException("Expected data packet " + expectedSequenceNumber + " but received " + sequenceNumber));

        // notify that something (an exception) is available
        notifyGateThatInputIsAvailable();

        if (LOG.isErrorEnabled()) {
          LOG.error("Input channel " + this.toString() + " expected envelope " + expectedSequenceNumber
              + " but received " + sequenceNumber);
        }

        // rescue the buffer
        final Buffer buffer = envelope.getBuffer();
        if (buffer != null) {
          buffer.recycleBuffer();
        }
      } else {

        this.queuedEnvelopes.add(envelope);
        this.lastReceivedEnvelope = sequenceNumber;
View Full Code Here


      final Iterator<Envelope> it = this.queuedEnvelopes.iterator();
      while (it.hasNext()) {

        final Envelope envelope = it.next();
        ++numberOfQueuedEnvelopes;
        final Buffer buffer = envelope.getBuffer();
        if (buffer == null) {
          continue;
        }

        ++numberOfQueuedEnvelopesWithMemoryBuffers;
View Full Code Here

      // serialize with corresponding serializer and send full buffer
      RecordSerializer<T> serializer = this.serializers[targetChannel];

      RecordSerializer.SerializationResult result = serializer.addRecord(record);
      while (result.isFullBuffer()) {
        Buffer buffer = serializer.getCurrentBuffer();
        if (buffer != null) {
          sendBuffer(buffer, targetChannel);
        }

        buffer = this.bufferPool.requestBufferBlocking(this.bufferPool.getBufferSize());
View Full Code Here

  public void flush() throws IOException, InterruptedException {
    for (int targetChannel = 0; targetChannel < this.numChannels; targetChannel++) {
      RecordSerializer<T> serializer = this.serializers[targetChannel];

      Buffer buffer = serializer.getCurrentBuffer();
      if (buffer != null) {
        sendBuffer(buffer, targetChannel);
      }

      serializer.clear();
View Full Code Here

  @Override
  public void broadcastEvent(AbstractEvent event) throws IOException, InterruptedException {
    for (int targetChannel = 0; targetChannel < this.numChannels; targetChannel++) {
      RecordSerializer<T> serializer = this.serializers[targetChannel];

      Buffer buffer = serializer.getCurrentBuffer();
      if (buffer == null) {
        super.sendEvent(event, targetChannel);
      } else {
        super.sendBufferAndEvent(buffer, event, targetChannel);
View Full Code Here

  @Override
  public void sendEndOfSuperstep() throws IOException, InterruptedException {
    for (int targetChannel = 0; targetChannel < this.numChannels; targetChannel++) {
      RecordSerializer<T> serializer = this.serializers[targetChannel];

      Buffer buffer = serializer.getCurrentBuffer();
      if (buffer == null) {
        super.sendEvent(EndOfSuperstepEvent.INSTANCE, targetChannel);
      } else {
        super.sendBufferAndEvent(buffer, EndOfSuperstepEvent.INSTANCE, targetChannel);
View Full Code Here

  }
 
  public void clearBuffers() {
    if (this.serializers != null) {
      for (RecordSerializer<?> s: this.serializers) {
        Buffer b = s.getCurrentBuffer();
        if (b != null) {
          b.recycleBuffer();
        }
      }
    }
  }
View Full Code Here

    // --------------------------------------------------------------------
    // (3) buffer (var length)
    // --------------------------------------------------------------------
    if (env.getBuffer() != null) {
      Buffer envBuffer = env.getBuffer();
      out.writeBytes(envBuffer.getMemorySegment().wrap(0, envBuffer.size()));

      // Recycle the buffer from OUR buffer pool after everything has been
      // copied to Nettys buffer space.
      envBuffer.recycleBuffer();
    }
  }
View Full Code Here

    // --------------------------------------------------------------------
    // (a) request a buffer from OUR pool
    if (this.currentBufferRequestSize > 0) {
      JobID jobId = this.currentEnvelope.getJobID();
      ChannelID sourceId = this.currentEnvelope.getSource();
      Buffer buffer = requestBufferForTarget(jobId, sourceId, this.currentBufferRequestSize);

      if (buffer == null) {
        return DecoderState.NO_BUFFER_AVAILABLE;
      }
      else {
        this.currentEnvelope.setBuffer(buffer);
        this.currentDataBuffer = buffer.getMemorySegment().wrap(0, this.currentBufferRequestSize);
        this.currentBufferRequestSize = 0;
      }
    }

    // (b) copy data to OUR buffer
View Full Code Here

   * This task should be executed by the IO thread to ensure safe access to the staged buffer.
   */
  private class BufferAvailabilityChangedTask implements Runnable {
    @Override
    public void run() {
      Buffer availableBuffer = bufferBroker.poll();
      if (availableBuffer == null) {
        throw new IllegalStateException("The BufferAvailabilityChangedTask" +
            "should only be executed when a Buffer has been offered" +
            "to the Buffer broker (after becoming available).");
      }

      // This alters the state of the last `decodeEnvelope(ByteBuf)`
      // call to set the buffer, which has become available again
      availableBuffer.limitSize(currentBufferRequestSize);
      currentEnvelope.setBuffer(availableBuffer);
      currentDataBuffer = availableBuffer.getMemorySegment().wrap(0, InboundEnvelopeDecoder.this.currentBufferRequestSize);
      currentBufferRequestSize = 0;

      stagedBuffer.release();

      try {
        if (decodeBuffer(stagedBuffer, channelHandlerContext)) {
          stagedBuffer = null;
          channelHandlerContext.channel().config().setAutoRead(true);
          if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Set channel %s auto read to true.", channelHandlerContext.channel()));
          }
        }
      } catch (IOException e) {
        availableBuffer.recycleBuffer();
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.flink.runtime.io.network.Buffer

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.