Author: rareddy
Date: 2009-03-30 18:31:07 -0400 (Mon, 30 Mar 2009)
New Revision: 668
Modified:
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java
trunk/server/src/main/java/com/metamatrix/server/connector/service/ConnectorService.java
Log:
TEIID-418: The common extension class loader will be cached and shared to use by all the
services. If any extension modules changed or configuration changed then this classloader
will be recycled and next time a service needs the class loader it will be re-created.
Modified:
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java
===================================================================
---
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java 2009-03-30
22:26:36 UTC (rev 667)
+++
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java 2009-03-30
22:31:07 UTC (rev 668)
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -61,12 +62,14 @@
import com.metamatrix.common.config.api.VMComponentDefnID;
import com.metamatrix.common.config.api.VMComponentDefnType;
import com.metamatrix.common.config.api.exceptions.ConfigurationException;
+import com.metamatrix.common.extensionmodule.ExtensionModuleEvent;
import com.metamatrix.common.extensionmodule.protocol.URLFactory;
import com.metamatrix.common.id.dbid.DBIDGenerator;
import com.metamatrix.common.id.dbid.DBIDGeneratorException;
import com.metamatrix.common.log.LogConfiguration;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.messaging.MessageBus;
+import com.metamatrix.common.messaging.MessagingException;
import com.metamatrix.common.queue.WorkerPool;
import com.metamatrix.common.queue.WorkerPoolFactory;
import com.metamatrix.common.queue.WorkerPoolStats;
@@ -74,6 +77,7 @@
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.common.util.VMNaming;
import com.metamatrix.common.util.LogContextsUtil.PlatformAdminConstants;
+import com.metamatrix.core.event.EventObjectListener;
import com.metamatrix.core.util.FileUtil;
import com.metamatrix.core.util.ZipFileUtil;
import com.metamatrix.metadata.runtime.RuntimeMetadataCatalog;
@@ -92,6 +96,7 @@
import com.metamatrix.platform.admin.apiimpl.RuntimeStateAdminAPIImpl;
import com.metamatrix.platform.admin.apiimpl.SessionAdminAPIImpl;
import com.metamatrix.platform.config.api.service.ConfigurationServiceInterface;
+import com.metamatrix.platform.config.event.ConfigurationChangeEvent;
import com.metamatrix.platform.registry.ClusteredRegistryState;
import com.metamatrix.platform.registry.ResourceNotBoundException;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
@@ -161,6 +166,8 @@
protected ClientServiceRegistry clientServices;
private Map<ComponentTypeID, Properties> defaultPropertiesCache = new
HashMap<ComponentTypeID, Properties>();
private Properties hostProperties;
+ private ClassLoader commonExtensionClassLoader = null;
+ private String commonExtensionClasspath;
private int force_shutdown_time = DEFAULT_FORCE_SHUTDOWN_TIME;
@@ -199,6 +206,8 @@
this.registerSubSystemAdminAPIs(hostManagement);
+ manageCommonExtensionClassloader();
+
addShutdownHook();
}
@@ -701,22 +710,63 @@
}
}
- private void startService(ClientServiceRegistry serverListenerRegistry, ServiceID
serviceID, DeployedComponent deployedComponent,final String
serviceClass,ProductServiceConfigID pscID,Properties serviceProps) {
- String serviceInstanceName = null;
-
- ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
- try {
-
+ /**
+ * Throw away the common extension class loader when there is change in the Extension
modules or has a changed extension
+ * classpath.
+ */
+ private void manageCommonExtensionClassloader() throws MessagingException {
+ this.messageBus.addListener(ExtensionModuleEvent.class, new EventObjectListener() {
+ @Override
+ public void processEvent(EventObject obj) {
+ if (obj instanceof ExtensionModuleEvent) {
+ ProcessController.this.commonExtensionClassLoader = null;
+ }
+ }
+ });
+
+ this.messageBus.addListener(ConfigurationChangeEvent.class, new
EventObjectListener() {
+ @Override
+ public void processEvent(EventObject obj) {
+ if (obj instanceof ConfigurationChangeEvent) {
+ String extensionClasspath =
CurrentConfiguration.getInstance().getProperties().getProperty(ServerPropertyNames.COMMON_EXTENSION_CLASPATH);
+ if (extensionClasspath != null) {
+ if (!extensionClasspath.equals(ProcessController.this.commonExtensionClasspath)) {
+ ProcessController.this.commonExtensionClassLoader = null;
+ }
+ }
+ else {
+ ProcessController.this.commonExtensionClassLoader = null;
+ }
+ }
+ }
+ });
+ }
+
+ private ClassLoader getCommonExtensionClassloader() {
+ if (this.commonExtensionClassLoader == null) {
String extensionClasspath =
CurrentConfiguration.getInstance().getProperties().getProperty(ServerPropertyNames.COMMON_EXTENSION_CLASPATH);
if (extensionClasspath != null && extensionClasspath.length() > 0) {
try {
- ClassLoader commonExtensionClassLoader = new
URLFilteringClassLoader(URLFactory.parseURLs(extensionClasspath, ";"),
currentClassLoader); //$NON-NLS-1$
- Thread.currentThread().setContextClassLoader(commonExtensionClassLoader);
- logMessage(PlatformPlugin.Util.getString("commonextensionspath_in_use",
extensionClasspath, serviceID)); //$NON-NLS-1$
+ this.commonExtensionClassLoader = new
URLFilteringClassLoader(URLFactory.parseURLs(extensionClasspath, ";"),
Thread.currentThread().getContextClassLoader()); //$NON-NLS-1$
+ this.commonExtensionClasspath = extensionClasspath;
+ logMessage(PlatformPlugin.Util.getString("commonextensionspath_in_use",
extensionClasspath)); //$NON-NLS-1$
} catch (MalformedURLException e) {
- logMessage(PlatformPlugin.Util.getString("commonextensionspath_not_in_use",extensionClasspath,
serviceID)); //$NON-NLS-1$
+ logMessage(PlatformPlugin.Util.getString("commonextensionspath_not_in_use",extensionClasspath));
//$NON-NLS-1$
}
}
+ }
+ return this.commonExtensionClassLoader;
+ }
+
+ private void startService(ClientServiceRegistry serverListenerRegistry, ServiceID
serviceID, DeployedComponent deployedComponent,final String
serviceClass,ProductServiceConfigID pscID,Properties serviceProps) {
+ String serviceInstanceName = null;
+
+ ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ ClassLoader commonExtensionClassLoader = getCommonExtensionClassloader();
+ if (commonExtensionClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(commonExtensionClassLoader);
+ }
if (serviceID == null) {
serviceID = this.createServiceID();
Modified:
trunk/server/src/main/java/com/metamatrix/server/connector/service/ConnectorService.java
===================================================================
---
trunk/server/src/main/java/com/metamatrix/server/connector/service/ConnectorService.java 2009-03-30
22:26:36 UTC (rev 667)
+++
trunk/server/src/main/java/com/metamatrix/server/connector/service/ConnectorService.java 2009-03-30
22:31:07 UTC (rev 668)
@@ -202,8 +202,8 @@
*/
private ClassLoader getCustomClassLoader(String urls) throws
ApplicationInitializationException{
if(urls == null || urls.trim().length() == 0){
- String msg =
ServerPlugin.Util.getString("ConnectorService.NoClassPath"); //$NON-NLS-1$
- throw new ApplicationInitializationException(msg);
+ LogManager.logDetail(LogCommonConstants.CTX_CONFIG,
ServerPlugin.Util.getString("ConnectorService.NoClassPath")); //$NON-NLS-1$
+ return null;
}
synchronized (ConnectorService.class) {
@@ -219,13 +219,13 @@
}
try {
- result = new URLFilteringClassLoader(URLFactory.parseURLs(urls,
";")); //$NON-NLS-1$
+ result = new URLFilteringClassLoader(URLFactory.parseURLs(urls,
";"), Thread.currentThread().getContextClassLoader()); //$NON-NLS-1$
if (cacheClassLoaders) {
classLoaderCache.put(urls, new
WeakReference<NonDelegatingClassLoader>(result));
}
return result;
} catch (MalformedURLException e1) {
- String msg =
ServerPlugin.Util.getString("ConnectorService.IllegalClassPath"); //$NON-NLS-1$
+ String msg =
ServerPlugin.Util.getString("ConnectorService.IllegalClassPath", urls);
//$NON-NLS-1$
throw new ApplicationInitializationException(msg);
}
}
@@ -239,23 +239,17 @@
* @throws ApplicationInitializationException
*/
private ConnectorManager createConnectorManager(Properties deMaskedProps, ClassLoader
loader) throws ApplicationLifecycleException {
- try {
- ConnectorManager connectorManager = (ConnectorManager)
ReflectionHelper.create(ConnectorManager.class.getName(), null, loader);
-
- // Create a stringified connector ID from the serviceID
- ServiceID id = this.getID();
- String connID = id.getHostName()+"|"+ id.getProcessName() +
"|" + id.getID(); //$NON-NLS-1$ //$NON-NLS-2$
- deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_ID, connID);
- deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_BINDING_NAME,
getInstanceName());
- deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_VM_NAME,
VMNaming.getProcessName());
- connectorManager.setClassloader(loader);
- connectorManager.initialize(deMaskedProps);
- return connectorManager;
-
- } catch(MetaMatrixCoreException e) {
- String msg =
ServerPlugin.Util.getString("ConnectorService.Unexpected_error_instantiating_ConnectorManagerImpl");
//$NON-NLS-1$
- throw new ApplicationLifecycleException(e, msg);
- }
+ ConnectorManager connectorManager = new ConnectorManager();
+
+ // Create a stringified connector ID from the serviceID
+ ServiceID id = this.getID();
+ String connID = id.getHostName()+"|"+ id.getProcessName() +
"|" + id.getID(); //$NON-NLS-1$ //$NON-NLS-2$
+ deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_ID, connID);
+ deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_BINDING_NAME,
getInstanceName());
+ deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_VM_NAME,
VMNaming.getProcessName());
+ connectorManager.setClassloader(loader);
+ connectorManager.initialize(deMaskedProps);
+ return connectorManager;
}
/**
@@ -364,7 +358,7 @@
*/
public void checkState() throws ServiceStateException {
- if (monitoringEnabled) {
+ if (monitoringEnabled && connectorMgr != null) {
Boolean status = connectorMgr.getStatus();
int state = getCurrentState();
if (state == ServiceState.STATE_OPEN && status == Boolean.FALSE) {