Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.as.domain.controller.operations.coordination;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXECUTE_FOR_COORDINATOR;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
 
 import java.util.Map;
 
Performs the host specific overall execution of an operation on a slave, on behalf of the domain controller.

Author(s):
Brian Stansberry (c) 2011 Red Hat Inc.
 
 public class OperationSlaveStepHandler {
 
     private final Map<StringProxyControllerserverProxies;
     private final ExtensionRegistry extensionRegistry;
 
     OperationSlaveStepHandler(final LocalHostControllerInfo localHostControllerInfoMap<StringProxyControllerserverProxies,
                               IgnoredDomainResourceRegistry ignoredDomainResourceRegistryExtensionRegistry extensionRegistry) {
         this. = localHostControllerInfo;
         this. = serverProxies;
         this. = ignoredDomainResourceRegistry;
         this. = extensionRegistry;
     }
 
     void intialize(ApplyMissingDomainModelResourcesHandler applyMissingDomainModelResourcesHandler) {
         this. = applyMissingDomainModelResourcesHandler;
     }
 
     void execute(OperationContext contextModelNode operationthrows OperationFailedException {
 
         ModelNode headers = operation.get();
         headers.remove();
 
             int id = headers.remove(.).asInt();
         }
 
         final HostControllerExecutionSupport hostControllerExecutionSupport = addSteps(contextoperationnulltrue);
 
         //Add the missing resources step first
         if (missingResources != null) {
             ModelNode applyMissingResourcesOp = ApplyMissingDomainModelResourcesHandler.createPiggyBackedMissingDataOperation(missingResources);
             context.addStep(applyMissingResourcesOp..true);
         }
 
 
 
         // In case the actual operation fails make sure the result still gets formatted
         context.completeStep(new OperationContext.RollbackHandler() {
             @Override
             public void handleRollback(OperationContext contextModelNode operation) {
                 if (hostControllerExecutionSupport.getDomainOperation() != null) {
                     final ModelNode domainResult = hostControllerExecutionSupport.getFormattedDomainResult(context.getResult());
                     context.getResult().set(domainResult);
                }
            }
        });
    }
    HostControllerExecutionSupport addSteps(final OperationContext contextfinal ModelNode operationfinal ModelNode responsefinal boolean recordResponsethrows OperationFailedException {
        final PathAddress originalAddress = PathAddress.pathAddress(operation.get());
        final ImmutableManagementResourceRegistration originalRegistration = context.getResourceRegistration();
        final HostControllerExecutionSupport hostControllerExecutionSupport =
                HostControllerExecutionSupport.Factory.create(operation.getLocalHostName(),
                        );
        ModelNode domainOp = hostControllerExecutionSupport.getDomainOperation();
        if (domainOp != null) {
            // Only require an existing registration if the domain op is not ignored
            if (originalRegistration == null) {
                throw new OperationFailedException(new ModelNode(..noSuchResourceType(originalAddress)));
            }
            addBasicStep(contextdomainOp);
        }
                resolverhostControllerExecutionSupportoriginalAddressoriginalRegistrationresponse);
        context.addStep(sorh..);
        return hostControllerExecutionSupport;
    }

    
Directly handles the op in the standard way the default prepare step handler would

Parameters:
context the operation execution context
operation the operation
Throws:
org.jboss.as.controller.OperationFailedException if no handler is registered for the operation
    private void addBasicStep(OperationContext contextModelNode operationthrows OperationFailedException {
        final String operationName = operation.require().asString();
        final OperationStepHandler stepHandler = context.getResourceRegistration().getOperationHandler(.operationName);
        if(stepHandler != null) {
            context.addStep(operationstepHandler..);
        } else {
            throw new OperationFailedException(new ModelNode(..noHandlerForOperation(operationName, PathAddress.pathAddress(operation.get()))));
        }
    }

    
Lazily provides a copy of the domain model
    private static class LazyDomainModelProvider implements HostControllerExecutionSupport.DomainModelProvider {
        private final OperationContext context;
        private Resource domainModelResource;
        private LazyDomainModelProvider(OperationContext context) {
            this. = context;
        }
        public Resource getDomainModel() {
            if ( == null) {
                 = .readResourceFromRoot(.true);
            }
            return ;
        }
    }
New to GrepCode? Check out our FAQ X