Search in sources :

Example 1 with NetworkFlushableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4 in project neo4j by neo4j.

the class TxPullRequestEncoder method encode.

@Override
protected void encode(ChannelHandlerContext ctx, TxPullRequest request, ByteBuf out) throws Exception {
    out.writeLong(request.previousTxId());
    StoreIdMarshal.INSTANCE.marshal(request.expectedStoreId(), new NetworkFlushableChannelNetty4(out));
}
Also used : NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4)

Example 2 with NetworkFlushableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4 in project neo4j by neo4j.

the class ReplicatedTransactionFactory method createImmutableReplicatedTransaction.

public static ReplicatedTransaction createImmutableReplicatedTransaction(TransactionRepresentation tx) {
    ByteBuf transactionBuffer = Unpooled.buffer();
    NetworkFlushableChannelNetty4 channel = new NetworkFlushableChannelNetty4(transactionBuffer, MAX_SERIALIZED_TX_SIZE);
    try {
        TransactionSerializer.write(tx, channel);
    } catch (MessageTooBigException e) {
        throw new IllegalStateException("Transaction size was too large to replicate across the cluster.", e);
    } catch (IOException e) {
        // Easier said than done though, we use the LogEntry handling routines which throw IOException
        throw new RuntimeException(e);
    }
    /*
         * This trims down the array to send up to the actual index it was written. While sending additional zeroes
         * is safe, since LogEntryReader stops reading once it sees a zero entry, it is wasteful.
         */
    byte[] txBytes = Arrays.copyOf(transactionBuffer.array(), transactionBuffer.writerIndex());
    transactionBuffer.release();
    return new ReplicatedTransaction(txBytes);
}
Also used : MessageTooBigException(org.neo4j.causalclustering.messaging.MessageTooBigException) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with NetworkFlushableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4 in project neo4j by neo4j.

the class ReplicatedTokenRequestSerializer method commandBytes.

public static byte[] commandBytes(Collection<StorageCommand> commands) {
    ByteBuf commandBuffer = Unpooled.buffer();
    NetworkFlushableChannelNetty4 channel = new NetworkFlushableChannelNetty4(commandBuffer);
    try {
        new LogEntryWriter(channel).serialize(commands);
    } catch (IOException e) {
        // TODO: Handle or throw.
        e.printStackTrace();
    }
    byte[] commandsBytes = commandBuffer.array().clone();
    commandBuffer.release();
    return commandsBytes;
}
Also used : NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with NetworkFlushableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4 in project neo4j by neo4j.

the class MemberIdMarshalTest method shouldThrowExceptionForHalfWrittenInstance.

@Test
public void shouldThrowExceptionForHalfWrittenInstance() throws Exception {
    // given
    // a CoreMember and a ByteBuffer to write it to
    MemberId.Marshal marshal = new MemberId.Marshal();
    final MemberId aRealMember = new MemberId(UUID.randomUUID());
    ByteBuf buffer = Unpooled.buffer(1000);
    // and the CoreMember is serialized but for 5 bytes at the end
    marshal.marshal(aRealMember, new NetworkFlushableChannelNetty4(buffer));
    ByteBuf bufferWithMissingBytes = buffer.copy(0, buffer.writerIndex() - 5);
    // when
    try {
        marshal.unmarshal(new NetworkReadableClosableChannelNetty4(bufferWithMissingBytes));
        fail("Should have thrown exception");
    } catch (EndOfStreamException e) {
    // expected
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) Test(org.junit.Test)

Example 5 with NetworkFlushableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4 in project neo4j by neo4j.

the class MemberIdMarshalTest method shouldSerializeAndDeserialize.

@Test
public void shouldSerializeAndDeserialize() throws Exception {
    // given
    MemberId.Marshal marshal = new MemberId.Marshal();
    final MemberId member = new MemberId(UUID.randomUUID());
    // when
    ByteBuf buffer = Unpooled.buffer(1_000);
    marshal.marshal(member, new NetworkFlushableChannelNetty4(buffer));
    final MemberId recovered = marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer));
    // then
    assertEquals(member, recovered);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) Test(org.junit.Test)

Aggregations

NetworkFlushableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4)6 ByteBuf (io.netty.buffer.ByteBuf)5 Test (org.junit.Test)3 NetworkReadableClosableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)3 IOException (java.io.IOException)2 MemberId (org.neo4j.causalclustering.identity.MemberId)2 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)1 MessageTooBigException (org.neo4j.causalclustering.messaging.MessageTooBigException)1 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)1