And I've implemented this for the ServiceControllerContext:
| public ControllerState lifecycleInvocation(String name, Object[] parameters,
String[] signature) throws Throwable
| {
| if (lifecycleInfo == null)
| lifecycleInfo = new LifecycleInfo(this);
|
| return lifecycleInfo.lifecycleInvocation(name, signature);
| }
|
| public class LifecycleInfo
| {
| private ServiceControllerContext context;
| private Map<String, StateInfo> lifecycleOps;
|
| public LifecycleInfo(ServiceControllerContext context) throws Throwable
| {
| if (context == null)
| throw new IllegalArgumentException("Null context");
|
| this.context = context;
| // build possible lifecycle ops
| lifecycleOps = new HashMap<String, StateInfo>();
| lifecycleOps.put("create", new StateInfo(false, true,
ControllerState.CREATE));
| lifecycleOps.put("start", new StateInfo(false, true,
ControllerState.START));
| lifecycleOps.put("stop", new StateInfo(false, false,
ControllerState.CREATE));
| lifecycleOps.put("destroy", new StateInfo(false, false,
ControllerState.CONFIGURED));
|
| ServiceController controller = context.getServiceController();
| MBeanServer server = controller.getMBeanServer();
| if (server != null)
| {
| MBeanInfo info = server.getMBeanInfo(context.getObjectName());
| MBeanOperationInfo[] ops = info.getOperations();
| if (ops != null)
| {
| for (MBeanOperationInfo op : ops)
| {
| String name = op.getName();
|
| StateInfo flag = lifecycleOps.get(name);
| if (flag == null)
| {
| continue;
| }
|
| // Validate that is a no-arg void return type method
| if (op.getReturnType().equals("void") == false)
| {
| continue;
| }
| if (op.getSignature().length != 0)
| {
| continue;
| }
|
| flag.opExists = true;
| }
| }
| }
| }
|
| /**
| * Is this invocation a lifecycle invocation.
| *
| * Return state value to which this context should be moved
| * or return current state if we're already past the lifecycle state
| * or null if the invocation is actually not a lifecycle invocation.
| *
| * @param opName operation name
| * @param signature method's parameter types / signatures
| * @return state to which we should move this context, or null if this is not
lifecycle invocation
| * @throws Throwable for any error
| */
| public ControllerState lifecycleInvocation(String opName, String[] signature)
throws Throwable
| {
| if (signature != null && signature.length > 0)
| return null;
|
| StateInfo flag = lifecycleOps.get(opName);
| if (flag == null || flag.opExists == false)
| return null;
|
| Controller controller = context.getController();
| ControllerStateModel model = controller.getStates();
| ControllerState state = context.getState();
| if (flag.installPhase)
| {
| if (model.isAfterState(flag.state, state))
| return flag.state;
| else
| return state;
| }
| else
| {
| if (model.isBeforeState(flag.state, state))
| return flag.state;
| else
| return state;
| }
| }
|
| /**
| * State info holder.
| */
| private class StateInfo
| {
| boolean opExists;
| boolean installPhase;
| ControllerState state;
|
| private StateInfo(boolean opExists, boolean installPhase, ControllerState
state)
| {
| this.opExists = opExists;
| this.installPhase = installPhase;
| this.state = state;
| }
| }
| }
|
Or should there be some more logic to it?
e.g. handling 'jbossInternalLifecycle'
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4232870#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...