Skip to content

Commit 4ec7685

Browse files
Added support for grouping notifications from subscriptions.
1 parent bab41ac commit 4ec7685

File tree

6 files changed

+86
-14
lines changed

6 files changed

+86
-14
lines changed

doc/src/connection.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ Connection Object
480480
This attribute is an extension to the DB API definition.
481481

482482

483-
.. method:: Connection.subscribe(namespace=cx_Oracle.SUBSCR_NAMESPACE_DBCHANGE, protocol=cx_Oracle.SUBSCR_PROTO_OCI, callback=None, timeout=0, operations=OPCODE_ALLOPS, port=0, qos=0, ipAddress=None)
483+
.. method:: Connection.subscribe(namespace=cx_Oracle.SUBSCR_NAMESPACE_DBCHANGE, protocol=cx_Oracle.SUBSCR_PROTO_OCI, callback=None, timeout=0, operations=OPCODE_ALLOPS, port=0, qos=0, ipAddress=None, groupingClass=0, groupingValue=0, groupingType=cx_Oracle.SUBSCR_GROUPING_TYPE_SUMMARY)
484484

485485
Return a new :ref:`subscription object <subscrobj>` using the connection.
486486
Currently the namespace and protocol parameters cannot have any other
@@ -498,9 +498,9 @@ Connection Object
498498
(insert, update, delete). The default value will send notifications for all
499499
operations.
500500

501-
The port specifies the listening port for callback notifications from the
502-
database server. If not specified, an unused port will be selected by the
503-
database.
501+
The port parameter specifies the listening port for callback notifications
502+
from the database server. If not specified, an unused port will be selected
503+
by the database.
504504

505505
The qos parameter specifies quality of service options. It should be one or
506506
more of the following flags, OR'ed together:
@@ -510,9 +510,20 @@ Connection Object
510510
:data:`cx_Oracle.SUBSCR_QOS_QUERY`,
511511
:data:`cx_Oracle.SUBSCR_QOS_BEST_EFFORT`.
512512

513-
The ipAddress specifies the IP address (IPv4 or IPv6) to bind for callback
514-
notifications from the database server. If not specified, the client IP
515-
address will be determined by the Oracle Client libraries.
513+
The ipAddress parameter specifies the IP address (IPv4 or IPv6) to bind for
514+
callback notifications from the database server. If not specified, the
515+
client IP address will be determined by the Oracle Client libraries.
516+
517+
The groupingClass parameter specifies what type of grouping of
518+
notifications should take place. Currently, if set, this value can only be
519+
set to the value :data:`cx_Oracle.SUBSCR_GROUPING_CLASS_TIME`, which
520+
will group notifications by the number of seconds specified in the
521+
groupingValue parameter. The groupingType parameter should be one of the
522+
values :data:`cx_Oracle.SUBSCR_GROUPING_TYPE_SUMMARY` (the default) or
523+
:data:`cx_Oracle.SUBSCR_GROUPING_TYPE_LAST`.
524+
525+
*New in version 6.4:* The parameters ipAddress, groupingClass,
526+
groupingValue and groupingType were added.
516527

517528
.. note::
518529

doc/src/module.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,39 @@ in database resident connection pooling (DRCP).
781781
need not be new and may have prior session state.
782782

783783

784+
Subscription Grouping Classes
785+
-----------------------------
786+
787+
These constants are extensions to the DB API definition. They are possible
788+
values for the groupingClass parameter of the :meth:`Connection.subscribe()`
789+
method.
790+
791+
.. data:: SUBSCR_GROUPING_CLASS_TIME
792+
793+
This constant is used to specify that events are to be grouped by the
794+
period of time in which they are received.
795+
796+
797+
Subscription Grouping Types
798+
---------------------------
799+
800+
These constants are extensions to the DB API definition. They are possible
801+
values for the groupingType parameter of the :meth:`Connection.subscribe()`
802+
method.
803+
804+
.. data:: SUBSCR_GROUPING_TYPE_SUMMARY
805+
806+
This constant is used to specify that when events are grouped a summary of
807+
the events should be sent instead of the individual events. This is the
808+
default value.
809+
810+
.. data:: SUBSCR_GROUPING_TYPE_LAST
811+
812+
This constant is used to specify that when events are grouped the last
813+
event that makes up the group should be sent instead of the individual
814+
events.
815+
816+
784817
Subscription Namespaces
785818
-----------------------
786819

src/cxoConnection.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,21 +1456,28 @@ static PyObject *cxoConnection_subscribe(cxoConnection *conn, PyObject* args,
14561456
PyObject* keywordArgs)
14571457
{
14581458
static char *keywordList[] = { "namespace", "protocol", "callback",
1459-
"timeout", "operations", "port", "qos", "ipAddress", NULL };
1459+
"timeout", "operations", "port", "qos", "ipAddress",
1460+
"groupingClass", "groupingValue", "groupingType", NULL };
14601461
uint32_t namespace, protocol, port, timeout, operations, qos;
1462+
uint8_t groupingClass, groupingType;
14611463
PyObject *callback, *ipAddress;
1464+
uint32_t groupingValue;
14621465

1463-
timeout = port = qos = 0;
1466+
groupingClass = 0;
14641467
callback = ipAddress = NULL;
1468+
timeout = port = qos = groupingValue = 0;
1469+
groupingType = DPI_SUBSCR_GROUPING_TYPE_SUMMARY;
14651470
namespace = DPI_SUBSCR_NAMESPACE_DBCHANGE;
14661471
protocol = DPI_SUBSCR_PROTO_CALLBACK;
14671472
operations = DPI_OPCODE_ALL_OPS;
1468-
if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "|iiOiiiiO",
1473+
if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "|iiOiiiiObib",
14691474
keywordList, &namespace, &protocol, &callback, &timeout,
1470-
&operations, &port, &qos, &ipAddress))
1475+
&operations, &port, &qos, &ipAddress, &groupingClass,
1476+
&groupingValue, &groupingType))
14711477
return NULL;
14721478
return (PyObject*) cxoSubscr_new(conn, namespace, protocol, ipAddress,
1473-
port, callback, timeout, operations, qos);
1479+
port, callback, timeout, operations, qos, groupingClass,
1480+
groupingValue, groupingType);
14741481
}
14751482

14761483

src/cxoModule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,16 @@ static PyObject *cxoModule_initialize(void)
439439
CXO_ADD_INT_CONSTANT("SUBSCR_NAMESPACE_DBCHANGE",
440440
DPI_SUBSCR_NAMESPACE_DBCHANGE)
441441

442+
// add constants for subscription grouping classes
443+
CXO_ADD_INT_CONSTANT("SUBSCR_GROUPING_CLASS_TIME",
444+
DPI_SUBSCR_GROUPING_CLASS_TIME)
445+
446+
// add constants for subscription grouping types
447+
CXO_ADD_INT_CONSTANT("SUBSCR_GROUPING_TYPE_SUMMARY",
448+
DPI_SUBSCR_GROUPING_TYPE_SUMMARY)
449+
CXO_ADD_INT_CONSTANT("SUBSCR_GROUPING_TYPE_LAST",
450+
DPI_SUBSCR_GROUPING_TYPE_LAST)
451+
442452
// add constants for event types
443453
CXO_ADD_INT_CONSTANT("EVENT_NONE", DPI_EVENT_NONE)
444454
CXO_ADD_INT_CONSTANT("EVENT_STARTUP", DPI_EVENT_STARTUP)

src/cxoModule.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ struct cxoSubscr {
364364
uint32_t timeout;
365365
uint32_t operations;
366366
uint32_t qos;
367+
uint8_t groupingClass;
368+
uint32_t groupingValue;
369+
uint8_t groupingType;
367370
uint64_t id;
368371
};
369372

@@ -433,7 +436,8 @@ cxoObjectType *cxoObjectType_newByName(cxoConnection *connection,
433436
cxoSubscr *cxoSubscr_new(cxoConnection *connection, uint32_t namespace,
434437
uint32_t protocol, PyObject *ipAddress, uint32_t port,
435438
PyObject *callback, uint32_t timeout, uint32_t operations,
436-
uint32_t qos);
439+
uint32_t qos, uint8_t groupingClass, uint32_t groupingValue,
440+
uint8_t groupingType);
437441

438442
PyObject *cxoTransform_dateFromTicks(PyObject *args);
439443
int cxoTransform_fromPython(cxoTransformNum transformNum, PyObject *pyValue,

src/cxoSubscr.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ static void cxoSubscr_callback(cxoSubscr *subscr,
520520
cxoSubscr *cxoSubscr_new(cxoConnection *connection, uint32_t namespace,
521521
uint32_t protocol, PyObject *ipAddress, uint32_t port,
522522
PyObject *callback, uint32_t timeout, uint32_t operations,
523-
uint32_t qos)
523+
uint32_t qos, uint8_t groupingClass, uint32_t groupingValue,
524+
uint8_t groupingType)
524525
{
525526
dpiSubscrCreateParams params;
526527
cxoSubscr *subscr;
@@ -541,6 +542,9 @@ cxoSubscr *cxoSubscr_new(cxoConnection *connection, uint32_t namespace,
541542
subscr->timeout = timeout;
542543
subscr->operations = operations;
543544
subscr->qos = qos;
545+
subscr->groupingClass = groupingClass;
546+
subscr->groupingValue = groupingValue;
547+
subscr->groupingType = groupingType;
544548

545549
if (dpiContext_initSubscrCreateParams(cxoDpiContext, &params) < 0) {
546550
cxoError_raiseAndReturnNull();
@@ -566,6 +570,9 @@ cxoSubscr *cxoSubscr_new(cxoConnection *connection, uint32_t namespace,
566570
params.timeout = timeout;
567571
params.operations = operations;
568572
params.qos = qos;
573+
params.groupingClass = groupingClass;
574+
params.groupingValue = groupingValue;
575+
params.groupingType = groupingType;
569576
if (dpiConn_newSubscription(connection->handle, &params, &subscr->handle,
570577
&subscr->id) < 0) {
571578
cxoError_raiseAndReturnNull();

0 commit comments

Comments
 (0)