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.ejb3.subsystem;
 
 
 import java.util.List;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOWED;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEFAULT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUEST_PROPERTIES;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUIRED;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TYPE;
 import static org.jboss.as.ejb3.subsystem.EJB3SubsystemModel.INSTANCE_ACQUISITION_TIMEOUT;
 import static org.jboss.as.ejb3.subsystem.EJB3SubsystemModel.INSTANCE_ACQUISITION_TIMEOUT_UNIT;
 import static org.jboss.as.ejb3.subsystem.EJB3SubsystemModel.MAX_POOL_SIZE;

Adds a strict-max-pool to the EJB3 subsystem's bean-instance-pools. The {#performRuntime runtime action} will create and install a org.jboss.as.ejb3.component.pool.PoolConfigService

User: Jaikiran Pai

 
 public class StrictMaxPoolAdd extends AbstractAddStepHandler implements DescriptionProvider {
 
     public static final StrictMaxPoolAdd INSTANCE = new StrictMaxPoolAdd();

    
Description provider for the strict-max-pool add operation
 
     @Override
     public ModelNode getModelDescription(Locale locale) {
         return EJB3SubsystemDescriptions.getStrictMaxPoolAddDescription(locale);
     }


    
Populate the strictMaxPoolModel from the operation

Parameters:
operation the operation
strictMaxPoolModel strict-max-pool ModelNode
Throws:
org.jboss.as.controller.OperationFailedException
 
     @Override
     protected void populateModel(ModelNode operationModelNode strictMaxPoolModelthrows OperationFailedException {
         final String poolName = PathAddress.pathAddress(operation.get(.)).getLastElement().getValue();
         strictMaxPoolModel.get(.).set(poolName);
         // max-pool-size
 
         if (operation.hasDefined(.)) {
             int maxPoolSize = operation.get(.).asInt();
             if (maxPoolSize <= 0) {
                 throw new IllegalArgumentException("Invalid value: " + maxPoolSize + " for " + .);
             }
             strictMaxPoolModel.get(.).set(maxPoolSize);
         }
 
         // instance-acquisition-timeout
         if (operation.hasDefined()) {
             long instanceAcquisitionTimeout = operation.get().asLong();
             if (instanceAcquisitionTimeout <= 0) {
                 throw new IllegalArgumentException("Invalid value: " + instanceAcquisitionTimeout + " for " + );
             }
            strictMaxPoolModel.get().set(instanceAcquisitionTimeout);
        }
        // instance-acquisition-timeout-unit
        if (operation.hasDefined()) {
            String instanceAcquisitionTimeoutUnit = operation.get().asString();
            if (!this.isValidTimeoutUnit(instanceAcquisitionTimeoutUnit)) {
                throw new IllegalArgumentException("Invalid value: " + instanceAcquisitionTimeoutUnit + " for " + );
            }
            strictMaxPoolModel.get().set(instanceAcquisitionTimeoutUnit.trim().toUpperCase(.));
        }
    }
    @Override
    protected void performRuntime(OperationContext contextModelNode operationModelNode strictMaxPoolModel,
                                  ServiceVerificationHandler verificationHandler,
                                  List<ServiceController<?>> serviceControllersthrows OperationFailedException {
        final String poolName = strictMaxPoolModel.require(.).asString();
        final int maxPoolSize = strictMaxPoolModel.get(.).asInt(.);
        final long timeout = strictMaxPoolModel.get(.).asLong(.);
        final String unit = strictMaxPoolModel.hasDefined(.)
                ? strictMaxPoolModel.get(.).asString()
                : ..name();
        // create the pool config
        final PoolConfig strictMaxPoolConfig = new StrictMaxPoolConfig(poolNamemaxPoolSizetimeout, TimeUnit.valueOf(unit));
        // create and install the service
        final PoolConfigService poolConfigService = new PoolConfigService(strictMaxPoolConfig);
        final ServiceName serviceName = ..append(poolName);
        final ServiceController serviceController = context.getServiceTarget().addService(serviceNamepoolConfigService).install();
        // add this to the service controllers
        serviceControllers.add(serviceController);
    }
    private boolean isValidTimeoutUnit(final String val) {
        if (val == null || val.trim().isEmpty()) {
            return false;
        }
        final String upperCaseUnitValue = val.toUpperCase(.);
        try {
            final TimeUnit unit = TimeUnit.valueOf(upperCaseUnitValue);
            if (unit == . || unit == . || unit == . || unit == .) {
                return true;
            }
        } catch (IllegalArgumentException iae) {
            return false;
        }
        return false;
    }
New to GrepCode? Check out our FAQ X