Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52fdc1f
commit 00de8c6
Showing
8 changed files
with
238 additions
and
10 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...ua-stack/transport/src/main/java/org/eclipse/milo/opcua/stack/transport/ClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
package org.eclipse.milo.opcua.stack.transport; | ||
|
||
public interface ClientConfig extends OpcTransportConfig {} |
13 changes: 13 additions & 0 deletions
13
...k/transport/src/main/java/org/eclipse/milo/opcua/stack/transport/ClientConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
package org.eclipse.milo.opcua.stack.transport; | ||
|
||
interface ClientConfigBuilder {} |
78 changes: 78 additions & 0 deletions
78
...a-stack/transport/src/main/java/org/eclipse/milo/opcua/stack/transport/ClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
package org.eclipse.milo.opcua.stack.transport; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
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.structured.EndpointDescription; | ||
import org.eclipse.milo.opcua.stack.core.util.EndpointUtil; | ||
|
||
public class ClientFactory { | ||
|
||
|
||
public static AbstractClient create(OpcTransportConfig config) { | ||
return null; | ||
} | ||
|
||
public static AbstractClient create(String endpointUrl) { | ||
return null; | ||
} | ||
|
||
public static AbstractClient create( | ||
String endpointUrl, | ||
Function<List<EndpointDescription>, Optional<EndpointDescription>> selectEndpoint, | ||
Function<ClientConfigBuilder, ClientConfig> buildConfig | ||
) throws UaException { | ||
|
||
String scheme = EndpointUtil.getScheme(endpointUrl); | ||
|
||
String profileUri; | ||
|
||
switch (Objects.requireNonNullElse(scheme, "").toLowerCase()) { | ||
case "opc.tcp": | ||
profileUri = Stack.TCP_UASC_UABINARY_TRANSPORT_URI; | ||
break; | ||
|
||
case "http": | ||
case "https": | ||
case "opc.http": | ||
case "opc.https": | ||
profileUri = Stack.HTTPS_UABINARY_TRANSPORT_URI; | ||
break; | ||
|
||
case "opc.ws": | ||
case "opc.wss": | ||
profileUri = Stack.WSS_UASC_UABINARY_TRANSPORT_URI; | ||
break; | ||
|
||
default: | ||
throw new UaException( | ||
StatusCodes.Bad_InternalError, | ||
"unsupported protocol: " + scheme | ||
); | ||
} | ||
|
||
var configBuilder = new ClientConfigBuilder() {}; | ||
ClientConfig config = buildConfig.apply(configBuilder); | ||
|
||
OpcTransport transport = TransportFactory.getInstance().create(profileUri, config); | ||
|
||
return new AbstractClient(transport) {}; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...ck/transport/src/main/java/org/eclipse/milo/opcua/stack/transport/OpcTransportConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
package org.eclipse.milo.opcua.stack.transport; | ||
|
||
import org.eclipse.milo.opcua.stack.transport.uasc.UascClientConfig; | ||
|
||
interface OpcTransportConfig extends UascClientConfig { | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...tack/transport/src/main/java/org/eclipse/milo/opcua/stack/transport/TransportFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
package org.eclipse.milo.opcua.stack.transport; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
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; | ||
|
||
public class TransportFactory { | ||
|
||
private static final TransportFactory INSTANCE; | ||
|
||
static { | ||
INSTANCE = new TransportFactory(); | ||
INSTANCE.register(Stack.TCP_UASC_UABINARY_TRANSPORT_URI, new OpcTcpTransportFactory()); | ||
} | ||
|
||
public static TransportFactory getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
private final Map<String, Function<OpcTransportConfig, OpcTransport>> functions = new ConcurrentHashMap<>(); | ||
|
||
public OpcTransport create(String profileUri, OpcTransportConfig config) throws UaException { | ||
Function<OpcTransportConfig, OpcTransport> f = functions.get(profileUri); | ||
|
||
if (f != null) { | ||
return f.apply(config); | ||
} else { | ||
throw new UaException(StatusCodes.Bad_NotSupported, "transport: " + profileUri); | ||
} | ||
} | ||
|
||
public void register(String profileUri, Function<OpcTransportConfig, OpcTransport> createTransport) { | ||
functions.put(profileUri, createTransport); | ||
} | ||
|
||
private static class OpcTcpTransportFactory implements Function<OpcTransportConfig, OpcTransport> { | ||
@Override | ||
public OpcTransport apply(OpcTransportConfig clientConfig) { | ||
return new OpcTcpTransport(clientConfig); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters