Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- zooVersion :: Version
- zookeeperResInit :: CBytes -> Maybe WatcherFn -> CInt -> Maybe ClientID -> CInt -> Resource ZHandle
- withResource :: (MonadMask m, MonadIO m, HasCallStack) => Resource a -> (HasCallStack => a -> m b) -> m b
- data Resource a
- zooSetDebugLevel :: ZooLogLevel -> IO ()
- data StdLogStream
- zooSetStdLogStream :: StdLogStream -> IO ()
- data FileLogStream
- withZooSetFileLogStream :: CBytes -> CBytes -> IO a -> IO a
- zooCreate :: HasCallStack => ZHandle -> CBytes -> Maybe Bytes -> AclVector -> CreateMode -> IO StringCompletion
- zooCreateIfMissing :: ZHandle -> CBytes -> Maybe Bytes -> AclVector -> CreateMode -> IO (Maybe StringCompletion)
- zooSet :: HasCallStack => ZHandle -> CBytes -> Maybe Bytes -> Maybe CInt -> IO StatCompletion
- zooGet :: HasCallStack => ZHandle -> CBytes -> IO DataCompletion
- zooWatchGet :: HasCallStack => ZHandle -> CBytes -> (HsWatcherCtx -> IO ()) -> (DataCompletion -> IO ()) -> IO ()
- zooGetChildren :: HasCallStack => ZHandle -> CBytes -> IO StringsCompletion
- zooWatchGetChildren :: HasCallStack => ZHandle -> CBytes -> (HsWatcherCtx -> IO ()) -> (StringsCompletion -> IO ()) -> IO ()
- zooGetChildren2 :: HasCallStack => ZHandle -> CBytes -> IO StringsStatCompletion
- zooWatchGetChildren2 :: HasCallStack => ZHandle -> CBytes -> (HsWatcherCtx -> IO ()) -> (StringsStatCompletion -> IO ()) -> IO ()
- zooDelete :: HasCallStack => ZHandle -> CBytes -> Maybe CInt -> IO ()
- zooDeleteAll :: HasCallStack => ZHandle -> CBytes -> IO ()
- zooExists :: HasCallStack => ZHandle -> CBytes -> IO (Maybe StatCompletion)
- zooWatchExists :: HasCallStack => ZHandle -> CBytes -> (HsWatcherCtx -> IO ()) -> (Maybe StatCompletion -> IO ()) -> IO ()
- zooGetAcl :: HasCallStack => ZHandle -> CBytes -> IO AclCompletion
- zooMulti :: HasCallStack => ZHandle -> [ZooOp] -> IO [ZooOpResult]
- zooCreateOpInit :: CBytes -> Maybe Bytes -> CInt -> AclVector -> CreateMode -> ZooOp
- zooDeleteOpInit :: CBytes -> Maybe CInt -> ZooOp
- zooSetOpInit :: CBytes -> Maybe Bytes -> Maybe CInt -> ZooOp
- zooCheckOpInit :: CBytes -> CInt -> ZooOp
- assertZooOpResultOK :: HasCallStack => ZooOpResult -> IO ()
- zooClientID :: ZHandle -> IO ClientID
- peekClientId :: ClientID -> IO HsClientID
- zooState :: ZHandle -> IO ZooState
- zooRecvTimeout :: ZHandle -> IO CInt
- isUnrecoverable :: ZHandle -> IO Bool
- zookeeperInit :: CBytes -> Maybe WatcherFn -> CInt -> Maybe ClientID -> CInt -> IO (ZHandle, FunPtr CWatcherFn)
- zookeeperClose :: (ZHandle, FunPtr CWatcherFn) -> IO ()
- openFileLogStream :: CBytes -> CBytes -> IO FileLogStream
- closeFileLogStream :: FileLogStream -> IO ()
Documentation
zooVersion :: Version Source #
:: CBytes | host, comma separated host:port pairs, each corresponding to a zk server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" |
-> Maybe WatcherFn | the global watcher callback function. When notifications are triggered this function will be invoked. FIXME: Calling any zoo operations (e.g. zooGet) will cause an infinite block. |
-> CInt | session expiration time in milliseconds |
-> Maybe ClientID | The id of a previously established session that this client will be
reconnecting to. Pass |
-> CInt | flags, reserved for future use. Should be set to zero. |
-> Resource ZHandle |
Create a resource of handle to used communicate with zookeeper.
withResource :: (MonadMask m, MonadIO m, HasCallStack) => Resource a -> (HasCallStack => a -> m b) -> m b Source #
Create a new resource and run some computation, resource is guarantee to be closed.
Be careful, don't leak the resource through the computation return value because after the computation finishes, the resource is already closed.
A Resource
is an IO
action which acquires some resource of type a and
also returns a finalizer of type IO () that releases the resource.
The only safe way to use a Resource
is withResource
and withResource'
,
You should not use the acquire
field directly, unless you want to implement
your own resource management. In the later case, you should mask_
acquire
since some resource initializations may assume async exceptions are masked.
MonadIO
instance is provided so that you can lift IO
computation inside
Resource
, this is convenient for propagating Resource
around since many
IO
computations carry finalizers.
zooSetDebugLevel :: ZooLogLevel -> IO () Source #
Sets the debugging level for the zookeeper library
zooSetStdLogStream :: StdLogStream -> IO () Source #
data FileLogStream Source #
withZooSetFileLogStream Source #
:: CBytes | File name, see |
-> CBytes | Mode, see |
-> IO a | Computation to run in-between |
-> IO a |
Sets the file to be used by the library for logging.
The file will be closed after the computation you run, and the LogStream will be set to defaut stderr.
let res = zookeeperResInit "127.0.0.1:2181" Nothing 5000 Nothing 0 withZooSetFileLogStream "/tmp/zk.log" "a+" $ do withResource res $ \zh -> do undefined
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> Maybe Bytes | The data to be stored in the node. |
-> AclVector | The initial ACL of the node. The ACL must not be null or empty. |
-> CreateMode | This parameter can be set to |
-> IO StringCompletion | The result when the request completes. One of the following exceptions will be thrown if error happens:
|
Create a node.
This method will create a node in ZooKeeper. A node can only be created if
it does not already exist. The Create Flags affect the creation of nodes.
If ZooEphemeral
flag is set, the node will automatically get removed if
the client session goes away. If the ZooSequence
flag is set, a unique
monotonically increasing sequence number is appended to the path name. The
sequence number is always fixed length of 10 digits, 0 padded.
Throw one of the following exceptions on failure:
- ZBADARGUMENTS - invalid input parameters
- ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
- ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
zooCreateIfMissing :: ZHandle -> CBytes -> Maybe Bytes -> AclVector -> CreateMode -> IO (Maybe StringCompletion) Source #
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> Maybe Bytes | Data to be written to the node. |
-> Maybe CInt | The expected version of the node. The function will fail if the actual version of the node does not match the expected version. If Nothing is used the version check will not take place. |
-> IO StatCompletion | The result when the request completes. One of the following exceptions will be thrown if error happens:
|
Sets the data associated with a node.
Throw one of the following exceptions on failure:
- ZBADARGUMENTS - invalid input parameters
- ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
- ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> IO DataCompletion | The result when the request completes. One of the following exceptions will be thrown if:
|
Gets the data associated with a node.
Throw one of the following exceptions on failure:
- ZBADARGUMENTS - invalid input parameters
- ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
- ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | |
-> CBytes | |
-> (HsWatcherCtx -> IO ()) | The watcher callback. A watch will be set at the server to notify the client if the node changes. /NOTE: this works different with c client. You will only receive data and child watches, no session watches./ |
-> (DataCompletion -> IO ()) | The result callback when the request completes. One of the following exceptions will be thrown if:
|
-> IO () |
Gets the data associated with a node.
Throw one of the following exceptions on failure:
- ZBADARGUMENTS - invalid input parameters
- ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
- ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> IO StringsCompletion | The result when the request completes. Throw one of the following exceptions if the request completes failed:
|
Lists the children of a node.
Throw one of the following exceptions on failure:
- ZBADARGUMENTS - invalid input parameters
- ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
- ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> (HsWatcherCtx -> IO ()) | The watcher callback. A watch will be set at the server to notify the client if the node changes. /NOTE: this works different with c client. You will only receive data and child watches, no session watches./ |
-> (StringsCompletion -> IO ()) | The result callback when the request completes. One of the following exceptions will be thrown if error happens:
|
-> IO () |
Lists the children of a node.
This function is similar to zooGetChildren
except it allows one specify
a watcher object.
Note that there is only one thread for triggering callbacks. Which means this function will first block on the completion, and then wating on the watcher.
Throw one of the following exceptions on failure:
ZBADARGUMENTS - invalid input parameters ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> IO StringsStatCompletion | The result when the request completes. Throw one of the following exceptions if the request completes failed:
|
Lists the children of a node, and get the parent stat.
This function is new in version 3.3.0
Throw one of the following exceptions on failure:
ZBADARGUMENTS
- invalid input parametersZINVALIDSTATE
- zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATEZMARSHALLINGERROR
- failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> (HsWatcherCtx -> IO ()) | The watcher callback. A watch will be set at the server to notify the client if the node changes. /NOTE: this works different with c client. You will only receive data and child watches, no session watches./ |
-> (StringsStatCompletion -> IO ()) | The result callback when the request completes. One of the following exceptions will be thrown if error happens:
|
-> IO () |
Lists the children of a node, and get the parent stat.
This function is new in version 3.3.0
Note that there is only one thread for triggering callbacks. Which means this function will first block on the completion, and then wating on the watcher.
Throw one of the following exceptions on failure:
ZBADARGUMENTS
- invalid input parametersZINVALIDSTATE
- zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATEZMARSHALLINGERROR
- failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> Maybe CInt | The expected version of the node. The function will fail if the actual version of the node does not match the expected version. If Nothing is used the version check will not take place. |
-> IO () |
Delete a node in zookeeper.
Throw one of the following exceptions on failure:
ZBADARGUMENTS
- invalid input parametersZINVALIDSTATE
- zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATEZMARSHALLINGERROR
- failed to marshall a request; possibly, out of memory
Throw one of the following exceptions if the request completes failed:
- ZNONODE the node does not exist.
- ZNOAUTH the client does not have permission.
- ZBADVERSION expected version does not match actual version.
- ZNOTEMPTY children are present; node cannot be deleted.
zooDeleteAll :: HasCallStack => ZHandle -> CBytes -> IO () Source #
Delete a node and all its children in zookeeper.
NOTE: the path should not have a trailing /
If fails, this will throw exceptions, check zooDeleteAll
and zooGetChildren
for more details.
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> IO (Maybe StatCompletion) | The result when the request completes. Nothing means the node does not exist. One of the following exceptions will be thrown if error happens:
|
Checks the existence of a node in zookeeper.
Throw one of the following exceptions on failure:
- ZBADARGUMENTS - invalid input parameters
- ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
- ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> (HsWatcherCtx -> IO ()) | The watcher callback. A watch will set on the specified znode on the server. The watch will be set even if the node does not exist. This allows clients to watch for nodes to appear. /NOTE: this works different with c client. You will only receive data and child watches, no session watches./ |
-> (Maybe StatCompletion -> IO ()) | The result callback when the request completes. Nothing means the node does not exist. One of the following exceptions will be thrown if error happens:
|
-> IO () |
Checks the existence of a node in zookeeper.
This function is similar to zooExists
except it allows one specify
a watcher object. The function will be called once the watch has fired.
Note that the watch will fire both when the node is created and its associated data is set.
Note that there is only one thread for triggering callbacks. Which means this function will first block on the completion, and then wating on the watcher.
Throw one of the following exceptions on failure:
- ZBADARGUMENTS - invalid input parameters
- ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
- ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> IO AclCompletion | The result when the request completes. Throw one of the following exceptions if the request completes failed:
|
Gets the acl associated with a node.
Throw one of the following exceptions on failure:
ZBADARGUMENTS - invalid input parameters ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
:: HasCallStack | |
=> ZHandle | The zookeeper handle obtained by a call to |
-> [ZooOp] | An list of operations to commit |
-> IO [ZooOpResult] |
:: CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> Maybe Bytes | The data to be stored in the node. |
-> CInt | Max Size of the buffer results in Note: we do NOT check if the size is non-negative. If this size is 0, you will get an empty ZooCreateOpResult. If the path of the new node exceeds the buffer size, the path string will be truncated to fit. The actual path of the new node in the server will not be affected by the truncation. |
-> AclVector | The initial ACL of the node. The ACL must not be null or empty. |
-> CreateMode | This parameter can be set to |
-> ZooOp |
Init create op.
This function initializes a ZooOp
with the arguments for a ZOO_CREATE_OP.
:: CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> Maybe CInt | The expected version of the node. The function will fail if the actual version of the node does not match the expected version. If Nothing is used the version check will not take place. |
-> ZooOp |
Init delete op.
This function initializes a ZooOp
with the arguments for a ZOO_DELETE_OP.
:: CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> Maybe Bytes | Data to be written to the node. To set NULL as data use this parameter as Nothing. |
-> Maybe CInt | The expected version of the node. The function will fail if the actual version of the node does not match the expected version. If Nothing is used the version check will not take place. |
-> ZooOp |
Init set op.
This function initializes an ZooOp
with the arguments for a ZOO_SETDATA_OP.
:: CBytes | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
-> CInt | The expected version of the node. The function will fail if the actual version of the node does not match the expected version. |
-> ZooOp |
Init check op.
This function initializes an ZooOp
with the arguments for a ZOO_CHECK_OP.
assertZooOpResultOK :: HasCallStack => ZooOpResult -> IO () Source #
zooClientID :: ZHandle -> IO ClientID Source #
Return the opaque client session id, only valid if the connections
is currently connected (ie. last watcher state is ZooConnectedState
)
peekClientId :: ClientID -> IO HsClientID Source #
zooState :: ZHandle -> IO ZooState Source #
Get the state of the zookeeper connection
The return valud will be one of the State Consts
zooRecvTimeout :: ZHandle -> IO CInt Source #
Return the timeout for this session, only valid if the connections is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE). This value may change after a server re-connect.
:: ZHandle | The zookeeper handle obtained by a call to |
-> IO Bool | Return True if connection is unrecoverable |
Checks if the current zookeeper connection state can't be recovered.
If True, the application must close the zhandle and then try to reconnect.
Internal function
:: CBytes | host, comma separated host:port pairs, each corresponding to a zk server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" |
-> Maybe WatcherFn | the global watcher callback function. When notifications are triggered this function will be invoked. FIXME: Calling any zoo operations (e.g. zooGet) will cause an infinite block. |
-> CInt | session expiration time in milliseconds |
-> Maybe ClientID | The id of a previously established session that this client will be
reconnecting to. Pass |
-> CInt | flags, reserved for future use. Should be set to zero. |
-> IO (ZHandle, FunPtr CWatcherFn) |
Create a handle to used communicate with zookeeper.
This function creates a new handle and a zookeeper session that corresponds to that handle. At the underlying c side, session establishment is asynchronous, meaning that the session should not be considered established until (and unless) an event of state ZOO_CONNECTED_STATE is received. In haskell, this will block until state received.
If it fails to create a new zhandle or not connected, an exception will be throwed.
:: CBytes | File name |
-> CBytes | Mode A string beginning with one of the following sequences: r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. Output is always appended to the end of the file. POSIX is silent on what the initial read position is when using this mode. For glibc, the initial file position for reading is at the beginning of the file, but for AndroidBSDMacOS, the initial file position for reading is at the end of the file. |
-> IO FileLogStream |
Open the file by filename using the given mode.
The operation may fail with IOError if open filed.
Also see: https://man7.org/linux/man-pages/man3/fopen.3.html
closeFileLogStream :: FileLogStream -> IO () Source #