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).
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).-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentLinkedQueue<CompletableFuture<EslMessage>>private final ExecutorServiceprivate final ConcurrentHashMap<String,CompletableFuture<EslEvent>> static final Stringstatic final Stringprivate final ReentrantLock -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, EslMessage message) voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable e) protected abstract voidhandleAuthRequest(io.netty.channel.ChannelHandlerContext ctx) protected abstract voidprotected abstract voidhandleEslEvent(io.netty.channel.ChannelHandlerContext ctx, EslEvent event) protected voidhandleEslMessage(io.netty.channel.ChannelHandlerContext ctx, EslMessage message) 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 incomingEslMessageand attach it to the callback.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 incomingEslMessageand attach it to the callback.sendBackgroundApiCommand(io.netty.channel.Channel channel, String command) Returns the Job UUID of that the response event will have.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.Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
MESSAGE_TERMINATOR
- See Also:
-
LINE_TERMINATOR
- See Also:
-
syncLock
-
apiCalls
-
backgroundJobs
-
backgroundJobExecutor
-
-
Constructor Details
-
AbstractEslClientHandler
public AbstractEslClientHandler()
-
-
Method Details
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable e) throws Exception - Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead0
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, EslMessage message) throws Exception - Specified by:
channelRead0in classio.netty.channel.SimpleChannelInboundHandler<EslMessage>- Throws:
Exception
-
handleEslMessage
-
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 incomingEslMessageand attach it to the callback.- Parameters:
channel-command- single string to send- Returns:
- the
EslMessageattached 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 anEslMessageobject.- Parameters:
channel-command- API command to sendarg- command arguments- Returns:
- an
EslMessagecontaining 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 incomingEslMessageand attach it to the callback.- Parameters:
channel-- Returns:
- the
EslMessageattached 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
-
handleAuthRequest
protected abstract void handleAuthRequest(io.netty.channel.ChannelHandlerContext ctx) -
handleDisconnectionNotice
protected abstract void handleDisconnectionNotice()
-