Class AbstractEslClientHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<EslMessage>
com.bytedesk.call.esl.client.internal.AbstractEslClientHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler
Direct Known Subclasses:
InboundClientHandler, OutboundClientHandler

public abstract class AbstractEslClientHandler extends io.netty.channel.SimpleChannelInboundHandler<EslMessage>
Specialised SimpleChannelInboundHandler that implements the logic of an ESL connection that is common to both inbound and outbound clients. This handler expects to receive decoded EslMessage or EslEvent objects. The key responsibilities for this class are:
  • To synthesise a synchronous command/response api. All IO operations using the underlying Netty library are intrinsically asynchronous which provides for excellent response and scalability. This class provides for a blocking wait mechanism for responses to commands issued to the server. A key assumption here is that the FreeSWITCH server will process synchronous requests in the order they are received.
  • Concrete sub classes are expected to 'terminate' the Netty IO processing pipeline (ie be the 'last' handler).
Note: implementation requirement is that an ExecutionHandler is placed in the processing pipeline prior to this handler. This will ensure that each incoming message is processed in its own thread (although still guaranteed to be processed in the order of receipt).
  • Field Details

  • Constructor Details

    • AbstractEslClientHandler

      public AbstractEslClientHandler()
  • Method Details

    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable e) throws Exception
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelRead0

      protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, EslMessage message) throws Exception
      Specified by:
      channelRead0 in class io.netty.channel.SimpleChannelInboundHandler<EslMessage>
      Throws:
      Exception
    • handleEslMessage

      protected void handleEslMessage(io.netty.channel.ChannelHandlerContext ctx, EslMessage message)
    • sendApiSingleLineCommand

      public CompletableFuture<EslMessage> sendApiSingleLineCommand(io.netty.channel.Channel channel, String command)
      Synthesise a synchronous command/response by creating a callback object which is placed in queue and blocks waiting for another IO thread to process an incoming EslMessage and attach it to the callback.
      Parameters:
      channel -
      command - single string to send
      Returns:
      the EslMessage attached to this command's callback
    • sendSyncApiCommand

      public CompletableFuture<EslMessage> sendSyncApiCommand(io.netty.channel.Channel channel, String command, String arg)
      Sends a FreeSWITCH API command to the channel and blocks, waiting for an immediate response from the server.

      The outcome of the command from the server is returned in an EslMessage object.

      Parameters:
      channel -
      command - API command to send
      arg - command arguments
      Returns:
      an EslMessage containing command results
    • sendApiMultiLineCommand

      public CompletableFuture<EslMessage> sendApiMultiLineCommand(io.netty.channel.Channel channel, List<String> commandLines)
      Synthesise a synchronous command/response by creating a callback object which is placed in queue and blocks waiting for another IO thread to process an incoming EslMessage and attach it to the callback.
      Parameters:
      channel -
      Returns:
      the EslMessage attached to this command's callback
    • sendBackgroundApiCommand

      public CompletableFuture<EslEvent> sendBackgroundApiCommand(io.netty.channel.Channel channel, String command)
      Returns the Job UUID of that the response event will have.
      Parameters:
      channel -
      command -
      Returns:
      Job-UUID as a string
    • handleEslEvent

      protected abstract void handleEslEvent(io.netty.channel.ChannelHandlerContext ctx, EslEvent event)
    • handleAuthRequest

      protected abstract void handleAuthRequest(io.netty.channel.ChannelHandlerContext ctx)
    • handleDisconnectionNotice

      protected abstract void handleDisconnectionNotice()