Package com.tailf.conf
Class ConfInternal
Object
com.tailf.conf.ConfInternal
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Writes OP + stringstatic void
bufWrite
(SelectionKey key, int cdbop, int thandle, byte[] buf) Writes OP + stringstatic void
diffIterate
(Object socket, ConfIterate iter, Object initstate) static void
diffIterate
(SelectionKey key, ConfIterate iter, Object initstate) Common static method for diffIterate with CdbSubscription.static long
static long
doConnect
(SelectionKey key, int id) Connects the provided selectable channel to the Erlang process using the supplied selector with the buffer buf with the identifier id.static void
flushToSocket
(Object socket, ConfOutputStream out) static void
flushToSocket
(SelectionKey key, ConfOutputStream out) static int
get_int16
(int offset, byte[] s) static long
get_int32
(int offset, byte[] s) static ConfObject[]
hk_keypath
(ConfEObject term) Create a hkeypath from a term.static void
Writes an integer op, a thandle, and a single integer argument to ConfD/NCS.static ConfObject[]
mk_keypath
(ConfEObject term, ArrayList<ConfNamespace> ns_list) Makes a keypath from a term.static void
put_int16
(int offset, int i, byte[] s) static void
put_int32
(int offset, int i, byte[] s) static void
Reads data into a buffer.static void
readFill
(SelectionKey key, ByteBuffer buf, int siz) Read exactlysiz
data into the bufferbuf
.static void
readPayLoad
(SelectionKey key, ByteBuffer buf, int size) static void
readSize
(SelectionKey key, ByteBuffer buf, int size) static int
requestInt
(Socket socket, int op) Request an integer from ConfD/NCS.static int
requestInt
(Socket socket, int op, int thandle) Requests an integer value from ConfD/NCS.static ConfResponse
requestTerm
(Socket socket, int op) Requests a term from ConfD/NCS.static ConfResponse
requestTerm
(Socket socket, int op, int thandle, boolean isrel, ConfEObject arg) Requests a term from ConfD/NCS.static ConfResponse
requestTerm
(Socket socket, int op, ConfEObject arg) Requests a term from ConfD/NCS.static ConfResponse
requestTerm
(SelectionKey key, int op) Request the operationop
with no argument, and read the response from ConfD/NCS.static ConfResponse
requestTerm
(SelectionKey key, int op, int thandle, boolean isrel, ConfEObject arg) Write a termarg
for the specified operationop
, transaction handlethandle
( if available -1 otherwise ) and read the response, from ConfD/NCS.static ConfResponse
requestTerm
(SelectionKey key, int op, ConfEObject arg) Write a termarg
for the specified operationop
and read the response, from ConfD/NCS.static String
substitute_percent
(String fmt, Object... arguments) static ConfResponse
Common method to read a term from ConfD/NCS NOTE: This method should not be used by users of this API.static ConfResponse
Request one term from ConfD/NCS.static ConfResponse
Request one term from ConfD/NCS.static ConfResponse
termRead
(SelectionKey key) Common method to read ( request ) a term from ConfD/NCS NOTE: This method should not be used by users of this API.static ConfResponse
termRead
(SelectionKey key, int cdbop) Read a response, term from ConfD/NCS with the givenSelectionKey
and the opcdbop
.static byte[]
termWrite
(int cdbop, int thandle, ConfEObject term) static void
termWrite
(Socket socket, int cdbop, int thandle, ConfEObject term) Writes a term argument to ConfD/NCS.static void
termWrite
(Socket socket, int op, ConfEObject term) Writes a term argument to ConfD/NCS.static void
termWrite
(Socket socket, ConfEObject term) Writes a term argument to ConfD/NCS.static void
termWrite
(SelectionKey key, int cdbop, int thandle, ConfEObject term) Request that the operationop
should be performed, with argument termterm
and with the transaction handlethandle
to ConfD/NCS.static byte[]
write
(int op, int thandle) static void
Write a simple op to ConfD/NCSstatic void
Writes an op and a transaction handle to ConfD/NCS.static void
write
(SelectionKey key, int op, int thandle) Request that the operationop
should be performed, with no argument and with the transaction handlethandle
to ConfD/NCS.
-
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
Request one term from ConfD/NCS.- Parameters:
sock
- A socket connected to ConfD/NCS- Throws:
ConfException
IOException
-
termRead
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 occurredConfException
- if ConfD/NCS protocol error occurred
-
termRead
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 occurredConfException
- if ConfD/NCS protocol error occurred
-
termRead
Request one term from ConfD/NCS.- Parameters:
sock
- A socket connected to ConfD/NCScdbop
- The op code- Throws:
ConfException
IOException
-
termRead
Read a response, term from ConfD/NCS with the givenSelectionKey
and the opcdbop
. NOTE: This method is called by Cdb when used with aSocketChannel
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 occurredConfException
- if ConfD/NCS protocol error occurred
-
readFill
Reads data into a buffer. Exactly all bytes as specified by the buffer size is read.- Parameters:
socket
- A socket connected to ConfD/NCSb
- 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 exactlysiz
data into the bufferbuf
.- 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 intosiz
- The number of bytes to read into the bufferbuf
- Throws:
IOException
- if an general I/O error occurredConfException
- 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/NCSop
- The op code.isrel
- Boolean flag that says that if the provided arg is a path if it is relative or notarg
- 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 termarg
for the specified operationop
, transaction handlethandle
( if available -1 otherwise ) and read the response, from ConfD/NCS. Theisrel
parameter determines if the term written contains path that should treated as a relative. NOTE: This method is called by Cdb when used with aSocketChannel
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/NCSthandle
- The transaction handle ( if Maapi) -1 otherwiseisrel
- Determines if the operation is relativearg
- The argument term to the operationop
- Returns:
- The response for the operation
op
- Throws:
IOException
- if an general I/O error occurredConfException
- if ConfD/NCS protocol error occurred
-
requestTerm
Requests a term from ConfD/NCS.- Parameters:
socket
- A socket connected to ConfD/NCSop
- The op code.- Throws:
ConfException
IOException
-
requestTerm
Request the operationop
with no argument, and read the response from ConfD/NCS. Specifying the operation as not relative. Theisrel
parameter determines if the term written contains path that should treated as a relative. Request a term for the specified operationop
. NOTE: This method is called by Cdb when used with aSocketChannel
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 occurredConfException
- 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/NCSop
- 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 termarg
for the specified operationop
and read the response, from ConfD/NCS. Specifying the operation as not relative. NOTE: This method is called by Cdb when used with aSocketChannel
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 occurredConfException
- if ConfD/NCS protocol error occurred
-
requestInt
Requests an integer value from ConfD/NCS.- Parameters:
socket
- A socket connected to ConfD/NCSop
- The op code.thandle
- The transaction handle.- Throws:
ConfException
IOException
-
requestInt
Request an integer from ConfD/NCS.- Parameters:
socket
- A socket connected to ConfD/NCSop
- The op code.- Throws:
ConfException
IOException
-
write
Writes an op and a transaction handle to ConfD/NCS.- Parameters:
socket
- A socket connected to ConfD/NCSop
- The op code.- Throws:
IOException
-
write
Request that the operationop
should be performed, with no argument and with the transaction handlethandle
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/NCSthandle
- The transaction handle ( if Maapi) -1 otherwise- Throws:
IOException
- if an general I/O error occurred
-
write
- Throws:
IOException
-
write
Write a simple op to ConfD/NCS- Parameters:
socket
- A socket connected to ConfD/NCSop
- The op code.- Throws:
IOException
-
intWrite
Writes an integer op, a thandle, and a single integer argument to ConfD/NCS.- Parameters:
socket
- A socket connected to ConfD/NCScdbop
- 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/NCScdbop
- The op code.thandle
- The transaction handleterm
- 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 operationop
should be performed, with argument termterm
and with the transaction handlethandle
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/NCSthandle
- The transaction handle ( if Maapi) -1 otherwise usually when Cdbterm
- The argument term to the operationop
- Throws:
IOException
- if an general I/O error occurred
-
termWrite
- Throws:
IOException
-
termWrite
Writes a term argument to ConfD/NCS.- Parameters:
socket
- A socket connected to ConfD/NCSop
- The op code.term
- The ConfEObject term to write.- Throws:
IOException
-
termWrite
Writes a term argument to ConfD/NCS.- Parameters:
socket
- A socket connected to ConfD/NCSterm
- The ConfEObject term to write.- Throws:
IOException
-
bufWrite
Writes OP + string- Parameters:
socket
- A socket connected to ConfD/NCScdbop
- The op code.thandle
- The transaction handlebuf
- 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/NCScdbop
- The op code.thandle
- The transaction handlebuf
- 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
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
-
doConnect
- Throws:
ConfException
-
doConnect
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 codeinitstate
- The opaque object passed from user code- Throws:
IOException
- if an general I/O error occurredConfException
- if ConfD/NCS protocol error occurred
-
flushToSocket
- Throws:
IOException
-
flushToSocket
- Throws:
IOException
-