Class LogicalChannels

java.lang.Object
cl.netswitch.lib.client.LogicalChannels

public final class LogicalChannels extends Object
Pool of reusable thread-safe logical channels. This pool is intended to be used in multithreaded environments. Each pool is identified by a unique name (case insensitive), and provides a logical channel to a channel executor. When the channel executor completes execution, the logical channel is returned to the pool, so it can be reused by other channel executors.
 
Property Description Type Default
logical.channels.props.file Full path of the property file of logical channels String LogicalChannels.properties
  • Method Details

    • getProperties

      public static Properties getProperties()
      Returns the properties of all logical channels.
      Returns:
      the properties of all logical channels.
    • execute

      public static <T> T execute(ChannelExecutor<T> executor) throws Exception
      Allocates a logical channel from the default channel pool and executes the supplied channel executor. The logical channel is returned to the pool when the executor completes execution, either successfully or by throwing an exception.

      The default channel pool is called "default", so this convenience method produces the same result as the following invocation:

      execute("default", executor);
      Type Parameters:
      T - the type of the value returned by the executor.
      Parameters:
      executor - the channel executor to be executed.
      Returns:
      the value returned by the executor.
      Throws:
      NullPointerException - if executor is null.
      Exception - if another error occurs.
    • execute

      public static <T> T execute(String poolName, ChannelExecutor<T> executor) throws Exception
      Allocates a logical channel from the specified channel pool and executes the supplied channel executor. The logical channel is returned to the pool when the executor completes execution, either successfully or by throwing an exception.
      Type Parameters:
      T - the type of the value returned by the executor.
      Parameters:
      poolName - the name of the channel pool.
      executor - the channel executor to be executed.
      Returns:
      the value returned by the executor.
      Throws:
      NullPointerException - if an argument is null.
      Exception - if another error occurs.
    • clear

      public static void clear()
      Closes and releases all existing channel pools, and clears the properties of logical channels. This is useful when the property file has been modified, and new values need to be loaded.

      When a channel pool is closed, all it's associatted logical channels are closed and released. If a channel executor is using one of these logical channels, it may terminate throwing an exception.