Author: rareddy
Date: 2009-11-17 14:07:47 -0500 (Tue, 17 Nov 2009)
New Revision: 1570
Removed:
branches/JCA/build/kit-jboss-container/conf/jboss-cache-configuration.xml
Modified:
branches/JCA/build/assembly/jboss-container/dependencies.xml
branches/JCA/build/kit-jboss-container/deploy/teiid-jboss-beans.xml
branches/JCA/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCacheFactory.java
branches/JCA/engine/src/main/java/com/metamatrix/dqp/ResourceFinder.java
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java
branches/JCA/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java
branches/JCA/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java
branches/JCA/jboss-integration/pom.xml
branches/JCA/pom.xml
branches/JCA/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
branches/JCA/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java
Log:
TEIID-833: Initialized the JBoss Cache using the MC framework.
Modified: branches/JCA/build/assembly/jboss-container/dependencies.xml
===================================================================
--- branches/JCA/build/assembly/jboss-container/dependencies.xml 2009-11-17 13:31:34 UTC
(rev 1569)
+++ branches/JCA/build/assembly/jboss-container/dependencies.xml 2009-11-17 19:07:47 UTC
(rev 1570)
@@ -23,7 +23,7 @@
<include>org.jboss.teiid:teiid-runtime</include>
<include>org.jboss.teiid:teiid-engine</include>
<include>org.jboss.teiid:teiid-metadata</include>
- <include>org.jboss.teiid:jboss-integration</include>
+ <include>org.jboss.teiid:teiid-jboss-integration</include>
</includes>
<binaries>
Deleted: branches/JCA/build/kit-jboss-container/conf/jboss-cache-configuration.xml
===================================================================
--- branches/JCA/build/kit-jboss-container/conf/jboss-cache-configuration.xml 2009-11-17
13:31:34 UTC (rev 1569)
+++ branches/JCA/build/kit-jboss-container/conf/jboss-cache-configuration.xml 2009-11-17
19:07:47 UTC (rev 1570)
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache xmlns="urn:jboss:jbosscache-core:config:3.1">
-
- <locking isolationLevel="READ_COMMITTED"
lockAcquisitionTimeout="15000" lockParentForChildInsertRemove="true"
/>
- <transaction
transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"
/>
-
- <shutdown hookBehavior="DEFAULT" />
-
- <loaders passivation="true" shared="false">
- <loader class="org.jboss.cache.loader.FileCacheLoader"
fetchPersistentState="true" purgeOnStartup="true">
- <properties>location=./teiid/cache</properties>
- </loader>
- </loaders>
-
- <eviction wakeUpInterval="15000">
- <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm"
eventQueueSize="100000">
- <property name="maxNodes" value="10000" />
- <!-- 0 = immediate eviction, -1 = no limit -->
- <property name="timeToLive" value="-1" />
- </default>
- </eviction>
-
-</jbosscache>
Modified: branches/JCA/build/kit-jboss-container/deploy/teiid-jboss-beans.xml
===================================================================
--- branches/JCA/build/kit-jboss-container/deploy/teiid-jboss-beans.xml 2009-11-17
13:31:34 UTC (rev 1569)
+++ branches/JCA/build/kit-jboss-container/deploy/teiid-jboss-beans.xml 2009-11-17
19:07:47 UTC (rev 1570)
@@ -24,6 +24,81 @@
</bean>
+ <!-- JBOSS Cache -->
+ <!-- First we create a Configuration object for the cache -->
+ <bean name="TeiidJBossCacheConfig"
class="org.jboss.cache.config.Configuration">
+
+ <!-- Externally injected services -->
+ <property name="runtimeConfig">
+ <bean class="org.jboss.cache.config.RuntimeConfig">
+ <property name="transactionManager">
+ <inject bean="TransactionManager"
property="transactionManager"/>
+ </property>
+ </bean>
+ </property>
+
+ <!-- Node locking level : SERIALIZABLE, REPEATABLE_READ
(default),READ_COMMITTED,READ_UNCOMMITTED,NONE -->
+ <property name="isolationLevel">READ_COMMITTED</property>
+
+ <!-- Valid modes are LOCAL,REPL_ASYNC,REPL_SYNC -->
+ <property name="cacheMode">LOCAL</property>
+
+ <!-- Max number of milliseconds to wait for a lock acquisition -->
+ <property name="lockAcquisitionTimeout">15000</property>
+
+ <property name="exposeManagementStatistics">true</property>
+
+ <!-- Specific eviction policy configurations. This is LRU -->
+ <property name="evictionConfig">
+ <bean class="org.jboss.cache.config.EvictionConfig">
+ <property
name="defaultEvictionPolicyClass">org.jboss.cache.eviction.LRUPolicy</property>
+ <property name="wakeupIntervalSeconds">15</property>
+ <property name="evictionRegionConfigs">
+ <list>
+ <bean
class="org.jboss.cache.config.EvictionRegionConfig">
+ <property
name="regionName">/_default_</property>
+ <property name="evictionPolicyConfig">
+ <bean name="ExampleDefaultLRUConfig"
class="org.jboss.cache.eviction.LRUConfiguration">
+ <property
name="maxNodes">10000</property>
+ <property
name="timeToLiveSeconds">-1</property>
+ </bean>
+ </property>
+ </bean>
+ </list>
+ </property>
+ </bean>
+ </property>
+
+ </bean>
+
+ <!-- Factory to build the Cache. -->
+ <bean name="TeiidDefaultCacheFactory"
class="org.jboss.cache.DefaultCacheFactory">
+ <constructor factoryClass="org.jboss.cache.DefaultCacheFactory"
factoryMethod="getInstance"/>
+ </bean>
+
+ <!-- The caches themselves -->
+ <bean name="TeiidJBossCache" class="org.jboss.cache.Cache">
+ <constructor factoryMethod="createCache">
+ <factory bean="TeiidDefaultCacheFactory"/>
+ <parameter
class="org.jboss.cache.config.Configuration"><inject
bean="TeiidJBossCacheConfig"/></parameter>
+ <parameter class="boolean">false</parameter>
+ </constructor>
+ </bean>
+
+ <bean name="TeiidJBossCacheMBean"
class="org.jboss.cache.jmx.CacheJmxWrapper">
+
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.cache:service=TeiidCache",exposedInterface=org.jboss.cache.jmx.CacheJmxWrapperMBean.class,registerDirectly=true)</annotation>
+ <constructor>
+ <parameter class="org.jboss.cache.Cache"><inject
bean="TeiidJBossCache"/></parameter>
+ </constructor>
+ </bean>
+
+ <bean name="TeiidCache"
class="com.metamatrix.cache.jboss.JBossCacheFactory">
+
<annotation>(a)org.jboss.aop.microcontainer.aspects.jndi.JndiBinding(name="teiid/cache")</annotation>
+ <property
name="cacheName">jboss.cache:service=TeiidCache</property>
+ <demand>TransactionManager</demand>
+ <demand>TeiidJBossCacheMBean</demand>
+ </bean>
+
<!-- Connector Types -->
<bean name="connector-jdbc-template"
class="org.teiid.templates.connector.ConnectorTypeTemplate">
<property name="info"><inject
bean="connector-jdbc-templateinfo"/></property>
Modified:
branches/JCA/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCacheFactory.java
===================================================================
---
branches/JCA/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCacheFactory.java 2009-11-17
13:31:34 UTC (rev 1569)
+++
branches/JCA/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCacheFactory.java 2009-11-17
19:07:47 UTC (rev 1570)
@@ -22,69 +22,47 @@
package com.metamatrix.cache.jboss;
-import java.util.List;
-import java.util.Properties;
+import java.io.Serializable;
-import org.jboss.cache.DefaultCacheFactory;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.Region;
import org.jboss.cache.config.EvictionAlgorithmConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.eviction.FIFOAlgorithmConfig;
import org.jboss.cache.eviction.LFUAlgorithmConfig;
import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.eviction.MRUAlgorithmConfig;
-import org.jboss.cache.jmx.JmxRegistrationManager;
+import org.jboss.cache.jmx.CacheJmxWrapperMBean;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
import com.metamatrix.cache.Cache;
import com.metamatrix.cache.CacheConfiguration;
import com.metamatrix.cache.CacheFactory;
import com.metamatrix.cache.Cache.Type;
import com.metamatrix.cache.CacheConfiguration.Policy;
import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
-@Singleton
-public class JBossCacheFactory implements CacheFactory {
- //private static final String NAME = "Cache"; //$NON-NLS-1$
- private org.jboss.cache.Cache cacheStore;
+public class JBossCacheFactory implements CacheFactory, Serializable{
+ private transient org.jboss.cache.Cache cacheStore;
private volatile boolean destroyed = false;
- JmxRegistrationManager jmxManager;
- private Properties props;
-
- @Inject
- public JBossCacheFactory(@Named("DQPProperties") Properties props) {
-
- this.props = props;
-
- if (this.cacheStore == null) {
- this.cacheStore = initCache();
- }
-// try {
-// jmxManager = new JmxRegistrationManager(jmx.getMBeanServer(), cacheStore,
jmx.buildName(JMXUtil.MBeanType.SERVICE, NAME));
-// jmxManager.registerAllMBeans();
-// } catch (FailedToRegisterException e) {
-// throw new MetaMatrixRuntimeException(e.getCause());
-// }
- }
- private org.jboss.cache.Cache initCache() {
- org.jboss.cache.Cache cache = new
DefaultCacheFactory().createCache("jboss-cache-configuration.xml", false);
//$NON-NLS-1$
- List<IndividualCacheLoaderConfig> configs =
cache.getConfiguration().getCacheLoaderConfig().getIndividualCacheLoaderConfigs();
- Properties p = configs.get(0).getProperties();
- String workspaceDir = this.props.getProperty(DQPEmbeddedProperties.DQP_WORKDIR);
- p.setProperty("location", workspaceDir + "/cache"); //$NON-NLS-1$
//$NON-NLS-2$
- configs.get(0).setProperties(p);
- cache.create();
- cache.start();
- return cache;
- }
+ public void setCacheName(String jmxName) {
+ try {
+ MBeanServer server = MBeanServerFactory.findMBeanServer(null).get(0);
+ ObjectName on = new ObjectName(jmxName);
+ CacheJmxWrapperMBean cacheWrapper =
MBeanServerInvocationHandler.newProxyInstance(server, on, CacheJmxWrapperMBean.class,
false);
+ this.cacheStore = cacheWrapper.getCache();
+ } catch (MalformedObjectNameException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ }
/**
* {@inheritDoc}
@@ -132,9 +110,11 @@
}
public void destroy() {
- jmxManager.unregisterAllMBeans();
- this.cacheStore.stop();
- this.cacheStore.destroy();
this.destroyed = true;
}
+
+ // this will be called by microcontainer.
+ public void stop() {
+ destroy();
+ }
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/dqp/ResourceFinder.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/dqp/ResourceFinder.java 2009-11-17
13:31:34 UTC (rev 1569)
+++ branches/JCA/engine/src/main/java/com/metamatrix/dqp/ResourceFinder.java 2009-11-17
19:07:47 UTC (rev 1570)
@@ -23,20 +23,21 @@
package com.metamatrix.dqp;
-import com.google.inject.Injector;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
import com.metamatrix.cache.CacheFactory;
+import com.metamatrix.core.MetaMatrixRuntimeException;
public class ResourceFinder {
- protected static Injector injector;
public static CacheFactory getCacheFactory() {
- if (injector == null) {
- throw new IllegalStateException();
+ try {
+ InitialContext ic = new InitialContext();
+ return (CacheFactory)ic.lookup("teiid/cache");
+ } catch (NamingException e) {
+ throw new MetaMatrixRuntimeException(e);
}
- return injector.getInstance(CacheFactory.class);
}
- public static void setInjector(Injector i) {
- injector = i;
- }
}
Modified:
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java
===================================================================
---
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java 2009-11-17
13:31:34 UTC (rev 1569)
+++
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java 2009-11-17
19:07:47 UTC (rev 1570)
@@ -21,31 +21,27 @@
*/
package org.teiid.dqp.internal.cache;
-import java.util.Properties;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
import com.metamatrix.cache.Cache;
import com.metamatrix.cache.CacheConfiguration;
import com.metamatrix.cache.CacheFactory;
import com.metamatrix.cache.CacheConfiguration.Policy;
import com.metamatrix.common.log.LogManager;
-import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.dqp.util.LogConstants;
-@Singleton
public class DQPContextCache {
private static enum Scope {REQUEST,SESSION,SERVICE,VDB,GLOBAL;}
private Cache cache;
private String processIdentifier;
- @Inject
- public DQPContextCache(@Named("DQPProperties") Properties props, CacheFactory
cacheFactory) {
+ // called by mc
+ public void setCacheFactory(CacheFactory cacheFactory) {
this.cache = cacheFactory.get(Cache.Type.SCOPED_CACHE, new
CacheConfiguration(Policy.LRU, 600, 10000));
- this.processIdentifier = props.getProperty(DQPEmbeddedProperties.PROCESSNAME);
}
+ //called by mc
+ public void setProcessName(String name) {
+ this.processIdentifier = name;
+ }
public Cache getGlobalScopedCache() {
return this.cache.addChild(Scope.GLOBAL.name());
Modified:
branches/JCA/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java
===================================================================
---
branches/JCA/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java 2009-11-17
13:31:34 UTC (rev 1569)
+++
branches/JCA/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java 2009-11-17
19:07:47 UTC (rev 1570)
@@ -59,6 +59,9 @@
@Override
public DQPContextCache getContextCache() {
- return new DQPContextCache(new Properties(), new FakeCacheFactory());
+ DQPContextCache cache = new DQPContextCache();
+ cache.setCacheFactory(new FakeCacheFactory());
+ cache.setProcessName("test");
+ return cache;
}
}
Modified:
branches/JCA/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java
===================================================================
---
branches/JCA/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java 2009-11-17
13:31:34 UTC (rev 1569)
+++
branches/JCA/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java 2009-11-17
19:07:47 UTC (rev 1570)
@@ -21,15 +21,12 @@
*/
package org.teiid.dqp.internal.cache;
-import java.util.Properties;
-
import junit.framework.TestCase;
import org.teiid.dqp.internal.process.DQPWorkContext;
import com.metamatrix.cache.Cache;
import com.metamatrix.cache.FakeCache.FakeCacheFactory;
-import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.platform.security.api.MetaMatrixSessionID;
import com.metamatrix.platform.security.api.SessionToken;
@@ -40,10 +37,9 @@
@Override
protected void setUp() throws Exception {
- Properties p = new Properties();
- p.setProperty(DQPEmbeddedProperties.PROCESSNAME, "host-process");
//$NON-NLS-1$
- cacheContext = new DQPContextCache(p, new FakeCacheFactory());
-
+ cacheContext = new DQPContextCache();
+ cacheContext.setCacheFactory(new FakeCacheFactory());
+ cacheContext.setProcessName("host-process");
}
private DQPWorkContext getContext() {
Modified: branches/JCA/jboss-integration/pom.xml
===================================================================
--- branches/JCA/jboss-integration/pom.xml 2009-11-17 13:31:34 UTC (rev 1569)
+++ branches/JCA/jboss-integration/pom.xml 2009-11-17 19:07:47 UTC (rev 1570)
@@ -6,7 +6,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.teiid</groupId>
- <artifactId>jboss-integration</artifactId>
+ <artifactId>teiid-jboss-integration</artifactId>
<name>teiid-jboss-integration</name>
<version>6.3.0-SNAPSHOT</version>
<description>JBoss specific integration layer for teiid</description>
Modified: branches/JCA/pom.xml
===================================================================
--- branches/JCA/pom.xml 2009-11-17 13:31:34 UTC (rev 1569)
+++ branches/JCA/pom.xml 2009-11-17 19:07:47 UTC (rev 1570)
@@ -375,6 +375,7 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
@@ -392,7 +393,7 @@
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
- </exclusion>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -404,6 +405,20 @@
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
<version>3.1.0.GA</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.jboss.man</groupId>
Modified:
branches/JCA/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
===================================================================
---
branches/JCA/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java 2009-11-17
13:31:34 UTC (rev 1569)
+++
branches/JCA/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java 2009-11-17
19:07:47 UTC (rev 1570)
@@ -165,7 +165,6 @@
EmbeddedGuiceModule config = new EmbeddedGuiceModule(bootstrapURL, props,
address, this.ra);
Injector injector = Guice.createInjector(config);
- ResourceFinder.setInjector(injector);
config.setInjector(injector);
// start the DQP
@@ -354,9 +353,6 @@
this.socketTransport = null;
}
- // shutdown the cache.
- ResourceFinder.getCacheFactory().destroy();
-
this.restart = restart;
}
Modified: branches/JCA/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java
===================================================================
---
branches/JCA/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java 2009-11-17
13:31:34 UTC (rev 1569)
+++
branches/JCA/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java 2009-11-17
19:07:47 UTC (rev 1570)
@@ -42,14 +42,13 @@
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
-import com.metamatrix.cache.CacheFactory;
-import com.metamatrix.cache.jboss.JBossCacheFactory;
import com.metamatrix.common.application.ApplicationService;
import com.metamatrix.common.application.DQPConfigSource;
import com.metamatrix.common.log.LogConfiguration;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.log.LogListener;
+import com.metamatrix.dqp.ResourceFinder;
import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.dqp.embedded.services.EmbeddedBufferService;
import com.metamatrix.dqp.embedded.services.EmbeddedConfigurationService;
@@ -93,9 +92,8 @@
bind(InetAddress.class).annotatedWith(Names.named(DQPEmbeddedProperties.HOST_ADDRESS)).toInstance(bindAddress);
- bind(CacheFactory.class).to(JBossCacheFactory.class).in(Scopes.SINGLETON);
+ bind(DQPContextCache.class).toInstance(getContextCache());
- bind(DQPContextCache.class).in(Scopes.SINGLETON);
bind(DQPCore.class).in(Scopes.SINGLETON);
bind(new
TypeLiteral<Collection<AuthorizationPolicy>>(){}).annotatedWith(Names.named("AdminRoles")).toProvider(AdminAuthorizationPolicyProvider.class).in(Scopes.SINGLETON);
//$NON-NLS-1$
@@ -105,6 +103,13 @@
binder().requestStaticInjection(LogManager.class);
}
+ private DQPContextCache getContextCache() {
+ DQPContextCache cache = new DQPContextCache();
+ cache.setCacheFactory(ResourceFinder.getCacheFactory());
+ cache.setProcessName(this.props.getProperty(DQPEmbeddedProperties.PROCESSNAME));
+ return cache;
+ }
+
private void configureServices() {
Map<String, Class<? extends ApplicationService>> defaults =
getDefaultServiceClasses();
for(int i=0; i<DQPServiceNames.ALL_SERVICES.length; i++) {