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));
}
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);
}
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;
}
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
}
}
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);
}
Aggregations