You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by de...@apache.org on 2006/10/05 14:32:42 UTC
svn commit: r453202 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: ./
deployment/ description/ engine/
Author: deepal
Date: Thu Oct 5 05:32:41 2006
New Revision: 453202
URL: http://svn.apache.org/viewvc?view=rev&rev=453202
Log:
changed Axis2 as we discussed in http://marc.theaimsgroup.com/?t=115829377800001&r=1&w=2
- add a new interface called ServiceLifeCycle
- remove service interface
- no need to add new parameter called "loadonstrtup"
- you can specify service life cycle as
<service name="foo" class="impl">
Added:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ServiceLifeCycle.java
Removed:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Service.java
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ServiceBuilder.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ListenerManager.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java?view=diff&rev=453202&r1=453201&r2=453202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java Thu Oct 5 05:32:41 2006
@@ -211,8 +211,6 @@
public static final String COOKIE_STRING = "Cookie";
public static final String SESSION_COOKIE = "axis_session";
- public static final String LOAD_ON_STARTUP = "load-on-startup";
-
/**
* Addressing Constants
*/
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java?view=diff&rev=453202&r1=453201&r2=453202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java Thu Oct 5 05:32:41 2006
@@ -31,8 +31,8 @@
import org.apache.axis2.deployment.util.Utils;
import org.apache.axis2.description.*;
import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.axis2.engine.DependencyManager;
import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.engine.ServiceLifeCycle;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.commons.logging.Log;
@@ -428,15 +428,11 @@
Iterator services = serviceGroup.getServices();
while (services.hasNext()) {
AxisService axisService = (AxisService) services.next();
- Parameter load_on_startup = axisService.getParameter(Constants.LOAD_ON_STARTUP);
- if (load_on_startup != null) {
- String value = (String) load_on_startup.getValue();
- if ("true".equals(value.trim())) {
- DependencyManager.startService(axisService, configContext);
- }
+ ServiceLifeCycle serviceLifeCycle = axisService.getServiceLifeCycle();
+ if (serviceLifeCycle != null) {
+ serviceLifeCycle.startUp(configContext, axisService);
}
}
-
}
private void addAsWebResources(File in, String serviceFileName, AxisServiceGroup serviceGroup) {
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ServiceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ServiceBuilder.java?view=diff&rev=453202&r1=453201&r2=453202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ServiceBuilder.java Thu Oct 5 05:32:41 2006
@@ -25,7 +25,9 @@
import org.apache.axis2.description.*;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.engine.ServiceLifeCycle;
import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.util.Loader;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -114,6 +116,22 @@
if (service.getTargetNamespace() == null ||
"".equals(service.getTargetNamespace())) {
service.setTargetNamespace(Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE);
+ }
+ }
+ //Processing service lifecycle attribute
+ OMAttribute serviceLifeCycleClass = service_element.
+ getAttribute(new QName(TAG_CLASS_NAME));
+ if (serviceLifeCycleClass != null) {
+ String className = serviceLifeCycleClass.getAttributeValue();
+ if (className != null) {
+ try {
+ ClassLoader loader = service.getClassLoader();
+ Class serviceLifeCycleClassImpl = Loader.loadClass(loader, className);
+ service.setServiceLifeCycle(
+ (ServiceLifeCycle) serviceLifeCycleClassImpl.newInstance());
+ } catch (Exception e) {
+ throw new DeploymentException(e.getMessage(), e);
+ }
}
}
//Setting schema namespece if any
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?view=diff&rev=453202&r1=453201&r2=453202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java Thu Oct 5 05:32:41 2006
@@ -27,6 +27,7 @@
import org.apache.axis2.deployment.util.Utils;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.engine.ServiceLifeCycle;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.modules.Module;
import org.apache.axis2.phaseresolver.PhaseResolver;
@@ -123,6 +124,9 @@
private boolean enableAllTransports = true;
private List exposedTransports = new ArrayList();
+ //To keep reference to ServiceLifeCycle instance , if the user has
+ // specified in services.xml
+ private ServiceLifeCycle serviceLifeCycle;
/**
* Keeps track whether the schema locations are adjusted
@@ -1550,5 +1554,13 @@
}
}
return false;
+ }
+
+ public ServiceLifeCycle getServiceLifeCycle() {
+ return serviceLifeCycle;
+ }
+
+ public void setServiceLifeCycle(ServiceLifeCycle serviceLifeCycle) {
+ this.serviceLifeCycle = serviceLifeCycle;
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java?view=diff&rev=453202&r1=453201&r2=453202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java Thu Oct 5 05:32:41 2006
@@ -19,8 +19,6 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-import org.apache.axis2.util.Loader;
-import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.context.ServiceGroupContext;
@@ -28,6 +26,7 @@
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.util.Loader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -51,25 +50,19 @@
throws AxisFault {
try {
- // if this service is implementing the o.a.a.Service interface, then use that fact to invoke the
- // proper method.
- if (obj instanceof Service) {
- ((org.apache.axis2.engine.Service) obj).setOperationContext(opCtx);
- } else {
- Class classToLoad = obj.getClass();
-
- // We can not call classToLoad.getDeclaredMethed() , since there
- // can be insatnce where mutiple services extends using one class
- // just for init and other reflection methods
- Method[] methods = classToLoad.getMethods();
+ Class classToLoad = obj.getClass();
- for (int i = 0; i < methods.length; i++) {
- if (MESSAGE_CONTEXT_INJECTION_METHOD.equals(methods[i].getName())
- && (methods[i].getParameterTypes().length == 1)
- && (methods[i].getParameterTypes()[0] == OperationContext.class)) {
- methods[i].invoke(obj, new Object[]{opCtx});
- break;
- }
+ // We can not call classToLoad.getDeclaredMethed() , since there
+ // can be insatnce where mutiple services extends using one class
+ // just for init and other reflection methods
+ Method[] methods = classToLoad.getMethods();
+
+ for (int i = 0; i < methods.length; i++) {
+ if (MESSAGE_CONTEXT_INJECTION_METHOD.equals(methods[i].getName())
+ && (methods[i].getParameterTypes().length == 1)
+ && (methods[i].getParameterTypes()[0] == OperationContext.class)) {
+ methods[i].invoke(obj, new Object[]{opCtx});
+ break;
}
}
} catch (SecurityException e) {
@@ -90,23 +83,19 @@
public static void initServiceClass(Object obj,
ServiceContext serviceContext) throws AxisFault {
try {
- if (obj instanceof org.apache.axis2.engine.Service) {
- Service service = (org.apache.axis2.engine.Service) obj;
- service.init(serviceContext);
- } else {
- Class classToLoad = obj.getClass();
- // We can not call classToLoad.getDeclaredMethed() , since there
- // can be insatnce where mutiple services extends using one class
- // just for init and other reflection methods
- Method[] methods = classToLoad.getMethods();
- for (int i = 0; i < methods.length; i++) {
- if (SERVICE_INIT_METHOD.equals(methods[i].getName())
- && (methods[i].getParameterTypes().length == 1)
- && (methods[i].getParameterTypes()[0] == ServiceContext.class)) {
- methods[i].invoke(obj, new Object[]{serviceContext});
- break;
- }
+ Class classToLoad = obj.getClass();
+ // We can not call classToLoad.getDeclaredMethed() , since there
+ // can be insatnce where mutiple services extends using one class
+ // just for init and other reflection methods
+ Method[] methods = classToLoad.getMethods();
+
+ for (int i = 0; i < methods.length; i++) {
+ if (SERVICE_INIT_METHOD.equals(methods[i].getName())
+ && (methods[i].getParameterTypes().length == 1)
+ && (methods[i].getParameterTypes()[0] == ServiceContext.class)) {
+ methods[i].invoke(obj, new Object[]{serviceContext});
+ break;
}
}
} catch (SecurityException e) {
@@ -156,62 +145,23 @@
}
}
- /**
- * To startup service when user puts load-on-startup parameter
- */
- public static void startService(AxisService axisService,
- ConfigurationContext configCtx) {
- ClassLoader classLoader = axisService.getClassLoader();
- Parameter implInfoParam = axisService.getParameter(Constants.SERVICE_CLASS);
- if (implInfoParam != null) {
- try {
- Class implClass = Loader.loadClass(
- classLoader,
- ((String) implInfoParam.getValue()).trim());
- Object serviceImpl = implClass.newInstance();
- if (serviceImpl instanceof Service) {
- org.apache.axis2.engine.Service service = (Service) serviceImpl;
- service.startUp(configCtx, axisService);
- } else {
- Method[] methods = serviceImpl.getClass().getMethods();
- for (int i = 0; i < methods.length; i++) {
- if (SERVICE_START_METHOD.equals(methods[i].getName())
- && (methods[i].getParameterTypes().length == 2)
- && (methods[i].getParameterTypes()[0] == ConfigurationContext.class)
- && (methods[i].getParameterTypes()[1] == AxisService.class)) {
- methods[i].invoke(serviceImpl, new Object[]{configCtx, axisService});
- break;
- }
- }
- }
- } catch (Exception e) {
- log.info("Exception trying to call " + SERVICE_START_METHOD, e);
- new AxisFault(e);
- }
- }
- }
-
public static void destroyServiceObject(ServiceContext serviceContext) throws AxisFault {
try {
Object obj = serviceContext.getProperty(ServiceContext.SERVICE_OBJECT);
if (obj != null) {
Class classToLoad = obj.getClass();
- if (obj instanceof Service) {
- org.apache.axis2.engine.Service service = (Service) obj;
- service.destroy(serviceContext);
- } else {
- // We can not call classToLoad.getDeclaredMethed() , since there
- // can be insatnce where mutiple services extends using one class
- // just for init and other reflection methods
- Method[] methods = classToLoad.getMethods();
-
- for (int i = 0; i < methods.length; i++) {
- if (SERVICE_DESTROY_METHOD.equals(methods[i].getName())
- && (methods[i].getParameterTypes().length == 1)
- && (methods[i].getParameterTypes()[0] == ServiceContext.class)) {
- methods[i].invoke(obj, new Object[]{serviceContext});
- break;
- }
+
+ // We can not call classToLoad.getDeclaredMethed() , since there
+ // can be insatnce where mutiple services extends using one class
+ // just for init and other reflection methods
+ Method[] methods = classToLoad.getMethods();
+
+ for (int i = 0; i < methods.length; i++) {
+ if (SERVICE_DESTROY_METHOD.equals(methods[i].getName())
+ && (methods[i].getParameterTypes().length == 1)
+ && (methods[i].getParameterTypes()[0] == ServiceContext.class)) {
+ methods[i].invoke(obj, new Object[]{serviceContext});
+ break;
}
}
}
@@ -229,6 +179,4 @@
throw new AxisFault(e);
}
}
-
-
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ListenerManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ListenerManager.java?view=diff&rev=453202&r1=453201&r2=453202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ListenerManager.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ListenerManager.java Thu Oct 5 05:32:41 2006
@@ -174,6 +174,8 @@
}
}
}
+ //calling service shutdown method
+ shutDownServices(configctx);
configctx.cleanupContexts();
stopped = true;
}
@@ -202,5 +204,20 @@
public boolean isStopped() {
return stopped;
+ }
+
+ /**
+ * This will call shutDown method of all the service , if they have implemnted
+ * the ServiceLifeCycle interface
+ */
+ private void shutDownServices(ConfigurationContext configCtx) {
+ Iterator services = configCtx.getAxisConfiguration().getServices().values().iterator();
+ while (services.hasNext()) {
+ AxisService axisService = (AxisService) services.next();
+ ServiceLifeCycle serviceLifeCycle = axisService.getServiceLifeCycle();
+ if (serviceLifeCycle != null) {
+ serviceLifeCycle.shutDown(configCtx, axisService);
+ }
+ }
}
}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ServiceLifeCycle.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ServiceLifeCycle.java?view=auto&rev=453202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ServiceLifeCycle.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/ServiceLifeCycle.java Thu Oct 5 05:32:41 2006
@@ -0,0 +1,43 @@
+package org.apache.axis2.engine;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*
+*/
+
+/**
+ * When you want to initialize database connections , starting threads and etc..
+ * at the time you deploy service (similar to loadonstartup).
+ * You need to implement this interface and add additional (optional) attribute
+ * into services.xml <service name=Foo class=Service life cycle impl class>
+ */
+
+public interface ServiceLifeCycle {
+
+ /**
+ * this will be called during the deployement time of the service. irrespective
+ * of the service scope this method will be called
+ */
+ public void startUp(ConfigurationContext configctx, AxisService service);
+
+ /**
+ * this will be called during the system shut down time. irrespective
+ * of the service scope this method will be called
+ */
+ public void shutDown(ConfigurationContext configctx, AxisService service);
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org