Java UaTcpStackServer Example

说明

java uatcpstackserver示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Java

类/类型: UaTcpStackServer

示例#1
文件: FallbackServer.java项目: kevinherron/opc-ua-stack

    @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
文件: FallbackServer.java项目: kevinherron/opc-ua-stack

    @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
文件: FallbackServer.java项目: kevinherron/opc-ua-stack

  public FallbackServer() {
    UaTcpStackServerConfig config =
        UaTcpStackServerConfig.builder()
            .setApplicationName(LocalizedText.english("Stack Discovery Server"))
            .setApplicationUri("urn:digitalpetri:stack:discovery")
            .setProductUri("http://www.digitalpetri.com/opc-ua")
            .build();

    server = new UaTcpStackServer(config);
    server.addRequestHandler(FindServersRequest.class, new FindServersHandler());
    server.addRequestHandler(GetEndpointsRequest.class, new GetEndpointsHandler());
  }

示例#4
文件: FallbackServer.java项目: kevinherron/opc-ua-stack

 public void unregisterServer(UaTcpStackServer server) {
   if (registered.remove(server)) {
     server.getDiscoveryUrls().forEach(servers::remove);
   }
 }

示例#5
文件: FallbackServer.java项目: kevinherron/opc-ua-stack

 public void registerServer(UaTcpStackServer server) {
   if (registered.add(server)) {
     server.getDiscoveryUrls().forEach(url -> servers.put(url, server));
   }
 }

展开阅读全文