{-# LANGUAGE DeriveDataTypeable, FunctionalDependencies, MultiParamTypeClasses,
RecordWildCards #-}-- |-- Module: Network.Riak.Types.Internal-- Copyright: (c) 2011 MailRank, Inc.-- License: Apache-- Maintainer: Bryan O'Sullivan <bos@mailrank.com>-- Stability: experimental-- Portability: portable---- Basic types.moduleNetwork.Riak.Types.Internal(-- * Client managementClientID,Client(..)-- * Connection management,Connection(..)-- * Errors,RiakException(excModule,excFunction,excMessage),netError,typeError-- * Data types,Bucket,Key,Tag,VClock(..),Job(..)-- * Quorum management,Quorum(..),DW,R,RW,W,fromQuorum,toQuorum-- * Message identification,Request(..),Response,Exchange,MessageTag(..),Tagged(..))whereimportControl.Exception(Exception,throw)importData.ByteString.Lazy(ByteString)importData.Digest.Pure.MD5(md5)importData.IORef(IORef)importData.Typeable(Typeable)importData.Word(Word32)importNetwork.Socket(HostName,ServiceName,Socket)importText.ProtocolBuffers(ReflectDescriptor,Wire)-- | A client identifier. This is used by the Riak cluster when-- logging vector clock changes, and should be unique for each client.typeClientID=ByteStringdataClient=Client{host::HostName-- ^ Name of the server to connect to.,port::ServiceName-- ^ Port number to connect to (default is 8087).,clientID::ClientID-- ^ Client identifier.}deriving(Eq,Show,Typeable)-- | A connection to a Riak server.dataConnection=Connection{connSock::Socket,connClient::Client-- ^ The configuration we connected with.,connBuffer::IORefByteString-- ^ Received data that has not yet been consumed.}deriving(Eq)-- | The main Riak exception type.dataRiakException=NetException{excModule::String,excFunction::String,excMessage::String}|TypeException{excModule::String,excFunction::String,excMessage::String}deriving(Eq,Typeable)showRiakException::RiakException->StringshowRiakExceptionexc@NetException{..}="Riak network error "++formatRiakExceptionexcshowRiakExceptionexc@TypeException{..}="Riak type error "++formatRiakExceptionexcformatRiakException::RiakException->StringformatRiakExceptionexc="("++excModuleexc++"."++excFunctionexc++"): "++excMessageexcinstanceShowRiakExceptionwhereshow=showRiakExceptioninstanceExceptionRiakExceptionnetError::String->String->String->anetErrormodufuncmsg=throw(NetExceptionmodufuncmsg)typeError::String->String->String->atypeErrormodufuncmsg=throw(TypeExceptionmodufuncmsg)instanceShowConnectionwhereshowconn=show"Connection "++hostc++":"++portcwherec=connClientconn-- | A Bucket is a container and keyspace for data stored in Riak,-- with a set of common properties for its contents (the number of-- replicas, for instance).typeBucket=ByteString-- | Keys are unique object identifiers in Riak and are scoped within-- buckets.typeKey=ByteString-- | An application-specific identifier for a link. See-- <http://wiki.basho.com/Links.html> for details.typeTag=ByteString-- | A specification of a MapReduce-- job. <http://wiki.basho.com/MapReduce.html>.dataJob=JSONByteString|ErlangByteStringderiving(Eq,Show,Typeable)-- | An identifier for an inbound or outbound message.dataMessageTag=ErrorResponse|PingRequest|PingResponse|GetClientIDRequest|GetClientIDResponse|SetClientIDRequest|SetClientIDResponse|GetServerInfoRequest|GetServerInfoResponse|GetRequest|GetResponse|PutRequest|PutResponse|DeleteRequest|DeleteResponse|ListBucketsRequest|ListBucketsResponse|ListKeysRequest|ListKeysResponse|GetBucketRequest|GetBucketResponse|SetBucketRequest|SetBucketResponse|MapReduceRequest|MapReduceResponsederiving(Eq,Show,Enum,Typeable)-- | Messages are tagged.classTaggedmsgwheremessageTag::msg->MessageTag-- ^ Retrieve a message's tag.instanceTaggedMessageTagwheremessageTagm=m{-# INLINE messageTag #-}-- | A message representing a request from client to server.class(Taggedmsg,ReflectDescriptormsg,Showmsg,Wiremsg)=>RequestmsgwhereexpectedResponse::msg->MessageTag-- | A message representing a response from server to client.class(Taggedmsg,ReflectDescriptormsg,Showmsg,Wiremsg)=>Responsemsgclass(Requestreq,Responseresp)=>Exchangereqresp|req->resp,resp->reqinstance(Taggeda,Taggedb)=>Tagged(Eitherab)wheremessageTag(Leftl)=messageTaglmessageTag(Rightr)=messageTagr{-# INLINE messageTag #-}-- | A wrapper that keeps Riak vector clocks opaque.newtypeVClock=VClock{fromVClock::ByteString-- ^ Unwrap the 'ByteString'. (This is really only useful for-- printing the raw vclock string.)}deriving(Eq,Typeable)instanceShowVClockwhereshow(VClocks)="VClock "++show(md5s)-- | A read/write quorum. The quantity of replicas that must respond-- to a read or write request before it is considered successful. This-- is defined as a bucket property or as one of the relevant-- parameters to a single request ('R','W','DW','RW').dataQuorum=Default-- ^ Use the default quorum settings for the bucket.|One-- ^ Success after one server has responded.|Quorum-- ^ Success after a quorum of servers has responded.|All-- ^ Success after all servers have responded.deriving(Bounded,Eq,Enum,Ord,Show,Typeable)-- | Read/write quorum. How many replicas need to collaborate when-- deleting a value.typeRW=Quorum-- | Read quorum. How many replicas need to agree when retrieving a-- value.typeR=Quorum-- | Write quorum. How many replicas to write to before returning a-- successful response.typeW=Quorum-- | Durable write quorum. How many replicas to commit to durable-- storage before returning a successful response.typeDW=QuorumfromQuorum::Quorum->MaybeWord32fromQuorumDefault=Just4294967291fromQuorumOne=Just4294967294fromQuorumQuorum=Just4294967293fromQuorumAll=Just4294967292{-# INLINE fromQuorum #-}toQuorum::Word32->MaybeQuorumtoQuorum4294967294=JustOnetoQuorum4294967293=JustQuorumtoQuorum4294967292=JustAlltoQuorum4294967291=JustDefaulttoQuorumv=error$"invalid quorum value "++showv{-# INLINE toQuorum #-}