Skip to content

Commit

Permalink
WIP transport refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Sep 19, 2022
1 parent 00de8c6 commit 8763bf4
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 91 deletions.
74 changes: 74 additions & 0 deletions opc-ua-stack/client-transport-https/pom.xml
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2022 the Eclipse Milo Authors
~
~ This program and the accompanying materials are made
~ available under the terms of the Eclipse Public License 2.0
~ which is available at https://www.eclipse.org/legal/epl-2.0/
~
~ SPDX-License-Identifier: EPL-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.milo</groupId>
<artifactId>opc-ua-stack</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>client-transport-https</artifactId>

<properties>
<javaModuleName>org.eclipse.milo.opcua.stack.client.transport.https</javaModuleName>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>stack-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>stack-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>client-transport</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
74 changes: 74 additions & 0 deletions opc-ua-stack/client-transport-websocket/pom.xml
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2022 the Eclipse Milo Authors
~
~ This program and the accompanying materials are made
~ available under the terms of the Eclipse Public License 2.0
~ which is available at https://www.eclipse.org/legal/epl-2.0/
~
~ SPDX-License-Identifier: EPL-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.milo</groupId>
<artifactId>opc-ua-stack</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>client-transport-websocket</artifactId>

<properties>
<javaModuleName>org.eclipse.milo.opcua.stack.client.transport.websocket</javaModuleName>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>stack-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>stack-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>client-transport</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Expand Up @@ -19,10 +19,10 @@
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>transport</artifactId>
<artifactId>client-transport</artifactId>

<properties>
<javaModuleName>org.eclipse.milo.opcua.stack.transport</javaModuleName>
<javaModuleName>org.eclipse.milo.opcua.stack.client.transport</javaModuleName>
</properties>

<dependencies>
Expand Down
Expand Up @@ -13,16 +13,19 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;

import org.eclipse.milo.opcua.stack.core.Stack;
import org.eclipse.milo.opcua.stack.core.StatusCodes;
import org.eclipse.milo.opcua.stack.core.UaException;
import org.eclipse.milo.opcua.stack.core.types.UaRequestMessageType;
import org.eclipse.milo.opcua.stack.core.types.UaResponseMessageType;
import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription;
import org.eclipse.milo.opcua.stack.core.util.EndpointUtil;

public class ClientFactory {

public abstract class AbstractClient {

public static AbstractClient create(OpcTransportConfig config) {
return null;
Expand Down Expand Up @@ -69,10 +72,46 @@ public static AbstractClient create(
var configBuilder = new ClientConfigBuilder() {};
ClientConfig config = buildConfig.apply(configBuilder);

OpcTransport transport = TransportFactory.getInstance().create(profileUri, config);
OpcTransport transport = ClientTransportFactory.getInstance().create(profileUri, config);

return new AbstractClient(transport) {};
}

private final OpcTransport transport;

public AbstractClient(OpcTransport transport) {
this.transport = transport;
}

public void connect() throws UaException {
try {
transport.connect().get();
} catch (InterruptedException | ExecutionException e) {
throw UaException.extract(e)
.orElseGet(() -> new UaException(StatusCodes.Bad_UnexpectedError, e));
}
}

public void disconnect() throws UaException {
try {
transport.disconnect().get();
} catch (InterruptedException | ExecutionException e) {
throw UaException.extract(e)
.orElseGet(() -> new UaException(StatusCodes.Bad_UnexpectedError, e));
}
}

public UaResponseMessageType sendRequest(UaRequestMessageType request) throws UaException {
try {
return transport.sendRequestMessage(request).get();
} catch (InterruptedException | ExecutionException e) {
throw UaException.extract(e)
.orElseGet(() -> new UaException(StatusCodes.Bad_UnexpectedError, e));
}
}

public CompletableFuture<UaResponseMessageType> sendRequestAsync(UaRequestMessageType request) {
return transport.sendRequestMessage(request);
}

}
Expand Up @@ -17,17 +17,18 @@
import org.eclipse.milo.opcua.stack.core.Stack;
import org.eclipse.milo.opcua.stack.core.StatusCodes;
import org.eclipse.milo.opcua.stack.core.UaException;
import org.eclipse.milo.opcua.stack.transport.tcp.OpcTcpTransport;

public class TransportFactory {
public class ClientTransportFactory {

private static final TransportFactory INSTANCE;
private static final ClientTransportFactory INSTANCE;

static {
INSTANCE = new TransportFactory();
INSTANCE = new ClientTransportFactory();
INSTANCE.register(Stack.TCP_UASC_UABINARY_TRANSPORT_URI, new OpcTcpTransportFactory());
}

public static TransportFactory getInstance() {
public static ClientTransportFactory getInstance() {
return INSTANCE;
}

Expand Down
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.milo.opcua.stack.transport;
package org.eclipse.milo.opcua.stack.transport.tcp;

import java.net.ConnectException;
import java.util.Map;
Expand Down Expand Up @@ -51,6 +51,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader;
import org.eclipse.milo.opcua.stack.core.util.EndpointUtil;
import org.eclipse.milo.opcua.stack.core.util.Unit;
import org.eclipse.milo.opcua.stack.transport.OpcTransport;
import org.eclipse.milo.opcua.stack.transport.uasc.UascClientAcknowledgeHandler;
import org.eclipse.milo.opcua.stack.transport.uasc.UascClientConfig;
import org.eclipse.milo.opcua.stack.transport.uasc.UascClientResponseHandler;
Expand Down
4 changes: 3 additions & 1 deletion opc-ua-stack/pom.xml
Expand Up @@ -23,14 +23,16 @@
<packaging>pom</packaging>

<modules>
<module>client-transport</module>
<module>client-transport-https</module>
<module>client-transport-websocket</module>
<module>encoding-json</module>
<module>encoding-xml</module>
<module>guava-dependencies</module>
<module>stack-client</module>
<module>stack-core</module>
<module>stack-server</module>
<module>stack-tests</module>
<module>transport</module>
</modules>

<build>
Expand Down
20 changes: 0 additions & 20 deletions opc-ua-stack/stack-tests/pom.xml
Expand Up @@ -38,26 +38,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>transport</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
Expand Down

This file was deleted.

0 comments on commit 8763bf4

Please sign in to comment.