use of org.apache.cassandra.io.IVersionedSerializer in project cassandra by apache.
the class MessageIn method read.
public static <T2> MessageIn<T2> read(DataInputPlus in, int version, int id, long constructionTime) throws IOException {
InetAddress from = CompactEndpointSerializationHelper.deserialize(in);
MessagingService.Verb verb = MessagingService.Verb.fromId(in.readInt());
int parameterCount = in.readInt();
Map<String, byte[]> parameters;
if (parameterCount == 0) {
parameters = Collections.emptyMap();
} else {
ImmutableMap.Builder<String, byte[]> builder = ImmutableMap.builder();
for (int i = 0; i < parameterCount; i++) {
String key = in.readUTF();
byte[] value = new byte[in.readInt()];
in.readFully(value);
builder.put(key, value);
}
parameters = builder.build();
}
int payloadSize = in.readInt();
IVersionedSerializer<T2> serializer = (IVersionedSerializer<T2>) MessagingService.verbSerializers.get(verb);
if (serializer instanceof MessagingService.CallbackDeterminedSerializer) {
CallbackInfo callback = MessagingService.instance().getRegisteredCallback(id);
if (callback == null) {
// reply for expired callback. we'll have to skip it.
in.skipBytesFully(payloadSize);
return null;
}
serializer = (IVersionedSerializer<T2>) callback.serializer;
}
if (payloadSize == 0 || serializer == null)
return create(from, null, parameters, verb, version, constructionTime);
T2 payload = serializer.deserialize(in, version);
return MessageIn.create(from, payload, parameters, verb, version, constructionTime);
}
use of org.apache.cassandra.io.IVersionedSerializer in project cassandra by apache.
the class ConnectionTest method testInsufficientSpace.
@Test
public void testInsufficientSpace() throws Throwable {
test(new Settings(null).outbound(settings -> settings.withApplicationReserveSendQueueCapacityInBytes(1 << 15, new ResourceLimits.Concurrent(1 << 16)).withApplicationSendQueueCapacityInBytes(1 << 16)), (inbound, outbound, endpoint) -> {
CountDownLatch done = new CountDownLatch(1);
Message<?> message = Message.out(Verb._TEST_1, new Object());
MessagingService.instance().callbacks.addWithExpiration(new RequestCallback() {
@Override
public void onFailure(InetAddressAndPort from, RequestFailureReason failureReason) {
done.countDown();
}
@Override
public boolean invokeOnFailure() {
return true;
}
@Override
public void onResponse(Message msg) {
throw new IllegalStateException();
}
}, message, endpoint);
AtomicInteger delivered = new AtomicInteger();
unsafeSetSerializer(Verb._TEST_1, () -> new IVersionedSerializer<Object>() {
public void serialize(Object o, DataOutputPlus out, int version) throws IOException {
for (int i = 0; i <= 4 << 16; i += 8L) out.writeLong(1L);
}
public Object deserialize(DataInputPlus in, int version) throws IOException {
in.skipBytesFully(4 << 16);
return null;
}
public long serializedSize(Object o, int version) {
return 4 << 16;
}
});
unsafeSetHandler(Verb._TEST_1, () -> msg -> delivered.incrementAndGet());
outbound.enqueue(message);
Assert.assertTrue(done.await(10, SECONDS));
Assert.assertEquals(0, delivered.get());
check(outbound).submitted(1).sent(0, 0).pending(0, 0).overload(1, message.serializedSize(current_version)).expired(0, 0).error(0, 0).check();
check(inbound).received(0, 0).processed(0, 0).pending(0, 0).expired(0, 0).error(0, 0).check();
});
}
Aggregations