public class Zab extends Object
Constructor and Description |
---|
Zab(StateMachine stateMachine,
ZabConfig config)
Constructs a Zab instance by recovering from the log directory.
|
Zab(StateMachine stateMachine,
ZabConfig config,
String serverId,
Set<String> peers)
Constructs a Zab instance by booting from static cluster configuration.
|
Zab(StateMachine stateMachine,
ZabConfig config,
String serverId,
String joinPeer)
Constructs a Zab instance by joining an existing cluster.
|
Modifier and Type | Method and Description |
---|---|
void |
flush(ByteBuffer request,
Object ctx)
Flushes a request through pipeline.
|
Future<Void> |
getFuture()
Get the future of the background working thread of Zab.
|
String |
getServerId()
Returns the server Id for this Zab instance.
|
void |
remove(String peerId,
Object ctx)
Removes a peer from the cluster.
|
void |
send(ByteBuffer request,
Object ctx)
Submits a request to Zab.
|
void |
shutdown()
Shut down the Zab.
|
void |
takeSnapshot(Object ctx)
Issues the request to take a snapshot.
|
public Zab(StateMachine stateMachine, ZabConfig config)
stateMachine
- the state machine implementation of application.config
- the configuration for Jzab, see ZabConfig
.public Zab(StateMachine stateMachine, ZabConfig config, String serverId, String joinPeer)
Zab
which recovers the Zab instance
from log directory.stateMachine
- the state machine implementation of application.config
- the configuration for Jzab, see ZabConfig
.serverId
- ID ("host:port") of this server.joinPeer
- the ID of peer you want to join in, the ID is a host:port
string of the peer. The first server bootstraps the cluster by joining
itself.public Zab(StateMachine stateMachine, ZabConfig config, String serverId, Set<String> peers)
Zab
which recovers the
Zab instance from log directory.stateMachine
- the state machine implementation of application.config
- the configuration for Jzab, see ZabConfig
.serverId
- ID ("host:port") of this server.peers
- the IDs of the servers in cluster, including itself.public Future<Void> getFuture()
public void send(ByteBuffer request, Object ctx) throws ZabException.InvalidPhase, ZabException.TooManyPendingRequests
request
- the request to send through Zabctx
- context to be provided to the callbackZabException.InvalidPhase
- if Zab is not in broadcasting phase.ZabException.TooManyPendingRequests
- if the pending requests exceeds
the certain size, for example: if there are more pending requests than
ZabConfig.MAX_PENDING_REQS.public void flush(ByteBuffer request, Object ctx) throws ZabException.InvalidPhase, ZabException.TooManyPendingRequests
request
- the request to be flushed.ctx
- context to be provided to the callbackZabException.InvalidPhase
- if Zab is not in broadcasting phase.ZabException.TooManyPendingRequests
- if the pending requests exceeds
the certain size, for example: if there are more pending requests than
ZabConfig.MAX_PENDING_REQS.public void remove(String peerId, Object ctx) throws ZabException.InvalidPhase, ZabException.TooManyPendingRequests
peerId
- the id of the peer who will be removed from the cluster.ctx
- context to be provided to the callbackZabException.InvalidPhase
- if Zab is not in broadcasting phase.ZabException.TooManyPendingRequests
- if there is a pending snapshot
request.public void takeSnapshot(Object ctx) throws ZabException.InvalidPhase, ZabException.TooManyPendingRequests
StateMachine.save(java.io.FileOutputStream)
callback will be called for serializing the application's state to disk.ctx
- context to be provided to the callbackZabException.InvalidPhase
- if Zab is not in broadcasting phase.ZabException.TooManyPendingRequests
- if there is a pending snapshot
request.public void shutdown() throws InterruptedException
InterruptedException
- in case of it's interrupted.public String getServerId()
Copyright © 2015. All rights reserved.