예제 #1
0
    @Override
    public void handle(ServiceRequest<GetEndpointsRequest, GetEndpointsResponse> service)
        throws UaException {
      GetEndpointsRequest request = service.getRequest();

      String endpointUrl = request.getEndpointUrl();
      if (endpointUrl == null) endpointUrl = "";

      UaTcpStackServer server = servers.get(endpointUrl);

      EndpointDescription[] endpoints =
          (server != null) ? server.getEndpointDescriptions() : new EndpointDescription[0];

      List<String> profileUris =
          request.getProfileUris() != null
              ? Lists.newArrayList(request.getProfileUris())
              : Lists.newArrayList();

      EndpointDescription[] filtered =
          Arrays.stream(endpoints)
              .filter(ed -> filterProfileUris(ed, profileUris))
              .filter(this::filterEndpointUrls)
              .toArray(EndpointDescription[]::new);

      service.setResponse(new GetEndpointsResponse(service.createResponseHeader(), filtered));
    }
예제 #2
0
    @Override
    public void handle(ServiceRequest<FindServersRequest, FindServersResponse> service)
        throws UaException {
      FindServersRequest request = service.getRequest();

      List<ApplicationDescription> servers = Lists.newArrayList();
      List<String> serverUris = Lists.newArrayList(request.getServerUris());

      for (UaTcpStackServer server : registered) {
        ApplicationDescription description = server.getApplicationDescription();

        if (serverUris.isEmpty()) {
          servers.add(description);
        } else {
          if (serverUris.contains(description.getApplicationUri())) {
            servers.add(description);
          }
        }
      }

      ResponseHeader header = service.createResponseHeader();
      FindServersResponse response =
          new FindServersResponse(
              header, servers.toArray(new ApplicationDescription[servers.size()]));

      service.setResponse(response);
    }
예제 #3
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);
  }
예제 #4
0
  private void returnKeepAlive(ServiceRequest<PublishRequest, PublishResponse> service) {
    ResponseHeader header = service.createResponseHeader();

    UInteger sequenceNumber = uint(currentSequenceNumber());

    NotificationMessage notificationMessage =
        new NotificationMessage(sequenceNumber, DateTime.now(), new ExtensionObject[0]);

    UInteger[] available = getAvailableSequenceNumbers();

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

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

    service.setResponse(response);

    logger.debug(
        "[id={}] returned keep-alive NotificationMessage sequenceNumber={}.",
        subscriptionId,
        sequenceNumber);
  }
예제 #5
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);
  }