View Javadoc

1   /*
2    * Copyright 2007 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  package org.kuali.rice.ksb.messaging.service.impl;
17  
18  import org.kuali.rice.core.config.ConfigContext;
19  import org.kuali.rice.core.lifecycle.BaseLifecycle;
20  import org.kuali.rice.ksb.messaging.AsynchronousCall;
21  import org.kuali.rice.ksb.messaging.PersistedMessage;
22  import org.kuali.rice.ksb.messaging.callforwarding.ForwardedCallHandlerImpl;
23  import org.kuali.rice.ksb.messaging.config.ServiceBasedServiceDefinitionRegisterer;
24  import org.kuali.rice.ksb.messaging.service.BusAdminService;
25  import org.kuali.rice.ksb.messaging.threadpool.KSBThreadPool;
26  import org.kuali.rice.ksb.service.KSBServiceLocator;
27  
28  
29  /**
30   * Implementation of the Bus Admin service.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class BusAdminServiceImpl extends BaseLifecycle implements BusAdminService {
35  
36      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BusAdminServiceImpl.class);
37  
38      private ServiceBasedServiceDefinitionRegisterer defRegisterer;
39  
40      public void forward(PersistedMessage message) throws Exception {
41  	// this is just weird...
42  	AsynchronousCall methodCall = message.getPayload().getMethodCall();
43  	message.setMethodCall(methodCall);
44  	// TODO there's probably a better way to servisize or refactor this
45  	new ForwardedCallHandlerImpl().handleCall(message);
46      }
47  
48      public void ping() {
49      }
50  
51      public void setCorePoolSize(int corePoolSize) {
52  	LOG.info("Setting core pool size to " + corePoolSize);
53  	KSBServiceLocator.getThreadPool().setCorePoolSize(corePoolSize);
54      }
55  
56      public void setMaximumPoolSize(int maxPoolSize) {
57  	LOG.info("Setting max pool size to " + maxPoolSize);
58  	KSBThreadPool threadPool = KSBServiceLocator.getThreadPool();
59  	if (maxPoolSize < threadPool.getCorePoolSize()) {
60  	    maxPoolSize = threadPool.getCorePoolSize();
61  	}
62  	threadPool.setMaximumPoolSize(maxPoolSize);
63      }
64  
65      public void setConfigProperty(String propertyName, String propertyValue) {
66  	String originalValue = ConfigContext.getCurrentContextConfig().getProperty(propertyName);
67  	LOG.info("Changing config property '" + propertyName + "' from " + originalValue + " to " + propertyValue);
68  	if (propertyValue == null) {
69  	    ConfigContext.getCurrentContextConfig().removeProperty(propertyName);
70  	} else {
71  	    ConfigContext.getCurrentContextConfig().putProperty(propertyName, propertyValue);
72  	}
73      }
74  
75      public void start() throws Exception {
76  	this.defRegisterer = new ServiceBasedServiceDefinitionRegisterer("ksb.busAdminServiceDefinition");
77  	this.defRegisterer.registerServiceDefinition(false);
78  	setStarted(true);
79      }
80  
81      public void stop() throws Exception {
82  	this.defRegisterer.unregisterServiceDefinition();
83  	setStarted(false);
84      }
85  
86  }