publish: function (request, callback) {
     assert(request._schema.name === "PublishRequest");
     // let simulate a server sending a PublishResponse for subscription:1
     // after a short delay of 150 milliseconds
     publishQueue.push(callback);
     //xx console.log("nbPendingPublishRequests",clientPublishEngine.nbPendingPublishRequests);
 }
    subscribe(target, callback, options = [], subId = '') {
        this.connect();

        if (subId === '') {
            subId = Random.hex()(Random.engines.nativeMath, 64);
        }

        if (this.connected) {
            return this.session.subscribe(target, callback, options).then(function(subscription) {
                this.client.subscriptionMap.set(this.subId, subscription);
                return this.subId;
            }.bind({
                client: this,
                subId:  subId,
            }));
        }

        let deferred = when.defer();

        this.queuedCalls.push(deferred);

        return deferred.promise.then(function() {
            return this.client.subscribe(this.target, this.callback, this.options);
        }.bind({
            client:   this,
            target:   target,
            callback: callback,
            options:  options,
        }));
    }
Пример #3
0
    flow.flows.forEach(function(f){
	if(deque.length<100000){
	    deque.push(formRecord(f));
	}else{
	    console.log("################ BUFFER OVERFLOWED!! ####################################");
	}
    })
Пример #4
0
    /**
     * extract up to maxNotificationsPerPublish notificiation into a Dequeue
     * @param monitoredItems
     * @param maxNotificationsPerPublish
     * @returns {Deque|exports|module.exports}
     */
    function extract_notifications_chunk(monitoredItems, maxNotificationsPerPublish) {
        var n = maxNotificationsPerPublish === 0 ?
            monitoredItems.length :
            Math.min(monitoredItems.length, maxNotificationsPerPublish);

        var chunk_monitoredItems = new Dequeue();
        while (n) {
            chunk_monitoredItems.push(monitoredItems.shift());
            n--;
        }
        return chunk_monitoredItems;
    }
Пример #5
0
 parentNodes.forEach(function(parent){
     if (sameNodeId(parent.nodeId,objectsFolder.nodeId)) {
         return ; // nothing to do
     }
     if (parent.nodeClass === NodeClass.View) {
         results.push(parent);
     } else {
         var key = parent.nodeId.toString();
         if (visitedMap.hasOwnProperty(key)) {
             return;
         }
         visitedMap[key] = parent;
         q.push(parent);
     }
 });
Пример #6
0
Subscription.prototype.collectDataChangeNotification = function(){

    var self = this;
    var all_notifications = new Dequeue();

    // visit all monitored items
    var keys = Object.keys(self.monitoredItems);
    keys.forEach(function(key){
       var monitoredItem = self.monitoredItems[key];
       var notifications = monitoredItem.extractMonitoredItemNotifications();
       all_notifications = all_notifications.concat(notifications);
    });

    assert(all_notifications instanceof Dequeue);

    function extract_monitoredItems(monitoredItems,maxNotificationsPerPublish) {

        var n = maxNotificationsPerPublish === 0 ?
                           monitoredItems.length :
                           Math.min(monitoredItems.length,maxNotificationsPerPublish);

        var chunk_monitoredItems = new Dequeue();
        while(n) {
            chunk_monitoredItems.push(monitoredItems.shift());
            n--;
        }
        return chunk_monitoredItems;
    }

    var dataChangeNotifications = new Dequeue();
    while (all_notifications.length > 0) {

        // split into one or multiple dataChangeNotification with no more than
        //  self.maxNotificationsPerPublish monitoredItems
        var chunk_monitoredItems = extract_monitoredItems(all_notifications,self.maxNotificationsPerPublish);
        var dataChangeNotification = new DataChangeNotification({
            monitoredItems: chunk_monitoredItems.toArray(),
            diagnosticInfos: []
        });
        assert(self.maxNotificationsPerPublish === 0 || dataChangeNotification.monitoredItems.length <= self.maxNotificationsPerPublish);
        //
        //xx console.log("xxxxxxxxx Pushing dataChangeNotifications ");
        //xx console.log("xxxxxxxxxxxxxxx                monitoredItems length = ".yellow,dataChangeNotification.monitoredItems.length);
        dataChangeNotifications.push(dataChangeNotification);
    }
    return dataChangeNotifications;
};
    unsubscribe(subId) {
        let subscription = this.subscriptionMap.get(subId);
        this.subscriptionMap.delete(subId);

        if (this.connected) {
            return this.session.unsubscribe(subscription);
        }

        let deferred = when.defer();
        this.queuedCalls.push(deferred);

        return deferred.promise.then(function() {
            this.client.unsubscribe(this.subscription);
        }.bind({
            client:       this,
            subscription: subscription,
        }));
    }
Пример #8
0
AddressSpace.prototype.extractRootViews = function(node) {

    var addressSpace = this;
    assert(node.nodeClass === NodeClass.Object || node.nodeClass === NodeClass.Variable);

    var Dequeue = require("collections/deque");
    var visitedMap ={};

    var q = new Dequeue();
    q.push(node);


    var objectsFolder = addressSpace.rootFolder.objects;
    assert(objectsFolder instanceof UAObject);

    var results = [];

    while(q.length) {
        node = q.shift();

        var references = node.findReferencesEx("HierarchicalReferences",BrowseDirection.Inverse);
        var parentNodes = references.map(function(r){
            return Reference._resolveReferenceNode(addressSpace,r);
        });

        parentNodes.forEach(function(parent){
            if (sameNodeId(parent.nodeId,objectsFolder.nodeId)) {
                return ; // nothing to do
            }
            if (parent.nodeClass === NodeClass.View) {
                results.push(parent);
            } else {
                var key = parent.nodeId.toString();
                if (visitedMap.hasOwnProperty(key)) {
                    return;
                }
                visitedMap[key] = parent;
                q.push(parent);
            }
        });
    }
    return results;
};
    rpc(target, args = []) {
        this.connect();

        if (this.connected) {
            return this.session.call(target, args);
        }

        let deferred = when.defer();

        this.queuedCalls.push(deferred);

        return deferred.promise.then(function() {
            return this.client.rpc(this.target, this.args);
        }.bind({
            client: this,
            target: target,
            args:   args,
        }));
    }
Пример #10
0
Subscription.prototype.collectNotificationData = function () {

    var self = this;
    var all_notifications = new Dequeue();

    // visit all monitored items
    var keys = Object.keys(self.monitoredItems);
    keys.forEach(function (key) {
        var monitoredItem = self.monitoredItems[key];
        var notifications = monitoredItem.extractMonitoredItemNotifications();
        all_notifications = all_notifications.concat(notifications);
    });
    assert(all_notifications instanceof Dequeue);

    /**
     * extract up to maxNotificationsPerPublish notificiation into a Dequeue
     * @param monitoredItems
     * @param maxNotificationsPerPublish
     * @returns {Deque|exports|module.exports}
     */
    function extract_notifications_chunk(monitoredItems, maxNotificationsPerPublish) {
        var n = maxNotificationsPerPublish === 0 ?
            monitoredItems.length :
            Math.min(monitoredItems.length, maxNotificationsPerPublish);

        var chunk_monitoredItems = new Dequeue();
        while (n) {
            chunk_monitoredItems.push(monitoredItems.shift());
            n--;
        }
        return chunk_monitoredItems;
    }

    var notificationsMessage = new Dequeue();

    function filter_instanceof(Class,e) {
        return (e instanceof Class);
    }

    while (all_notifications.length > 0) {

        // split into one or multiple dataChangeNotification with no more than
        //  self.maxNotificationsPerPublish monitoredItems
        var notifications_chunk = extract_notifications_chunk(all_notifications, self.maxNotificationsPerPublish);

        notifications_chunk = notifications_chunk.toArray();

        // separate data for DataChangeNotification (MonitoredItemNotification) from data for EventNotificationList(EventFieldList)
        var dataChangedNotificationData = notifications_chunk.filter(filter_instanceof.bind(null,subscription_service.MonitoredItemNotification));
        var eventNotificationListData = notifications_chunk.filter(filter_instanceof.bind(null,subscription_service.EventFieldList));
        assert(notifications_chunk.length === dataChangedNotificationData.length +  eventNotificationListData.length);



        var notifications = [];


        // add dataChangeNotification
        if (dataChangedNotificationData.length) {
            var dataChangeNotification = new DataChangeNotification({
                monitoredItems: dataChangedNotificationData,
                diagnosticInfos: []
            });
            notifications.push(dataChangeNotification);
        }

        // add dataChangeNotification
        if (eventNotificationListData.length) {
            var eventNotificationList = new EventNotificationList({
                events: eventNotificationListData
            });
            notifications.push(eventNotificationList);
        }

        assert(notifications.length === 1 || notifications.length === 2);
        notificationsMessage.push(notifications);
    }

    assert(notificationsMessage instanceof Dequeue);
    return notificationsMessage;
};