Class AbstractMessageHandler

java.lang.Object
org.jboss.as.protocol.mgmt.AbstractMessageHandler
All Implemented Interfaces:
EventListener, ManagementMessageHandler, ManagementChannelShutdownHandle, org.jboss.remoting3.CloseHandler<org.jboss.remoting3.Channel>
Direct Known Subclasses:
ManagementChannelHandler

public abstract class AbstractMessageHandler extends Object implements ManagementMessageHandler, ManagementChannelShutdownHandle, org.jboss.remoting3.CloseHandler<org.jboss.remoting3.Channel>
Base class for ManagementMessageHandler implementations.
Author:
Emanuel Muckenhuber
  • Constructor Details

    • AbstractMessageHandler

      protected AbstractMessageHandler(ExecutorService executorService)
  • Method Details

    • handleChannelClosed

      public void handleChannelClosed(org.jboss.remoting3.Channel closed, IOException e)
      Receive a notification that the channel was closed.

      This is used for the ManagementClientChannelStrategy.Establishing since it might use multiple channels.

      Parameters:
      closed - the closed resource
      e - the exception which occurred during close, if any
    • isShutdown

      protected boolean isShutdown()
      Is shutdown.
      Returns:
      true if the shutdown method was called, false otherwise
    • shutdown

      public void shutdown()
      Prevent new active operations get registered.
      Specified by:
      shutdown in interface ManagementChannelShutdownHandle
    • shutdownNow

      public void shutdownNow()
      This will attempt to cancel all active operations, without waiting for their completion.
      Specified by:
      shutdownNow in interface ManagementChannelShutdownHandle
    • awaitCompletion

      public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException
      Await the completion of all currently active operations.
      Specified by:
      awaitCompletion in interface ManagementChannelShutdownHandle
      Parameters:
      timeout - the timeout
      unit - the time unit
      Returns:
      false if the timeout was reached and there were still active operations
      Throws:
      InterruptedException - if the thread is interrupted while waiting
    • getExecutor

      protected ExecutorService getExecutor()
      Get the executor
      Returns:
      the executor
    • getRequestHandler

      protected ManagementRequestHandler<?,?> getRequestHandler(ManagementRequestHeader header)
      Get the request handler.
      Parameters:
      header - the request header
      Returns:
      the request handler
    • validateRequest

      protected ManagementRequestHeader validateRequest(ManagementProtocolHeader header)
      Validate whether the request can be handled.
      Parameters:
      header - the protocol header
      Returns:
      the management request header
    • handleMessage

      public void handleMessage(org.jboss.remoting3.Channel channel, DataInput input, ManagementProtocolHeader header)
      Handle a message.
      Specified by:
      handleMessage in interface ManagementMessageHandler
      Parameters:
      channel - the channel
      input - the message
      header - the management protocol header
    • executeRequest

      protected <T, A> org.jboss.threads.AsyncFuture<T> executeRequest(ManagementRequest<T,A> request, org.jboss.remoting3.Channel channel, ActiveOperation<T,A> support)
      Execute a request.
      Parameters:
      request - the request
      channel - the channel
      support - the request support
      Returns:
      the future result
    • handleMessage

      protected <T, A> void handleMessage(org.jboss.remoting3.Channel channel, DataInput message, ManagementRequestHeader header, ManagementRequestHandler<T,A> handler) throws IOException
      Handle a message.
      Parameters:
      channel - the channel
      message - the message
      header - the protocol header
      handler - the request handler
      Throws:
      IOException - if header's batch id doesn't match any active operation
    • handleMessage

      protected <T, A> void handleMessage(org.jboss.remoting3.Channel channel, DataInput message, ManagementProtocolHeader header, ActiveOperation<T,A> support, ManagementRequestHandler<T,A> handler)
      Handle a message.
      Parameters:
      channel - the channel
      message - the message
      header - the protocol header
      support - the request support
      handler - the request handler
    • handleClose

      public void handleClose(org.jboss.remoting3.Channel closed, IOException exception)
      Specified by:
      handleClose in interface org.jboss.remoting3.CloseHandler<org.jboss.remoting3.Channel>
    • registerActiveOperation

      protected <T, A> ActiveOperation<T,A> registerActiveOperation(A attachment)
      Register an active operation. The operation-id will be generated.
      Parameters:
      attachment - the shared attachment
      Returns:
      the active operation
    • registerActiveOperation

      protected <T, A> ActiveOperation<T,A> registerActiveOperation(A attachment, ActiveOperation.CompletedCallback<T> callback)
      Register an active operation. The operation-id will be generated.
      Parameters:
      attachment - the shared attachment
      callback - the completed callback
      Returns:
      the active operation
    • registerActiveOperation

      protected <T, A> ActiveOperation<T,A> registerActiveOperation(Integer id, A attachment)
      Register an active operation with a specific operation id.
      Parameters:
      id - the operation id
      attachment - the shared attachment
      Returns:
      the created active operation
      Throws:
      IllegalStateException - if an operation with the same id is already registered
    • registerActiveOperation

      protected <T, A> ActiveOperation<T,A> registerActiveOperation(Integer id, A attachment, ActiveOperation.CompletedCallback<T> callback)
      Register an active operation with a specific operation id.
      Parameters:
      id - the operation id
      attachment - the shared attachment
      callback - the completed callback
      Returns:
      the created active operation
      Throws:
      IllegalStateException - if an operation with the same id is already registered
    • getActiveOperation

      protected <T, A> ActiveOperation<T,A> getActiveOperation(ManagementRequestHeader header)
      Get an active operation.
      Parameters:
      header - the request header
      Returns:
      the active operation, null if there is no registered operation
    • getActiveOperation

      protected <T, A> ActiveOperation<T,A> getActiveOperation(Integer id)
      Get the active operation.
      Parameters:
      id - the active operation id
      Returns:
      the active operation, null if there is no registered operation
    • cancelAllActiveOperations

      protected List<Integer> cancelAllActiveOperations()
      Cancel all currently active operations.
      Returns:
      a list of cancelled operations
    • removeActiveOperation

      protected <T, A> ActiveOperation<T,A> removeActiveOperation(Integer id)
      Remove an active operation.
      Parameters:
      id - the operation id
      Returns:
      the removed active operation, null if there was no registered operation
    • safeWriteErrorResponse

      protected static void safeWriteErrorResponse(org.jboss.remoting3.Channel channel, ManagementProtocolHeader header, Throwable error)
      Safe write error response.
      Parameters:
      channel - the channel
      header - the request header
      error - the exception
    • writeErrorResponse

      protected static void writeErrorResponse(org.jboss.remoting3.Channel channel, ManagementRequestHeader header, Throwable error) throws IOException
      Write an error response.
      Parameters:
      channel - the channel
      header - the request
      error - the error
      Throws:
      IOException - if a problem occurs writing the message
    • writeHeader

      protected static FlushableDataOutput writeHeader(ManagementProtocolHeader header, OutputStream os) throws IOException
      Write the management protocol header.
      Parameters:
      header - the mgmt protocol header
      os - the output stream
      Throws:
      IOException - if any problems occur writing the output
    • getFallbackHandler

      protected static <T, A> ManagementRequestHandler<T,A> getFallbackHandler(ManagementRequestHeader header)
      Get a fallback handler.
      Parameters:
      header - the protocol header
      Returns:
      the fallback handler