private ByteBuffer generateCompleteOutput() { ByteBuffer res = ByteBuffer.allocate(pagingState.length + hash.length + 6); res.putShort((short) pagingState.length); res.putShort((short) hash.length); res.put(pagingState); res.put(hash); res.putShort((short) protocolVersion.toInt()); res.rewind(); return res; }
private static int sizeOfValue(ByteBuffer value, ProtocolVersion version) { switch (version) { case V1: case V2: int elemSize = value.remaining(); if (elemSize > 65535) throw new IllegalArgumentException( String.format( "Native protocol version %d supports only elements with size up to 65535 bytes - but element size is %d bytes", version.toInt(), elemSize)); return 2 + elemSize; case V3: case V4: case V5: return value == null ? 4 : 4 + value.remaining(); default: throw version.unsupported(); } }
@Override protected void encode(ChannelHandlerContext ctx, Frame frame, List<Object> out) throws Exception { ProtocolVersion protocolVersion = frame.header.version; ByteBuf header = ctx.alloc().ioBuffer(Frame.Header.lengthFor(protocolVersion)); // We don't bother with the direction, we only send requests. header.writeByte(frame.header.version.toInt()); header.writeByte(Header.Flag.serialize(frame.header.flags)); writeStreamId(frame.header.streamId, header, protocolVersion); header.writeByte(frame.header.opcode); header.writeInt(frame.body.readableBytes()); out.add(header); out.add(frame.body); }
/** * Utility method that writes a size value. Mainly intended for collection codecs when serializing * CQL collections. * * @param output The ByteBuffer to write to. * @param size The collection size. * @param version The protocol version to use. */ public static void writeSize(ByteBuffer output, int size, ProtocolVersion version) { switch (version) { case V1: case V2: if (size > 65535) throw new IllegalArgumentException( String.format( "Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", version.toInt(), size)); output.putShort((short) size); break; case V3: case V4: case V5: output.putInt(size); break; default: throw version.unsupported(); } }
private ByteBuffer generateCompleteOutput() { ByteBuffer res = ByteBuffer.allocate(pagingState.length + hash.length + 6); res.putShort((short) pagingState.length); res.putShort((short) hash.length); res.put(pagingState); res.put(hash); res.putShort((short) protocolVersion.toInt()); res.rewind(); return res; }
private ByteBuffer generateCompleteOutput() { ByteBuffer res = ByteBuffer.allocate(pagingState.length + hash.length + 6); res.putShort((short) pagingState.length); res.putShort((short) hash.length); res.put(pagingState); res.put(hash); res.putShort((short) protocolVersion.toInt()); res.rewind(); return res; }
private ByteBuffer generateCompleteOutput() { ByteBuffer res = ByteBuffer.allocate(pagingState.length + hash.length + 6); res.putShort((short) pagingState.length); res.putShort((short) hash.length); res.put(pagingState); res.put(hash); res.putShort((short) protocolVersion.toInt()); res.rewind(); return res; }
private static int sizeOfValue(ByteBuffer value, ProtocolVersion version) { switch (version) { case V1: case V2: int elemSize = value.remaining(); if (elemSize > 65535) throw new IllegalArgumentException(String.format("Native protocol version %d supports only elements with size up to 65535 bytes - but element size is %d bytes", version.toInt(), elemSize)); return 2 + elemSize; case V3: case V4: return value == null ? 4 : 4 + value.remaining(); default: throw version.unsupported(); } }
private static int sizeOfValue(ByteBuffer value, ProtocolVersion version) { switch (version) { case V1: case V2: int elemSize = value.remaining(); if (elemSize > 65535) throw new IllegalArgumentException(String.format("Native protocol version %d supports only elements with size up to 65535 bytes - but element size is %d bytes", version.toInt(), elemSize)); return 2 + elemSize; case V3: case V4: return value == null ? 4 : 4 + value.remaining(); default: throw version.unsupported(); } }
private static int sizeOfValue(ByteBuffer value, ProtocolVersion version) { switch (version) { case V1: case V2: int elemSize = value.remaining(); if (elemSize > 65535) throw new IllegalArgumentException(String.format("Native protocol version %d supports only elements with size up to 65535 bytes - but element size is %d bytes", version.toInt(), elemSize)); return 2 + elemSize; case V3: case V4: case V5: return value == null ? 4 : 4 + value.remaining(); default: throw version.unsupported(); } }
/** * Utility method that writes a size value. * Mainly intended for collection codecs when serializing CQL collections. * * @param output The ByteBuffer to write to. * @param size The collection size. * @param version The protocol version to use. */ public static void writeSize(ByteBuffer output, int size, ProtocolVersion version) { switch (version) { case V1: case V2: if (size > 65535) throw new IllegalArgumentException(String.format("Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", version.toInt(), size)); output.putShort((short) size); break; case V3: case V4: output.putInt(size); break; default: throw version.unsupported(); } }
/** * Utility method that writes a size value. * Mainly intended for collection codecs when serializing CQL collections. * * @param output The ByteBuffer to write to. * @param size The collection size. * @param version The protocol version to use. */ public static void writeSize(ByteBuffer output, int size, ProtocolVersion version) { switch (version) { case V1: case V2: if (size > 65535) throw new IllegalArgumentException(String.format("Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", version.toInt(), size)); output.putShort((short) size); break; case V3: case V4: output.putInt(size); break; default: throw version.unsupported(); } }
@Override protected void encode(ChannelHandlerContext ctx, Frame frame, List<Object> out) throws Exception { ProtocolVersion protocolVersion = frame.header.version; ByteBuf header = ctx.alloc().ioBuffer(Frame.Header.lengthFor(protocolVersion)); // We don't bother with the direction, we only send requests. header.writeByte(frame.header.version.toInt()); header.writeByte(Header.Flag.serialize(frame.header.flags)); writeStreamId(frame.header.streamId, header, protocolVersion); header.writeByte(frame.header.opcode); header.writeInt(frame.body.readableBytes()); out.add(header); out.add(frame.body); }
@Override protected void encode(ChannelHandlerContext ctx, Frame frame, List<Object> out) throws Exception { ProtocolVersion protocolVersion = frame.header.version; ByteBuf header = ctx.alloc().ioBuffer(Frame.Header.lengthFor(protocolVersion)); // We don't bother with the direction, we only send requests. header.writeByte(frame.header.version.toInt()); header.writeByte(Header.Flag.serialize(frame.header.flags)); writeStreamId(frame.header.streamId, header, protocolVersion); header.writeByte(frame.header.opcode); header.writeInt(frame.body.readableBytes()); out.add(header); out.add(frame.body); }
/** * Utility method that writes a size value. * Mainly intended for collection codecs when serializing CQL collections. * * @param output The ByteBuffer to write to. * @param size The collection size. * @param version The protocol version to use. */ public static void writeSize(ByteBuffer output, int size, ProtocolVersion version) { switch (version) { case V1: case V2: if (size > 65535) throw new IllegalArgumentException(String.format("Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", version.toInt(), size)); output.putShort((short) size); break; case V3: case V4: case V5: output.putInt(size); break; default: throw version.unsupported(); } }
@Override protected void encode(ChannelHandlerContext ctx, Frame frame, List<Object> out) throws Exception { ProtocolVersion protocolVersion = frame.header.version; ByteBuf header = ctx.alloc().ioBuffer(Frame.Header.lengthFor(protocolVersion)); // We don't bother with the direction, we only send requests. header.writeByte(frame.header.version.toInt()); header.writeByte(Header.Flag.serialize(frame.header.flags)); writeStreamId(frame.header.streamId, header, protocolVersion); header.writeByte(frame.header.opcode); header.writeInt(frame.body.readableBytes()); out.add(header); out.add(frame.body); }
private void registerCodecs() { complexTypeCodecs = getCodecsForUserDefinedTypes(); if (complexTypeCodecs != null) { CodecRegistry registry = cluster.getConfiguration().getCodecRegistry(); if (cluster.getConfiguration().getProtocolOptions().getProtocolVersion().toInt() < 4) { LOG.error("Custom codecs are not supported for protocol version < 4"); throw new RuntimeException("Custom codecs are not supported for protocol version < 4"); } for (String typeCodecStr : complexTypeCodecs.keySet()) { TypeCodec codec = complexTypeCodecs.get(typeCodecStr); registry.register(codec); userDefinedTypesClass.put(typeCodecStr, codec.getJavaType().getRawType()); } } else { complexTypeCodecs = new HashMap<>(); } }
private void registerCodecs() { complexTypeCodecs = getCodecsForUserDefinedTypes(); if (complexTypeCodecs != null) { CodecRegistry registry = cluster.getConfiguration().getCodecRegistry(); if (cluster.getConfiguration().getProtocolOptions().getProtocolVersion().toInt() < 4) { LOG.error("Custom codecs are not supported for protocol version < 4"); throw new RuntimeException("Custom codecs are not supported for protocol version < 4"); } for (String typeCodecStr : complexTypeCodecs.keySet()) { TypeCodec codec = complexTypeCodecs.get(typeCodecStr); registry.register(codec); userDefinedTypesClass.put(typeCodecStr, codec.getJavaType().getRawType()); } } else { complexTypeCodecs = new HashMap<>(); } }
isProtocolV3OrAbove || length < 65536, "Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", protocolVersion.toInt(), length);
public CassandraConfig(DataService dataService, String configId, Map<String, String> properties, boolean odataEnable) throws DataServiceFault { super(dataService, configId, DataSourceTypes.CASSANDRA, properties, odataEnable); Builder builder = Cluster.builder(); this.populateSettings(builder, properties); String keyspace = properties.get(DBConstants.Cassandra.KEYSPACE); this.cluster = builder.build(); try { if (keyspace != null && keyspace.trim().length() > 0) { this.session = this.cluster.connect(keyspace); } else { this.session = this.cluster.connect(); } this.nativeBatchRequestsSupported = this.session.getCluster(). getConfiguration().getProtocolOptions().getProtocolVersion().toInt() > 1; } catch (NoHostAvailableException e) { throw new DataServiceFault(e, DBConstants.FaultCodes.CONNECTION_UNAVAILABLE_ERROR, e.getMessage()); } }