Пример #1
0
  void returnStatusChangeNotification(ServiceRequest<PublishRequest, PublishResponse> service) {
    StatusChangeNotification statusChange =
        new StatusChangeNotification(new StatusCode(StatusCodes.Bad_Timeout), null);

    UInteger sequenceNumber = uint(nextSequenceNumber());

    NotificationMessage notificationMessage =
        new NotificationMessage(
            sequenceNumber,
            new DateTime(),
            new ExtensionObject[] {ExtensionObject.encode(statusChange)});

    ResponseHeader header = service.createResponseHeader();

    PublishResponse response =
        new PublishResponse(
            header,
            subscriptionId,
            new UInteger[0],
            false,
            notificationMessage,
            new StatusCode[0],
            new DiagnosticInfo[0]);

    service.setResponse(response);

    logger.debug(
        "[id={}] returned StatusChangeNotification sequenceNumber={}.",
        subscriptionId,
        sequenceNumber);
  }
Пример #2
0
  private void sendNotifications(
      ServiceRequest<PublishRequest, PublishResponse> service, List<UaStructure> notifications) {

    List<MonitoredItemNotification> dataNotifications = Lists.newArrayList();
    List<EventFieldList> eventNotifications = Lists.newArrayList();

    notifications.forEach(
        notification -> {
          if (notification instanceof MonitoredItemNotification) {
            dataNotifications.add((MonitoredItemNotification) notification);
          } else if (notification instanceof EventFieldList) {
            eventNotifications.add((EventFieldList) notification);
          }
        });

    List<ExtensionObject> notificationData = Lists.newArrayList();

    if (dataNotifications.size() > 0) {
      DataChangeNotification dataChange =
          new DataChangeNotification(
              dataNotifications.toArray(new MonitoredItemNotification[dataNotifications.size()]),
              new DiagnosticInfo[0]);

      notificationData.add(ExtensionObject.encode(dataChange));
    }

    if (eventNotifications.size() > 0) {
      EventNotificationList eventChange =
          new EventNotificationList(
              eventNotifications.toArray(new EventFieldList[eventNotifications.size()]));

      notificationData.add(ExtensionObject.encode(eventChange));
    }

    UInteger sequenceNumber = uint(nextSequenceNumber());

    NotificationMessage notificationMessage =
        new NotificationMessage(
            sequenceNumber,
            new DateTime(),
            notificationData.toArray(new ExtensionObject[notificationData.size()]));

    availableMessages.put(notificationMessage.getSequenceNumber(), notificationMessage);
    UInteger[] available = getAvailableSequenceNumbers();

    UInteger requestHandle = service.getRequest().getRequestHeader().getRequestHandle();
    StatusCode[] acknowledgeResults = subscriptionManager.getAcknowledgeResults(requestHandle);

    ResponseHeader header = service.createResponseHeader();

    PublishResponse response =
        new PublishResponse(
            header,
            subscriptionId,
            available,
            moreNotifications,
            notificationMessage,
            acknowledgeResults,
            new DiagnosticInfo[0]);

    service.setResponse(response);

    logger.debug(
        "[id={}] returning {} DataChangeNotification(s) and {} EventNotificationList(s) sequenceNumber={}.",
        subscriptionId,
        dataNotifications.size(),
        eventNotifications.size(),
        sequenceNumber);
  }