WorkerManagerConfigurationParser.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  *
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  *
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.management.configuration;
022 
023 import java.util.UUID;
024 
025 import org.apache.qpid.management.Messages;
026 import org.apache.qpid.transport.util.Logger;
027 
028 /**
029  * Parser used for building worker manager settings.
030  * The corresponding section of the configuration file is :
031  
032   <work-manager>
033     <pool-capacity>5</pool-capacity>
034       <max-pool-capacity>15</max-pool-capacity>
035       <keep-alive-time>5000</keep-alive-time>
036   </work-manager>
037 
038  
039  @author Andrea Gazzarini
040  */
041 class WorkerManagerConfigurationParser implements IParser
042 {
043     private final static Logger LOGGER = Logger.get(Configuration.class);
044     private String _currentValue;
045     
046     private String _poolSizeAsString;
047     private String _maxPoolSizeAsString;
048     private String _keepAliveTimeAsString;
049     
050     /**
051      * Callback : the given value is the text content of the current node.
052      */
053     public void setCurrrentAttributeValue (String value)
054     {
055         this._currentValue = value;
056     }
057 
058     /**
059      * Callback: each time the end of an element is reached 
060      * this method is called.
061      */
062     public void setCurrentAttributeName (String name)
063     {
064         switch (Tag.get(name))
065         {
066             case POOL_CAPACITY: 
067             {
068                 _poolSizeAsString = _currentValue.trim();
069                 break;
070             }
071             case MAX_POOL_CAPACITY : 
072             {
073               _maxPoolSizeAsString = _currentValue;
074             }
075             case KEEP_ALIVE_TIME: 
076             {
077               _keepAliveTimeAsString = _currentValue;
078                 break;
079             }
080             case WORK_MANAGER: 
081             {
082               Configuration configuration = Configuration.getInstance();
083                 try 
084                 {
085                   configuration.setWorkerManagerPoolSize(Integer.parseInt(_poolSizeAsString));
086                     configuration.setWorkerManagerMaxPoolSize(Integer.parseInt(_maxPoolSizeAsString));
087                     configuration.setWorkerManagerKeepAliveTime(Long.parseLong(_keepAliveTimeAsString));                    
088                 catch(Exception exception
089                 {
090                     LOGGER.error(Messages.QMAN_100039_UNABLE_TO_CONFIGURE_PROPERLY_WORKER_MANAGER);
091                 finally {
092                     LOGGER.info(Messages.QMAN_000035_WORK_MANAGER_POOL_SIZE,configuration.getWorkerManagerPoolSize());
093                     LOGGER.info(Messages.QMAN_000036_WORK_MANAGER_MAX_POOL_SIZE,configuration.getWorkerManagerMaxPoolSize());
094                     LOGGER.info(Messages.QMAN_000037_WORK_MANAGER_KEEP_ALIVE_TIME,configuration.getWorkerManagerKeepAliveTime());                  
095                 }
096                 break;
097             }
098         }
099     }
100     
101     /**
102      * Gets an uuid in order to associate current connection data with a broker.
103      @return
104      */
105     UUID getUUId(){
106       return UUID.randomUUID();  
107     }
108 }