View Javadoc

1   /*
2    * Copyright 2006-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.rice.ksb.messaging.service.impl;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.core.api.config.property.ConfigContext;
21  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
22  import org.kuali.rice.core.api.lifecycle.BaseLifecycle;
23  import org.kuali.rice.ksb.messaging.service.BusAdminService;
24  import org.kuali.rice.ksb.messaging.threadpool.KSBThreadPool;
25  
26  
27  /**
28   * Implementation of the Bus Admin service.
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class BusAdminServiceImpl extends BaseLifecycle implements BusAdminService {
33  
34      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BusAdminServiceImpl.class);
35  
36      private KSBThreadPool threadPool;
37  
38      public void setThreadPool(KSBThreadPool threadPool) {
39      	this.threadPool = threadPool;
40      }
41      
42      protected KSBThreadPool getThreadPool() {
43      	return this.threadPool;
44      }
45  
46      @Override
47      public void ping() {
48          LOG.info("ping called");
49      }
50  
51      @Override
52      public void setCorePoolSize(int corePoolSize) {
53      	if (corePoolSize < 0) {
54              throw new RiceIllegalArgumentException("corePoolSize < 0");
55          }
56  
57          LOG.info("Setting core pool size to " + corePoolSize);
58      	getThreadPool().setCorePoolSize(corePoolSize);
59      }
60  
61      @Override
62      public void setMaximumPoolSize(int maxPoolSize) {
63      	if (maxPoolSize < 0) {
64              throw new RiceIllegalArgumentException("maxPoolSize < 0");
65          }
66      	LOG.info("Setting max pool size to " + maxPoolSize);
67      	if (maxPoolSize < getThreadPool().getCorePoolSize()) {
68      		maxPoolSize = getThreadPool().getCorePoolSize();
69      	}
70      	getThreadPool().setMaximumPoolSize(maxPoolSize);
71      }
72  
73      @Override
74      public void setConfigProperty(String propertyName, String propertyValue) {
75      	if (StringUtils.isBlank(propertyName)) {
76              throw new RiceIllegalArgumentException("propertyName is null or blank");
77          }
78  
79          String originalValue = ConfigContext.getCurrentContextConfig().getProperty(propertyName);
80      	LOG.info("Changing config property '" + propertyName + "' from " + originalValue + " to " + propertyValue);
81      	if (propertyValue == null) {
82      		ConfigContext.getCurrentContextConfig().removeProperty(propertyName);
83      	} else {
84      		ConfigContext.getCurrentContextConfig().putProperty(propertyName, propertyValue);
85      	}
86      }
87  
88      @Override
89      public void start() throws Exception {
90      	if (getThreadPool() == null) {
91      		throw new IllegalStateException("The threadPool has not been set on the busAdminService");
92      	}
93      	setStarted(true);
94      }
95  
96      @Override
97      public void stop() throws Exception {
98      	setStarted(false);
99      }
100 
101 }