Enum MemcacheProtocol

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> body​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
      Returns the body of the message if available.
      static long cas​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
      Helper method to extract the cas from a message.
      static byte datatype​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
      Helper method to return the datatype from a request or response.
      static ResponseStatus decodeStatus​(short status)
      Converts the KeyValue protocol status into its generic format.
      static ResponseStatus decodeStatus​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
      Decodes and converts the status from a message.
      static SubDocumentOpResponseStatus decodeSubDocumentStatus​(short status)
      Converts a KeyValue protocol status into its generic format.
      static Optional<MutationToken> extractToken​(boolean enabled, short partition, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf msg, String bucket)
      Tries to extract the mutation token if the surround msg and environment allows for it.
      static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> extras​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)  
      static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf flexibleRequest​(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc, MemcacheProtocol.Opcode opcode, byte datatype, short partition, int opaque, long cas, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf framingExtras, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
      Create a flexible memcached protocol request with all fields necessary.
      static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf flexibleSyncReplication​(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc, DurabilityLevel type, Duration timeout)
      Helper method to create the flexible extras for sync replication.
      static SubDocumentException mapSubDocumentError​(SubDocumentOpResponseStatus status, String path, String id)
      For any response that can be returned by a SubDocument command - path, document, or execution-based - map it to an appropriate SubDocumentException.
      static String messageToString​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
      Helper method during development and debugging to dump the raw message as a verbose string.
      static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noBody()
      Helper to express no body is used for this message.
      static long noCas()
      Helper to express no cas is used for this message.
      static byte noDatatype()
      Helper to express no datatype is used for this message.
      static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noExtras()
      Helper to express no extras are used for this message.
      static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noFramingExtras()
      Helper to express no framing extras are used for this message.
      static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noKey()
      Helper to express no key is used for this message.
      static int noOpaque()
      Helper to express no opaque is used for this message.
      static short noPartition()
      Helper to express no partition is used for this message.
      static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf request​(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc, MemcacheProtocol.Opcode opcode, byte datatype, short partition, int opaque, long cas, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
      Create a regular, non-flexible memcached protocol request with all fields necessary.
      static short status​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
      Returns the status of that response.
      static boolean successful​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
      Helper method to check if the given response has a successful status.
      static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf tryCompression​(byte[] input, double minRatio)
      Try to compress the input, but if it is below the min ratio then it will return null.
      static byte[] tryDecompression​(byte[] input, byte datatype)
      Try to decompress the input if the datatype has the snappy flag enabled.
      static MemcacheProtocol valueOf​(String name)
      Returns the enum constant of this type with the specified name.
      static MemcacheProtocol[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
    • Field Detail

      • UNSIGNED_SHORT_MAX

        public static final int UNSIGNED_SHORT_MAX
        Holds the max value a unsigned short can represent.
        See Also:
        Constant Field Values
      • SYNC_REPLICATION_FLEXIBLE_IDENT

        public static final byte SYNC_REPLICATION_FLEXIBLE_IDENT
        Flag which indicates that this flexible extra frame is for syc replication.
        See Also:
        Constant Field Values
      • SYNC_REPLICATION_TIMEOUT_FLOOR_MS

        public static final short SYNC_REPLICATION_TIMEOUT_FLOOR_MS
        Minimum sync durability timeout that can be set and which will override any lower user-provided value.
        See Also:
        Constant Field Values
    • Method Detail

      • values

        public static MemcacheProtocol[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (MemcacheProtocol c : MemcacheProtocol.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static MemcacheProtocol valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • flexibleRequest

        public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf flexibleRequest​(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
                                                                                             MemcacheProtocol.Opcode opcode,
                                                                                             byte datatype,
                                                                                             short partition,
                                                                                             int opaque,
                                                                                             long cas,
                                                                                             com.couchbase.client.core.deps.io.netty.buffer.ByteBuf framingExtras,
                                                                                             com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras,
                                                                                             com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key,
                                                                                             com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
        Create a flexible memcached protocol request with all fields necessary.
      • request

        public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf request​(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
                                                                                     MemcacheProtocol.Opcode opcode,
                                                                                     byte datatype,
                                                                                     short partition,
                                                                                     int opaque,
                                                                                     long cas,
                                                                                     com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras,
                                                                                     com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key,
                                                                                     com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
        Create a regular, non-flexible memcached protocol request with all fields necessary.
      • status

        public static short status​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
        Returns the status of that response.
        Parameters:
        message - the memcache message to extract from.
        Returns:
        the status field.
      • successful

        public static boolean successful​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
        Helper method to check if the given response has a successful status.
        Parameters:
        message - the memcache message to extract from.
        Returns:
        true if success.
      • datatype

        public static byte datatype​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
        Helper method to return the datatype from a request or response.
        Parameters:
        message - the message to get the datatype from.
        Returns:
        the datatype as a byte.
      • cas

        public static long cas​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
        Helper method to extract the cas from a message.
        Parameters:
        message - the message to extract the cas from.
        Returns:
        the cas as a long.
      • body

        public static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> body​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
        Returns the body of the message if available.
        Parameters:
        message - the message of the body or empty if none found.
        Returns:
        an optional either containing the body of the message or none.
      • extras

        public static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> extras​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
      • noKey

        public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noKey()
        Helper to express no key is used for this message.
      • noExtras

        public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noExtras()
        Helper to express no extras are used for this message.
      • noFramingExtras

        public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noFramingExtras()
        Helper to express no framing extras are used for this message.
      • noBody

        public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noBody()
        Helper to express no body is used for this message.
      • noDatatype

        public static byte noDatatype()
        Helper to express no datatype is used for this message.
      • noPartition

        public static short noPartition()
        Helper to express no partition is used for this message.
      • noOpaque

        public static int noOpaque()
        Helper to express no opaque is used for this message.
      • noCas

        public static long noCas()
        Helper to express no cas is used for this message.
      • decodeStatus

        public static ResponseStatus decodeStatus​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
        Decodes and converts the status from a message.

        This is a convenience method usually used in decoders.

        Parameters:
        message - the message to extract from.
        Returns:
        the decoded status.
      • flexibleSyncReplication

        public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf flexibleSyncReplication​(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
                                                                                                     DurabilityLevel type,
                                                                                                     Duration timeout)
        Helper method to create the flexible extras for sync replication.

        Note that this method writes a short value from an integer deadline. The netty method will make sure to only look at the lower 16 bits - this allows us to write an unsigned short!

        Parameters:
        alloc - the allocator to use.
        type - the type of sync replication.
        timeout - the timeout to use.
        Returns:
        a buffer which contains the flexible extras.
      • decodeStatus

        public static ResponseStatus decodeStatus​(short status)
        Converts the KeyValue protocol status into its generic format.
        Parameters:
        status - the protocol status.
        Returns:
        the response status.
      • decodeSubDocumentStatus

        public static SubDocumentOpResponseStatus decodeSubDocumentStatus​(short status)
        Converts a KeyValue protocol status into its generic format. It must be a status that can be returned from a sub-document operation.
        Parameters:
        status - the protocol status.
        Returns:
        the response status.
      • mapSubDocumentError

        public static SubDocumentException mapSubDocumentError​(SubDocumentOpResponseStatus status,
                                                               String path,
                                                               String id)
        For any response that can be returned by a SubDocument command - path, document, or execution-based - map it to an appropriate SubDocumentException.
        Parameters:
        status - the SubDocument status code
        path - the path of the SubDocument command
        id - the id of the document
      • tryCompression

        public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf tryCompression​(byte[] input,
                                                                                            double minRatio)
        Try to compress the input, but if it is below the min ratio then it will return null.
        Parameters:
        input - the input array.
        minRatio - the minimum ratio to accept and return the buffer.
        Returns:
        a ByteBuf if compressed, or null if below the min ratio.
      • tryDecompression

        public static byte[] tryDecompression​(byte[] input,
                                              byte datatype)
        Try to decompress the input if the datatype has the snappy flag enabled.

        If datatype does not indicate snappy enabled, then the input is returned as presented.

        Parameters:
        input - the input byte array.
        datatype - the datatype for the response.
        Returns:
        the byte array, either decoded or the input straight.
      • messageToString

        public static String messageToString​(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
        Helper method during development and debugging to dump the raw message as a verbose string.
      • extractToken

        public static Optional<MutationToken> extractToken​(boolean enabled,
                                                           short partition,
                                                           com.couchbase.client.core.deps.io.netty.buffer.ByteBuf msg,
                                                           String bucket)
        Tries to extract the mutation token if the surround msg and environment allows for it.
        Parameters:
        enabled - if enabled
        partition - the partition id
        msg - the msg to check
        bucket - the bucket for this msg
        Returns:
        an optional with content if successful, false otherwise.