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 forManagementMessageHandlerimplementations.- Author:
- Emanuel Muckenhuber
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMessageHandler(ExecutorService executorService)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitCompletion(long timeout, TimeUnit unit)Await the completion of all currently active operations.protected List<Integer>cancelAllActiveOperations()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>getActiveOperation(Integer id)Get the active operation.protected <T,A>
ActiveOperation<T,A>getActiveOperation(ManagementRequestHeader header)Get an active operation.protected ExecutorServicegetExecutor()Get the executorprotected static <T,A>
ManagementRequestHandler<T,A>getFallbackHandler(ManagementRequestHeader header)Get a fallback handler.protected ManagementRequestHandler<?,?>getRequestHandler(ManagementRequestHeader header)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>
voidhandleMessage(org.jboss.remoting3.Channel channel, DataInput message, ManagementProtocolHeader header, ActiveOperation<T,A> support, ManagementRequestHandler<T,A> handler)Handle a message.protected <T,A>
voidhandleMessage(org.jboss.remoting3.Channel channel, DataInput message, ManagementRequestHeader header, ManagementRequestHandler<T,A> handler)Handle a message.protected <T,A>
voidhandleRequest(org.jboss.remoting3.Channel channel, DataInput message, ManagementProtocolHeader header, org.jboss.as.protocol.mgmt.AbstractMessageHandler.ActiveRequest<T,A> activeRequest)Handle a message.protected booleanisShutdown()Is 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>removeActiveOperation(Integer id)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.voidshutdownNow()This will attempt to cancel all active operations, without waiting for their completion.protected ManagementRequestHeadervalidateRequest(ManagementProtocolHeader header)Validate 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 Detail
-
AbstractMessageHandler
protected AbstractMessageHandler(ExecutorService executorService)
-
-
Method Detail
-
handleChannelClosed
public void handleChannelClosed(org.jboss.remoting3.Channel closed, IOException e)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
public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedExceptionAwait 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
-
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) throws IOException
Validate whether the request can be handled.- Parameters:
header- the protocol header- Returns:
- the management request header
- Throws:
IOException
-
handleMessage
public void handleMessage(org.jboss.remoting3.Channel channel, DataInput input, ManagementProtocolHeader header) throws IOExceptionHandle a message.- Specified by:
handleMessagein interfaceManagementMessageHandler- Parameters:
channel- the channelinput- the messageheader- the management protocol header- Throws:
IOException
-
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
-
handleRequest
protected <T,A> void handleRequest(org.jboss.remoting3.Channel channel, DataInput message, ManagementProtocolHeader header, org.jboss.as.protocol.mgmt.AbstractMessageHandler.ActiveRequest<T,A> activeRequest)Handle a message.- Parameters:
channel- the channelmessage- the messageheader- the protocol headeractiveRequest- the active request
-
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
-
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
public void handleClose(org.jboss.remoting3.Channel closed, IOException exception)- Specified by:
handleClosein interfaceorg.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 attachmentcallback- 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 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
protected <T,A> ActiveOperation<T,A> getActiveOperation(ManagementRequestHeader header)
Get an active operation.- Parameters:
header- the request header- Returns:
- the active operation,
nullif 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,
nullif 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,
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 IOExceptionWrite an error response.- Parameters:
channel- the channelheader- the requesterror- the error- Throws:
IOException
-
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
-
getFallbackHandler
protected static <T,A> ManagementRequestHandler<T,A> getFallbackHandler(ManagementRequestHeader header)
Get a fallback handler.- Parameters:
header- the protocol header- Returns:
- the fallback handler
-
-