Class Realm

java.lang.Object
uk.co.sculptor.kflibjava.Realm
All Implemented Interfaces:
AutoCloseable

public class Realm extends Object implements AutoCloseable

Realm where servers live. Used to define the transaction scope.

Note: This class implements the AutoCloseable interface, meaning that an object may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.
Author:
Marcos Gutierrez Batz
  • Constructor Details

    • Realm

      public Realm(String realmName)
      Constructor: Create the Realm object
      Parameters:
      realmName - The realm name.
  • Method Details

    • begin

      public void begin() throws IOException, KfException
      Begin transaction on all the servers that belong to the current Realm.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - When a protocol error or a server error is detected.
    • close

      public void close() throws IOException, KfException
      Close all Servers hanging from the realm
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - If an I/O error occurs when dealing with the socket
      KfException - Any error on the KfServer protocol or on the server closing process.
    • commit

      public void commit() throws IOException, KfException
      Commit transaction on all the servers that belong to the current Realm.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - When a protocol error or a server error is detected.
    • getRealmName

      public String getRealmName()
      Get the current Realm provided name
      Returns:
      the realmName
    • openServer

      public Server openServer(String serverName) throws KfException, IOException, InterruptedException
      Create a Server object.
      Parameters:
      serverName - The server name where the KfServer process is executing
      Returns:
      the Server object to be used to create Databases
      Throws:
      KfException - Any error on the KfServer protocol or parameters.
      IOException - If an I/O error occurs when using the socket.
      InterruptedException - If an interrupt is received while waiting for next connection retry.
    • openServer

      public Server openServer(String serverName, int timeOut) throws KfException, IOException, InterruptedException
      Create a Server object.
      Parameters:
      serverName - The server name where the KfServer process is executing
      timeOut - Seconds to try the server connection (-1 means default value, 15 seconds)
      Returns:
      the Server object to be used to create Databases
      Throws:
      KfException - Any error on the KfServer protocol or parameters.
      IOException - If an I/O error occurs when using the socket.
      InterruptedException - If an interrupt is received while waiting for next connection retry.
    • rollBack

      public void rollBack() throws IOException, KfException
      Roll back transaction on all the servers that belong to the current Realm.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - When a protocol error or a server error is detected.
    • sendKeepAlives

      public void sendKeepAlives(long intervalSecs) throws IOException, KfException
      Send Keep Alives to all the Realm Servers (programs must use their own timer).
      Parameters:
      intervalSecs - Keep alive interval
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - When a protocol error or a server error is detected.