Class ConfInternal

Object
com.tailf.conf.ConfInternal

public class ConfInternal extends Object
This class implements the internal communication API in Java. The class contains internal static methods to read and write Erlang structures,terms. The Java representations of Erlang terms resides in com.tailf.proto package. It is used internally by the API and thus should not be used by user of this API directly.

This class is a translation of the C library confd_internal.c.

  • Constructor Details

    • ConfInternal

      public ConfInternal()
  • Method Details

    • get_int32

      public static long get_int32(int offset, byte[] s)
    • get_int16

      public static int get_int16(int offset, byte[] s)
    • put_int32

      public static void put_int32(int offset, int i, byte[] s)
    • put_int16

      public static void put_int16(int offset, int i, byte[] s)
    • termRead

      public static ConfResponse termRead(Socket sock) throws ConfException, IOException
      Request one term from ConfD/NCS.
      Parameters:
      sock - A socket connected to ConfD/NCS
      Throws:
      ConfException
      IOException
    • termRead

      public static ConfResponse termRead(SelectionKey key) throws ConfException, IOException
      Common method to read ( request ) a term from ConfD/NCS NOTE: This method should not be used by users of this API. This method is used by Cdb API ( where Cdb instance is created with a instance of a SocketChannel ). PRECONDITION: A term should have been written to ConfD/NCS before calling this method.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      Returns:
      The response which have been sent back from ConfD/NCS
      Throws:
      IOException - if an general I/O error occurred
      ConfException - if ConfD/NCS protocol error occurred
    • termRead

      public static ConfResponse termRead(Object sock) throws ConfException, IOException
      Common method to read a term from ConfD/NCS NOTE: This method should not be used by users of this API. This method delegates to either termRead( Socket ) or to termRead ( SelectionKey ). PRECONDITION: A term should have been written to ConfD/NCS before calling this method.
      Parameters:
      sock - Either instance of a Socket or a SocketChannel.
      Returns:
      The response which have been sent back from ConfD/NCS
      Throws:
      IOException - if an general I/O error occurred
      ConfException - if ConfD/NCS protocol error occurred
    • termRead

      public static ConfResponse termRead(Socket sock, int cdbop) throws ConfException, IOException
      Request one term from ConfD/NCS.
      Parameters:
      sock - A socket connected to ConfD/NCS
      cdbop - The op code
      Throws:
      ConfException
      IOException
    • termRead

      public static ConfResponse termRead(SelectionKey key, int cdbop) throws ConfException, IOException
      Read a response, term from ConfD/NCS with the given SelectionKey and the op cdbop. NOTE: This method is called by Cdb when used with a SocketChannel and should not be used directly by the user of this API.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      Throws:
      IOException - if an general I/O error occurred
      ConfException - if ConfD/NCS protocol error occurred
    • readFill

      public static void readFill(Socket socket, byte[] b) throws ConfException, IOException
      Reads data into a buffer. Exactly all bytes as specified by the buffer size is read.
      Parameters:
      socket - A socket connected to ConfD/NCS
      b - Buffer array of bytes to read data into
      Throws:
      ConfException
      IOException
    • readSize

      public static void readSize(SelectionKey key, ByteBuffer buf, int size) throws ConfException, IOException
      Throws:
      ConfException
      IOException
    • readPayLoad

      public static void readPayLoad(SelectionKey key, ByteBuffer buf, int size) throws ConfException, IOException
      Throws:
      ConfException
      IOException
    • readFill

      public static void readFill(SelectionKey key, ByteBuffer buf, int siz) throws ConfException, IOException
      Read exactly siz data into the buffer buf.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS. NOTE: The attached buffer is supplied from the readPayLoad method only!
      buf - ByteBuffer of bytes to read data into
      siz - The number of bytes to read into the buffer buf
      Throws:
      IOException - if an general I/O error occurred
      ConfException - if ConfD/NCS protocol error occurred
    • requestTerm

      public static ConfResponse requestTerm(Socket socket, int op, int thandle, boolean isrel, ConfEObject arg) throws ConfException, IOException
      Requests a term from ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      op - The op code.
      isrel - Boolean flag that says that if the provided arg is a path if it is relative or not
      arg - Argument ConfObject object
      Throws:
      ConfException
      IOException
    • requestTerm

      public static ConfResponse requestTerm(SelectionKey key, int op, int thandle, boolean isrel, ConfEObject arg) throws ConfException, IOException
      Write a term arg for the specified operation op , transaction handle thandle ( if available -1 otherwise ) and read the response, from ConfD/NCS. The isrel parameter determines if the term written contains path that should treated as a relative. NOTE: This method is called by Cdb when used with a SocketChannel and should not be used directly by the user of this API.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      op - The operation performed on ConfD/NCS
      thandle - The transaction handle ( if Maapi) -1 otherwise
      isrel - Determines if the operation is relative
      arg - The argument term to the operation op
      Returns:
      The response for the operation op
      Throws:
      IOException - if an general I/O error occurred
      ConfException - if ConfD/NCS protocol error occurred
    • requestTerm

      public static ConfResponse requestTerm(Socket socket, int op) throws ConfException, IOException
      Requests a term from ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      op - The op code.
      Throws:
      ConfException
      IOException
    • requestTerm

      public static ConfResponse requestTerm(SelectionKey key, int op) throws ConfException, IOException
      Request the operation op with no argument, and read the response from ConfD/NCS. Specifying the operation as not relative. The isrel parameter determines if the term written contains path that should treated as a relative. Request a term for the specified operation op. NOTE: This method is called by Cdb when used with a SocketChannel and should not be used directly by the user of this API.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      op - The operation performed on ConfD/NCS
      Returns:
      The response for the operation op
      Throws:
      IOException - if an general I/O error occurred
      ConfException - if ConfD/NCS protocol error occurred
    • requestTerm

      public static ConfResponse requestTerm(Socket socket, int op, ConfEObject arg) throws ConfException, IOException
      Requests a term from ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      op - The op code.
      arg - An argument to send in the request
      Throws:
      ConfException
      IOException
    • requestTerm

      public static ConfResponse requestTerm(SelectionKey key, int op, ConfEObject arg) throws ConfException, IOException
      Write a term arg for the specified operation op and read the response, from ConfD/NCS. Specifying the operation as not relative. NOTE: This method is called by Cdb when used with a SocketChannel and should not be used directly by the user of this API.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      op - The operation performed on ConfD/NCS
      Returns:
      The response for the operation op
      Throws:
      IOException - if an general I/O error occurred
      ConfException - if ConfD/NCS protocol error occurred
    • requestInt

      public static int requestInt(Socket socket, int op, int thandle) throws ConfException, IOException
      Requests an integer value from ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      op - The op code.
      thandle - The transaction handle.
      Throws:
      ConfException
      IOException
    • requestInt

      public static int requestInt(Socket socket, int op) throws ConfException, IOException
      Request an integer from ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      op - The op code.
      Throws:
      ConfException
      IOException
    • write

      public static void write(Socket socket, int op, int thandle) throws IOException
      Writes an op and a transaction handle to ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      op - The op code.
      Throws:
      IOException
    • write

      public static void write(SelectionKey key, int op, int thandle) throws IOException
      Request that the operation op should be performed, with no argument and with the transaction handle thandle to ConfD/NCS.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      op - The operation performed on ConfD/NCS
      thandle - The transaction handle ( if Maapi) -1 otherwise
      Throws:
      IOException - if an general I/O error occurred
    • write

      public static byte[] write(int op, int thandle) throws IOException
      Throws:
      IOException
    • write

      public static void write(Socket socket, int op) throws IOException
      Write a simple op to ConfD/NCS
      Parameters:
      socket - A socket connected to ConfD/NCS
      op - The op code.
      Throws:
      IOException
    • intWrite

      public static void intWrite(Socket socket, int cdbop, int thandle, int arg) throws IOException
      Writes an integer op, a thandle, and a single integer argument to ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      cdbop - The op code.
      Throws:
      IOException
    • termWrite

      public static void termWrite(Socket socket, int cdbop, int thandle, ConfEObject term) throws IOException
      Writes a term argument to ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      cdbop - The op code.
      thandle - The transaction handle
      term - The ConfEObject term to write.
      Throws:
      IOException
    • termWrite

      public static void termWrite(SelectionKey key, int cdbop, int thandle, ConfEObject term) throws IOException
      Request that the operation op should be performed, with argument term term and with the transaction handle thandle to ConfD/NCS.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      cdbop - The operation performed on ConfD/NCS
      thandle - The transaction handle ( if Maapi) -1 otherwise usually when Cdb
      term - The argument term to the operation op
      Throws:
      IOException - if an general I/O error occurred
    • termWrite

      public static byte[] termWrite(int cdbop, int thandle, ConfEObject term) throws IOException
      Throws:
      IOException
    • termWrite

      public static void termWrite(Socket socket, int op, ConfEObject term) throws IOException
      Writes a term argument to ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      op - The op code.
      term - The ConfEObject term to write.
      Throws:
      IOException
    • termWrite

      public static void termWrite(Socket socket, ConfEObject term) throws IOException
      Writes a term argument to ConfD/NCS.
      Parameters:
      socket - A socket connected to ConfD/NCS
      term - The ConfEObject term to write.
      Throws:
      IOException
    • bufWrite

      public static void bufWrite(Socket socket, int cdbop, int thandle, byte[] buf) throws IOException
      Writes OP + string
      Parameters:
      socket - A socket connected to ConfD/NCS
      cdbop - The op code.
      thandle - The transaction handle
      buf - The byte buffer to write
      Throws:
      IOException
    • bufWrite

      public static void bufWrite(SelectionKey key, int cdbop, int thandle, byte[] buf) throws IOException
      Writes OP + string
      Parameters:
      key - A socket connected to ConfD/NCS
      cdbop - The op code.
      thandle - The transaction handle
      buf - The byte buffer to write
      Throws:
      IOException
    • mk_keypath

      public static ConfObject[] mk_keypath(ConfEObject term, ArrayList<ConfNamespace> ns_list) throws ConfException
      Makes a keypath from a term. This method us obsolete but the problem is that deref() did not get hashes even though useikp = false on erlang side val2ext() does not work correctly. So if the schema is not loaded the ConfNamespace.findNamespace() will fail and throw a ConfException.
      Throws:
      ConfException
    • hk_keypath

      public static ConfObject[] hk_keypath(ConfEObject term) throws ConfException
      Create a hkeypath from a term. This method takes a ConfEList as its actual polymorphic type. The ConfEList should represent e HKEY-Path.
      Parameters:
      term - - A HKey path as ConfEList
      Returns:
      KeyPath of ConfEObject.
      Throws:
      ConfException
    • substitute_percent

      public static String substitute_percent(String fmt, Object... arguments)
    • doConnect

      public static long doConnect(Socket socket, int id) throws ConfException
      Throws:
      ConfException
    • doConnect

      public static long doConnect(SelectionKey key, int id) throws ConfException, IOException
      Connects the provided selectable channel to the Erlang process using the supplied selector with the buffer buf with the identifier id. This should be the first call by the constructor from Cdb.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      id - the integer which specifies what kind of socket ( should always be CdbProto.OP_CLIENT_NAME )
      Throws:
      ConfException - If the IPCAccessSecret check throws IOException it will be wrapped inside the ConfExcepion to be able to retrieve the cause use getCause().
      IOException - if an I/O error occured
    • diffIterate

      public static void diffIterate(Object socket, ConfIterate iter, Object initstate) throws IOException, ConfException
      Throws:
      IOException
      ConfException
    • diffIterate

      public static void diffIterate(SelectionKey key, ConfIterate iter, Object initstate) throws IOException, ConfException
      Common static method for diffIterate with CdbSubscription. This method is used internally by the Cdb API.
      Parameters:
      key - The registration representation of a particular channel object with a particular selector object. The key parameter is not part of the "ready set" but its internal "interest set" has been registered with the selector. The key's attachment holds a reference to the ByteBuffer that is used to read/write bytes from/to ConfD/NCS.
      iter - The callback user code
      initstate - The opaque object passed from user code
      Throws:
      IOException - if an general I/O error occurred
      ConfException - if ConfD/NCS protocol error occurred
    • flushToSocket

      public static void flushToSocket(SelectionKey key, ConfOutputStream out) throws IOException
      Throws:
      IOException
    • flushToSocket

      public static void flushToSocket(Object socket, ConfOutputStream out) throws IOException
      Throws:
      IOException