public class Ha extends Object
Constructor and Description |
---|
Ha(Socket socket,
String token)
Constructor for management of an HA Cluster node.
|
Modifier and Type | Method and Description |
---|---|
void |
beMaster(ConfValue myNodeId)
Instruct an HA node to be master and also give the node a name.
|
void |
beNone()
Instruct a node to resume the initial state, i.e.
|
void |
beRelay()
Instruct a slave node to be a relay for other slaves.
|
void |
beSlave(ConfValue myNodeId,
ConfHaNode master,
boolean waitForReply)
Instruct an HA node to be a slave to a named master.
|
void |
slaveDead(ConfValue nodeId)
This function must be used by the application to inform the HA subsystem
that another node which is possibly connected to the server is dead.
|
HaStatus |
status()
Query an HA node for its status.
|
public Ha(Socket socket, String token) throws IOException, HaException
Constructor for management of an HA Cluster node. This constructor implicitly connects an HA socket which can be used to control a ConfD/NCS HA node. The token is a secret string that must be shared by all participants in the cluster. There can only be one HA socket towards the server, which implies only on HA instance. If a new HA instance is created the previous connection is closed and the cluster node is reset with the new token value.
Since the ConfD/NCS daemon expects initialization within 5 seconds after a new socket is established, this constructor should be called immediately for a new socket. For instance:
// int port = Conf.PORT for ConfD or Conf.NCS_PORT for NCS Ha ha = new Ha(new Socket("localhost", port), "xyz");
If encrypted communication towards ConfD/NCS is desired, an environment variable "CONFD_IPC_ACCESS_FILE" or "NCS_IPC_ACCESS_FILE" need to be set. This variable is expected to point to a file containing a secret salt. Example:
export CONFD_IPC_ACCESS_FILE=./secret_file.txt
An alternative to the environment variable is to set a java system property with the same name pointing to the file.
Note, if this constructor fails the socket must be closed and a new socket created before the call is re-attempted.
socket
- Ha control sockettoken
- cluster common shared secretIOException
HaException
public void beMaster(ConfValue myNodeId) throws IOException, HaException
myNodeId
- ConfValue naming the ha nodeIOException
HaException
public void beSlave(ConfValue myNodeId, ConfHaNode master, boolean waitForReply) throws IOException, HaException
myNodeId
- ConfValue naming the ha nodemaster
- Master ConfHaNodewaitForReply
- boolean, set true if call should block until responseIOException
HaException
public void beNone() throws IOException, HaException
IOException
HaException
public void beRelay() throws IOException, HaException
IOException
HaException
public HaStatus status() throws IOException, HaException
IOException
HaException
public void slaveDead(ConfValue nodeId) throws IOException, HaException
nodeId
- ConfValue naming the cluster nodeIOException
HaException