Python3 bindings for writing Enduro/X clients and servers

tplog(lev, message)

Print logfile message with specified level.

tplog_debug(message)

Print debug message to log file.

tplog_info(message)

Print info message to log file.

tplog_warn(message)

Print warning message to log file.

tplog_error(message)

Print error message to log file.

tplog_always(message)

Print fatal message to log file.

tplog_exception(msg)

Print exception backtrace at error level.

tplogconfig(logger, lev, debug_string, ...)

Configure Enduro/X logger.

tplogqinfo(lev, flags)

Query logger information.

tplogsetreqfile(data[, filename, filesvc])

Redirect logger to request file extracted from buffer, filename or file name service.

tplogsetreqfile_direct([filename])

Set logfile from given filename.

tploggetreqfile()

Get current request file name for tp topic.

tploggetbufreqfile(data)

Extract request file from the UBF buffer.

tplogdelbufreqfile(data)

Delete request file name from the given UBF buffer.

tplogclosethread()

Close thread logging file.

tplogdump(lev, comment, data)

Dump byte array to log file.

tplogdumpdiff(lev, comment, data1, data2)

Compare two byte arrays and print differences for the common length.

tplogfplock([lev, flags])

Locks and returns logging handle.

tplogfpget(dbg[, flags])

Get fileno for currently locked logger (i.e.

tplogfpunlock(dbg)

Unlock logger handle for given process previously locked by tplogfplock().

tplogprintubf(lev, title, data)

Print UBF buffer to log file.

userlog(*args, **kwargs)

Overloaded function.

Bfldtype(fldid)

Return UBF field type by given field id.

Bfldno(fldid)

Return field number from compiled field id.

Bmkfldid(type, num)

Create field identifier (compiled id) from field type and field number.

Bfname(fldid)

Get field name from compiled field id.

Bfldid(name)

Get field name from compiled field id.

Bboolpr(expression, iop)

Compile and print boolean expression to file descriptor.

Bboolev(fbfr, expression)

Evaluate Boolean expression on given UBF buffer.

Bfloatev(fbfr, expression)

Evaluate Boolean expression as float number on given UBF buffer.

Bfprint(fbfr, iop)

Print UBF buffer to specified stream.

Bprint(fbfr)

Print UBF buffer to stdout.

Bextread(iop)

Restore ATMI UBF buffer from Bfprint() output.

tpinit([flags])

Joins thread to application

tptoutset(tout)

Set process level ATMI call timeout.

tptoutget()

Return current ATMI level timeout setting.

tpsprio(prio[, flags])

Set priority for next ATMI service call.

tpgprio()

Get last last service call priority.

tpgetnodeid()

Return current Enduro/X cluster node id.

tpterm()

Leaves application, closes ATMI session.

tpgetctxt([flags])

Retrieve current ATMI context handle and put current thread in TPNULLCONTEXT context.

tpnewctxt(auto_destroy, auto_set)

Create new ATMI Context.

tpsetctxt(*args, **kwargs)

Overloaded function.

tpfreectxt(context)

Free ATMI context.

tuxgetenv(envname)

Get environment variable.

tpsblktime(blktime, flags)

Set ATMI call timeout value.

tpgblktime(flags)

Get current ATMI call timeout setting configure for thread.

tpcall(svc, idata[, flags])

Synchronous service call.

tpacall(svc, idata[, flags])

Asynchronous service call.

tpgetrply(cd[, flags])

Get reply message for asynchronous call initiated by tpacall().

tpcancel([cd])

Cancel asynchronous call.

tpconnect(svc, idata[, flags])

Connect to conversational service.

tpsend(cd, idata[, flags])

Send conversational data to connected peer.

tprecv(cd[, flags])

Receive conversation data block.

tpdiscon([cd])

Force disconnect from the conversation session.

tpnotify(clientid, idata[, flags])

Send unsolicited notification to the client process.

tpbroadcast(lmid, usrname, cltname, idata[, ...])

Broadcast unsolicited message to several processes at once.

tpsetunsol(func)

Set unsolicited message callback handler.

tpchkunsol()

Check and process (do callback) unsolicited messages delivered by tpnotify() and tpbroadcast() to given process.

tppost(eventname, data[, flags])

Post event to the event broker.

tpbegin(timeout[, flags])

Start global transaction.

tpsuspend([flags])

Suspend global transaction.

tpresume(tranid[, flags])

Resume previously suspended global transaction.

tpcommit([flags])

Commit global transaction currently associated with given thread.

tpabort([flags])

Abort global transaction.

tpgetlev()

Get global transaction status.

tpopen()

Open XA sub-system.

tpclose()

Close XA sub-system previously open by tpopen

tpexport(ibuf[, flags])

Export ATMI buffer.

tpimport(istr[, flags])

Import previously exported ATMI buffer.

tpenqueue(qspace, qname, ctl, data[, flags])

Enqueue message to persistent message queue.

tpdequeue(qspace, qname, ctl[, flags])

Dequeue message from persistent queue.

tpscmt(flags)

Set commit mode, how tpcommit() returns, either after full two phase commit, or only after decision logged (i.e.

tpencrypt(*args, **kwargs)

Overloaded function.

tpdecrypt(*args, **kwargs)

Overloaded function.

xaoSvcCtx()

Returns the OCI service handle for a given XA connection.

tprun(server, args)

Run Enduro/X ATMI server process.

tpsubscribe(eventexpr, filter, ctl[, flags])

Subscribe to event.

tpunsubscribe(subscription[, flags])

Unsubscribe from event.

tpreturn(rval, rcode, data[, flags])

Return from ATMI service call.

tpforward(svc, data[, flags])

Forward control to other service.

tpadvertise(*args, **kwargs)

Overloaded function.

tpunadvertise(svcname)

Unadvertise service.

tpsrvgetctxdata()

Retrieve ATMI server context data.

tpsrvsetctxdata(ctxt[, flags])

Restore ATMI context data, previously captured by tpsrvgetctxdata() in ATMI service main thread.

tpcontinue()

Continue ATMI service processing with next request, without tpreturn() or tpforward().

tpexit()

Restart after return or terminate immediately (if running from other thread than main).

tpext_addb4pollcb(func)

Register callback handler for server going.

tpext_delb4pollcb()

Remove current before server poll callback previously set by tpext_addb4pollcb().

tpext_delperiodcb()

Remove periodic XATMI server idle time callback handle previously set by tpext_addperiodcb().

tpext_addpollerfd(fd, events, ptr1, func)

Monitor file descriptor in XATMI server main dispatcher.

tpext_delpollerfd(fd)

Delete file descriptor for ATMI server poller.

ndrx_epoll_mode()

Return poller code used by used Enduro/X Core build.

ndrx_stdcfgstr_parse(cfgstr)

Enduro/X standard configuration string parser.

ndrxpy_ubfdict_enable(do_use)

Disable UbfDict mode.

ndrxpy_ubfdict_delonset(delonset)

Configure UbfDict API to zap existing field value, when setting unspecified field occurrence.

How to read this documentation

This documentation contains only short description of the API calls which mentions core functionality provided by the API. Each API call contains reference to underlying C call which explains in deep details how exactly given function behaves.

Sample application

This sections lists basic ATMI client and server examples using endurox-python module.

ATMI Server

ATMI Python server example
 #!/usr/bin/env python3

 import sys
 import endurox as e

 class Server:

     def tpsvrinit(self, args):
         e.tplog_info("Doing server init...");
         e.tpadvertise("TESTSV", "TESTSV", Server.TESTSV)
         e.tpadvertise("ECHO", "ECHO", Server.ECHO)
         return 0

     def tpsvrdone(self):
         e.tplog_info("Server shutdown")

     # This is advertised service
     def TESTSV(self, args):
         e.tplogprintubf(e.log_info, "Incoming request:", args.data)
         args.data["data"]["T_STRING_2_FLD"]="Hello World from XATMI server"
         return e.tpreturn(e.TPSUCCESS, 0, args.data)

     # another service, just echo request buffer
     def ECHO(self, args):
         return e.tpreturn(e.TPSUCCESS, 0, args.data)

 if __name__ == "__main__":
     e.tprun(Server(), sys.argv)

The testsv.py shall be present in system PATH, and script may be started when it is registered in ndrxconfig.xml configuration file:

ATMI server registration
 <server name="testsv.py">
     <min>1</min>
     <max>1</max>
     <srvid>140</srvid>
     <sysopt>-e ${NDRX_ULOG}/testsv.log -r --</sysopt>
 </server>

For full instructions how to run server or client programs on Enduro/X platform see Getting Started Tutorial user guide from Enduro/X Core package.

ATMI Client

ATMI Client example
 #!/usr/bin/env python3

 import sys
 import endurox as e

 def run():

     #
     # Do some work here
     # may use buf = {"data":{}} for dictionary based UBF buffer
     # however, when tpcall returns, that would be converted to UbfDict, unless
     # e.ndrxpy_ubfdict_enable(False) is configured.
     #
     buf = {"data":e.UbfDict()}
     buf["data"]["T_STRING_FLD"] = "Hello world!"

     tperrno, tpurcode, buf = e.tpcall("TESTSV", buf)

     if 0!=tperrno:
         e.tplog_error("Failed to get configuration: %d" % tperrno)
         raise AtmiExcept(e.TPESVCFAIL, "Failed to call TESTSV")

     e.tplogprintubf(e.log_info, "Got server reply", buf);

 def appinit():
     e.tplog_info("Doing client init...");
     e.tpinit()

 def unInit():
     e.tpterm()

 if __name__ == '__main__':
     try:
         appinit()
         run()
         unInit()
     except Exception as ee:
         e.tplog_error("Exception: %s occurred: %s" % (ee.__class__, str(ee)))

ATMI buffer formats

Core of ATMI IPC consists of messages being sent between binaries. Message may encode different type of data. Enduro/X supports following data buffer types:

  • UBF (Unified Buffer Format) which is similar to JSON or YAML buffer format, except
    that it is typed and all fields must be defined in definition (fd) files. Basically
    it is dictionary where every field may have several occurrences (i.e. kind of array).
    Following field types are supported: BFLD_CHAR (C char type), BFLD_SHORT (C short type),
    BFLD_LONG (C long type), BFLD_FLOAT (C float type), BFLD_DOUBLE (C double type),
    BFLD_STRING (C zero terminated string type), BFLD_CARRAY (byte array), BFLD_VIEW
    (C structure record), BFLD_UBF (recursive buffer) and BFLD_PTR (pointer to another
    ATMI buffer).
  • STRING this is plain C string buffer. When using with Python, data is converted
    from to/from UTF-8 format.
  • CARRAY byte array buffer.
  • NULL this is empty buffer without any data and type. This buffer cannot be associated
    with call-info buffer.
  • JSON this basically is C string buffer, but with indication that it contains JSON
    formatted data. These buffer may be automatically converted to UBF and vice versa
    for certain ATMI server configurations.
  • VIEW this buffer basically may hold a C structure record.

Following chapters lists ATMI data encoding principles.

UBF Data encoding

UBF high speed key/value buffer, where value basically is list of value occurrences. Following list of field types are supported: BFLD_SHORT, BFLD_LONG, BFLD_CHAR, BFLD_FLOAT, BFLD_DOUBLE, BFLD_STRING, BFLD_CARRAY, BFLD_PTR, BFLD_UBF, BFLD_VIEW. All fields used in the system, must be declared previously by accessing the name, type and field id. See mkfldhdr(8) for format reference. Remember that declared field table files and directories where files exist, must be set in FIELDTBLS and FLDTBLDIR environment variables respectively, see ex_env(5) manpage for more information. The main benefit from the UBF buffer is that: it provides hash of lists dynamic access to fields in the buffer with having zero marshaling when buffer is sent between XATMI services. Also the buffer is typed, and the same field access is available in C/C++/Java and Go programming languages.

Enduro/X Python module supports two approaches when working in UBF buffers.

1) First approach is when working with UBF, standard Python dictionaries are used to represent the the UBF contents. However this approach requires dictionary marshaling whenever Enduro/X Core related call is issued. And in the same way to process the result marshaling is done from the UBF format to Python dictionary. With large buffers, this can be CPU time consuming, on the other hand when buffer is marshaled, the the field access is cheap, as operating with Python native objects.

2) Second approach is to use special UbfDict class which provides the dictionary like interface for accessing the UBF data. In this mode, there is zero marshalling whenever data is sent and received from other Enduro/X programs (either Python or C/Go/Java based). This means if request consists of several hundreds of the fields, and the give Python code processes only few fields, then only those few fields are read and constructed in the Python space, thus reaching much higher transactions throughput.

Mode 2) is available and made default approach from the module version 8.0.4. Mode 1) can be enabled by calling module function ndrxpy_ubfdict_enable() with False flag or provide NDRXPY_UBFDICT_ENABLE environment variable set to 0. Note that ndrxpy_ubfdict_enable() is per thread configuration flag.

When ndrxpy_ubfdict_enable() set to False, incoming service requests are provided as standard Python dict types. Also when module returns buffers from Enduro/X (e.g. tpcall()), then buffers are provided as dict types. When passing data to Enduro/X XATMI/UBF sub-system, both formats are accepted, regardless of the ndrxpy_ubfdict_enable() setting.

For both buffer modes:

When building ATMI buffer from Python dictionary, endurox-python library accepts values to be present as list of values, in such case values are loaded into UBF occurrences accordingly. Value may be presented directly without the list, in such case the value is loaded into UBF field occurrence 0.

When ATMI UBF buffer dictionary is received from Enduro/X, all values are loaded into lists, regardless of did field had several occurrences or just one.

UBF buffer type is selected by following rules:

  • data key is UbfDict or standard python dictionary and buftype key is not present.

  • data key is UbfDict or standard python dictionary and buftype key is set to UBF.

Example call to echo service:

UBF buffer encoding call
 import endurox as e

 tperrno, tpurcode, retbuf = e.tpcall("ECHO", { "data":e.UbfDict({
     # 3x occs:
     "T_CHAR_FLD": ["X", "Y", 0]
     , "T_SHORT_FLD": 3200
     , "T_LONG_FLD": 99999111
     , "T_FLOAT_FLD": 1000.99
     , "T_DOUBLE_FLD": 1000111.99
     , "T_STRING_FLD": "HELLO INPUT"
     # contains sub-ubf buffer, which againt contains sub-buffer
     , "T_UBF_FLD": {"T_SHORT_FLD":99, "T_UBF_FLD":{"T_LONG_2_FLD":1000091}}
     # at occ 0 EMPTY view is used
     , "T_VIEW_FLD": [ {}, {"vname":"UBTESTVIEW2", "data":{
                     "tshort1":5
                     , "tlong1":100000
                     , "tchar1":"J"
                     , "tfloat1":9999.9
                     , "tdouble1":11119999.9
                     , "tstring1":"HELLO VIEW"
                     , "tcarray1":[b'\x00\x00', b'\x01\x01']
                     }}]
     # contains pointer to STRING buffer:
     , "T_PTR_FLD":{"data":"HELLO WORLD"}
 }}))
 print(retbuf)
UBF buffer encoding output (line wrapped)
 {
     'buftype': 'UBF', 'data':
     {
         'T_SHORT_FLD': [3200]
         , 'T_LONG_FLD': [99999111]
         , 'T_CHAR_FLD': ['X', 'Y', b'\x00']
         , 'T_FLOAT_FLD': [1000.989990234375]
         , 'T_DOUBLE_FLD': [1000111.99]
         , 'T_STRING_FLD': ['HELLO INPUT']
         , 'T_PTR_FLD': [{'buftype': 'STRING', 'data': 'HELLO WORLD'}]
         , 'T_UBF_FLD': [{'T_SHORT_FLD': [99], 'T_UBF_FLD': [{'T_LONG_2_FLD': [1000091]}]}]
         , 'T_VIEW_FLD': [{}, {'vname': 'UBTESTVIEW2', 'data': {
                 'tshort1': [5]
                 , 'tlong1': [100000]
                 , 'tchar1': ['J']
                 , 'tfloat1': [9999.900390625]
                 , 'tdouble1': [11119999.9]
                 , 'tstring1': ['HELLO VIEW']
                 , 'tcarray1': [b'\x00\x00', b'\x01\x01']
         }}]
     }
 }

Following exceptions may be throw, when ATMI buffer is instantiated:

  • AtmiException with code: TPENOENT - view name in vname is not found.
  • UbfException with code: BEINVAL - invalid view field occurrance.
    BNOSPACE - no space in view field.

STRING Data encoding

STRING data buffer may contain arbitrary UTF-8 string. STRING buffer type is selected by following rules:

  • data key value is string (does not contain 0x00 byte) and buftype key is not present.

  • buftype key is set and contains STRING keyword.

STRING buffer encoding call
 tperrno, tpurcode, retbuf = e.tpcall("ECHO", { "data":"HELLO WORLD" })

 print(retbuf)
STRING buffer encoding output
 {'buftype': 'STRING', 'data': 'HELLO WORLD'}

CARRAY Data encoding

CARRAY buffer type may transport arbitrary byte array. CARRAY buffer type is selected by following rules:

  • data key value is byte array and buftype key is not present.

  • data key value is byte array and buftype is set to CARRAY.

CARRAY buffer encoding call
 import endurox as e

 tperrno, tpurcode, retbuf = e.tpcall("ECHO", { "data":b'\x00\x00\x01\x02\x04' })

 print(retbuf)
CARRAY buffer encoding output
 {'buftype': 'CARRAY', 'data': b'\x00\x00\x01\x02\x04'}

NULL Data encoding

NULL buffers are empty dictionaries, selected by following rules:

  • data key value is empty dictionary and buftype key is not present.

  • data key value is empty dictionary and buftype is set to NULL.

NULL buffer encoding call
 import endurox as e

 tperrno, tpurcode, retbuf = e.tpcall("ECHO", {})

 print(retbuf)
NULL buffer encoding output
 {'buftype': 'NULL'}

JSON Data encoding

JSON buffer type basically is valid UTF-8 string, but with indication that it contains json formatted data. JSON buffer is selected by following rules:

  • data is string value and buftype is set to JSON.

JSON buffer encoding call
 import endurox as e

 tperrno, tpurcode, retbuf = e.tpcall("ECHO", { "buftype":"JSON", "data":'{"name":"Jim", "age":30, "car":null}'})

 print(retbuf)
JSON buffer encoding output
 {'buftype': 'JSON', 'data': '{"name":"Jim", "age":30, "car":null}'}

VIEW Data encoding

VIEW buffer encodes record/structure data. On the Python side data is encoded in dictionary, and similarly as with UBF, values may be set as direct values for the dictionary keys (and are loaded into occurrence 0 of the view field). Or lists may be used to encode values, if the view field is array, in such case values are loaded in corresponding occurrences.

When Python code receives VIEW buffer, any NULL fields (as set by NULL_VAL see viewfile(5)) are not converted to Python dictionary values, except in case if NULLs proceed valid array values.

For received buffers all values are encapsulated in lists.

VIEW buffer type is selected by following rules:

  • buftype is set to VIEW, subtype is set to valid view name and data is dictionary.

VIEW buffer encoding call
 import endurox as e

 tperrno, tpurcode, retbuf = e.tpcall("ECHO", { "buftype":"VIEW", "subtype":"UBTESTVIEW2", "data":{
     "tshort1":5
     , "tlong1":100000
     , "tchar1":"J"
     , "tfloat1":9999.9
     , "tdouble1":11119999.9
     , "tstring1":"HELLO VIEW"
     , "tcarray1":[b'\x00\x00', b'\x01\x01']
 }})

 print(retbuf)
VIEW buffer encoding output
 {
     'buftype': 'VIEW', 'subtype': 'UBTESTVIEW2', 'data':
     {
         'tshort1': [5]
         , 'tlong1': [100000]
         , 'tchar1': ['J']
         , 'tfloat1': [9999.900390625]
         , 'tdouble1': [11119999.9]
         , 'tstring1': ['HELLO VIEW']
         , 'tcarray1': [b'\x00\x00', b'\x01\x01']
     }
 }

CALL-INFO ATMI buffer association

Call-info block is additional UBF buffer that may be linked with Any ATMI buffer (except NULL buffer). The concept behind with call-info block is similar like HTTP headers information, i.e. additional data linked to the message body.

Call info example
 import endurox as e

 tperrno, tpurcode, retbuf = e.tpcall("ECHO", {
         "data":"HELLO STRING"
         , "callinfo":{"T_SHORT_FLD":55, "T_STRING_FLD":"HELLO"}
     })
 print(retbuf)
Call info example
 {'buftype': 'STRING', 'data': 'HELLO STRING'
     , 'callinfo': {'T_SHORT_FLD': [55], 'T_STRING_FLD': ['HELLO']}}

Flags

Flags to service routines

endurox.TPNOBLOCK

Non-blocking send/rcv

endurox.TPSIGRSTRT

Restart rcv on interrupt

endurox.TPNOREPLY

No reply expected

endurox.TPNOTRAN

Not sent in transaction mode

endurox.TPTRAN

Sent in transaction mode

endurox.TPNOTIME

No timeout

endurox.TPABSOLUTE

Absolute value on tmsetprio

endurox.TPGETANY

Get any valid reply

endurox.TPNOCHANGE

Force incoming buffer to match

endurox.RESERVED_BIT1

Reserved for future use

endurox.TPCONV

Conversational service

endurox.TPSENDONLY

Send-only mode

endurox.TPRECVONLY

Recv-only mode

endurox.TPREGEXMATCH

Match by regular expression.

endurox.TPTRANSUSPEND

Suspend global transaction.

endurox.TPNOABORT

Do not abort global transaction in case of failure.

Flags to tpreturn

endurox.TPFAIL

Service FAILURE for tpreturn

endurox.TPEXIT

Service FAILURE with server exit

endurox.TPSUCCESS

Service SUCCESS for tpreturn

Flags to tpsblktime/tpgblktime

endurox.TPBLK_SECOND

This flag sets the blocktime value, in seconds. This is default behavior.

endurox.TPBLK_NEXT

This flag sets the blocktime value for the next potential blocking API.

endurox.TPBLK_ALL

This flag sets the blocktime value for the all subsequent potential blocking APIs.

Flags to tpenqueue/tpdequeue

endurox.TPQCORRID

Set/get correlation id

endurox.TPQFAILUREQ

Set/get failure queue

endurox.TPQBEFOREMSGID

Enqueue before message id

endurox.TPQGETBYMSGIDOLD

Deprecated, RFU

endurox.TPQMSGID

Get msgid of enq/deq message

endurox.TPQPRIORITY

Set/get message priority, RFU

endurox.TPQTOP

Enqueue at queue top, RFU

endurox.TPQWAIT

Wait for dequeuing, RFU

endurox.TPQREPLYQ

Set/get reply queue, RFU

endurox.TPQTIME_ABS

Set absolute time, RFU

endurox.TPQTIME_REL

Set absolute time, RFU

endurox.TPQGETBYCORRIDOLD

Deprecated, RFU

endurox.TPQPEEK

Peek

endurox.TPQDELIVERYQOS

Delivery quality of service, RFU

endurox.TPQREPLYQOS

Reply message quality of service, RFU

endurox.TPQEXPTIME_ABS

Absolute expiration time, RFU

endurox.TPQEXPTIME_REL

Relative expiration time, RFU

endurox.TPQEXPTIME_NONE

Never expire, RFU

endurox.TPQGETBYMSGID

Dequeue by msgid

endurox.TPQGETBYCORRID

Dequeue by corrid

endurox.TPQQOSDEFAULTPERSIST

Queue’s default persistence policy

endurox.TPQQOSPERSISTENT

Disk message, RFU

endurox.TPQQOSNONPERSISTENT

Memory message, RFU

Flags to tpsubscribe/tpunsubscribe (TPEVCTL.flags)

endurox.TPEVSERVICE

Must be present when ATMI server subscribes to event.

endurox.TPEVPERSIST

Do not unsubscribe from event in case if service failed when event was delivered.

endurox.TPEVQUEUE

RFU.

endurox.TPEVTRAN

RFU.

Events returned by conversational API

endurox.TPEV_DISCONIMM

Immediate disconnect event.

endurox.TPEV_SVCERR

Server died or tpreturn() failed.

endurox.TPEV_SVCFAIL

Server returned TPFAIL with tpreturn().

endurox.TPEV_SVCSUCC

Server returned with success.

endurox.TPEV_SENDONLY

Sender puts receiving party in sender mode.

Flags for tplogqinfo() input and return

endurox.TPLOGQI_GET_NDRX

Query logging information about NDRX topic.

endurox.TPLOGQI_GET_UBF

Query logging information about UBF topic.

endurox.TPLOGQI_GET_TP

Query logging information about TP topic.

endurox.TPLOGQI_EVAL_RETURN

Evaluate request regardless of log level.

endurox.TPLOGQI_RET_HAVDETAILED

Detailed flag have been set for logger.

Error Codes

This section lists error codes used in API interface.

ATMI Errors

Atmi Errors are thrown in AtmiException object. Following constants may be set in code field.

Error code values are given for reference reasons only. The codes may change in future without a notice.

endurox.TPMINVAL

0 - Minimum error, no error.

endurox.TPEABORT

1 - Transaction aborted.

endurox.TPEBADDESC

2 - Bad descriptor.

endurox.TPEBLOCK

3 - Blocking condition found but resource is configured as non blocking (e.g. flag TPNOBLOCK was passed).

endurox.TPEINVAL

4 - Invalid arguments.

endurox.TPELIMIT

5 - Limit reached.

endurox.TPENOENT

6 - No entry.

endurox.TPEOS

7 - Operating system error.

endurox.TPEPERM

8 - Permissions error.

endurox.TPEPROTO

9 - Protocol error. Invalid call sequence.

endurox.TPESVCERR

10 - Service crashed.

endurox.TPESVCFAIL

11 - Service user code failed.

endurox.TPESYSTEM

12 - Enduro/X system error.

endurox.TPETIME

13 - Call timed out.

endurox.TPETRAN

14 - Transaction error.

endurox.TPGOTSIG

15 - Got signal.

endurox.TPERMERR

15 - Resource manager error.

endurox.TPEITYPE

17 - Input ATMI buffer error.

endurox.TPEOTYPE

18 - Output ATMI buffer error.

endurox.TPERELEASE

19 - Invalid release version.

endurox.TPEHAZARD

20 - Partial transaction commit/abort error.

endurox.TPEHEURISTIC

21 - Partial transaction commit/abort error.

endurox.TPEEVENT

22 - Event occurred.

endurox.TPEMATCH

23 - Matching identifier, duplicate.

endurox.TPEDIAGNOSTIC

24 - Diagnostic error returned in TPQCTL.diagnostic.

endurox.TPEMIB

25 - RFU.

UBF Errors

Unified Buffer Format (UBF) errors are thrown in UbfException object. Following constants may be set in code field.

Error code values are given for reference reasons only. The codes may change in future without a notice.

endurox.BMINVAL

0 - Minimum error, no error.

endurox.BERFU0

1 - Reserved for future use.

endurox.BALIGNERR

2 - Buffer not aligned to platform address or corrupted.

endurox.BNOTFLD

3 - Buffer not fielded / TLV formatted.

endurox.BNOSPACE

4 - No space in buffer.

endurox.BNOTPRES

5 - Field not present.

endurox.BBADFLD

6 - Bad field ID.

endurox.BTYPERR

7 - Bad field type.

endurox.BEUNIX

8 - System error occurred.

endurox.BBADNAME

9 - Bad field name.

endurox.BMALLOC

10 - Malloc failed, out of mem?

endurox.BSYNTAX

11 - UBF Boolean expression error or UBF bad text format.

endurox.BFTOPEN

12 - Failed to open field tables.

endurox.BFTSYNTAX

13 - Field table syntax error.

endurox.BEINVAL

14 - Invalid value.

endurox.BERFU1

15 - Reserved for future use.

endurox.BBADTBL

16 - Reserved for future use.

endurox.BBADVIEW

17 - Invalid compiled VIEW file.

endurox.BVFSYNTAX

18 - Source VIEW file syntax error.

endurox.BVFOPEN

19 - Failed to open VIEW file.

endurox.BBADACM

20 - Reserved for future use.

endurox.BNOCNAME

21 - Structure field not found for VIEW.

endurox.BEBADOP

22 - Buffer operation not supported (complex type).

endurox.BMAXVAL

22 - Maximum error code.

Enduro/X standard errors

Enduro/X standard library errors are thrown in NstdException object. Following constants may be set in code field.

Error code values are given for reference reasons only. The codes may change in future without a notice.

endurox.NMINVAL

0 - Minimum error code.

endurox.NEINVALINI

1 - Invalid INI file.

endurox.NEMALLOC

2 - Malloc failed.

endurox.NEUNIX

3 - Unix error occurred.

endurox.NEINVAL

4 - Invalid value passed to function.

endurox.NESYSTEM

5 - System failure.

endurox.NEMANDATORY

6 - Mandatory field is missing.

endurox.NEFORMAT

7 - Format error.

endurox.NETOUT

8 - Time-out condition.

endurox.NENOCONN

9 - Connection not found.

endurox.NELIMIT

10 - Limit reached.

endurox.NEPLUGIN

11 - Plugin error.

endurox.NENOSPACE

12 - No space.

endurox.NEINVALKEY

13 - Invalid key (probably).

endurox.NENOENT

14 - No such file or directory.

endurox.NEWRITE

15 - Failed to open/write.

endurox.NEEXEC

16 - Failed to execute.

endurox.NESUPPORT

17 - Command not supported.

endurox.NEEXISTS

18 - Duplicate action.

endurox.NEVERSION

19 - API version conflict.

endurox.NMAXVAL

19 - Maximum error code.

Persistent queue errors

Following TPQCTL.diagnostic (QmException.code) codes may be returned.

Error code values are given for reference reasons only. The codes may change in future without a notice.

endurox.QMEINVAL

-1 - Invalid data.

endurox.QMEBADRMID

-2 - RFU.

endurox.QMENOTOPEN

-3 - RFU.

endurox.QMETRAN

-4 - RFU.

endurox.QMEBADMSGID

-5 - RFU.

endurox.QMESYSTEM

-6 - System error.

endurox.QMEOS

-7 - OS error.

endurox.QMEABORTED

-8 - RFU.

endurox.QMENOTA

-8 - RFU.

endurox.QMEPROTO

-9 - RFU.

endurox.QMEBADQUEUE

-10 - Bad queue name.

endurox.QMENOMSG

-11 - No messages in queue.

endurox.QMEINUSE

-12 - RFU.

endurox.QMENOSPACE

-13 - RFU.

endurox.QMERELEASE

-14 - RFU.

endurox.QMEINVHANDLE

-15 - RFU.

endurox.QMESHARE

-16 - RFU.

Other constants

This section lists other constants used in the Enduro/X Python module.

Log levels

endurox.log_always

2 - Fatal loging level.

endurox.log_error

2 - Error loging level.

endurox.log_warn

3 - Warning logging level.

endurox.log_info

4 - Info logging level.

endurox.log_debug

5 - Debug logging level.

endurox.log_dump

6 - Unofficial log level, dump.

Logging topics aka facilities

endurox.LOG_FACILITY_NDRX

Process level, Enduro/X core logging topic.

endurox.LOG_FACILITY_UBF

Process level, Enduro/X UBF library logging topic.

endurox.LOG_FACILITY_TP

Process level, user logging topic.

endurox.LOG_FACILITY_NDRX_THREAD

Thread level, Enduro/X core logging topic.

endurox.LOG_FACILITY_UBF_THREAD

Thread level, Enduro/X UBF library logging topic.

endurox.LOG_FACILITY_TP_THREAD

Thread level, user logging topic.

endurox.LOG_FACILITY_NDRX_REQUEST

Request logging (per context), Enduro/X core logging topic.

endurox.LOG_FACILITY_UBF_REQUEST

Request logging (per context), Enduro/X UBF library logging topic.

endurox.LOG_FACILITY_TP_REQUEST

Request logging (per context), user logging topic.

Transaction completion

endurox.TP_CMT_LOGGED

Return from commit when logged.

endurox.TP_CMT_COMPLETE

Return from commit when fully complete.

Transaction completion

endurox.TPMULTICONTEXTS

Atmi context was intialized.

endurox.TPNULLCONTEXT

Atmi context as not initialized.

MIB interface

endurox.TAOK

Value for TA_ERROR, success.

endurox.TAUPDATED

Value for TA_ERROR, success, data updated.

endurox.TAPARTIAL

Value for TA_ERROR, Partial succeed, have updates.

Generic status codes

endurox.EXSUCCEED

Success

endurox.EXFAIL

Failure

Key Classes

This section describes key classes used by Enduro/X API.

TPSVCINFO

This class is used to deliver call information to the service. Object of this class is received after the self (Server instance) argument.

class endurox.TPSVCINFO

Service call information.

name

str – Service name invoked.

fname

str – Function name invoked

flags

int – Matches flags set by service caller (e.g. tpcall())

appkey

int – RFU.

cd

int – Call descriptor as seen by caller.

cltid

CLIENTID – Client ID making a call. May be used for tpnotify()

data

dict – XATMI data buffer.

TPQCTL

This class is used to pass/receive additional information to/from tpenqueue() and tpdequeue() module function.

class endurox.TPQCTL

Persistent queue API control class

flags

int – See bellow flags

deq_time

int – RFU

msgid
bytes – is assigned by Enduro/X when message is enqueued.

Message id is 32 bytes long. When doing dequeue, may specify message id to read from Q.

diagnostic

int – See exception codes bellow.

diagmsg

str – Diagnostic messages. Used in QmException.

priority

int – RFU.

corrid

bytes – is correlator between messages. ID is 32 bytes long.

urcode

int – RFU.

cltid

CLIENTID – RFU.

replyqueue
str – is queue name where automatic queues may post the

response provided by destination service.

failurequeue
str – is queue name where failed message

(destination automatic service failed all attempts) are enqueued.

delivery_qos

int – RFU.

reply_qos

int – RFU.

exp_time

int – RFU.

Following TPQCTL.flags are supported on Enduro/X platform: TPQCORRID, TPQGETBYCORRID, TPQGETBYMSGID, TPQREPLYQ and TPQFAILUREQ.

TPEVCTL

Class used to control event subscription for the ATMI servers. Used by tpsubscribe() and tpunsubscribe().

class endurox.TPEVCTL

Event control class

flags

int – Bitwise flags of: TPEVSERVICE and TPEVPERSIST.

name1

str – Data field 1

name2

str – Data field 2

PyTpSrvCtxtData

Class is used for holding the XATMI server context, used by tpsrvgetctxdata() and tpsrvsetctxdata().

class endurox.PyTpSrvCtxtData(pyctxt: bytes)

XATMI Server Context transfer type.

pyctxt
pyctxt – Serialized XATMI server context. This value may be tranfered to other

threads or processes. If transfering to other process than Enduro/X Python code, remember to use TPNOAUTBUF flag there for tpsrvsetctxdata() call.

class endurox.UbfDict(*args, **kwargs)

UBF Based dictionary, direct access to fields without full transformation. When using UbfDict there are some considerations to take:

  1. In case if using BFLD_PTR only one UBF buffer may hold the reference when

    the buffer are garbage collected. As when XATMI buffer is freed it removes any ptrs inside the buffer. When assinging free standing UbfDict object to the BFLD_PTR field of some UBF buffer, the free standing buffer is marked as ptr kind sub-buffer for which GC is disabled.

  2. If different buffers reference the he same buffer via BFLD_PTR, then programmer

    is responsible for having the buffer alive (not freed).

  3. If using BFLD_UBF sub-buffers and having the UbfDict reference to it,

    programmer is responsible for having the main buffer (for which given field is subfield) alive and not changed, as when accessing to the BFLD_UBF subfield the UbfDict is allocated with C pointer to the data offset in the main bufer.

__contains__(key)

Check the UBF field is present in UBF buffer

Returns:

resultTrue if present, False if not

Return type:

bool

__copy__()

Make deep copy of the UBF buffer.

Returns:

ret – Newly allocated buffer with data from the original buffer.

Return type:

UbfDict

__deepcopy__(memodict={})

Make deep copy of the UBF buffer.

Returns:

ret – Newly allocated buffer with data from the original buffer.

Return type:

UbfDict

__del__()

Free linked XATMI buffer.

__delattr__(name)

Delete UBF field occurrence

Parameters:

name (str) – field name to remove from buffer (delete all occurrences).

Raises:
  • IndexError – Invalid index specified (occurrence not present)

  • AttributeError – Read only buffer (sub-UBF)

  • UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF. BBADFLD - Invalid field ID given (normally would not be thrown).

__delitem__(key)

Delete key from UbfDict. This removes all occurrences of the key from the UBF buffer.

Parameters:

key (str or int) – Field name (str) or field id (int)

Raises:

UbfException – Following error codes may be present: BALIGNERR Corrupted buffer or pointing to not aligned memory area. BNOTFLD Buffer not fielded, not correctly allocated or corrupted. BBADFLD Invalid field id passed. BNOTPRES Field not present thus not deleted.

__eq__(other)

Compare two UbfDict object. The comparator also accepts the Python standard dict object.

Parameters:

other (UbfDict or dict.) – Reference to UbfDict or dict object to compare.

Returns:

ret – True if buffers matches, False if not.

Return type:

bool

__getattr__(attr)

Access to UBF field values as of class attributes. Attributed names __is_sub_buffer and _buf are reserved for internal purpose only. If such name shall be read from UBF buffer, access them by UbfDict.__getitem__() (i.e. index access by the key).

Returns:

ret – Initialized dictionary field is returned (ready for occurrence access).

Return type:

UbfDictFld

Raises:

UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF.

__getitem__(key)

Return initialized UbfDictFld object which allows to access to field occurrences. This method by itself does not validate that field is present in UBF buffer, instead it resolves the field identifier and returns the UbfDictFld with the field id and reference to given UbfDict object.

Parameters:

key (object) – Field name (str) or field id (int)

Returns:

ret – initialized UBF Dictionary Field.

Return type:

UbfDictFld

Raises:

UbfException – Following error codes may be present: BFTOPEN - Failed to open field definition files. BBADNAME - Field not found.

__init__(*args, **kwargs)

Initialize UbfDict object. This normally allocates XATMI buffer linked to given object and buffer being initialized by passed in value.

Parameters:
  • args (object) – If only one argument is passed and it is UbfDict typed, then value then buffer is copied from UbfDict param. If value type is bool with value False, no buffer is allocated. If param is dictionary, then buffer is initialised from dictionary. If value

  • kwargs (object) – Used for building dictionary argument for buffer initialization.

Returns:

ret – Python UbfDict object.

Return type:

UbfDict

Raises:
  • UbfException – Following error codes may be present: BFTOPEN - Failed to open field definition files. BBADNAME - Field not found. BALIGNERR - Corrupted buffer or pointing to not aligned memory area. BNOTFLD - Buffer not fielded, not correctly allocated or corrupted. p_ub is NUL BALIGNERR - Corrupted buffer or pointing to not aligned memory area. BNOSPACE - No space in buffer for string data (not likely to be throw).

  • AtmiException – Following error codes may be present: TPEINVAL - Enduro/X is not configured or buffer pointer is NULL or not allocated by tpalloc(), invalid environment. TPENOENT - Invalid type specified to function. (not likely to be throw) TPESYSTEM - System failure occurred during serving. See logs i.e. user log, or debugs for more info. TPEOS - System failure occurred during serving. See logs i.e. user log, or debugs for more info.

__iter__()

Start iteration over the dictionary.

__len__()

Return number if keys in UbfDict object.

Returns:

ret – Number of unique keys / fieldids in the buffer.

Return type:

int

Raises:

UbfException – Following error codes may be present: ????

__next__()

Return next key in the UBF buffer. This lists only unique keys.

__repr__()

Returns UBF buffer representation in dictionary initialization format.

Returns:

ret – Returns buffer in dictionary string form

Return type:

str

Raises:

UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF.

__setattr__(attr, value)

Set UBF field value as an attribute. Note that two names are reserved for this purpose: __is_sub_buffer and _buf, which are internal use members and for these values must not be changed. If such name shall be stored in UBF buffer, access them by UbfDict.__setitem__() (i.e. index access by the key).

Parameters:
  • attr (str) – Field name

  • value (object) – Single value or list of values. Depending on the field type, the value can be str, int, double, byte array, or dictionary (in case of BFLD_UBF, BFLD_PTR or BFLD_VIEW) and UbfDict in case of BFLD_UBF.

Returns:

ret – Python dictionary.

Return type:

dict

Raises:
  • AttributeError – If given buffer is sub-buffer (sub-UBF), values of the buffer is read only.

  • ValueError – Given value cannot be converted to UBF format.

  • UbfException – Following error codes may be present: BALIGNERR Corrupted buffer or pointing to not aligned memory area.     :data:.BNOTFLD Buffer not fielded, not correctly allocated or corrupted. BFTOPEN - Failed to open field definition files. BBADNAME - Field not found.

  • AtmiExceptionBBADNAME - Field not found. TPEINVAL Invalid ptr pointer passed in. Either buffer not allocated by tpalloc() or ptr is NULL. TPEOS System failure occurred during serving. See logs i.e. user log, or debugs for more info.

__setitem__(key, value)

Set field value. Either single occurrence value or list of values. For performance reasons, note that this does not delete existing fields, the existing matching occurrences are replaced. If buffer exists more occurrences than setting, those will not be changed, nor deleted. If full replacement of the field is required, firstly delete the key.

Parameters:
  • key (str or int) – Key to set

  • value (object) – Single value or list of values. Depending on the field type, the value can be str, int, double, byte array, or dictionary (in case of BFLD_UBF, BFLD_PTR or BFLD_VIEW) and UbfDict in case of BFLD_UBF.

Raises:
  • AttributeError – If given buffer is sub-buffer (sub-UBF), values of the buffer is read only.

  • ValueError – Given value cannot be converted to UBF format.

  • UbfException – Following error codes may be present: BALIGNERR Corrupted buffer or pointing to not aligned memory area.     :data:.BNOTFLD Buffer not fielded, not correctly allocated or corrupted. BFTOPEN - Failed to open field definition files. BBADNAME - Field not found.

  • AtmiExceptionBBADNAME - Field not found. TPEINVAL Invalid ptr pointer passed in. Either buffer not allocated by tpalloc() or ptr is NULL. TPEOS System failure occurred during serving. See logs i.e. user log, or debugs for more info.

free()

Free linked XATMI buffer. Does nothing for sub-ubf buffers.

items()

Returns object for iterating over the buffer in form of key/value.

Returns:

ret – Iterator for key/value loop over the buffer. Value returned contains the list of field occurrences.

Return type:

UbfDictItems

itemsocc()

Returns object for iterating over the buffer in form of key/value. The values returns here each field occurrences. During the iteration if field have several occurrences, then the same key is returned several times, for each of the occurrence of the given key value.

Returns:

ret – Iterator for key/value loop over the buffer. Value returned contains the end value present in every field occurrences.

Return type:

UbfDictItemsOcc

to_dict()

Convert given UbfDict object to Python standard dictionary.

Returns:

ret – Python dictionary.

Return type:

dict

Raises:

UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF.

class endurox.UbfDictFld

Access to UBF field dictionary. Provides list-like interface for UBF buffer field occurrences

__delitem__(i)

Delete UBF field occurrence

Parameters:

i (int) – Index/occurrence to delete

Raises:
  • IndexError – Invalid index specified (occurrence not present)

  • AttributeError – Read only buffer (sub-UBF)

  • UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF. BBADFLD - Invalid field ID given (normally would not be thrown).

__eq__(other)

Compare this field value with other field. The other field shall be standard list or UbfDictFld.

Parameters:
Returns:

ret – True if matched, False if not.

Return type:

bool

Raises:

UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF. BBADFLD - Invalid field ID given (normally would not be thrown).

__getitem__(i)

Get UBF dictionary field object

Parameters:

i (int) – Index/occurrence to get

Returns:

ret – Value from UBF buffer field.

Return type:

UbfDictFld

Raises:
  • IndexError – Invalid index specified

  • UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF.

__len__()

Return number field occurrences

Raises:

UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF. BBADFLD - Invalid field ID given (normally would not be thrown).

__repr__() str

Return the field/occurrence representation in standard list format. This transfers all UBF field occurrences to the standard Python list and standard list generates the representation.

Returns:

ret – UBF field representation in standard list format.

Return type:

str

Raises:

UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF. BBADFLD - Invalid field ID given (normally would not be thrown).

__setitem__(i, value)

Set UBF buffer field at given index

Parameters:
  • i (int) – Index/occurrence to set

  • value (object) – Value to set

Raises:

UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF. BBADFLD - Invalid field ID given (normally would not be thrown).

insert(i, value)

Set UBF buffer field at given index

Parameters:
  • i (int) – Index/occurrence to set

  • value (object) – Value to set

Raises:

UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD - Buffer not UBF. BBADFLD - Invalid field ID given (normally would not be thrown).

class endurox.UbfDictItems(ubf_dict)

Class provides UbfDict key/value iteration interface Object is created by UbfDict.items() method call.

__init__(ubf_dict)

Internal initialised

Parameters:

ubf_dict (UbfDict) – UBF Dictionary object to iterate over

__iter__()

Start iteration over the dictionary.

__next__()

Return next field from UBF buffer

Returns:

  • fname (str or int) – Field name, if not resolved int typed field id returned.

  • dictfld (UbfDictFld) – UbfDictFld allocated object.

  • UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD Buffer not fielded, not correctly allocated or corrupted.

class endurox.UbfDictItemsOcc(ubf_dict)

Class provides UbfDict key/value iteration interface Object is created by UbfDict.itemsocc() method call. This iterator returns each field occurrence value instead of the list of values as with UbfDictItems.

__init__(ubf_dict)

Internal initialised

Parameters:

ubf_dict (UbfDict) – UBF Dictionary object to iterate over

__iter__()

Start iteration over the dictionary.

__len__()

UBF Buffer length in number of fields in the buffer thus counts every occurrence o

Returns:

  • cnt (int) – Total number of fields present in UBF buffer.

  • UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD Buffer not fielded, not correctly allocated or corrupted.

__next__()

Return next field from UBF buffer

Returns:

  • fname (str or int) – Field name, if not resolved int typed field id returned.

  • dictfld (object) – Actual field value.

  • UbfException – Following error codes may be present: BALIGNERR - Corrupted UBF buffer. BNOTFLD Buffer not fielded, not correctly allocated or corrupted.