Java Code Examples for org.agrona.DirectBuffer#getBytes()

The following examples show how to use org.agrona.DirectBuffer#getBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DebugLogger.java    From artio with Apache License 2.0 6 votes vote down vote up
public void log(
    final LogTag tag, final String prefixString, final DirectBuffer buffer, final int offset, final int length)
{
    appendStart();
    builder.append(prefixString);

    if (needsSeparatorSubstitution())
    {
        final byte[] data = getByteArray(length);
        buffer.getBytes(offset, data, 0, length);
        substituteSeparator(data);
        asciiView.wrap(this.buffer, 0, length);
    }
    else
    {
        asciiView.wrap(buffer, offset, length);
    }

    builder.append(asciiView);
    finish(tag);
}
 
Example 2
Source File: FileReceiver.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void fileChunk(
    final long correlationId,
    final long chunkOffset,
    final long chunkLength,
    final DirectBuffer buffer,
    final int offset)
{
    final UnsafeBuffer fileBuffer = fileSessionByIdMap.get(correlationId);
    buffer.getBytes(offset + CHUNK_PAYLOAD_OFFSET, fileBuffer, (int)chunkOffset, (int)chunkLength);

    if ((chunkOffset + chunkLength) >= fileBuffer.capacity())
    {
        fileSessionByIdMap.remove(correlationId);
        IoUtil.unmap(fileBuffer.byteBuffer());
    }
}
 
Example 3
Source File: BaseTransport.java    From nd4j with Apache License 2.0 6 votes vote down vote up
/**
 * This message handler is responsible for receiving messages on Shard side
 *
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void shardMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    /**
     * All incoming messages here are supposed to be unicast messages.
     */
    // TODO: implement fragmentation handler here PROBABLY. Or forbid messages > MTU?
    //log.info("shardMessageHandler message request incoming...");
    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    VoidMessage message = VoidMessage.fromBytes(data);
    if (message.getMessageType() == 7) {
        // if that's vector request message - it's special case, we don't send it to other shards yet
        //log.info("Shortcut for vector request");
        messages.add(message);
    } else {
        // and send it away to other Shards
        publicationForShards.offer(buffer, offset, length);
    }
}
 
Example 4
Source File: AeronUdpTransport.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * This method converts aeron buffer into VoidMessage and puts into temp queue for further processing
 *
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void jointMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    // deserialize message
    val message = VoidMessage.fromBytes(data);

    // we're checking if this is known connection or not, and add it if not
    if (!remoteConnections.containsKey(message.getOriginatorId()))
        addConnection(message.getOriginatorId());

    log.debug("Got [{}] message from [{}]", message.getClass().getSimpleName(), message.getOriginatorId());

    // we're just putting deserialized message into the buffer
    try {
        messageQueue.put(message);
    } catch (InterruptedException e) {
        // :(
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: BaseTransport.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * This message handler is responsible for receiving messages on Shard side
 *
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void shardMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    /**
     * All incoming messages here are supposed to be unicast messages.
     */
    // TODO: implement fragmentation handler here PROBABLY. Or forbid messages > MTU?
    //log.info("shardMessageHandler message request incoming...");
    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    VoidMessage message = VoidMessage.fromBytes(data);
    if (message.getMessageType() == 7) {
        // if that's vector request message - it's special case, we don't send it to other shards yet
        //log.info("Shortcut for vector request");
        messages.add(message);
    } else {
        // and send it away to other Shards
        publicationForShards.offer(buffer, offset, length);
    }
}
 
Example 6
Source File: JsonTokenListener.java    From simple-binary-encoding with Apache License 2.0 6 votes vote down vote up
public void onVarData(
    final Token fieldToken,
    final DirectBuffer buffer,
    final int bufferIndex,
    final int length,
    final Token typeToken)
{
    try
    {
        property(fieldToken.name());
        doubleQuote();

        final byte[] tempBuffer = new byte[length];
        buffer.getBytes(bufferIndex, tempBuffer, 0, length);
        final String str = new String(tempBuffer, 0, length, typeToken.encoding().characterEncoding());

        escape(str);

        doubleQuote();
        next();
    }
    catch (final UnsupportedEncodingException ex)
    {
        ex.printStackTrace();
    }
}
 
Example 7
Source File: DebugLogger.java    From artio with Apache License 2.0 5 votes vote down vote up
public void log(
    final LogTag tag,
    final CharFormatter formatter,
    final DirectBuffer buffer,
    final int bufferOffset,
    final int bufferLength)
{
    final byte[] data = getByteArray(bufferLength);
    buffer.getBytes(bufferOffset, data, 0, bufferLength);
    substituteSeparator(data);

    formatter.with(data, bufferLength);

    log(tag, formatter);
}
 
Example 8
Source File: BaseTransport.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * This message handler is responsible for receiving coordination messages on Shard side
 *
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void internalMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    /**
     * All incoming internal messages are either op commands, or aggregation messages that are tied to commands
     */
    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    VoidMessage message = VoidMessage.fromBytes(data);

    messages.add(message);

    //    log.info("internalMessageHandler message request incoming: {}", message.getClass().getSimpleName());
}
 
Example 9
Source File: BaseTransport.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * This message handler is responsible for receiving messages on Client side
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void clientMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    /**
     *  All incoming messages here are supposed to be "just messages", only unicast communication
     *  All of them should implement MeaningfulMessage interface
     */
    // TODO: to be implemented
    //  log.info("clientMessageHandler message request incoming");

    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    MeaningfulMessage message = (MeaningfulMessage) VoidMessage.fromBytes(data);
    completed.put(message.getTaskId(), message);
}
 
Example 10
Source File: BaseTransport.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * This message handler is responsible for receiving coordination messages on Shard side
 *
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void internalMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    /**
     * All incoming internal messages are either op commands, or aggregation messages that are tied to commands
     */
    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    VoidMessage message = VoidMessage.fromBytes(data);

    messages.add(message);

    //    log.info("internalMessageHandler message request incoming: {}", message.getClass().getSimpleName());
}
 
Example 11
Source File: BaseTransport.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * This message handler is responsible for receiving messages on Client side
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void clientMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    /**
     *  All incoming messages here are supposed to be "just messages", only unicast communication
     *  All of them should implement MeaningfulMessage interface
     */
    // TODO: to be implemented
    //  log.info("clientMessageHandler message request incoming");

    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    MeaningfulMessage message = (MeaningfulMessage) VoidMessage.fromBytes(data);
    completed.put(message.getTaskId(), message);
}
 
Example 12
Source File: ExampleTokenListener.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void onVarData(
    final Token fieldToken,
    final DirectBuffer buffer,
    final int bufferIndex,
    final int length,
    final Token typeToken)
{
    final String value;
    try
    {
        final String characterEncoding = typeToken.encoding().characterEncoding();
        if (null == characterEncoding)
        {
            value = length + " bytes of raw data";
        }
        else
        {
            buffer.getBytes(bufferIndex, tempBuffer, 0, length);
            value = new String(tempBuffer, 0, length, characterEncoding);
        }
    }
    catch (final UnsupportedEncodingException ex)
    {
        ex.printStackTrace();
        return;
    }

    printScope();
    out.append(fieldToken.name())
        .append('=')
        .append(value)
        .println();
}
 
Example 13
Source File: DirectBufferProxy.java    From lmdbjava with Apache License 2.0 4 votes vote down vote up
@Override
protected byte[] getBytes(final DirectBuffer buffer) {
  final byte[] dest = new byte[buffer.capacity()];
  buffer.getBytes(0, dest, 0, buffer.capacity());
  return dest;
}