org.opcfoundation.ua.utils
Class StackUtils

java.lang.Object
  extended by org.opcfoundation.ua.utils.StackUtils

public class StackUtils
extends Object

Utility methods for the OPC UA Java Stack.


Field Summary
static UnsignedInteger CLIENT_TOKEN_LIFETIME_REQUEST
          Requested token lifetime
static Random RANDOM
          Constant RANDOM
static UnsignedInteger SERVER_GIVEN_TOKEN_LIFETIME
          Maximum lifetime server is willing to offer
static int TCP_PROTOCOL_VERSION
          Constant TCP_PROTOCOL_VERSION=0
 
Constructor Summary
StackUtils()
           
 
Method Summary
static boolean barrierWait(AsyncResult<?>[] requests, long timeout)
          Wait for a group to requests to go into final state
static int cores()
          cores.
static Executor createBlockingWorkExecutor(String name, int maxThreadPoolSize)
          Get Executor for long term and potentially blocking operations.
static int getBlockingWorkerThreadPoolCoreSize()
          Getter for the field blockingWorkerThreadPoolCoreSize.
static long getBlockingWorkerThreadPoolTimeout()
          Getter for the field blockingWorkerThreadPoolTimeout.
static Executor getBlockingWorkExecutor()
          Get Executor for long term and potentially blocking operations.
static IEncodeableSerializer getDefaultSerializer()
          Get default encodeable serializer
static Executor getNonBlockingWorkExecutor()
          Get Executor for non-blocking operations.
static Executor getRejectionExecutor()
          Get Executor that handles tasks that are rejected by blocking work executor
static AsyncSelector getSelector()
          getSelector.
static Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
          The handler that is called, if any of the worker threads encounter an exception that is not handled.
static void logStatus()
          logStatus.
static ThreadFactory newNamedThreadFactory(String name)
          newNamedThreadFactory.
static void setBlockingWorkerThreadPoolCoreSize(int blockingWorkerThreadPoolCoreSize)
          Setter for the field blockingWorkerThreadPoolCoreSize.
static void setBlockingWorkerThreadPoolTimeout(long blockingWorkerThreadPoolTimeout)
          Define the timeout (in seconds) of the thread pool for BlockingWorkerExecutor.
static void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtexceptionhandler)
          Define the handler that is called, if any of the worker threads encounter an exception that is not handled.
static void shutdown()
          Perform a "context shutdown" to clean up the Stack resources.
static ServiceResultException toServiceResultException(Exception e)
          toServiceResultException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RANDOM

public static Random RANDOM
Constant RANDOM


CLIENT_TOKEN_LIFETIME_REQUEST

public static final UnsignedInteger CLIENT_TOKEN_LIFETIME_REQUEST
Requested token lifetime


SERVER_GIVEN_TOKEN_LIFETIME

public static final UnsignedInteger SERVER_GIVEN_TOKEN_LIFETIME
Maximum lifetime server is willing to offer


TCP_PROTOCOL_VERSION

public static final int TCP_PROTOCOL_VERSION
Constant TCP_PROTOCOL_VERSION=0

See Also:
Constant Field Values
Constructor Detail

StackUtils

public StackUtils()
Method Detail

barrierWait

public static boolean barrierWait(AsyncResult<?>[] requests,
                                  long timeout)
                           throws InterruptedException
Wait for a group to requests to go into final state

Parameters:
requests - a group of requests
timeout - timeout in seconds
Returns:
true if completed ok
Throws:
InterruptedException - if any.

cores

public static int cores()

cores.

Returns:
a int.

createBlockingWorkExecutor

public static Executor createBlockingWorkExecutor(String name,
                                                  int maxThreadPoolSize)
Get Executor for long term and potentially blocking operations.

Parameters:
maxThreadPoolSize - max number of threads to create in the thread pool
name - a String object.
Returns:
executor for blocking operations

getBlockingWorkerThreadPoolCoreSize

public static int getBlockingWorkerThreadPoolCoreSize()

Getter for the field blockingWorkerThreadPoolCoreSize.

Returns:
the core size of the thread pool for BlockingWorkerExecutor.

getBlockingWorkerThreadPoolTimeout

public static long getBlockingWorkerThreadPoolTimeout()

Getter for the field blockingWorkerThreadPoolTimeout.

Returns:
the timeout in seconds of the thread pool for BlockingWorkerExecutor.

getBlockingWorkExecutor

public static Executor getBlockingWorkExecutor()
Get Executor for long term and potentially blocking operations.

Calls getBlockingWorkExecutor(getDefaultMaxBlockingWorkerThreadPoolSize())

Returns:
executor for blocking operations

getDefaultSerializer

public static IEncodeableSerializer getDefaultSerializer()
Get default encodeable serializer

Returns:
encodeable serialier

getNonBlockingWorkExecutor

public static Executor getNonBlockingWorkExecutor()
Get Executor for non-blocking operations. This executor has one thread for one core in the system.

Returns:
Executor that executes non-blocking short term operations.

getRejectionExecutor

public static Executor getRejectionExecutor()
Get Executor that handles tasks that are rejected by blocking work executor

Returns:
the executor

getSelector

public static AsyncSelector getSelector()

getSelector.

Returns:
a AsyncSelector object.

getUncaughtExceptionHandler

public static Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
The handler that is called, if any of the worker threads encounter an exception that is not handled.

Returns:
the uncaughtexceptionhandler

logStatus

public static void logStatus()

logStatus.


newNamedThreadFactory

public static ThreadFactory newNamedThreadFactory(String name)

newNamedThreadFactory.

Parameters:
name - a String object.
Returns:
a ThreadFactory object.

setBlockingWorkerThreadPoolCoreSize

public static void setBlockingWorkerThreadPoolCoreSize(int blockingWorkerThreadPoolCoreSize)

Setter for the field blockingWorkerThreadPoolCoreSize.

Parameters:
blockingWorkerThreadPoolCoreSize - a int.

setBlockingWorkerThreadPoolTimeout

public static void setBlockingWorkerThreadPoolTimeout(long blockingWorkerThreadPoolTimeout)
Define the timeout (in seconds) of the thread pool for BlockingWorkerExecutor.

Default: 3

Parameters:
blockingWorkerThreadPoolTimeout - a long.

setUncaughtExceptionHandler

public static void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtexceptionhandler)
Define the handler that is called, if any of the worker threads encounter an exception that is not handled.

The default handler will just log the exception as an Error to the log4j log.

Set the handler to provide custom behavior in your application.

The handler is set when new worker threads are started and setting the value will not affect already running threads.

Parameters:
uncaughtexceptionhandler - the uncaughtexceptionhandler to set

shutdown

public static void shutdown()
Perform a "context shutdown" to clean up the Stack resources. Necessary for web service modules, etc.

Shuts down BLOCKING_EXECUTOR and NON_BLOCKING_EXECUTOR, closes SELECTOR and cancels TimerUtil.getTimer().


toServiceResultException

public static ServiceResultException toServiceResultException(Exception e)

toServiceResultException.

Parameters:
e - a Exception object.
Returns:
a ServiceResultException object.


Copyright © 2018. All rights reserved.