Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
   * as indicated by the @authors tag. All rights reserved.
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
  * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * 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,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  */
 package org.jboss.as.domain.controller.operations;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_CONFIG;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_GROUP;
 
 import java.util.Set;
 
Handler for the socket-binding-group resource's remove operation. If the socket binding group has running servers this operation will fail

Author(s):
Kabir Khan
 
 
     public static final String OPERATION_NAME = ;
 
     private volatile ServerInventory serverInventory;

    
Create the AbstractSocketBindingRemoveHandler
 
     protected DomainSocketBindingGroupRemoveHandler() {
     }
 
 
     public void initializeServerInventory(ServerInventory serverInventory) {
         //This is a Domain level operation, however the server inventory is not available until the host model has been created
         this. = serverInventory;
     }
 
     protected boolean requiresRuntime(OperationContext context) {
         return context.getProcessType().isServer();
     }
 
     @Override
     protected void performRemove(OperationContext contextModelNode operationModelNode modelthrows OperationFailedException {
         //Check that the socket binding group can be removed. This is not possible if there are running servers
         if (!context.getProcessType().isServer()) {
             //We are the host controller
 
             context.addStep(new OperationStepHandler() {
                 @Override
                 public void execute(OperationContext contextModelNode operationthrows OperationFailedException {
                     String socketBindingGroupName = PathAddress.pathAddress(operation.get()).getLastElement().getValue();
 
                     //Find all the server groups using the socket binding group
                     Set<StringserverGroups = new HashSet<String>();
                     for (ResourceEntry entry : context.readResourceFromRoot(.).getChildren()) {
                         if (entry.getModel().get().asString().equals(socketBindingGroupName)) {
                             serverGroups.add(entry.getName());
                         }
                     }
 
                     //Find all the server configs using the socket binding group
                     Set<StringrunningServers = new HashSet<String>();
                     for (ResourceEntry entry : context.readResourceFromRoot(.).getChildren().iterator().next().getChildren()) {
                         ModelNode configModel = entry.getModel();
                         if (configModel.hasDefined()) {
                             if (configModel.get().asString().equals(socketBindingGroupName)) {
                                 if (isRunningServer(entry.getName())) {
                                     runningServers.add(entry.getName());
                                 }
                            }
                        } else {
                            if (serverGroups.contains(configModel.get().asString())) {
                                if (isRunningServer(entry.getName())) {
                                    runningServers.add(entry.getName());
                                }
                            }
                        }
                    }
                    if (!runningServers.isEmpty()) {
                        throw new OperationFailedException("Could not remove socket-binding-group since the following servers are running: " + runningServers);
                    }
                    context.stepCompleted();
                }
            }, .);
        }
        super.performRemove(contextoperationmodel);
    }
    private boolean isRunningServer(String serverName) {
        ServerStatus status = .determineServerStatus(serverName);
        switch (status) {
            case :
            case :
            case :
                return true;
            default:
                return false;
        }
    }
New to GrepCode? Check out our FAQ X