Package eu.stratosphere.runtime.io

Examples of eu.stratosphere.runtime.io.Buffer


            return null;
          }
        }

        if (!isAsyncRequest) {
          return new Buffer(this.buffers.poll(), minBufferSize, this.recycler);
        }
      }
    }
  }
View Full Code Here


        if (this.numRequestedBuffers > this.numDesignatedBuffers) {
          this.globalBufferPool.returnBuffer(buffer);
          this.numRequestedBuffers--;

        } else if (!this.listeners.isEmpty()) {
          Buffer availableBuffer = new Buffer(buffer, buffer.size(), this.recycler);
          try {
            this.listeners.poll().bufferAvailable(availableBuffer);
          } catch (Exception e) {
            this.buffers.add(buffer);
            this.buffers.notify();
View Full Code Here

    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.isDebugEnabled()) {
          LOG.debug("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

  // -----------------------------------------------------------------------------------------------------------------
  //                                           Envelope processing
  // -----------------------------------------------------------------------------------------------------------------

  private void releaseEnvelope(Envelope envelope) {
    Buffer buffer = envelope.getBuffer();
    if (buffer != null) {
      buffer.recycleBuffer();
    }
  }
View Full Code Here

  @Override
  public void dispatchFromOutputChannel(Envelope envelope) throws IOException, InterruptedException {
    EnvelopeReceiverList receiverList = getReceiverListForEnvelope(envelope, true);

    Buffer srcBuffer = envelope.getBuffer();
    Buffer destBuffer = null;
   
    boolean success = false;
   
    try {
      if (receiverList.hasLocalReceiver()) {
        ChannelID receiver = receiverList.getLocalReceiver();
        Channel channel = this.channels.get(receiver);

        if (channel == null) {
          throw new LocalReceiverCancelledException(receiver);
        }

        if (!channel.isInputChannel()) {
          throw new IOException("Local receiver " + receiver + " is not an input channel.");
        }

        InputChannel<?> inputChannel = (InputChannel<?>) channel;
       
        // copy the buffer into the memory space of the receiver
        if (srcBuffer != null) {
          try {
            destBuffer = inputChannel.requestBufferBlocking(srcBuffer.size());
          } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
          }

          srcBuffer.copyToBuffer(destBuffer);
          envelope.setBuffer(destBuffer);
          srcBuffer.recycleBuffer();
        }
       
        inputChannel.queueEnvelope(envelope);
        success = true;
      }
      else if (receiverList.hasRemoteReceiver()) {
        RemoteReceiver remoteReceiver = receiverList.getRemoteReceiver();

        // Generate sender hint before sending the first envelope over the network
        if (envelope.getSequenceNumber() == 0) {
          generateSenderHint(envelope, remoteReceiver);
        }

        this.nettyConnectionManager.enqueue(envelope, remoteReceiver);
        success = true;
      }
    } finally {
      if (!success) {
        if (srcBuffer != null) {
          srcBuffer.recycleBuffer();
        }
        if (destBuffer != null) {
          destBuffer.recycleBuffer();
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of eu.stratosphere.runtime.io.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.