当前位置: 首页>>代码示例>>Java>>正文


Java ProtocolException类代码示例

本文整理汇总了Java中org.apache.cassandra.transport.ProtocolException的典型用法代码示例。如果您正苦于以下问题:Java ProtocolException类的具体用法?Java ProtocolException怎么用?Java ProtocolException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProtocolException类属于org.apache.cassandra.transport包,在下文中一共展示了ProtocolException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialize

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public static PagingState deserialize(ByteBuffer bytes)
{
    if (bytes == null)
        return null;

    try
    {
        DataInputStream in = new DataInputStream(ByteBufferUtil.inputStream(bytes));
        ByteBuffer pk = ByteBufferUtil.readWithShortLength(in);
        ByteBuffer cn = ByteBufferUtil.readWithShortLength(in);
        int remaining = in.readInt();
        return new PagingState(pk, cn, remaining);
    }
    catch (IOException e)
    {
        throw new ProtocolException("Invalid value for the paging state");
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:19,代码来源:PagingState.java

示例2: deserialize

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public static PagingState deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
{
    if (bytes == null)
        return null;

    try (DataInputBuffer in = new DataInputBuffer(bytes, true))
    {
        ByteBuffer pk;
        RowMark mark;
        int remaining, remainingInPartition;
        if (protocolVersion.isSmallerOrEqualTo(ProtocolVersion.V3))
        {
            pk = ByteBufferUtil.readWithShortLength(in);
            mark = new RowMark(ByteBufferUtil.readWithShortLength(in), protocolVersion);
            remaining = in.readInt();
            // Note that while 'in.available()' is theoretically an estimate of how many bytes are available
            // without blocking, we know that since we're reading a ByteBuffer it will be exactly how many
            // bytes remain to be read. And the reason we want to condition this is for backward compatility
            // as we used to not set this.
            remainingInPartition = in.available() > 0 ? in.readInt() : Integer.MAX_VALUE;
        }
        else
        {
            pk = ByteBufferUtil.readWithVIntLength(in);
            mark = new RowMark(ByteBufferUtil.readWithVIntLength(in), protocolVersion);
            remaining = (int)in.readUnsignedVInt();
            remainingInPartition = (int)in.readUnsignedVInt();
        }
        return new PagingState(pk.hasRemaining() ? pk : null,
                               mark.mark.hasRemaining() ? mark : null,
                               remaining,
                               remainingInPartition);
    }
    catch (IOException e)
    {
        throw new ProtocolException("Invalid value for the paging state");
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:39,代码来源:PagingState.java

示例3: decode

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public AuthResponse decode(ByteBuf body, int version)
{
    if (version == 1)
        throw new ProtocolException("SASL Authentication is not supported in version 1 of the protocol");

    ByteBuffer b = CBUtil.readValue(body);
    byte[] token = new byte[b.remaining()];
    b.get(token);
    return new AuthResponse(token);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:11,代码来源:AuthResponse.java

示例4: decode

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public CredentialsMessage decode(ByteBuf body, int version)
{
    if (version > 1)
        throw new ProtocolException("Legacy credentials authentication is not supported in " +
                "protocol versions > 1. Please use SASL authentication via a SaslResponse message");

    Map<String, String> credentials = CBUtil.readStringMap(body);
    return new CredentialsMessage(credentials);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:10,代码来源:CredentialsMessage.java

示例5: decode

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public AuthResponse decode(ChannelBuffer body, int version)
{
    if (version == 1)
        throw new ProtocolException("SASL Authentication is not supported in version 1 of the protocol");

    ByteBuffer b = CBUtil.readValue(body);
    byte[] token = new byte[b.remaining()];
    b.get(token);
    return new AuthResponse(token);
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:11,代码来源:AuthResponse.java

示例6: decode

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public CredentialsMessage decode(ChannelBuffer body, int version)
{
    if (version > 1)
        throw new ProtocolException("Legacy credentials authentication is not supported in " +
                "protocol versions > 1. Please use SASL authentication via a SaslResponse message");

    Map<String, String> credentials = CBUtil.readStringMap(body);
    return new CredentialsMessage(credentials);
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:10,代码来源:CredentialsMessage.java

示例7: deserialize

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public static PagingState deserialize(ByteBuffer bytes, int protocolVersion)
{
    if (bytes == null)
        return null;

    try (DataInputBuffer in = new DataInputBuffer(bytes, true))
    {
        ByteBuffer pk;
        RowMark mark;
        int remaining, remainingInPartition;
        if (protocolVersion <= Server.VERSION_3)
        {
            pk = ByteBufferUtil.readWithShortLength(in);
            mark = new RowMark(ByteBufferUtil.readWithShortLength(in), protocolVersion);
            remaining = in.readInt();
            // Note that while 'in.available()' is theoretically an estimate of how many bytes are available
            // without blocking, we know that since we're reading a ByteBuffer it will be exactly how many
            // bytes remain to be read. And the reason we want to condition this is for backward compatility
            // as we used to not set this.
            remainingInPartition = in.available() > 0 ? in.readInt() : Integer.MAX_VALUE;
        }
        else
        {
            pk = ByteBufferUtil.readWithVIntLength(in);
            mark = new RowMark(ByteBufferUtil.readWithVIntLength(in), protocolVersion);
            remaining = (int)in.readUnsignedVInt();
            remainingInPartition = (int)in.readUnsignedVInt();
        }
        return new PagingState(pk.hasRemaining() ? pk : null,
                               mark.mark.hasRemaining() ? mark : null,
                               remaining,
                               remainingInPartition);
    }
    catch (IOException e)
    {
        throw new ProtocolException("Invalid value for the paging state");
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:39,代码来源:PagingState.java

示例8: decode

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public QueryOptions decode(ByteBuf body, ProtocolVersion version)
{
    ConsistencyLevel consistency = CBUtil.readConsistencyLevel(body);
    EnumSet<Flag> flags = Flag.deserialize(version.isGreaterOrEqualTo(ProtocolVersion.V5)
                                           ? (int)body.readUnsignedInt()
                                           : (int)body.readByte());

    List<ByteBuffer> values = Collections.<ByteBuffer>emptyList();
    List<String> names = null;
    if (flags.contains(Flag.VALUES))
    {
        if (flags.contains(Flag.NAMES_FOR_VALUES))
        {
            Pair<List<String>, List<ByteBuffer>> namesAndValues = CBUtil.readNameAndValueList(body, version);
            names = namesAndValues.left;
            values = namesAndValues.right;
        }
        else
        {
            values = CBUtil.readValueList(body, version);
        }
    }

    boolean skipMetadata = flags.contains(Flag.SKIP_METADATA);
    flags.remove(Flag.VALUES);
    flags.remove(Flag.SKIP_METADATA);

    SpecificOptions options = SpecificOptions.DEFAULT;
    if (!flags.isEmpty())
    {
        int pageSize = flags.contains(Flag.PAGE_SIZE) ? body.readInt() : -1;
        PagingState pagingState = flags.contains(Flag.PAGING_STATE) ? PagingState.deserialize(CBUtil.readValue(body), version) : null;
        ConsistencyLevel serialConsistency = flags.contains(Flag.SERIAL_CONSISTENCY) ? CBUtil.readConsistencyLevel(body) : ConsistencyLevel.SERIAL;
        long timestamp = Long.MIN_VALUE;
        if (flags.contains(Flag.TIMESTAMP))
        {
            long ts = body.readLong();
            if (ts == Long.MIN_VALUE)
                throw new ProtocolException(String.format("Out of bound timestamp, must be in [%d, %d] (got %d)", Long.MIN_VALUE + 1, Long.MAX_VALUE, ts));
            timestamp = ts;
        }

        options = new SpecificOptions(pageSize, pagingState, serialConsistency, timestamp);
    }
    DefaultQueryOptions opts = new DefaultQueryOptions(consistency, values, skipMetadata, options, version);
    return names == null ? opts : new OptionsWithNames(opts, names);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:48,代码来源:QueryOptions.java

示例9: decode

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public QueryOptions decode(ByteBuf body, int version)
{
    ConsistencyLevel consistency = CBUtil.readConsistencyLevel(body);
    EnumSet<Flag> flags = Flag.deserialize((int)body.readByte());

    List<ByteBuffer> values = Collections.<ByteBuffer>emptyList();
    List<String> names = null;
    if (flags.contains(Flag.VALUES))
    {
        if (flags.contains(Flag.NAMES_FOR_VALUES))
        {
            Pair<List<String>, List<ByteBuffer>> namesAndValues = CBUtil.readNameAndValueList(body, version);
            names = namesAndValues.left;
            values = namesAndValues.right;
        }
        else
        {
            values = CBUtil.readValueList(body, version);
        }
    }

    boolean skipMetadata = flags.contains(Flag.SKIP_METADATA);
    flags.remove(Flag.VALUES);
    flags.remove(Flag.SKIP_METADATA);

    SpecificOptions options = SpecificOptions.DEFAULT;
    if (!flags.isEmpty())
    {
        int pageSize = flags.contains(Flag.PAGE_SIZE) ? body.readInt() : -1;
        PagingState pagingState = flags.contains(Flag.PAGING_STATE) ? PagingState.deserialize(CBUtil.readValue(body), version) : null;
        ConsistencyLevel serialConsistency = flags.contains(Flag.SERIAL_CONSISTENCY) ? CBUtil.readConsistencyLevel(body) : ConsistencyLevel.SERIAL;
        long timestamp = Long.MIN_VALUE;
        if (flags.contains(Flag.TIMESTAMP))
        {
            long ts = body.readLong();
            if (ts == Long.MIN_VALUE)
                throw new ProtocolException(String.format("Out of bound timestamp, must be in [%d, %d] (got %d)", Long.MIN_VALUE + 1, Long.MAX_VALUE, ts));
            timestamp = ts;
        }

        options = new SpecificOptions(pageSize, pagingState, serialConsistency, timestamp);
    }
    DefaultQueryOptions opts = new DefaultQueryOptions(consistency, values, skipMetadata, options, version);
    return names == null ? opts : new OptionsWithNames(opts, names);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:46,代码来源:QueryOptions.java

示例10: execute

import org.apache.cassandra.transport.ProtocolException; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
    try
    {
        if (options.getPageSize() == 0)
            throw new ProtocolException("The page size cannot be 0");

        UUID tracingId = null;
        if (isTracingRequested())
        {
            tracingId = UUIDGen.getTimeUUID();
            state.prepareTracingSession(tracingId);
        }

        if (state.traceNextQuery())
        {
            state.createTracingSession();

            ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
            builder.put("query", query);
            if (options.getPageSize() > 0)
                builder.put("page_size", Integer.toString(options.getPageSize()));
            if(options.getConsistency() != null)
                builder.put("consistency_level", options.getConsistency().name());
            if(options.getSerialConsistency() != null)
                builder.put("serial_consistency_level", options.getSerialConsistency().name());

            Tracing.instance.begin("Execute CQL3 query", state.getClientAddress(), builder.build());
        }

        Message.Response response = ClientState.getCQLQueryHandler().process(query, state, options, getCustomPayload());
        if (options.skipMetadata() && response instanceof ResultMessage.Rows)
            ((ResultMessage.Rows)response).result.metadata.setSkipMetadata();

        if (tracingId != null)
            response.setTracingId(tracingId);

        return response;
    }
    catch (Exception e)
    {
        JVMStabilityInspector.inspectThrowable(e);
        if (!((e instanceof RequestValidationException) || (e instanceof RequestExecutionException)))
            logger.error("Unexpected error during query", e);
        return ErrorMessage.fromException(e);
    }
    finally
    {
        Tracing.instance.stopSession();
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:52,代码来源:QueryMessage.java


注:本文中的org.apache.cassandra.transport.ProtocolException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。