Package org.jboss.as.protocol.mgmt
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitCompletion(long timeout, TimeUnit unit) Await the completion of all currently active operations.Cancel all currently active operations.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.protected <T,A> ActiveOperation<T, A> Get the active operation.protected <T,A> ActiveOperation<T, A> Get an active operation.protected ExecutorServiceGet the executorprotected static <T,A> ManagementRequestHandler<T, A> Get a fallback handler.protected ManagementRequestHandler<?,?> Get the request handler.voidhandleChannelClosed(org.jboss.remoting3.Channel closed, IOException e) Receive a notification that the channel was closed.voidhandleClose(org.jboss.remoting3.Channel closed, IOException exception) voidhandleMessage(org.jboss.remoting3.Channel channel, DataInput input, ManagementProtocolHeader header) Handle a message.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.protected <T,A> void handleMessage(org.jboss.remoting3.Channel channel, DataInput message, ManagementRequestHeader header, ManagementRequestHandler<T, A> handler) Handle a message.protected booleanIs shutdown.protected <T,A> ActiveOperation<T, A> registerActiveOperation(A attachment) Register an active operation.protected <T,A> ActiveOperation<T, A> registerActiveOperation(A attachment, ActiveOperation.CompletedCallback<T> callback) Register an active operation.protected <T,A> ActiveOperation<T, A> registerActiveOperation(Integer id, A attachment) Register an active operation with a specific operation id.protected <T,A> ActiveOperation<T, A> registerActiveOperation(Integer id, A attachment, ActiveOperation.CompletedCallback<T> callback) Register an active operation with a specific operation id.protected <T,A> ActiveOperation<T, A> Remove an active operation.protected static voidsafeWriteErrorResponse(org.jboss.remoting3.Channel channel, ManagementProtocolHeader header, Throwable error) Safe write error response.voidshutdown()Prevent new active operations get registered.voidThis will attempt to cancel all active operations, without waiting for their completion.protected ManagementRequestHeaderValidate whether the request can be handled.protected static voidwriteErrorResponse(org.jboss.remoting3.Channel channel, ManagementRequestHeader header, Throwable error) Write an error response.protected static FlushableDataOutputwriteHeader(ManagementProtocolHeader header, OutputStream os) Write the management protocol header.
-
Constructor Details
-
AbstractMessageHandler
-
-
Method Details
-
handleChannelClosed
Receive a notification that the channel was closed. This is used for theManagementClientChannelStrategy.Establishingsince it might use multiple channels.- Parameters:
closed- the closed resourcee- the exception which occurred during close, if any
-
isShutdown
protected boolean isShutdown()Is shutdown.- Returns:
trueif the shutdown method was called,falseotherwise
-
shutdown
public void shutdown()Prevent new active operations get registered.- Specified by:
shutdownin interfaceManagementChannelShutdownHandle
-
shutdownNow
public void shutdownNow()This will attempt to cancel all active operations, without waiting for their completion.- Specified by:
shutdownNowin interfaceManagementChannelShutdownHandle
-
awaitCompletion
Await the completion of all currently active operations.- Specified by:
awaitCompletionin interfaceManagementChannelShutdownHandle- Parameters:
timeout- the timeoutunit- 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
Get the executor- Returns:
- the executor
-
getRequestHandler
Get the request handler.- Parameters:
header- the request header- Returns:
- the request handler
-
validateRequest
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:
handleMessagein interfaceManagementMessageHandler- Parameters:
channel- the channelinput- the messageheader- 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 requestchannel- the channelsupport- 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 IOExceptionHandle a message.- Parameters:
channel- the channelmessage- the messageheader- the protocol headerhandler- the request handler- Throws:
IOException- ifheader'sbatch iddoesn'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 channelmessage- the messageheader- the protocol headersupport- the request supporthandler- the request handler
-
handleClose
- Specified by:
handleClosein interfaceorg.jboss.remoting3.CloseHandler<org.jboss.remoting3.Channel>
-
registerActiveOperation
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 attachmentcallback- the completed callback- Returns:
- the active operation
-
registerActiveOperation
Register an active operation with a specific operation id.- Parameters:
id- the operation idattachment- 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 idattachment- the shared attachmentcallback- the completed callback- Returns:
- the created active operation
- Throws:
IllegalStateException- if an operation with the same id is already registered
-
getActiveOperation
Get an active operation.- Parameters:
header- the request header- Returns:
- the active operation,
nullif there is no registered operation
-
getActiveOperation
Get the active operation.- Parameters:
id- the active operation id- Returns:
- the active operation,
nullif there is no registered operation
-
cancelAllActiveOperations
Cancel all currently active operations.- Returns:
- a list of cancelled operations
-
removeActiveOperation
Remove an active operation.- Parameters:
id- the operation id- Returns:
- the removed active operation,
nullif 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 channelheader- the request headererror- 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 channelheader- the requesterror- 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 headeros- 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
-