Package org.jboss.as.controller
Class AbstractWriteAttributeHandler<T>
- java.lang.Object
-
- org.jboss.as.controller.AbstractWriteAttributeHandler<T>
-
- Type Parameters:
T
- the type of an object that, if stored by theapplyUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, HandbackHolder)
implementation, will be passed torevertUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, Object)
.
- All Implemented Interfaces:
OperationStepHandler
- Direct Known Subclasses:
ModelOnlyWriteAttributeHandler
,ReloadRequiredWriteAttributeHandler
,RestartParentWriteAttributeHandler
public abstract class AbstractWriteAttributeHandler<T> extends Object implements OperationStepHandler
Abstract handler for the write aspect of aread-write attribute
.- Author:
- Brian Stansberry (c) 2011 Red Hat Inc.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractWriteAttributeHandler.HandbackHolder<T>
Holder subclasses can use to pass an object betweenapplyUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, HandbackHolder)
andrevertUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, Object)
.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractWriteAttributeHandler(Collection<AttributeDefinition> definitions)
protected
AbstractWriteAttributeHandler(AttributeDefinition... definitions)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
applyUpdateToRuntime(OperationContext context, org.jboss.dmr.ModelNode operation, String attributeName, org.jboss.dmr.ModelNode resolvedValue, org.jboss.dmr.ModelNode currentValue, AbstractWriteAttributeHandler.HandbackHolder<T> handbackHolder)
Hook to allow subclasses to make runtime changes to effect the attribute value change.void
execute(OperationContext context, org.jboss.dmr.ModelNode operation)
Execute this step.protected void
finishModelStage(OperationContext context, org.jboss.dmr.ModelNode operation, String attributeName, org.jboss.dmr.ModelNode newValue, org.jboss.dmr.ModelNode oldValue, Resource model)
Hook to allow subclasses to do any finalOperationContext.Stage.MODEL
processing following the application of the new attribute value.protected AttributeDefinition
getAttributeDefinition(String attributeName)
Gets theAttributeDefinition
provided to the constructor (if present) whosename
matches the givenattributeName
.protected void
recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attributeDefinition, org.jboss.dmr.ModelNode newValue, org.jboss.dmr.ModelNode oldValue)
Record any new requirements for othercapabilities
that now exist as a result of this operation, or remove any existing requirements that no longer exist.protected boolean
requiresRuntime(OperationContext context)
Gets whether aOperationContext.Stage.RUNTIME
handler should be added.protected abstract void
revertUpdateToRuntime(OperationContext context, org.jboss.dmr.ModelNode operation, String attributeName, org.jboss.dmr.ModelNode valueToRestore, org.jboss.dmr.ModelNode valueToRevert, T handback)
Hook to allow subclasses to revert runtime changes made inapplyUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, HandbackHolder)
.protected void
validateUpdatedModel(OperationContext context, Resource model)
Hook to allow subclasses to validate the model following the application of the new attribute value.
-
-
-
Constructor Detail
-
AbstractWriteAttributeHandler
protected AbstractWriteAttributeHandler(AttributeDefinition... definitions)
-
AbstractWriteAttributeHandler
protected AbstractWriteAttributeHandler(Collection<AttributeDefinition> definitions)
-
-
Method Detail
-
execute
public void execute(OperationContext context, org.jboss.dmr.ModelNode operation) throws OperationFailedException
Description copied from interface:OperationStepHandler
Execute this step. If the operation fails,context.getFailureDescription()
must be called, or anOperationFailedException
must be thrown. If the operation succeeded and the operation provides a return value,context.getResult()
should be called and the result populated with the outcome. If the handler wishes to take further action once the result of the overall operation execution is known, one of thecontext.completeStep variants
should be called to register a callback. The callback will not be invoked if this method throws an exception.When this method is invoked the
thread context classloader
will be set to be the defining class loader of the class that implements this interface.- Specified by:
execute
in interfaceOperationStepHandler
- Parameters:
context
- the operation contextoperation
- the operation being executed- Throws:
OperationFailedException
- if the operation failed before callingcontext.completeStep()
-
applyUpdateToRuntime
protected abstract boolean applyUpdateToRuntime(OperationContext context, org.jboss.dmr.ModelNode operation, String attributeName, org.jboss.dmr.ModelNode resolvedValue, org.jboss.dmr.ModelNode currentValue, AbstractWriteAttributeHandler.HandbackHolder<T> handbackHolder) throws OperationFailedException
Hook to allow subclasses to make runtime changes to effect the attribute value change.- Parameters:
context
- the context of the operationoperation
- the operationattributeName
- the name of the attribute being modifiedresolvedValue
- the new value for the attribute, after anyValueExpression
has been resolvedcurrentValue
- the existing value for the attributehandbackHolder
- holder for an arbitrary object to pass torevertUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, Object)
if the operation needs to be rolled back- Returns:
true
if the server requires reload to effect the attribute value change;false
if not- Throws:
OperationFailedException
-
revertUpdateToRuntime
protected abstract void revertUpdateToRuntime(OperationContext context, org.jboss.dmr.ModelNode operation, String attributeName, org.jboss.dmr.ModelNode valueToRestore, org.jboss.dmr.ModelNode valueToRevert, T handback) throws OperationFailedException
Hook to allow subclasses to revert runtime changes made inapplyUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, HandbackHolder)
.- Parameters:
context
- the context of the operationoperation
- the operationattributeName
- the name of the attribute being modifiedvalueToRestore
- the previous value for the attribute, before this operation was executedvalueToRevert
- the new value for the attribute that should be revertedhandback
- an object, if any, passed in to thehandbackHolder
by theapplyUpdateToRuntime
implementation- Throws:
OperationFailedException
-
recordCapabilitiesAndRequirements
protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attributeDefinition, org.jboss.dmr.ModelNode newValue, org.jboss.dmr.ModelNode oldValue)
Record any new requirements for othercapabilities
that now exist as a result of this operation, or remove any existing requirements that no longer exist.- Parameters:
context
- the context. Will not benull
attributeDefinition
- the definition of the attribute being modified. Will not benull
newValue
- the new value of the attributeoldValue
- the previous value of the attribute
-
finishModelStage
protected void finishModelStage(OperationContext context, org.jboss.dmr.ModelNode operation, String attributeName, org.jboss.dmr.ModelNode newValue, org.jboss.dmr.ModelNode oldValue, Resource model) throws OperationFailedException
Hook to allow subclasses to do any finalOperationContext.Stage.MODEL
processing following the application of the new attribute value. This default implementation callsvalidateUpdatedModel(OperationContext, Resource)
.NOTE: Implementations must not call
OperationContext.completeStep(OperationContext.ResultHandler)
or any of its variants. The method that calls this one handles step completion.- Parameters:
context
- the operation contextoperation
- the operationattributeName
- the name of the attribute being modifiednewValue
- the new value for the attributeoldValue
- the previous value for the attributemodel
- the updated model resource- Throws:
OperationFailedException
-
validateUpdatedModel
protected void validateUpdatedModel(OperationContext context, Resource model) throws OperationFailedException
Hook to allow subclasses to validate the model following the application of the new attribute value. This default implementation does nothing.- Parameters:
context
- the operation contextmodel
- the updated model resource- Throws:
OperationFailedException
-
requiresRuntime
protected boolean requiresRuntime(OperationContext context)
Gets whether aOperationContext.Stage.RUNTIME
handler should be added. This default implementation returns true if the process is anormal server
and the process is notbooting
. The rationale for the latter check is if the process is booting, the resource being modified will have been added as a previous step in the same context, and the Stage.RUNTIME handling for that add will see a model the reflects the changes made by this handler and will apply them to the runtime.- Parameters:
context
- operation context- Returns:
true
if a runtime stage handler should be added;false
otherwise.
-
getAttributeDefinition
protected AttributeDefinition getAttributeDefinition(String attributeName) throws IllegalArgumentException
Gets theAttributeDefinition
provided to the constructor (if present) whosename
matches the givenattributeName
.- Parameters:
attributeName
- the attribute name- Returns:
- the attribute definition of
attributeName
- Throws:
IllegalArgumentException
- if no attribute definition with nameattributeName
exists.
-
-