2525import org .eclipse .milo .opcua .stack .core .Stack ;
2626import org .eclipse .milo .opcua .stack .core .security .DefaultTrustListManager ;
2727import org .eclipse .milo .opcua .stack .core .types .builtin .LocalizedText ;
28+ import org .slf4j .Logger ;
2829import org .slf4j .LoggerFactory ;
2930
3031import java .io .File ;
4041
4142public class ClientRunner {
4243
44+ private static final Logger logger = LoggerFactory .getLogger (ClientRunner .class );
45+
4346 static {
4447 // Required for SecurityPolicy.Aes256_Sha256_RsaPss
4548 Security .addProvider (new BouncyCastleProvider ());
@@ -63,8 +66,8 @@ private OpcUaClient createClient() throws Exception {
6366
6467 final File pkiDir = securityTempDir .resolve ("pki" ).toFile ();
6568
66- System . out . println ("security dir: " + securityTempDir .toAbsolutePath ());
67- LoggerFactory . getLogger ( getClass ()) .info ("security pki dir: {}" , pkiDir .getAbsolutePath ());
69+ logger . info ("security dir: " + securityTempDir .toAbsolutePath ());
70+ logger .info ("security pki dir: {}" , pkiDir .getAbsolutePath ());
6871
6972 final IoTDBKeyStoreLoaderClient loader = new IoTDBKeyStoreLoaderClient ().load (securityTempDir );
7073
@@ -78,8 +81,8 @@ private OpcUaClient createClient() throws Exception {
7881 endpoints -> endpoints .stream ().filter (configurableUaClient .endpointFilter ()).findFirst (),
7982 configBuilder ->
8083 configBuilder
81- .setApplicationName (LocalizedText .english ("eclipse milo opc-ua client" ))
82- .setApplicationUri ("urn:eclipse:milo:examples: client" )
84+ .setApplicationName (LocalizedText .english ("Apache IoTDB OPC UA client" ))
85+ .setApplicationUri ("urn:apache:iotdb:opc-ua- client" )
8386 .setKeyPair (loader .getClientKeyPair ())
8487 .setCertificate (loader .getClientCertificate ())
8588 .setCertificateChain (loader .getClientCertificateChain ())
@@ -96,21 +99,21 @@ public void run() {
9699 future .whenCompleteAsync (
97100 (c , ex ) -> {
98101 if (ex != null ) {
99- System . out . println ("Error running example : " + ex . getMessage () );
102+ logger . warn ("Error running opc client : " , ex );
100103 }
101104
102105 try {
103106 client .disconnect ().get ();
104107 Stack .releaseSharedResources ();
105- } catch (InterruptedException | ExecutionException e ) {
108+ } catch (final InterruptedException | ExecutionException e ) {
106109 Thread .currentThread ().interrupt ();
107- System . out . println ("Error disconnecting: {}" + e . getMessage () );
110+ logger . warn ("Error disconnecting: " , e );
108111 }
109112
110113 try {
111114 Thread .sleep (1000 );
112115 System .exit (0 );
113- } catch (InterruptedException e ) {
116+ } catch (final InterruptedException e ) {
114117 Thread .currentThread ().interrupt ();
115118 e .printStackTrace ();
116119 }
@@ -119,21 +122,21 @@ public void run() {
119122 try {
120123 configurableUaClient .run (client );
121124 future .get (100000 , TimeUnit .SECONDS );
122- } catch (Throwable t ) {
123- System . out . println ("Error running client example: " + t . getMessage () + t );
124- future .completeExceptionally (t );
125+ } catch (final Exception e ) {
126+ logger . warn ("Error running client example: " , e );
127+ future .completeExceptionally (e );
125128 }
126- } catch (Throwable t ) {
127- System . out . println ("Error getting client: {}" + t . getMessage () );
129+ } catch (final Exception e ) {
130+ logger . warn ("Error getting client: " , e );
128131
129- future .completeExceptionally (t );
132+ future .completeExceptionally (e );
130133
131134 try {
132135 Thread .sleep (1000 );
133136 System .exit (0 );
134- } catch (InterruptedException e ) {
137+ } catch (InterruptedException interruptedException ) {
135138 Thread .currentThread ().interrupt ();
136- e . printStackTrace ( );
139+ logger . warn ( "Interrupted when running client: " , e );
137140 }
138141 }
139142 }
0 commit comments