exo-jcr SVN: r964 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-12-09 06:30:10 -0500 (Wed, 09 Dec 2009)
New Revision: 964
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
Log:
EXOJCR-293 : The implementation locks without tree.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-12-09 11:26:18 UTC (rev 963)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-12-09 11:30:10 UTC (rev 964)
@@ -1299,7 +1299,7 @@
public LockData getLockData(String identifier) throws RepositoryException
{
LockData lockData = null;
- Node<Serializable, Object> node = locksRoot.getChild(makeNodeFqn(identifier));
+ Node<Serializable, Object> node = locksRoot.getChild(Fqn.fromString(identifier));
if (node != null)
{
lockData = (LockData)node.get(JBossCacheStorage.LOCK_DATA);
@@ -1312,21 +1312,8 @@
*/
public List<LockData> getLocksData() throws RepositoryException
{
-// Set<Node<Serializable, Object>> lockSet = getNodes(locksRoot);
+ Set<Node<Serializable, Object>> lockSet = locksRoot.getChildren();
- // TODO Store the id of nodes in attributes of node $Locks. EXOJCR-293
- Set<Node<Serializable, Object>> lockSet = new HashSet<Node<Serializable,Object>>();
-
- for (Serializable nodeId : locksRoot.getKeys())
- {
- Node<Serializable, Object> node = locksRoot.getChild(makeNodeFqn((String) nodeId));
-
- if (node != null)
- {
- lockSet.add(node);
- }
- }
-
List<LockData> locksData = new ArrayList<LockData>();
for (Node<Serializable, Object> node : lockSet)
{
@@ -1384,11 +1371,8 @@
throw new RepositoryException("Lock data to write can't be null!");
}
// addChild will add if absent or return old if present
- Node<Serializable, Object> node = locksRoot.addChild(makeNodeFqn(lockData.getNodeIdentifier()));
+ Node<Serializable, Object> node = locksRoot.addChild(Fqn.fromString(lockData.getNodeIdentifier()));
- //TODO Need for optimization getLocksData. EXOJCR-293
- locksRoot.put(lockData.getNodeIdentifier(), JBossCacheStorage.LOCK_NODE_ID);
-
// this will prevent from deleting by eviction.
node.setResident(true);
@@ -1428,10 +1412,7 @@
{
throw new RepositoryException("Item ID to clear lock can't be null!");
}
- locksRoot.removeChild(makeNodeFqn(identifier));
-
- //TODO Need for optimization getLocksData. EXOJCR-293
- locksRoot.remove(identifier);
+ locksRoot.removeChild(Fqn.fromString(identifier));
}
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-12-09 11:26:18 UTC (rev 963)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-12-09 11:30:10 UTC (rev 964)
@@ -200,6 +200,9 @@
private void doRemove(Modification modification, JDBCStorageConnection conn) throws IllegalStateException,
RepositoryException
{
+ if (modification.getFqn().get(0).equals(JBossCacheStorage.LOCKS))
+ return;
+
Fqn fqn = IdTreeHelper.buildFqn(modification.getFqn());
if (fqn.size() == 2)
@@ -254,8 +257,7 @@
*/
private void doUpdate(Modification m, JDBCStorageConnection conn) throws IllegalStateException, RepositoryException
{
- // TODO We not persist locks. EXOJCR-293
- if (m.getFqn().get(0).equals(JBossCacheStorage.LOCKS))
+ if (m.getFqn().get(0).equals(JBossCacheStorage.LOCKS))
return;
Fqn fqn = IdTreeHelper.buildFqn(m.getFqn());
@@ -306,7 +308,8 @@
*/
public Map<Object, Object> get(Fqn fqn) throws Exception
{
- Fqn name = (fqn.size() > 1 ? IdTreeHelper.buildFqn(fqn) : fqn);
+ Fqn name = (fqn.size() > 1 ? (fqn.get(0).equals(JBossCacheStorage.LOCKS) ? fqn : IdTreeHelper.buildFqn(fqn)) : fqn);
+
Map<Object, Object> attrs;
if (name.size() > 1)
16 years, 7 months
exo-jcr SVN: r963 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-09 06:26:18 -0500 (Wed, 09 Dec 2009)
New Revision: 963
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
Log:
EXOJCR-291: Cleaned and updated code of CacheLoader.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2009-12-09 11:05:28 UTC (rev 962)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2009-12-09 11:26:18 UTC (rev 963)
@@ -17,6 +17,7 @@
package org.exoplatform.services.jcr.impl.core.query.jbosscache;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
import org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader;
@@ -57,70 +58,18 @@
this.parentHandler = parentHandler;
}
+ /**
+ * @see org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader#put(org.jboss.cache.Fqn, java.lang.Object, java.lang.Object)
+ */
@Override
- public void put(List<Modification> modifications) throws Exception
+ public Object put(Fqn arg0, Object key, Object val) throws Exception
{
- // FOR TESTING PURPOSES, avoid batches, use single puts.
- for (Modification m : modifications)
+ if (key.equals(JbossCacheIndexChangesFilter.LISTWRAPPER) && val instanceof ChangesFilterListsWrapper)
{
- switch (m.getType())
+ if (log.isDebugEnabled())
{
- case PUT_KEY_VALUE :
- put(m.getFqn(), m.getKey(), m.getValue());
- break;
- case REMOVE_DATA :
+ log.info("Received list wrapper, start indexing...");
}
- }
- // This code was used if batching.
- // if (log.isDebugEnabled())
- // {
- // log.info("Received list of modifications");
- // }
- // final Set<String> addedNodes = new HashSet<String>();
- // final Set<String> removedNodes = new HashSet<String>();
- //
- // final Set<String> parentAddedNodes = new HashSet<String>();
- // final Set<String> parentRemovedNodes = new HashSet<String>();
- // for (Modification m : modifications)
- // {
- //
- // if (m.getType() == ModificationType.PUT_KEY_VALUE && m.getFqn().size() == 1)
- // {
- // if (m.getKey().equals(JbossCacheIndexChangesFilter.ADDED) && m.getValue() instanceof Set<?>)
- // {
- // addedNodes.addAll((Set<String>)m.getValue());
- // }
- // else if (m.getKey().equals(JbossCacheIndexChangesFilter.REMOVED) && m.getValue() instanceof Set<?>)
- // {
- // removedNodes.addAll((Set<String>)m.getValue());
- // }
- // if (m.getKey().equals(JbossCacheIndexChangesFilter.PARENT_ADDED) && m.getValue() instanceof Set<?>)
- // {
- // parentAddedNodes.addAll((Set<String>)m.getValue());
- // }
- // else if (m.getKey().equals(JbossCacheIndexChangesFilter.PARENT_REMOVED) && m.getValue() instanceof Set<?>)
- // {
- // parentRemovedNodes.addAll((Set<String>)m.getValue());
- // }
- // }
- // else
- // {
- // if (log.isDebugEnabled())
- // {
- // log.info("Received " + m.getType() + " modification, skipping...");
- // }
- // }
- // }
- // updateIndex(addedNodes, removedNodes, parentAddedNodes, parentRemovedNodes);
-
- }
-
- // Put used avoiding patching
- @Override
- public Object put(Fqn arg0, Object key, Object val) throws Exception
- {
- if (key.equals("key"))
- {
ChangesFilterListsWrapper wrapper = (ChangesFilterListsWrapper)val;
log.info("Loader=" + this + " changes=" + wrapper.dump());
updateIndex(wrapper.getAddedNodes(), wrapper.getRemovedNodes(), wrapper.getParentAddedNodes(), wrapper
@@ -187,4 +136,52 @@
}
}
}
+
+ /**
+ * Switches Indexer mode from RO to RW, or
+ *
+ * @param ioMode
+ */
+ public void setMode(IndexerIoMode ioMode)
+ {
+ if (handler != null)
+ {
+ try
+ {
+ handler.setIndexerIoMode(ioMode);
+ }
+ catch (IOException e)
+ {
+ log.error(e);
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e);
+ }
+ }
+ if (parentHandler != null)
+ {
+ try
+ {
+ parentHandler.setIndexerIoMode(ioMode);
+ }
+ catch (IOException e)
+ {
+ log.error(e);
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e);
+ }
+ }
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader#put(java.util.List)
+ */
+ @Override
+ public void put(List<Modification> modifications) throws Exception
+ {
+ // batching is not used
+ }
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java 2009-12-09 11:05:28 UTC (rev 962)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java 2009-12-09 11:26:18 UTC (rev 963)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.core.query.jbosscache;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Fqn;
@@ -31,7 +32,7 @@
/**
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: IndexerSingleStoraCacheLoader.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ * @version $Id$
*
*/
public class IndexerSingletonStoreCacheLoader extends SingletonStoreCacheLoader
@@ -43,23 +44,19 @@
protected void activeStatusChanged(boolean newActiveState) throws PushStateException
{
// at first change indexer mode
- modeChanged(newActiveState);
+ // get base cache loader that is configured under SingletonStoreCacheLoader
+ // if it is IndexerCacheLoader need to call setMode(ioMode)
+ if (getCacheLoader() instanceof IndexerCacheLoader)
+ {
+ // if newActiveState is true IndexerCacheLoader is coordinator with write enabled;
+ ((IndexerCacheLoader)getCacheLoader()).setMode(newActiveState ? IndexerIoMode.READ_WRITE
+ : IndexerIoMode.READ_ONLY);
+ }
// and them push states if needed
super.activeStatusChanged(newActiveState);
}
- /**
- * Changes indexer mode RO->RW, RW->RO
- *
- * @param enableWrite
- * true when this node of cluster is coordinator, means that indexer is RW
- * false means that indexer is read only, and this node of cluster is no a coordinator
- */
- protected void modeChanged(boolean enableWrite)
- {
- }
-
@Override
protected Callable<?> createPushStateTask()
{
@@ -82,26 +79,18 @@
for (NodeSPI aChildren : children)
{
Fqn<?> fqn = aChildren.getFqn();
- Object value = cache.get(fqn, JbossCacheIndexChangesFilter.ADDED);
- if (value != null && value instanceof Set<?>)
+ Object value = cache.get(fqn, JbossCacheIndexChangesFilter.LISTWRAPPER);
+ if (value != null && value instanceof ChangesFilterListsWrapper)
{
- addedNodes.addAll((Set<String>)value);
+ // get wrapper object
+ ChangesFilterListsWrapper listsWrapper = (ChangesFilterListsWrapper)value;
+ // get search manager lists
+ addedNodes.addAll(listsWrapper.getAddedNodes());
+ removedNodes.addAll(listsWrapper.getRemovedNodes());
+ // parent search manager lists
+ parentAddedNodes.addAll(listsWrapper.getParentAddedNodes());
+ parentRemovedNodes.addAll(listsWrapper.getParentAddedNodes());
};
- value = cache.get(fqn, JbossCacheIndexChangesFilter.REMOVED);
- if (value != null && value instanceof Set<?>)
- {
- removedNodes.addAll((Set<String>)value);
- };
- value = cache.get(fqn, JbossCacheIndexChangesFilter.PARENT_ADDED);
- if (value != null && value instanceof Set<?>)
- {
- parentAddedNodes.addAll((Set<String>)value);
- };
- value = cache.get(fqn, JbossCacheIndexChangesFilter.PARENT_REMOVED);
- if (value != null && value instanceof Set<?>)
- {
- parentRemovedNodes.addAll((Set<String>)value);
- };
}
//TODO: recover logic is here, lists are: removedNodes and addedNodes
if (debugEnabled)
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-09 11:05:28 UTC (rev 962)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-09 11:26:18 UTC (rev 963)
@@ -60,6 +60,8 @@
public static String PARENT_REMOVED = "$premove".intern();
+ public static String LISTWRAPPER = "$lists".intern();
+
/**
* @param searchManager
* @param config
@@ -94,8 +96,12 @@
// set parameters
individualCacheLoaderConfig.setFetchPersistentState(false);
individualCacheLoaderConfig.setAsync(false);
+ individualCacheLoaderConfig.setIgnoreModifications(false);
+ individualCacheLoaderConfig.setPurgeOnStartup(false);
// create CacheLoaderConfig
CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ cacheLoaderConfig.setShared(true);
+ cacheLoaderConfig.setPassivation(false);
cacheLoaderConfig.addIndividualCacheLoaderConfig(individualCacheLoaderConfig);
// insert CacheLoaderConfig
this.cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
@@ -111,17 +117,8 @@
Set<String> parentAddedNodes)
{
String id = IdGenerator.generate();
- cache.put(id, "key", new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes, parentRemovedNodes));
-/* cache.startBatch();
- String id = IdGenerator.generate();
-
- cache.put(id, ADDED, addedNodes);
- cache.put(id, PARENT_ADDED, parentAddedNodes);
-
- cache.put(id, REMOVED, removedNodes);
- cache.put(id, PARENT_REMOVED, parentRemovedNodes);
-
- cache.endBatch(true);*/
+ cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes,
+ parentRemovedNodes));
}
}
16 years, 7 months
exo-jcr SVN: r962 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-09 06:05:28 -0500 (Wed, 09 Dec 2009)
New Revision: 962
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
Log:
EXOJCR-291: Added dump function
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2009-12-09 11:04:04 UTC (rev 961)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2009-12-09 11:05:28 UTC (rev 962)
@@ -122,6 +122,7 @@
if (key.equals("key"))
{
ChangesFilterListsWrapper wrapper = (ChangesFilterListsWrapper)val;
+ log.info("Loader=" + this + " changes=" + wrapper.dump());
updateIndex(wrapper.getAddedNodes(), wrapper.getRemovedNodes(), wrapper.getParentAddedNodes(), wrapper
.getParentRemovedNodes());
}
16 years, 7 months
exo-jcr SVN: r961 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-09 06:04:04 -0500 (Wed, 09 Dec 2009)
New Revision: 961
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java
Log:
EXOJCR-291: Added dump function
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java 2009-12-09 11:00:30 UTC (rev 960)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java 2009-12-09 11:04:04 UTC (rev 961)
@@ -77,4 +77,13 @@
return parentRemovedNodes;
}
+ public String dump()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Added=").append(addedNodes.toString()).append("\n");
+ buffer.append("Removed=").append(removedNodes.toString()).append("\n");
+ buffer.append("ParentAdded=").append(parentAddedNodes.toString()).append("\n");
+ buffer.append("ParentRemoved=").append(parentRemovedNodes.toString()).append("\n");
+ return buffer.toString();
+ }
}
16 years, 7 months
exo-jcr SVN: r960 - in kernel/branches/mc-int-branch: exo.kernel.container/src/main/java/org/exoplatform/container/util and 6 other directories.
by do-not-reply@jboss.org
Author: mstruk
Date: 2009-12-09 06:00:30 -0500 (Wed, 09 Dec 2009)
New Revision: 960
Added:
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/ExternallyControlledInjectingBean.java
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-config.xml
Removed:
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/AOPInterceptor.java
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/MissingNoArgsConstructorBean.java
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/PrivateNoArgsConstructorBean.java
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/ProtectedNoArgsConstructorBean.java
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-beans.xml
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-beans.xml
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/GenericWrapperUtil.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/JavassistAOPClassLoader.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentInfo.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCInterceptProxy.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/RootContainerVDFDecoratorInjector.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/WrapperMethodComposer.java
kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest5.java
kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/test/java/org/exoplatform/kernel/it/TestMCInjectionIntegration5.java
Modified:
kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegration.java
kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegrationContainer.java
kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegrationInvoker.java
kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/util/EnvSpecific.java
kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/util/JBossEnv.java
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/pom.xml
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/InjectedBean.java
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/InjectingBean.java
kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/configuration.xml
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/InterceptMC.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentAdapter.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCInjectionMode.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntConfig.java
kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntegrationImpl.java
kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest.java
kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest3.java
kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest4.java
Log:
Removed AOP support, renamed mc-int-beans.xml to mc-int-config.xml, passing mc-int-config.xml forward in full - external injections configuration, added JavaDoc
Modified: kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegration.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegration.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegration.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -5,12 +5,40 @@
import javax.servlet.ServletContext;
/**
+ * The interface used to loosely couple mc-integration to exo-container
+ *
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public interface MCIntegration
{
+ /**
+ * Apply mc-integration interception.
+ *
+ * @param componentAdapter the original component adapter
+ * @return appropriate compomnent adapter - either the original,
+ * or one wrapping the original with mc-integration wrapper
+ */
ComponentAdapter getMCAdapter(ComponentAdapter componentAdapter);
+
+ /**
+ * Check if JBoss MC Kernel is available.
+ *
+ * @param adapter
+ * @return true if mc kernel is available
+ */
boolean hasMCKernel(ComponentAdapter adapter);
+
+ /**
+ * Initialize thread context with mc kernel retrieved through ServletContext.
+ *
+ * @param ctx Servlet context
+ */
void initThreadCtx(ServletContext ctx);
+
+ /**
+ * Clean up any thread context data stored during initThreadCtx().
+ *
+ * @param ctx Servlet context
+ */
void resetThreadCtx(ServletContext ctx);
}
Modified: kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegrationContainer.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegrationContainer.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegrationContainer.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -8,31 +8,65 @@
import org.picocontainer.defaults.DefaultPicoContainer;
/**
+ * Container class that serves as an interception point for MC integration.
+ *
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class MCIntegrationContainer extends DefaultPicoContainer
{
+ /**
+ * Logger
+ */
private static Log log = ExoLogger.getLogger(MCIntegrationContainer.class);
+ /**
+ * Constructor that exposes super constructor.
+ *
+ * @param componentAdapterFactory
+ * @param parent
+ */
public MCIntegrationContainer(ComponentAdapterFactory componentAdapterFactory, PicoContainer parent)
{
super(componentAdapterFactory, parent);
}
+ /**
+ * Constructor that exposes super constructor.
+ *
+ * @param parent
+ */
public MCIntegrationContainer(PicoContainer parent)
{
super(parent);
}
+ /**
+ * Constructor that exposes super constructor.
+ *
+ * @param componentAdapterFactory
+ */
public MCIntegrationContainer(ComponentAdapterFactory componentAdapterFactory)
{
super(componentAdapterFactory);
}
+ /**
+ * Constructor that exposes super constructor.
+ */
public MCIntegrationContainer()
{
}
+ /**
+ * Method interception that swaps the original component adapter for intercepting one
+ * for components that require mc integration.
+ * If mc integration isn't available in the current runtime environment, then interception
+ * simply delegates to parent without interfering.
+ *
+ * @param componentAdapter original component adapter
+ * @return the original component adapter, or the intercepting component adapter
+ * that takes care of mc integration
+ */
public ComponentAdapter registerComponent(ComponentAdapter componentAdapter)
{
ComponentAdapter adapter = componentAdapter;
@@ -53,6 +87,12 @@
return adapter;
}
+ /**
+ * Check if runtime environment supports mc integration.
+ *
+ * @param componentAdapter original component adapter
+ * @return true if mc integration is supported
+ */
public static boolean hasMCKernel(ComponentAdapter componentAdapter)
{
try
Modified: kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegrationInvoker.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegrationInvoker.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/mc/MCIntegrationInvoker.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -8,15 +8,35 @@
import java.lang.reflect.Method;
/**
+ * This class performs a loosely coupled integration to mc-integration logic.
+ * MC integration provides the ability to inject JBoss MC configured beans into
+ * exo-kernel configured services.
+ *
+ * MC integration is only available when GateIn is running inside JBossAS or on top of JBoss MC.
+ * When integration is not available the default behavior is used - as if this class was never called.
+ *
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class MCIntegrationInvoker
{
+ /**
+ * Logger
+ */
private static Log log = ExoLogger.getLogger(MCIntegrationInvoker.class);
+ /**
+ * Reference to actual implementation of mc-integration - the one with hard dependencies on JBoss MC Kernel.
+ */
private static MCIntegration mcInt;
+
+ /**
+ * Error flag. When set it signals that MC integration is not available in current runtime environment.
+ */
private static boolean permFailure;
+ /**
+ * @see MCIntegration#getMCAdapter(org.picocontainer.ComponentAdapter)
+ */
public static synchronized ComponentAdapter getMCAdapter(ComponentAdapter componentAdapter)
{
MCIntegration mcInt = getMCIntegration();
@@ -28,6 +48,9 @@
return mcInt.getMCAdapter(componentAdapter);
}
+ /**
+ * @see MCIntegration#hasMCKernel(org.picocontainer.ComponentAdapter)
+ */
public static synchronized boolean hasMCKernel(ComponentAdapter adapter)
{
MCIntegration mcInt = getMCIntegration();
@@ -38,6 +61,9 @@
return mcInt.hasMCKernel(adapter);
}
+ /**
+ * @see MCIntegration#initThreadCtx(javax.servlet.ServletContext)
+ */
public static synchronized void initThreadCtx(ServletContext ctx)
{
MCIntegration mcInt = getMCIntegration();
@@ -48,6 +74,9 @@
mcInt.initThreadCtx(ctx);
}
+ /**
+ * @see MCIntegration#resetThreadCtx(javax.servlet.ServletContext)
+ */
public static synchronized void resetThreadCtx(ServletContext ctx)
{
MCIntegration mcInt = getMCIntegration();
@@ -58,6 +87,11 @@
mcInt.resetThreadCtx(ctx);
}
+ /**
+ * Get a reference to actual implementation of MCIntegration if one is available.
+ * Log a warning if mc integration is not available.
+ * @return MCIntegration implementation
+ */
private static MCIntegration getMCIntegration()
{
if (mcInt == null && permFailure == false)
@@ -86,6 +120,9 @@
return mcInt;
}
+ /**
+ * Helper method for proper classloading fallback.
+ */
static Class loadClass(String name) throws ClassNotFoundException
{
Class clazz = null;
Modified: kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/util/EnvSpecific.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/util/EnvSpecific.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/util/EnvSpecific.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -3,14 +3,14 @@
import javax.servlet.ServletContext;
/**
- * This class makes env specific thread context inits when GateIn runs inside JBossAS or MC
+ * This class makes environment specific thread context initializations.
*
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class EnvSpecific {
/**
- * Perform environment specific thread context initialization
+ * Perform environment specific thread context initialization.
*
* @param ctx ServletContext
*/
@@ -20,7 +20,7 @@
}
/**
- * Perform environment specific thread context cleanup
+ * Perform environment specific thread context cleanup.
*
* @param ctx ServletContext
*/
Modified: kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/util/JBossEnv.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/util/JBossEnv.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.container/src/main/java/org/exoplatform/container/util/JBossEnv.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -4,20 +4,23 @@
import org.exoplatform.container.mc.MCIntegrationInvoker;
/**
- * This class makes env specific thread context inits when GateIn runs inside JBossAS or MC
+ * This class makes thread context initialization when GateIn runs inside JBossAS or MC.
*
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class JBossEnv
{
- /** This value is equal to org.jboss.kernel.plugins.bootstrap.basic.KernelConstants.KERNEL_NAME */
+ /**
+ * A servlet context attribute to check for mc kernel.
+ * The value is equal to org.jboss.kernel.plugins.bootstrap.basic.KernelConstants.KERNEL_NAME.
+ */
private static final String MC_KERNEL_NAME = "jboss.kernel:service=Kernel";
/**
- * Check if MC Kernel is available
+ * Check if MC Kernel is available.
*
* @param ctx ServletContext
- * @return true if we're running within JBoss environment
+ * @return true if we're running within JBoss MC environment
*/
public static boolean isAvailable(ServletContext ctx)
{
@@ -25,7 +28,7 @@
}
/**
- * Use VDF to grab relevant information from ServletContext and store it in thread context
+ * Perform JBoss MC environment specific thread context initialization.
*
* @param ctx ServletContext
*/
@@ -35,7 +38,7 @@
}
/**
- * Perform thread context cleanup
+ * Perform thread context cleanup.
*
* @param ctx ServletContext
*/
Modified: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/pom.xml
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/pom.xml 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/pom.xml 2009-12-09 11:00:30 UTC (rev 960)
@@ -26,6 +26,11 @@
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-kernel</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.0.1B</version>
+ </dependency>
</dependencies>
</project>
Deleted: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/AOPInterceptor.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/AOPInterceptor.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/AOPInterceptor.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,52 +0,0 @@
-package org.exoplatform.kernel.demos.mc;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.proxy.container.ContainerProxyMethodInvocation;
-
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class AOPInterceptor implements Interceptor
-{
- private static Log log = ExoLogger.getLogger(AOPInterceptor.class);
- private static LinkedList<Invocation> invocations = new LinkedList<Invocation>();
-
- public String getName()
- {
- return getClass().getName();
- }
-
- public Object invoke(Invocation invocation) throws Throwable
- {
- StringBuilder sb = new StringBuilder();
- if (invocation instanceof ContainerProxyMethodInvocation)
- {
- ContainerProxyMethodInvocation methodInvocation = (ContainerProxyMethodInvocation) invocation;
- sb.append("Method: " + methodInvocation.getActualMethod().getName());
- sb.append(", Args:\n");
- Object[] args = methodInvocation.getArguments();
- for (int i = 0; i < args.length; i++)
- {
- sb.append(" " + i + ") " + args[i] + "\n");
- }
- }
- else
- {
- sb.append(invocation);
- }
- log.info("Interceptor: " + this + ", Target object: " + invocation.getTargetObject() + ", " + sb);
- invocations.add(invocation);
- return invocation.invokeNext();
- }
-
- public static List<Invocation> getInvocations()
- {
- return invocations;
- }
-}
Added: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/ExternallyControlledInjectingBean.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/ExternallyControlledInjectingBean.java (rev 0)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/ExternallyControlledInjectingBean.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -0,0 +1,77 @@
+package org.exoplatform.kernel.demos.mc;
+
+import org.picocontainer.Startable;
+
+import javax.transaction.TransactionManager;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class ExternallyControlledInjectingBean implements Startable
+{
+ private TransactionManager tm;
+ private InjectedBean bean;
+ private Map bindingsMap;
+ private String stringValue;
+ private int startCount;
+
+ public ExternallyControlledInjectingBean()
+ {
+
+ }
+
+ public TransactionManager getTransactionManager()
+ {
+ return tm;
+ }
+
+ public void setTransactionManager(TransactionManager tm)
+ {
+ this.tm = tm;
+ }
+
+ public InjectedBean getBean()
+ {
+ return bean;
+ }
+
+ public void setBean(InjectedBean bean)
+ {
+ this.bean = bean;
+ }
+
+ public Map getBindingsMap()
+ {
+ return bindingsMap;
+ }
+
+ public void setBindingsMap(Map bindingsMap)
+ {
+ this.bindingsMap = bindingsMap;
+ }
+
+ public String getStringValue()
+ {
+ return stringValue;
+ }
+
+ public void setStringValue(String stringValue)
+ {
+ this.stringValue = stringValue;
+ }
+
+ public int getStartCount()
+ {
+ return startCount;
+ }
+
+ public void start()
+ {
+ startCount++;
+ }
+
+ public void stop()
+ {
+ }
+}
Modified: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/InjectedBean.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/InjectedBean.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/InjectedBean.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -4,6 +4,8 @@
import org.exoplatform.services.log.Log;
/**
+ * A simple POJO that we use for injection.
+ *
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class InjectedBean
@@ -12,10 +14,7 @@
public static final String SOME_PROPERTY_VALUE = "[This is some property value]";
- //static
- //{
- // System.out.println("InjectedBean class loaded !!!");
- //}
+ private String anotherProperty;
public InjectedBean()
{
@@ -31,4 +30,14 @@
{
log.info("Method start() called on InjectedBean");
}
+
+ public String getAnotherProperty()
+ {
+ return anotherProperty;
+ }
+
+ public void setAnotherProperty(String anotherProperty)
+ {
+ this.anotherProperty = anotherProperty;
+ }
}
Modified: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/InjectingBean.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/InjectingBean.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/InjectingBean.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -12,13 +12,14 @@
import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
import org.jboss.kernel.spi.config.KernelConfigurator;
+import javax.transaction.TransactionManager;
import java.util.Map;
/**
* If we want our class to be instantiated at deploy time,
* it has to implement org.picocontainer.Startable, otherwise it will only
* be registered, but not instantiated. MC integration takes place
- * at instantiation time.
+ * at instantiation time, not at component registration time.
*
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
@@ -26,29 +27,76 @@
@InterceptMC(injectionMode = MCInjectionMode.ALL)
public class InjectingBean implements org.picocontainer.Startable
{
+ /**
+ * Logger
+ */
private static final Log log = ExoLogger.getLogger(InjectingBean.class);
+ /**
+ * Field to be injected through setter method by mc kernel.
+ */
private InjectedBean bean;
+
+ /**
+ * Field to be injected through setter method by mc kernel.
+ */
private KernelConfigurator configurator;
- // Avoid using field injection, it's an anti-pattern
+ /**
+ * Field to be injected directly through field injection by mc kernel.
+ * This is an anti-pattern as you're exposing implementation details,
+ * and giving up interception capability.
+ */
@Inject(bean = "InjectedBean")
private InjectedBean injectedBean;
+ /**
+ * An example of getting the JBoss MC configured transaction manager
+ * into an exo-kernel installed service.
+ * This field is to be injected through setter method by mc kernel.
+ */
+ private TransactionManager tm;
+
+ /**
+ * A map field to be injected through setter method by mc kernel.
+ */
private Map bindingsMap;
+
+ /**
+ * A field to be injected with a property value of existing mc bean.
+ * Demonstrates another kind of injection.
+ */
private String stringValue;
- private boolean started;
+ /**
+ * Field that counts how many times start() method is called.
+ * This is to demonstrate that start() method is called exactly once.
+ */
+ private int startCount;
+
+ /**
+ * In this demo this bean is to be instantiated by exo-kernel.
+ * We can not use constructor based injection that mc kernel supports,
+ * since it's not mc kernel that does the instantiation.
+ */
public InjectingBean()
{
log.info("Injecting bean instantiated");
}
+ /**
+ * Getter method.
+ * @return injected bean
+ */
public InjectedBean getBean()
{
return bean;
}
+ /**
+ * Setter method, annotated as injection point for type matching injection.
+ * @param bean
+ */
@Inject
public void setBean(InjectedBean bean)
{
@@ -56,11 +104,19 @@
log.info("Received InjectedBean: " + bean);
}
+ /**
+ * Getter method.
+ * @return injected component
+ */
public KernelConfigurator getConfigurator()
{
return configurator;
}
+ /**
+ * Setter method, annotated as injection point for name matching injection.
+ * @param configurator
+ */
@Inject(bean = KernelConstants.KERNEL_CONFIGURATOR_NAME)
public void setConfigurator(KernelConfigurator configurator)
{
@@ -68,11 +124,19 @@
log.info("InjectingBean Received KernelConfigurator: " + configurator);
}
+ /**
+ * Getter method.
+ * @return
+ */
public Map getBindings()
{
return bindingsMap;
}
+ /**
+ * Setter method, annotated as injection point with map injecting annotation.
+ * @param bindings
+ */
@MapValue(
value = {
@EntryValue(
@@ -107,11 +171,19 @@
this.bindingsMap = bindings;
}
+ /**
+ * Getter method.
+ * @return
+ */
public String getSomeStringProperty()
{
return stringValue;
}
+ /**
+ * Setter method annotated as injection point for property getter injection.
+ * @param value
+ */
@Inject(bean = "InjectedBean", property = "someString")
public void setSomeStringProperty(String value)
{
@@ -119,24 +191,57 @@
this.stringValue = value;
}
+ /**
+ * org.picocontainer.Startable lifecycle method. Supposed to be called exactly once.
+ */
public void start()
{
- log.warn("start() called (injectedBean is set to: " + injectedBean + ")");
- this.started = true;
+ log.warn("start() called (injectedBean is set to: " + injectedBean + ", transactionManager is setTo: " + tm + ")");
+ this.startCount++;
}
+ /**
+ * org.picocontainer.Startable lifecycle method.
+ */
public void stop()
{
log.info("stop() called");
}
+ /**
+ * Getter method for field-injected bean.
+ * @return field-injected bean
+ */
public InjectedBean getInjectedBean()
{
return injectedBean;
}
- public boolean isStarted()
+ /**
+ * Getter method.
+ * @return start count
+ */
+ public int getStartCount()
{
- return started;
+ return startCount;
}
+
+ /**
+ * Setter method annotated through external config (mc-int-config.xml) as injection point for type matching injection.
+ * @param tm
+ */
+ @Inject
+ public void setTransactionManager(TransactionManager tm)
+ {
+ this.tm = tm;
+ }
+
+ /**
+ * Getter method.
+ * @return
+ */
+ public TransactionManager getTransactionManager()
+ {
+ return tm;
+ }
}
Deleted: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/MissingNoArgsConstructorBean.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/MissingNoArgsConstructorBean.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/MissingNoArgsConstructorBean.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,42 +0,0 @@
-package org.exoplatform.kernel.demos.mc;
-
-import org.exoplatform.container.xml.InitParams;
-import org.exoplatform.container.xml.ValueParam;
-import org.picocontainer.Startable;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class MissingNoArgsConstructorBean implements Startable
-{
- private String name;
- private boolean started;
-
- public MissingNoArgsConstructorBean(InitParams params)
- {
- if (params == null)
- {
- return;
- }
- ValueParam val = params.getValueParam("name");
- if (val != null)
- {
- name = val.getValue();
- }
- }
-
- public String method01()
- {
- return "method01";
- }
-
- public void start()
- {
- started = true;
- }
-
- public void stop()
- {
- started = false;
- }
-}
Deleted: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/PrivateNoArgsConstructorBean.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/PrivateNoArgsConstructorBean.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/PrivateNoArgsConstructorBean.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,38 +0,0 @@
-package org.exoplatform.kernel.demos.mc;
-
-import org.exoplatform.container.xml.InitParams;
-import org.jboss.beans.metadata.api.annotations.Inject;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class PrivateNoArgsConstructorBean extends MissingNoArgsConstructorBean
-{
- private InjectedBean injectedBean;
-
- private PrivateNoArgsConstructorBean()
- {
- super(null);
- }
-
- public PrivateNoArgsConstructorBean(InitParams params)
- {
- super(params);
- }
-
- public String method12()
- {
- return "method12";
- }
-
- @Inject
- public void setInjectedBean(InjectedBean bean)
- {
- this.injectedBean = bean;
- }
-
- public InjectedBean getInjectedBean()
- {
- return injectedBean;
- }
-}
Deleted: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/ProtectedNoArgsConstructorBean.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/ProtectedNoArgsConstructorBean.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/java/org/exoplatform/kernel/demos/mc/ProtectedNoArgsConstructorBean.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,38 +0,0 @@
-package org.exoplatform.kernel.demos.mc;
-
-import org.exoplatform.container.xml.InitParams;
-import org.jboss.beans.metadata.api.annotations.Inject;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class ProtectedNoArgsConstructorBean extends MissingNoArgsConstructorBean
-{
- private InjectedBean injectedBean;
-
- protected ProtectedNoArgsConstructorBean()
- {
- super(null);
- }
-
- public ProtectedNoArgsConstructorBean(InitParams params)
- {
- super(params);
- }
-
- public String method11()
- {
- return "method11";
- }
-
- @Inject
- public void setInjectedBean(InjectedBean bean)
- {
- this.injectedBean = bean;
- }
-
- public InjectedBean getInjectedBean()
- {
- return injectedBean;
- }
-}
Modified: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/configuration.xml
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/configuration.xml 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/configuration.xml 2009-12-09 11:00:30 UTC (rev 960)
@@ -21,17 +21,7 @@
<type>org.exoplatform.kernel.demos.mc.InjectingBean</type>
</component>
<component>
- <key>InjectingBean5</key>
- <type>org.exoplatform.kernel.demos.mc.InjectingBean</type>
+ <key>ExternallyControlledInjectingBean</key>
+ <type>org.exoplatform.kernel.demos.mc.ExternallyControlledInjectingBean</type>
</component>
- <component>
- <key>ProtectedNoArgsConstructorBean</key>
- <type>org.exoplatform.kernel.demos.mc.ProtectedNoArgsConstructorBean</type>
- <init-params>
- <value-param>
- <name>name</name>
- <value>Some value</value>
- </value-param>
- </init-params>
- </component>
</configuration>
Deleted: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-beans.xml
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-beans.xml 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-beans.xml 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
- xmlns="urn:jboss:bean-deployer">
-
- <interceptor xmlns="urn:jboss:aop-beans:1.0" name="DemoAOPInterceptor"
- class="org.exoplatform.kernel.demos.mc.AOPInterceptor"/>
-
- <!-- Matching by exact type will not work, because of the mechanics of MC-integration AOP -->
- <!-- Use $instanceof instead -->
- <bind xmlns="urn:jboss:aop-beans:1.0"
- pointcut="execution(* $instanceof{org.exoplatform.kernel.demos.mc.MissingNoArgsConstructorBean}->*(..))">
- <interceptor-ref name="DemoAOPInterceptor"/>
- </bind>
-
- <bind xmlns="urn:jboss:aop-beans:1.0"
- pointcut="execution(* $instanceof{org.exoplatform.kernel.demos.mc.InjectingBean}->*(..))">
- <interceptor-ref name="DemoAOPInterceptor"/>
- </bind>
-
-</deployment>
\ No newline at end of file
Deleted: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-beans.xml
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-beans.xml 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-beans.xml 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<deployment xmlns="urn:jboss:bean-deployer:2.0">
- <bean class="org.exoplatform.container.definition.PortalContainerConfig">
- <annotation>@org.exoplatform.container.mc.impl.InterceptMC(enableAOP=true)</annotation>
- </bean>
- <bean name="InjectingBean2">
- <annotation>@org.exoplatform.container.mc.impl.InterceptMC(injectionMode=org.exoplatform.container.mc.impl.MCInjectionMode.STANDARD)</annotation>
- </bean>
- <bean name="InjectingBean3">
- <annotation>@org.exoplatform.container.mc.impl.InterceptMC(enableAOP=true,injectionMode=org.exoplatform.container.mc.impl.MCInjectionMode.ALL)</annotation>
- </bean>
- <bean name="InjectingBean4">
- <annotation>@org.exoplatform.container.mc.impl.InterceptMC(enableAOP=true)</annotation>
- </bean>
- <bean name="InjectingBean5" class="org.exoplatform.kernel.demos.mc.InjectingBean">
- <!-- NO ANNOTATION -->
- </bean>
- <bean name="ProtectedNoArgsConstructorBean">
- <annotation>@org.exoplatform.container.mc.impl.InterceptMC(enableAOP=true)</annotation>
- </bean>
-
-</deployment>
\ No newline at end of file
Copied: kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-config.xml (from rev 905, kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-beans.xml)
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-config.xml (rev 0)
+++ kernel/branches/mc-int-branch/exo.kernel.demos/mc-injection/src/main/resources/conf/mc-int-config.xml 2009-12-09 11:00:30 UTC (rev 960)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="InjectingBean2">
+ <annotation>@org.exoplatform.container.mc.impl.InterceptMC(injectionMode=org.exoplatform.container.mc.impl.MCInjectionMode.STANDARD)</annotation>
+ </bean>
+ <bean name="InjectingBean3">
+ <annotation>@org.exoplatform.container.mc.impl.InterceptMC(injectionMode=org.exoplatform.container.mc.impl.MCInjectionMode.ALL)</annotation>
+ </bean>
+ <bean name="InjectingBean4" class="org.exoplatform.kernel.demos.mc.InjectingBean">
+ <!-- NO ANNOTATION -->
+ </bean>
+ <bean name="ExternallyControlledInjectingBean">
+ <annotation>@org.exoplatform.container.mc.impl.InterceptMC</annotation>
+ <property name="transactionManager"><inject/></property>
+ <property name="bean"><inject bean="InjectedBean"/></property>
+ <property name="bindingsMap">
+ <map keyClass="java.lang.Class" valueClass="java.lang.Object">
+ <entry>
+ <key>org.jboss.dependency.spi.Controller</key>
+ <value><inject bean="jboss.kernel:service=KernelController"/></value>
+ </entry>
+ </map>
+ </property>
+ <property name="stringValue"><inject bean="InjectedBean" property="someString"/></property>
+ <!--property name="bean.anotherProperty">Test value</property-->
+ </bean>
+</deployment>
\ No newline at end of file
Deleted: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/GenericWrapperUtil.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/GenericWrapperUtil.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/GenericWrapperUtil.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,177 +0,0 @@
-package org.exoplatform.container.mc.impl;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtConstructor;
-import javassist.CtMethod;
-import javassist.CtNewMethod;
-import javassist.LoaderClassPath;
-import javassist.Modifier;
-import javassist.NotFoundException;
-import javassist.bytecode.AnnotationsAttribute;
-import javassist.bytecode.ClassFile;
-import javassist.bytecode.ConstPool;
-import javassist.bytecode.MethodInfo;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.plugins.structure.AbstractVFSDeploymentUnit;
-import org.jboss.mc.common.ThreadLocalUtils;
-import org.jboss.virtual.MemoryFileFactory;
-import org.jboss.virtual.VirtualFile;
-
-import java.net.URL;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @author <a href="mailto:ajustin@redhat.com">Ales Justin</a>
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-final class GenericWrapperUtil
-{
- private static AtomicInteger counter = new AtomicInteger(0);
-
- static MCComponentInfo generateAndInstallWrapper(Object instance) throws Exception
- {
- ClassPool pool = ClassPool.getDefault();
- pool.insertClassPath(new LoaderClassPath(Thread.currentThread().getContextClassLoader()));
-
- CtClass cc = pool.get(MCInterceptProxy.class.getName());
- CtClass pc = pool.get(instance.getClass().getName());
-
- zeroArgConstructorCheck(pc, instance);
-
- cc.setSuperclass(pc);
- cc.setName(getPackage(cc.getName()) + ".MCInterceptProxy$" + counter.getAndIncrement());
- WrapperMethodComposer composer = new WrapperMethodComposer(MCInterceptProxy.DELEGATE, pc.getName());
-
- ClassFile cf = cc.getClassFile();
- AnnotationsAttribute attr = setAnnotations(pc.getClassFile().getAttributes(), cf.getConstPool());
- if (attr != null)
- {
- cf.addAttribute(attr);
- }
- cf.setVersionToJava5();
-
- for (CtMethod m : pc.getMethods())
- {
- if (isMethodOverridable(m))
- {
- CtMethod method = CtNewMethod.make(composer.composeMethod(m), cc);
- MethodInfo minf = method.getMethodInfo();
- attr = setAnnotations(m.getMethodInfo().getAttributes(), minf.getConstPool());
- if (attr != null)
- {
- minf.addAttribute(attr);
- }
- cc.addMethod(method);
- }
- }
-
- installWrapper(cc);
-
- MCComponentInfo mcinf = new MCComponentInfo(cc.getName(),
- new JavassistAOPClassLoader(Thread.currentThread().getContextClassLoader(), cc.getClassPool()));
- Thread.currentThread().setContextClassLoader(mcinf.getClassLoader()); // TODO: ensure symetry - reset old CL when done
- return mcinf;
- }
-
- private static AnnotationsAttribute setAnnotations(List attrs, ConstPool cpool)
- {
- //AnnotationsAttribute attr = new AnnotationsAttribute(cpool, AnnotationsAttribute.visibleTag);
- for (Object a : attrs)
- {
- if (a instanceof AnnotationsAttribute)
- {
- AnnotationsAttribute aa = (AnnotationsAttribute) a;
- if (AnnotationsAttribute.visibleTag.equals(aa.getName()) == false)
- {
- continue;
- }
- //attr.setAnnotations(aa.getAnnotations());
- //return attr;
- return (AnnotationsAttribute) aa.copy(cpool, null);
- }
- }
- return null;
- }
-
- private static String getPackage(String name)
- {
- return name.substring(0, name.lastIndexOf("."));
- }
-
- private static void installWrapper(CtClass cc) throws Exception
- {
- // This is to make classloading work with jboss-aop and mc-classloading
- // - third-party (Tomcat) can be enabled through context classloader
- DeploymentUnit unit = ThreadLocalUtils.getUnit();
- String host = getVFSMemoryHost(unit);
- if (host != null)
- {
- URL vfsUrl = new URL("vfsmemory://" + host + "/" + getResourcePath(cc.getName()));
- MemoryFileFactory.putFile(vfsUrl, cc.toBytecode());
- return;
- }
- }
-
- static void postInstallCleanup()
- {
- // TODO: symmetry not 100% assured here
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl instanceof JavassistAOPClassLoader)
- {
- Thread.currentThread().setContextClassLoader(cl.getParent());
- }
- }
-
- private static String getResourcePath(String name)
- {
- return name.replace(".", "/") + ".class";
- }
-
- private static String getVFSMemoryHost(DeploymentUnit unit) throws Exception
- {
- if (unit instanceof AbstractVFSDeploymentUnit)
- {
- List<VirtualFile> classPath = ((AbstractVFSDeploymentUnit) unit).getClassPath();
- for (VirtualFile vf : classPath)
- {
- URL url = vf.toURL();
- if ("vfsmemory".equals(url.getProtocol()))
- {
- return url.getHost();
- }
- }
- return getVFSMemoryHost(unit.getParent());
- }
-
- return null;
- }
-
- private static boolean isMethodOverridable(CtMethod m)
- {
- return (m.getModifiers() & Modifier.FINAL) == 0
- && !"clone".equals(m.getName())
- && !"finalize".equals(m.getName());
- }
-
- private static void zeroArgConstructorCheck(CtClass pc, Object c)
- throws NotFoundException
- {
- CtConstructor[] ctors = pc.getDeclaredConstructors();
- boolean found = false;
- for (CtConstructor cons : ctors)
- {
- if (cons.getParameterTypes().length == 0
- && (cons.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED)) > 0)
- {
- found = true;
- break;
- }
- }
- if (!found)
- {
- throw new RuntimeException("Class can not be AOP instrumented - it has no zero-arguments public/protected constructor: " + c.getClass());
- }
- }
-}
\ No newline at end of file
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/InterceptMC.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/InterceptMC.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/InterceptMC.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -6,7 +6,7 @@
import java.lang.annotation.Target;
/**
- * Marks Gatein MC enabled component.
+ * Marks GateIn MC enabled component.
*
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
* @author <a href="mailto:ales.justin@redhat.com">Ales Justin</a>
@@ -16,13 +16,6 @@
public @interface InterceptMC
{
/**
- * Do we enable AOP for this component.
- *
- * @return true if we should enable AOP, false otherwise
- */
- boolean enableAOP() default false;
-
- /**
* Injection mode
*
* @return MCInjectionMode enumeration constant representing injection mode
Deleted: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/JavassistAOPClassLoader.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/JavassistAOPClassLoader.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/JavassistAOPClassLoader.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,67 +0,0 @@
-package org.exoplatform.container.mc.impl;
-
-import javassist.ClassPool;
-import javassist.Loader;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class JavassistAOPClassLoader extends Loader
-{
- public JavassistAOPClassLoader()
- {
- }
-
- public JavassistAOPClassLoader(ClassPool cp)
- {
- super(cp);
- }
-
- public JavassistAOPClassLoader(ClassLoader parent, ClassPool cp)
- {
- super(parent, cp);
- }
-
- @Override
- protected Class loadClassByDelegation(String name) throws ClassNotFoundException
- {
- if (name.startsWith("org.jboss.aop."))
- {
- return delegateToParent(name);
- }
-
- return super.loadClassByDelegation(name);
- }
-
- protected Class loadClass(String name, boolean resolve)
- throws ClassFormatError, ClassNotFoundException
- {
- name = name.intern();
- synchronized (name)
- {
- Class c = findLoadedClass(name);
- if (c == null)
- {
- try
- {
- c = delegateToParent(name);
- }
- catch (ClassNotFoundException ignored)
- {
- }
- }
-
- if (c == null)
- {
- c = findClass(name);
- }
-
- if (resolve)
- {
- resolveClass(c);
- }
-
- return c;
- }
- }
-}
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentAdapter.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentAdapter.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentAdapter.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,6 +1,8 @@
package org.exoplatform.container.mc.impl;
import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.dependency.plugins.helpers.StatelessController;
import org.jboss.dependency.spi.ControllerState;
@@ -14,17 +16,47 @@
import org.picocontainer.PicoVisitor;
/**
+ * A wrapping adapter, that takes care of mc integration at component instantiation time.
+ *
* @author <a href="mailto:ajustin@redhat.com">Ales Justin</a>
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class MCComponentAdapter implements ComponentAdapter
{
+ /**
+ * Kernel controller retrieved from associated mc kernel.
+ */
private KernelController controller;
+
+ /**
+ * Original component adapter.
+ */
private ComponentAdapter delegate;
+
+ /**
+ * Interception marking annotation, configured for the component.
+ */
private InterceptMC interceptMC;
+
+ /**
+ * A component instance handled by this component adapter.
+ */
private Object lastComponentInstance;
- public MCComponentAdapter(KernelController controller, ComponentAdapter delegate, InterceptMC interceptMC)
+ /**
+ * BeanMetaData parsed from mc-int-config.xml
+ */
+ private AbstractBeanMetaData metaData;
+
+ /**
+ * The only constructor.
+ *
+ * @param controller Kernel controller to use
+ * @param delegate original component adapter
+ * @param interceptMC mc-integration configuration in the form of annotation
+ */
+ public MCComponentAdapter(KernelController controller, ComponentAdapter delegate,
+ InterceptMC interceptMC, AbstractBeanMetaData data)
{
if (controller == null)
{
@@ -43,18 +75,39 @@
this.controller = controller;
this.delegate = delegate;
this.interceptMC = interceptMC;
+ this.metaData = data;
}
+ /**
+ * Getter method for component key.
+ *
+ * @return String or Class representing a key
+ */
public Object getComponentKey()
{
return delegate.getComponentKey();
}
+ /**
+ * Getter for component implementation class.
+ *
+ * @return component implementation class
+ */
public Class getComponentImplementation()
{
return delegate.getComponentImplementation();
}
+ /**
+ * This is where mc integration happens.
+ * Instantiation is first delegated to original component adapter, the resulting
+ * instance is then sent through kernel controller to be injected by mc kernel.
+ *
+ * @param container pico container that holds this component adapter
+ * @return object with injections already performed on it
+ * @throws PicoInitializationException
+ * @throws PicoIntrospectionException
+ */
public Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException
{
Object target = lastComponentInstance;
@@ -67,46 +120,35 @@
Object instance = delegate.getComponentInstance(container);
try
{
- BeanMetaDataBuilder builder;
- if (interceptMC != null && interceptMC.enableAOP())
+ if (metaData == null)
{
- MCComponentInfo mcinfo = GenericWrapperUtil.generateAndInstallWrapper(instance);
- builder = BeanMetaDataBuilder.createBuilder(key, mcinfo.getWrapperClassName());
- builder.addConstructorParameter(Object.class.getName(), instance);
+ metaData = new AbstractBeanMetaData();
}
- else
- {
- builder = BeanMetaDataBuilder.createBuilder(key, instance.getClass().getName());
- builder.setConstructorValue(instance);
- }
+ metaData.setName(key);
+ metaData.setBean(instance.getClass().getName());
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(metaData);
+ builder.setConstructorValue(instance);
builder.ignoreCreate();
builder.ignoreStart();
builder.ignoreStop();
builder.ignoreDestroy();
builder.setAccessMode(getInjectionMode(interceptMC));
+ KernelControllerContext ctx = new AbstractKernelControllerContext(null, builder.getBeanMetaData(), null);
- KernelControllerContext ctx = new AbstractKernelControllerContext(null, builder.getBeanMetaData(), null);
- try
+ StatelessController ctrl = new StatelessController(controller);
+ ctrl.install(ctx);
+ if (ctx.getError() != null)
{
- StatelessController ctrl = new StatelessController(controller);
- ctrl.install(ctx);
- if (ctx.getError() != null)
- {
- throw ctx.getError();
- }
- if (ctrl.getStates().isBeforeState(ctx.getState(), ControllerState.INSTALLED))
- {
- throw new IllegalArgumentException("Missing some dependency: " + ctx.getDependencyInfo().getUnresolvedDependencies(null));
- }
-
- target = ctx.getTarget();
- lastComponentInstance = target;
- return target;
+ throw ctx.getError();
}
- finally
+ if (ctrl.getStates().isBeforeState(ctx.getState(), ControllerState.INSTALLED))
{
- GenericWrapperUtil.postInstallCleanup();
+ throw new IllegalArgumentException("Missing some dependency: " + ctx.getDependencyInfo().getUnresolvedDependencies(null));
}
+
+ target = ctx.getTarget();
+ lastComponentInstance = target;
+ return target;
}
catch (Throwable ex)
{
@@ -114,6 +156,12 @@
}
}
+ /**
+ * Method to determine injection mode to be used by mc kernel.
+ *
+ * @param interceptMC configuration in form of InterceptMC annotation
+ * @return jboss-beans-info BeanAccessMode
+ */
private BeanAccessMode getInjectionMode(InterceptMC interceptMC)
{
MCInjectionMode mode = interceptMC.injectionMode();
@@ -129,11 +177,22 @@
}
}
+ /**
+ * Delegation-only method.
+ *
+ * @param container
+ * @throws PicoIntrospectionException
+ */
public void verify(PicoContainer container) throws PicoIntrospectionException
{
delegate.verify(container);
}
+ /**
+ * Delegation-only method.
+ *
+ * @param visitor
+ */
public void accept(PicoVisitor visitor)
{
delegate.accept(visitor);
Deleted: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentInfo.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentInfo.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentInfo.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,26 +0,0 @@
-package org.exoplatform.container.mc.impl;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class MCComponentInfo
-{
- private String name;
- private ClassLoader classLoader;
-
- public MCComponentInfo(String wrapperClassName, ClassLoader classLoader)
- {
- this.name = wrapperClassName;
- this.classLoader = classLoader;
- }
-
- public String getWrapperClassName()
- {
- return name;
- }
-
- public ClassLoader getClassLoader()
- {
- return classLoader;
- }
-}
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCInjectionMode.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCInjectionMode.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCInjectionMode.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,6 +1,9 @@
package org.exoplatform.container.mc.impl;
/**
+ * Annotation that represents injection mode.
+ * One-to-one mapped to org.jboss.beans.info.spi.BeanAccessMode
+ *
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public enum MCInjectionMode
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntConfig.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntConfig.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntConfig.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -2,6 +2,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.kernel.spi.deployment.KernelDeployment;
import org.jboss.xb.binding.Unmarshaller;
@@ -18,26 +19,67 @@
import java.util.Map;
/**
+ * Configuration reader and holder for conf/mc-int-config.xml
+ *
+ * mc-int-config.xml uses jboss bean deployer syntax (the one used in jboss-beans.xml).
+ * It is only interested in annotation configuration though, and doesn't treat <bean> element attributes
+ * as referring to mc bean declarations - it treats them as references to exo-kernel components.
+ * <p>
+ * Example:
+ * <pre>
+ * <deployment xmlns="urn:jboss:bean-deployer:2.0">
+ * <bean class="org.exoplatform.container.definition.PortalContainerConfig">
+ * <annotation>@org.exoplatform.container.mc.impl.InterceptMC</annotation>
+ * </bean>
+ * <bean name="InjectingBean2">
+ * <annotation>@org.exoplatform.container.mc.impl.InterceptMC(injectionMode=org.exoplatform.container.mc.impl.MCInjectionMode.STANDARD)</annotation>
+ * </bean>
+ * </pre>
+ * <p>
+ * In the above example the first <em>bean</em> declaration refers to exo-kernel configured service that
+ * is returned by exo container when calling getComponentInstanceOfType(clazz).
+ *
+ * The second <em>bean</em> declaration refers to exo-kernel configured service that is returned by exo
+ * container when calling getComponentInstance(name).
+ *
+ * This configuration makes it possible to activate injection outside of you classes. When annotations are declared both
+ * inside the class, and in mc-int-config.xml, the latter completely overrides the former.
+ * It is also possible to use mc-int-config.xml to nullify an existing annotation in your service class.
+ *
+ * <em>Warning:</em> Make sure there are no leading or trailing white spaces in the body of <em>annotation</em> element.
+ *
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class MCIntConfig
{
+ /**
+ * Logger.
+ */
private static final Log log = ExoLogger.getLogger(MCIntConfig.class);
+ /**
+ * Configuration for <em>beans</em> specified with <em>name</em>.
+ */
private Map<String, DeploymentData> confByKey = new HashMap<String, DeploymentData>();
+ /**
+ * Configuration for <em>beans</em> specified with <em>class</em>.
+ */
private Map<String, DeploymentData> confByBean = new HashMap<String, DeploymentData>();
+ /**
+ * The only constructor.
+ */
MCIntConfig()
{
Enumeration<URL> urls = null;
try
{
- urls = Thread.currentThread().getContextClassLoader().getResources("conf/mc-int-beans.xml");
+ urls = Thread.currentThread().getContextClassLoader().getResources("conf/mc-int-config.xml");
}
catch (IOException e)
{
- throw new RuntimeException("Failed to get resources: conf/mc-int-beans.xml", e);
+ throw new RuntimeException("Failed to get resources: conf/mc-int-config.xml", e);
}
UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
@@ -69,40 +111,64 @@
}
}
- public BeanMetaData getByKey(String key)
+ /**
+ * Retrieve configuration by component key.
+ *
+ * @param key component key
+ * @return configuration for specific component
+ */
+ public AbstractBeanMetaData getByKey(String key)
{
DeploymentData dd = confByKey.get(key);
if (dd == null)
{
return null;
}
- return dd.data;
+ return (AbstractBeanMetaData) dd.data;
}
- public BeanMetaData getByBean(String bean)
+ /**
+ * Retrieve configuration by component type.
+ *
+ * @param bean component type
+ * @return configuration for specific component
+ */
+ public AbstractBeanMetaData getByBean(String bean)
{
DeploymentData dd = confByBean.get(bean);
if (dd == null)
{
return null;
}
- return dd.data;
+ return (AbstractBeanMetaData) dd.data;
}
- public BeanMetaData getByAdapter(ComponentAdapter adapter)
+ /**
+ * Retrieve configuration for specific component adapter.
+ * First lookup by key, then by type.
+ *
+ * @param adapter component adapter
+ * @return configuration for specific component
+ */
+ public AbstractBeanMetaData getByAdapter(ComponentAdapter adapter)
{
Object key = adapter.getComponentKey();
String strKey = key instanceof Class ? ((Class) key).getName() : String.valueOf(key);
BeanMetaData ret = getByKey(strKey);
if (ret != null)
{
- return ret;
+ return (AbstractBeanMetaData) ret;
}
ret = getByBean(strKey);
- return ret;
+ return (AbstractBeanMetaData) ret;
}
+ /**
+ * Add parsed configuration for one component.
+ *
+ * @param deploymentData confiuration for specific component
+ */
private void addConf(DeploymentData deploymentData)
{
String name = deploymentData.data.getName();
@@ -122,6 +188,14 @@
}
}
+ /**
+ * Parse the configuration.
+ *
+ * @param factory JBoss XB unmarshaller factory
+ * @param resolver JBoss XB schema resolver
+ * @param url Url pointing to mc-int-config.xml file
+ * @return JBoss XB bean representing a parsed configuration
+ */
private KernelDeployment parseConfigURL(UnmarshallerFactory factory, MutableSchemaResolver resolver, URL url)
{
final boolean trace = log.isTraceEnabled();
@@ -157,6 +231,9 @@
return deployment;
}
+ /**
+ * Data structure that holds component configuration - deployment configuration association.
+ */
static class DeploymentData
{
KernelDeployment deployment;
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntegrationImpl.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntegrationImpl.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntegrationImpl.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -3,6 +3,7 @@
import org.exoplatform.container.mc.MCIntegration;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
import org.jboss.beans.metadata.spi.AnnotationMetaData;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.kernel.Kernel;
@@ -23,17 +24,35 @@
import java.util.Set;
/**
+ * Implementation of MCIntegration that contains hard dependencies on
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class MCIntegrationImpl implements MCIntegration
{
+ /**
+ * Logger
+ */
private static Log log = ExoLogger.getLogger(MCIntegrationImpl.class);
+
+ /**
+ * A singleton MCIntegration implementation
+ */
private static MCIntegration mcint;
+ /**
+ * JBoss MC kernel controller that we use
+ */
private AbstractKernelController rootController;
- private List<KernelDeployment> deployments = new LinkedList<KernelDeployment>();
+
+ /**
+ * Configuration parser and holder
+ */
private MCIntConfig conf;
+ /**
+ * A factory method. In principle can return different implementations based on the running environment.
+ * Currently only one implementation exists.
+ */
public synchronized static MCIntegration getInstance()
{
if (mcint == null)
@@ -43,12 +62,19 @@
return mcint;
}
+ /**
+ * Single constructor - private to force usage of factory method {@link MCIntegrationImpl#getInstance()}.
+ */
private MCIntegrationImpl()
{
- // load mc-int-beans.xml
+ // load conf/mc-int-config.xml
conf = new MCIntConfig();
}
+ /**
+ * Get kernel controller associated with appropriate mc kernel
+ * @return kernel controller
+ */
public synchronized AbstractKernelController getRootController()
{
if (rootController == null)
@@ -63,45 +89,22 @@
log.warn("GateIn - MC integration not available");
return null;
}
- processDeployments();
}
return rootController;
}
- private void processDeployments()
- {
- // Now deploy any AOP configuration - instantiates lifecycle callbacks
- BasicXMLDeployer deployer = new BasicXMLDeployer(rootController.getKernel());
- Enumeration<URL> urls = null;
- try
- {
- urls = Thread.currentThread().getContextClassLoader().getResources("conf/mc-beans.xml");
- }
- catch (IOException e)
- {
- throw new RuntimeException("Failed to load resources: conf/mc-beans.xml", e);
- }
-
- while (urls.hasMoreElements())
- {
- URL confUrl = urls.nextElement();
- try
- {
- deployments.add(deployer.deploy(confUrl));
- log.debug("Deployed mc-kernel configuration: " + confUrl);
- }
- catch (Throwable ex)
- {
- throw new RuntimeException("Failed to deploy: " + confUrl, ex);
- }
- }
- }
-
+ /**
+ * Check if component should pass through mc kernel injection based on class annotations,
+ * and mc-int-config.xml configuration.
+ * Wrap with intercepting component adapter (@link MCComponentAdapter} or return original adapter.
+ *
+ * @see MCIntegration#getMCAdapter(org.picocontainer.ComponentAdapter)
+ */
public ComponentAdapter getMCAdapter(ComponentAdapter adapter)
{
InterceptMC interceptAnnotation = null;
- BeanMetaData data = conf.getByAdapter(adapter);
+ AbstractBeanMetaData data = conf.getByAdapter(adapter);
if (data != null)
{
Set<AnnotationMetaData> annotationMetaData = data.getAnnotations();
@@ -131,21 +134,30 @@
AbstractKernelController controller = getRootController();
if (controller != null)
{
- adapter = new MCComponentAdapter(controller, adapter, interceptAnnotation);
+ adapter = new MCComponentAdapter(controller, adapter, interceptAnnotation, data);
}
return adapter;
}
+ /**
+ * @see MCIntegration#hasMCKernel(org.picocontainer.ComponentAdapter)
+ */
public boolean hasMCKernel(ComponentAdapter adapter)
{
return ThreadLocalUtils.getKernel() != null;
}
+ /**
+ * @see MCIntegration#initThreadCtx(javax.servlet.ServletContext)
+ */
public void initThreadCtx(ServletContext ctx)
{
VDFThreadLocalUtils.init(ctx);
}
+ /**
+ * @see MCIntegration#resetThreadCtx(javax.servlet.ServletContext)
+ */
public void resetThreadCtx(ServletContext ctx)
{
VDFThreadLocalUtils.reset();
Deleted: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCInterceptProxy.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCInterceptProxy.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCInterceptProxy.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,23 +0,0 @@
-package org.exoplatform.container.mc.impl;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class MCInterceptProxy
-{
- private static final Log __log = ExoLogger.getLogger(MCInterceptProxy.class);
- public static final String DELEGATE = "__delegate";
- private Object __delegate;
-
- public MCInterceptProxy(Object delegate)
- {
- this.__delegate = delegate;
- if (__log.isDebugEnabled())
- {
- __log.debug("MCInterceptProxy<init> - CL: " + delegate.getClass().getClassLoader());
- }
- }
-}
Deleted: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/RootContainerVDFDecoratorInjector.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/RootContainerVDFDecoratorInjector.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/RootContainerVDFDecoratorInjector.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,71 +0,0 @@
-package org.exoplatform.container.mc.impl;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtMethod;
-import javassist.LoaderClassPath;
-import org.jboss.beans.metadata.api.annotations.Inject;
-import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
-import org.jboss.mc.common.ThreadLocalUtils;
-import org.jboss.util.loading.Translator;
-
-import java.security.ProtectionDomain;
-
-public class RootContainerVDFDecoratorInjector implements Translator
-{
- @SuppressWarnings({"UnusedDeclaration"})
- private Kernel kernel;
- private ClassLoaderSystem system;
-
- private static final String RC_CLASSNAME = "org.exoplatform.container.RootContainer";
- private boolean found;
-
- public void start()
- {
- system.addTranslator(this);
- }
-
- public void stop()
- {
- system.removeTranslator(this);
- }
-
- protected byte[] decorate(ClassLoader cl) throws Exception
- {
- ClassPool pool = ClassPool.getDefault();
- pool.insertClassPath(new LoaderClassPath(cl));
- CtClass cc = pool.get(RC_CLASSNAME);
- CtMethod m = cc.getDeclaredMethod("getInstance");
- m.insertBefore(ThreadLocalUtils.class.getName() + ".putKernel(kernel);\ntry {\n");
- m.insertAfter("\n } finally { \n" + ThreadLocalUtils.class.getName() + ".removeKernel();\n }");
- return cc.toBytecode();
- }
-
- public byte[] transform(ClassLoader classLoader, String s, Class<?> aClass, ProtectionDomain protectionDomain, byte[] bytes) throws Exception
- {
- if (found == false && RC_CLASSNAME.equals(s))
- {
- found = true;
- return decorate(classLoader);
- }
- return bytes;
- }
-
- public void unregisterClassLoader(ClassLoader classLoader)
- {
- }
-
- @Inject(bean = KernelConstants.KERNEL_NAME)
- public void setKernel(Kernel kernel)
- {
- this.kernel = kernel;
- }
-
- @Inject
- public void setSystem(ClassLoaderSystem system)
- {
- this.system = system;
- }
-}
Deleted: kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/WrapperMethodComposer.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/WrapperMethodComposer.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/WrapperMethodComposer.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,158 +0,0 @@
-package org.exoplatform.container.mc.impl;
-
-import javassist.CtClass;
-import javassist.CtMethod;
-import javassist.NotFoundException;
-import javassist.bytecode.AccessFlag;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class WrapperMethodComposer
-{
- private String delegate;
- private String type;
-
- public WrapperMethodComposer(String delegateFldName, String type)
- {
- delegate = delegateFldName;
- this.type = type;
- }
-
- public String composeMethod(CtMethod method) throws NotFoundException
- {
- StringBuilder sb = new StringBuilder();
-
- String next = addModifiers(method.getModifiers());
- sb.append(next);
- if (next.length() > 0)
- {
- sb.append(" ");
- }
-
- CtClass ret = method.getReturnType();
- next = addReturnType(ret);
- sb.append(next).append(" ");
-
- sb.append(method.getName()).append("(");
- next = addParams(method.getParameterTypes());
- sb.append(next);
- sb.append(") ");
-
- next = addExceptions(method.getExceptionTypes());
- sb.append(next);
- if (next.length() > 0)
- {
- sb.append(" ");
- }
-
- sb.append("{ ");
- sb.append(delegateCall(method.getName(), method.getParameterTypes(), method.getReturnType()));
- sb.append("}");
-
- return sb.toString();
- }
-
- private String delegateCall(String name, CtClass[] parameterTypes, CtClass returnType)
- {
- StringBuilder sb = new StringBuilder();
- if (returnType != null)
- {
- sb.append("return ");
- }
- sb.append("((").append(type).append(")");
- sb.append(delegate).append(")").append(".").append(name).append("(");
- for (int i = 0; i < parameterTypes.length; i++)
- {
- if (i > 0)
- {
- sb.append(",");
- }
- sb.append("a").append(i);
- }
- sb.append(");");
-
- if (returnType == null)
- {
- sb.append("return;");
- }
-
- return sb.toString();
- }
-
-
- private String addParams(CtClass[] parameterTypes)
- {
- if (parameterTypes == null || parameterTypes.length == 0)
- {
- return "";
- }
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < parameterTypes.length; i++)
- {
- if (i > 0)
- {
- sb.append(",");
- }
- sb.append(parameterTypes[i].getName()).append(" a").append(i);
- }
- return sb.toString();
- }
-
- private String addExceptions(CtClass[] exceptionTypes)
- {
- StringBuilder ret = new StringBuilder();
- if (exceptionTypes == null || exceptionTypes.length == 0)
- {
- return "";
- }
-
- ret.append("throws ");
- for (int i = 0; i < exceptionTypes.length; i++)
- {
- if (i > 0)
- {
- ret.append(",");
- }
- ret.append(exceptionTypes[i].getName());
- }
- return ret.toString();
- }
-
- private String addReturnType(CtClass ret)
- {
- if (ret == null)
- {
- return "void";
- }
- else
- {
- return ret.getName();
- }
- }
-
- private String addModifiers(int modifiers)
- {
- if (AccessFlag.isPackage(modifiers))
- {
- return "";
- }
- else if (AccessFlag.isPrivate(modifiers))
- {
- return "private";
- }
- else if (AccessFlag.isPublic(modifiers))
- {
- return "public";
- }
- else if (AccessFlag.isProtected(modifiers))
- {
- return "protected";
- }
- else
- {
- throw new RuntimeException("Invalid modifiers: " + modifiers);
- }
- }
-}
Modified: kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -2,13 +2,10 @@
import org.exoplatform.commons.Environment;
import org.exoplatform.container.RootContainer;
-import org.exoplatform.kernel.demos.mc.AOPInterceptor;
import org.exoplatform.kernel.demos.mc.InjectedBean;
import org.exoplatform.kernel.demos.mc.InjectingBean;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.proxy.container.ContainerProxyMethodInvocation;
import org.jboss.dependency.spi.Controller;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.config.KernelConfigurator;
@@ -18,9 +15,10 @@
import org.junit.Assert;
import org.junit.Test;
-import java.lang.reflect.Method;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -37,8 +35,6 @@
protected InjectingBean bean;
protected boolean inJboss;
protected boolean mcIntActive = true;
- protected boolean aopIntActive = false;
- protected Map<String, Integer> expectedAOPResults;
public MCInjectionTest()
{
@@ -60,75 +56,9 @@
public void test()
{
init();
- // AOP tests first
- testAOP();
tests();
}
- protected void testAOP()
- {
- String className;
- Method m = null;
- try
- {
- m = bean.getClass().getDeclaredMethod("getDelegate");
- }
- catch (Exception ignored)
- {
- }
- catch (Error ignored)
- {
- }
-
- if (inJboss == false || aopIntActive == false)
- {
- Assert.assertNull("AOP Proxy should not be present", m);
- return;
- }
- Assert.assertNotNull("AOP Proxy should be present", m);
- try
- {
- Object delegate = m.invoke(bean);
- className = delegate.getClass().getName();
- }
- catch (Exception ex)
- {
- throw new RuntimeException("AOP Proxy getDelegate() filed");
- }
- CallCounter counter = new CallCounter();
- List<Invocation> invocations = AOPInterceptor.getInvocations();
- for (Invocation iv : invocations)
- {
- if (iv instanceof ContainerProxyMethodInvocation)
- {
- if (iv.getTargetObject().getClass().getName().startsWith(className))
- {
- counter.add(((ContainerProxyMethodInvocation) iv).getMethod().getName());
- }
- }
- }
-
- Map<String, Integer> called = counter.getCallMap();
- if (expectedAOPResults == null)
- {
- throw new IllegalArgumentException("expectedAOPResults == null");
- }
- if (expectedAOPResults.size() == 0)
- {
- throw new IllegalArgumentException("expectedAOPResults.size() == 0");
- }
- for (Map.Entry<String, Integer> ent : expectedAOPResults.entrySet())
- {
- Integer callCount = called.get(ent.getKey());
- if (callCount == null)
- {
- callCount = Integer.valueOf(0);
- }
- junit.framework.Assert.assertEquals(ent.getKey() + "() not called through AOP as expected",
- ent.getValue(), callCount);
- }
- }
-
protected void tests()
{
testFieldInjection();
@@ -136,9 +66,36 @@
testNameLookupMethodInjection();
testNameLookupMapInjection();
testPropertyValueMethodInjection();
+ testTransactionManager();
testStarted();
}
+ private void testTransactionManager()
+ {
+ TransactionManager tm = bean.getTransactionManager();
+
+ if (inJboss && mcIntActive)
+ {
+ try
+ {
+ log.info("Status before tx: " + tm.getStatus());
+ tm.begin();
+ log.info("Status in tx: " + tm.getStatus());
+ tm.commit();
+ log.info("Status after tx: " + tm.getStatus());
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException("Failed to use TransactionManager: ", ex);
+ }
+ }
+ else
+ {
+ Assert.assertNull("Injection should not have worked", tm);
+ }
+ log.info("testTransactionManager passed");
+ }
+
protected void testFieldInjection()
{
boolean found = bean.getInjectedBean() != null;
@@ -221,7 +178,7 @@
protected void testStarted()
{
- Assert.assertTrue("start() method not called", bean.isStarted());
+ Assert.assertEquals("start() method not called exactly once", 1, bean.getStartCount());
log.info("testStarted passed");
}
Modified: kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest3.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest3.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest3.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -5,18 +5,11 @@
/**
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
-public class MCInjectionTest3 extends MCInjectionTest2
+public class MCInjectionTest3 extends MCInjectionTest
{
public MCInjectionTest3()
{
super();
beanName = "InjectingBean3";
- expectedAOPResults = new HashMap<String, Integer>();
- expectedAOPResults.put("setBindings", 1);
- expectedAOPResults.put("setSomeStringProperty", 1);
- expectedAOPResults.put("setBean", 1);
- expectedAOPResults.put("setConfigurator", 1);
- expectedAOPResults.put("start", 1);
- aopIntActive = true;
}
}
\ No newline at end of file
Modified: kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest4.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest4.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest4.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -9,5 +9,6 @@
{
super();
beanName = "InjectingBean4";
+ mcIntActive = false;
}
}
\ No newline at end of file
Deleted: kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest5.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest5.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest5.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,14 +0,0 @@
-package org.exoplatform.kernel.it;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class MCInjectionTest5 extends MCInjectionTest
-{
- public MCInjectionTest5()
- {
- super();
- beanName = "InjectingBean5";
- mcIntActive = false;
- }
-}
\ No newline at end of file
Deleted: kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/test/java/org/exoplatform/kernel/it/TestMCInjectionIntegration5.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/test/java/org/exoplatform/kernel/it/TestMCInjectionIntegration5.java 2009-12-09 10:30:42 UTC (rev 959)
+++ kernel/branches/mc-int-branch/exo.kernel.tests/integration-tests/src/test/java/org/exoplatform/kernel/it/TestMCInjectionIntegration5.java 2009-12-09 11:00:30 UTC (rev 960)
@@ -1,12 +0,0 @@
-package org.exoplatform.kernel.it;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class TestMCInjectionIntegration5 extends TestMCInjectionIntegration
-{
- public TestMCInjectionIntegration5()
- {
- testClass = MCInjectionTest5.class.getName();
- }
-}
\ No newline at end of file
16 years, 7 months
exo-jcr SVN: r959 - in kernel/trunk: exo.kernel.component.ext.cache.impl.jboss.v3 and 6 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2009-12-09 05:30:42 -0500 (Wed, 09 Dec 2009)
New Revision: 959
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java
kernel/trunk/pom.xml
Log:
EXOJCR-296: Apply some remarks after the work done for KER-119
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml 2009-12-09 10:30:42 UTC (rev 959)
@@ -8,7 +8,7 @@
</parent>
<artifactId>exo.kernel.component.ext.cache.impl.jboss.v3</artifactId>
-
+ <name>eXo Kernel :: Cache Extension :: JBoss Cache Implementation</name>
<description>JBoss Cache Implementation for the Cache Service</description>
<dependencies>
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java 2009-12-09 10:30:42 UTC (rev 959)
@@ -18,15 +18,9 @@
*/
package org.exoplatform.services.cache.impl.jboss;
-import java.io.Serializable;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.atomic.AtomicInteger;
-
+import org.exoplatform.services.cache.CacheInfo;
import org.exoplatform.services.cache.CacheListener;
+import org.exoplatform.services.cache.CacheListenerContext;
import org.exoplatform.services.cache.CachedObjectSelector;
import org.exoplatform.services.cache.ExoCache;
import org.exoplatform.services.cache.ExoCacheConfig;
@@ -37,13 +31,20 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.notifications.annotation.NodeCreated;
+import org.jboss.cache.NodeSPI;
import org.jboss.cache.notifications.annotation.NodeEvicted;
import org.jboss.cache.notifications.annotation.NodeModified;
import org.jboss.cache.notifications.annotation.NodeRemoved;
import org.jboss.cache.notifications.event.EventImpl;
import org.jboss.cache.notifications.event.NodeEvent;
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
+
/**
* An {@link org.exoplatform.services.cache.ExoCache} implementation based on {@link org.jboss.cache.Node}.
* Created by The eXo Platform SAS
@@ -51,7 +52,7 @@
* exo(a)exoplatform.com
* 20 juil. 2009
*/
-public abstract class AbstractExoCache implements ExoCache
+public abstract class AbstractExoCache<K extends Serializable, V> implements ExoCache<K, V>
{
/**
@@ -59,12 +60,10 @@
*/
private static final Log LOG = ExoLogger.getLogger(AbstractExoCache.class);
- protected final AtomicInteger size = new AtomicInteger();
+ private final AtomicInteger hits = new AtomicInteger(0);
- private volatile int hits;
+ private final AtomicInteger misses = new AtomicInteger(0);
- private volatile int misses;
-
private String label;
private String name;
@@ -75,34 +74,33 @@
private boolean logEnabled;
- private final CopyOnWriteArrayList<CacheListener> listeners;
+ private final CopyOnWriteArrayList<ListenerContext<K, V>> listeners;
- protected final CacheSPI<Serializable, Object> cache;
+ protected final CacheSPI<K, V> cache;
- @SuppressWarnings("unchecked")
- public AbstractExoCache(ExoCacheConfig config, CacheSPI<Serializable, Object> cache)
+ public AbstractExoCache(ExoCacheConfig config, Cache<K, V> cache)
{
- this.cache = cache;
- this.listeners = new CopyOnWriteArrayList<CacheListener>();
+ this.cache = (CacheSPI<K, V>)cache;
+ this.listeners = new CopyOnWriteArrayList<ListenerContext<K, V>>();
setDistributed(config.isDistributed());
setLabel(config.getLabel());
setName(config.getName());
setLogEnabled(config.isLogEnabled());
setReplicated(config.isRepicated());
cache.getConfiguration().setInvocationBatchingEnabled(true);
- cache.addCacheListener(new SizeManager());
+ cache.addCacheListener(new CacheEventListener());
}
/**
* {@inheritDoc}
*/
- public void addCacheListener(CacheListener listener)
+ public void addCacheListener(CacheListener<? super K, ? super V> listener)
{
if (listener == null)
{
- return;
+ throw new NullPointerException();
}
- listeners.add(listener);
+ listeners.add(new ListenerContext<K, V>(listener, this));
}
/**
@@ -110,8 +108,8 @@
*/
public void clearCache() throws Exception
{
- final Node<Serializable, Object> rootNode = cache.getRoot();
- for (Node<Serializable, Object> node : rootNode.getChildren())
+ final Node<K, V> rootNode = cache.getRoot();
+ for (Node<K, V> node : rootNode.getChildren())
{
if (node == null)
{
@@ -125,18 +123,23 @@
/**
* {@inheritDoc}
*/
- public Object get(Serializable name) throws Exception
+ @SuppressWarnings("unchecked")
+ public V get(Serializable name) throws Exception
{
- final Object result = cache.get(Fqn.fromElements(name), name);
+ if (name == null)
+ {
+ return null;
+ }
+ final V result = cache.get(getFqn(name), (K)name);
if (result == null)
{
- misses++;
+ misses.incrementAndGet();
}
else
{
- hits++;
+ hits.incrementAndGet();
}
- onGet(name, result);
+ onGet((K)name, result);
return result;
}
@@ -145,7 +148,7 @@
*/
public int getCacheHit()
{
- return hits;
+ return hits.get();
}
/**
@@ -153,13 +156,12 @@
*/
public int getCacheMiss()
{
- return misses;
+ return misses.get();
}
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
public int getCacheSize()
{
return cache.getNumberOfNodes();
@@ -168,16 +170,16 @@
/**
* {@inheritDoc}
*/
- public List<Object> getCachedObjects()
+ public List<V> getCachedObjects()
{
- final LinkedList<Object> list = new LinkedList<Object>();
- for (Node<Serializable, Object> node : cache.getRoot().getChildren())
+ final LinkedList<V> list = new LinkedList<V>();
+ for (Node<K, V> node : cache.getRoot().getChildren())
{
if (node == null)
{
continue;
}
- final Object value = node.get(getKey(node));
+ final V value = node.get(getKey(node));
if (value != null)
{
list.add(value);
@@ -229,33 +231,48 @@
/**
* {@inheritDoc}
*/
- public void put(Serializable name, Object obj) throws Exception
+ public void put(K key, V value) throws Exception
{
- putOnly(name, obj);
- onPut(name, obj);
+ if (key == null)
+ {
+ throw new NullPointerException("No null cache key accepted");
+ }
+ putOnly(key, value);
+ onPut(key, value);
}
/**
* Only puts the data into the cache nothing more
*/
- private Object putOnly(Serializable name, Object obj) throws Exception
+ private V putOnly(K key, V value) throws Exception
{
- return cache.put(Fqn.fromElements(name), name, obj);
+ return cache.put(getFqn(key), key, value);
}
/**
* {@inheritDoc}
*/
- public void putMap(Map<Serializable, Object> objs) throws Exception
+ public void putMap(Map<? extends K, ? extends V> objs) throws NullPointerException, IllegalArgumentException
{
+ if (objs == null)
+ {
+ throw new NullPointerException("No null map accepted");
+ }
+ for (Serializable name : objs.keySet())
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("No null cache key accepted");
+ }
+ }
cache.startBatch();
int total = 0;
try
{
// Start transaction
- for (Entry<Serializable, Object> entry : objs.entrySet())
+ for (Map.Entry<? extends K, ? extends V> entry : objs.entrySet())
{
- Object value = putOnly(entry.getKey(), entry.getValue());
+ V value = putOnly(entry.getKey(), entry.getValue());
if (value == null)
{
total++;
@@ -263,7 +280,7 @@
}
cache.endBatch(true);
// End transaction
- for (Entry<Serializable, Object> entry : objs.entrySet())
+ for (Map.Entry<? extends K, ? extends V> entry : objs.entrySet())
{
onPut(entry.getKey(), entry.getValue());
}
@@ -271,35 +288,40 @@
catch (Exception e)
{
cache.endBatch(false);
- throw e;
+ LOG.warn("An error occurs while executing the putMap method", e);
}
}
/**
* {@inheritDoc}
*/
- public Object remove(Serializable name) throws Exception
+ @SuppressWarnings("unchecked")
+ public V remove(Serializable name) throws Exception
{
- final Fqn<Serializable> fqn = Fqn.fromElements(name);
- final Node<Serializable, Object> node = cache.getNode(fqn);
+ if (name == null)
+ {
+ throw new NullPointerException("No null cache key accepted");
+ }
+ final Fqn<Serializable> fqn = getFqn(name);
+ final NodeSPI<K, V> node = cache.getNode(fqn);
+ V result = null;
if (node != null)
{
- final Object result = node.get(name);
+ result = node.getDirect((K)name);
if (cache.removeNode(fqn))
{
- onRemove(name, result);
+ onRemove((K)name, result);
}
- return result;
}
- return null;
+ return result;
}
/**
* {@inheritDoc}
*/
- public List<Object> removeCachedObjects() throws Exception
+ public List<V> removeCachedObjects() throws Exception
{
- final List<Object> list = getCachedObjects();
+ final List<V> list = getCachedObjects();
clearCache();
return list;
}
@@ -307,19 +329,23 @@
/**
* {@inheritDoc}
*/
- public void select(CachedObjectSelector selector) throws Exception
+ public void select(CachedObjectSelector<? super K, ? super V> selector) throws Exception
{
- for (Node<Serializable, Object> node : cache.getRoot().getChildren())
+ if (selector == null)
{
+ throw new IllegalArgumentException("No null selector");
+ }
+ for (Node<K, V> node : cache.getRoot().getChildren())
+ {
if (node == null)
{
continue;
}
- final Serializable key = getKey(node);
- final Object value = node.get(key);
- ObjectCacheInfo info = new ObjectCacheInfo()
+ final K key = getKey(node);
+ final V value = node.get(key);
+ ObjectCacheInfo<V> info = new ObjectCacheInfo<V>()
{
- public Object get()
+ public V get()
{
return value;
}
@@ -380,7 +406,7 @@
/**
* Returns the key related to the given node
*/
- private Serializable getKey(Node<Serializable, Object> node)
+ private K getKey(Node<K, V> node)
{
return getKey(node.getFqn());
}
@@ -389,22 +415,30 @@
* Returns the key related to the given Fqn
*/
@SuppressWarnings("unchecked")
- private Serializable getKey(Fqn fqn)
+ private K getKey(Fqn fqn)
{
- return (Serializable)fqn.get(0);
+ return (K)fqn.get(0);
}
- void onExpire(Serializable key, Object obj)
+ /**
+ * Returns the Fqn related to the given name
+ */
+ private Fqn<Serializable> getFqn(Serializable name)
{
+ return Fqn.fromElements(name);
+ }
+
+ void onExpire(K key, V obj)
+ {
if (listeners.isEmpty())
{
return;
}
- for (CacheListener listener : listeners)
+ for (ListenerContext<K, V> context : listeners)
{
try
{
- listener.onExpire(this, key, obj);
+ context.onExpire(key, obj);
}
catch (Exception e)
{
@@ -414,17 +448,17 @@
}
}
- void onRemove(Serializable key, Object obj)
+ void onRemove(K key, V obj)
{
if (listeners.isEmpty())
{
return;
}
- for (CacheListener listener : listeners)
+ for (ListenerContext<K, V> context : listeners)
{
try
{
- listener.onRemove(this, key, obj);
+ context.onRemove(key, obj);
}
catch (Exception e)
{
@@ -434,16 +468,16 @@
}
}
- void onPut(Serializable key, Object obj)
+ void onPut(K key, V obj)
{
if (listeners.isEmpty())
{
return;
}
- for (CacheListener listener : listeners)
+ for (ListenerContext<K, V> context : listeners)
try
{
- listener.onPut(this, key, obj);
+ context.onPut(key, obj);
}
catch (Exception e)
{
@@ -452,16 +486,16 @@
}
}
- void onGet(Serializable key, Object obj)
+ void onGet(K key, V obj)
{
if (listeners.isEmpty())
{
return;
}
- for (CacheListener listener : listeners)
+ for (ListenerContext<K, V> context : listeners)
try
{
- listener.onGet(this, key, obj);
+ context.onGet(key, obj);
}
catch (Exception e)
{
@@ -476,10 +510,10 @@
{
return;
}
- for (CacheListener listener : listeners)
+ for (ListenerContext<K, V> context : listeners)
try
{
- listener.onClearCache(this);
+ context.onClearCache();
}
catch (Exception e)
{
@@ -489,7 +523,7 @@
}
@org.jboss.cache.notifications.annotation.CacheListener
- public class SizeManager
+ public class CacheEventListener
{
@NodeEvicted
@@ -507,43 +541,100 @@
@NodeRemoved
public void nodeRemoved(NodeEvent ne)
{
- if (ne.isPre())
+ if (ne.isPre() && !ne.isOriginLocal())
{
- if (!ne.isOriginLocal())
- {
- final Node<Serializable, Object> node = cache.getNode(ne.getFqn());
- final Serializable key = getKey(ne.getFqn());
- onRemove(key, node.get(key));
- }
+ final Node<K, V> node = cache.getNode(ne.getFqn());
+ final K key = getKey(ne.getFqn());
+ onRemove(key, node.get(key));
}
}
- @NodeCreated
- public void nodeCreated(NodeEvent ne)
- {
- size.incrementAndGet();
- }
-
@SuppressWarnings("unchecked")
@NodeModified
public void nodeModified(NodeEvent ne)
{
if (!ne.isOriginLocal() && !ne.isPre())
{
- final Serializable key = getKey(ne.getFqn());
+ final K key = getKey(ne.getFqn());
if (ne instanceof EventImpl)
{
EventImpl evt = (EventImpl)ne;
- Map<Serializable, Object> data = evt.getData();
+ Map<K, V> data = evt.getData();
if (data != null)
{
onPut(key, data.get(key));
return;
}
}
- final Node<Serializable, Object> node = cache.getNode(ne.getFqn());
+ final Node<K, V> node = cache.getNode(ne.getFqn());
onPut(key, node.get(key));
}
}
}
+
+ private static class ListenerContext<K extends Serializable, V> implements CacheListenerContext, CacheInfo
+ {
+
+ /** . */
+ private final ExoCache<K, V> cache;
+
+ /** . */
+ final CacheListener<? super K, ? super V> listener;
+
+ public ListenerContext(CacheListener<? super K, ? super V> listener, ExoCache<K, V> cache)
+ {
+ this.listener = listener;
+ this.cache = cache;
+ }
+
+ public CacheInfo getCacheInfo()
+ {
+ return this;
+ }
+
+ public String getName()
+ {
+ return cache.getName();
+ }
+
+ public int getMaxSize()
+ {
+ return cache.getMaxSize();
+ }
+
+ public long getLiveTime()
+ {
+ return cache.getLiveTime();
+ }
+
+ public int getSize()
+ {
+ return cache.getCacheSize();
+ }
+
+ void onExpire(K key, V obj) throws Exception
+ {
+ listener.onExpire(this, key, obj);
+ }
+
+ void onRemove(K key, V obj) throws Exception
+ {
+ listener.onRemove(this, key, obj);
+ }
+
+ void onPut(K key, V obj) throws Exception
+ {
+ listener.onPut(this, key, obj);
+ }
+
+ void onGet(K key, V obj) throws Exception
+ {
+ listener.onGet(this, key, obj);
+ }
+
+ void onClearCache() throws Exception
+ {
+ listener.onClearCache(this);
+ }
+ }
}
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheCreator.java 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheCreator.java 2009-12-09 10:30:42 UTC (rev 959)
@@ -18,13 +18,13 @@
*/
package org.exoplatform.services.cache.impl.jboss;
-import java.io.Serializable;
-
import org.exoplatform.services.cache.ExoCache;
import org.exoplatform.services.cache.ExoCacheConfig;
import org.exoplatform.services.cache.ExoCacheInitException;
import org.jboss.cache.Cache;
+import java.io.Serializable;
+
/**
* This class is used to create the cache according to the given
* configuration {@link org.exoplatform.services.cache.ExoCacheConfig}
@@ -43,7 +43,7 @@
* @param cache the cache to initialize
* @exception ExoCacheInitException if an exception happens while initializing the cache
*/
- public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException;
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException;
/**
* Returns the type of {@link org.exoplatform.services.cache.ExoCacheConfig} expected by the creator
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheCreator.java 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheCreator.java 2009-12-09 10:30:42 UTC (rev 959)
@@ -18,8 +18,6 @@
*/
package org.exoplatform.services.cache.impl.jboss.fifo;
-import java.io.Serializable;
-
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
import org.exoplatform.services.cache.ExoCache;
@@ -34,6 +32,8 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.FIFOAlgorithmConfig;
+import java.io.Serializable;
+
/**
* The FIFO Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
* Created by The eXo Platform SAS
@@ -68,7 +68,7 @@
/**
* {@inheritDoc}
*/
- public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
{
if (config instanceof FIFOExoCacheConfig)
{
@@ -85,7 +85,7 @@
/**
* Creates a new ExoCache instance with the relevant parameters
*/
- private ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long minTimeToLive)
+ private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long minTimeToLive)
throws ExoCacheInitException
{
final Configuration configuration = cache.getConfiguration();
@@ -97,7 +97,7 @@
final EvictionConfig evictionConfig = configuration.getEvictionConfig();
evictionConfig.setDefaultEvictionRegionConfig(erc);
- return new AbstractExoCache(config, cache)
+ return new AbstractExoCache<Serializable, Object>(config, cache)
{
public void setMaxSize(int max)
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java 2009-12-09 10:30:42 UTC (rev 959)
@@ -18,8 +18,6 @@
*/
package org.exoplatform.services.cache.impl.jboss.lfu;
-import java.io.Serializable;
-
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -35,6 +33,8 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.LFUAlgorithmConfig;
+import java.io.Serializable;
+
/**
* The LFU Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
* Created by The eXo Platform SAS
@@ -58,7 +58,7 @@
/**
* {@inheritDoc}
*/
- public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
{
if (config instanceof LFUExoCacheConfig)
{
@@ -75,7 +75,7 @@
/**
* Creates a new ExoCache instance with the relevant parameters
*/
- private ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, int minNodes,
+ private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, int minNodes,
long minTimeToLive) throws ExoCacheInitException
{
final Configuration configuration = cache.getConfiguration();
@@ -108,7 +108,7 @@
/**
* The LRU implementation of an ExoCache
*/
- public static class LFUExoCache extends AbstractExoCache
+ public static class LFUExoCache extends AbstractExoCache<Serializable, Object>
{
private final LFUAlgorithmConfig lfu;
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheCreator.java 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheCreator.java 2009-12-09 10:30:42 UTC (rev 959)
@@ -18,8 +18,6 @@
*/
package org.exoplatform.services.cache.impl.jboss.lru;
-import java.io.Serializable;
-
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -35,6 +33,8 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.LRUAlgorithmConfig;
+import java.io.Serializable;
+
/**
* The LRU Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
* Created by The eXo Platform SAS
@@ -63,7 +63,7 @@
/**
* {@inheritDoc}
*/
- public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
{
if (config instanceof LRUExoCacheConfig)
{
@@ -82,7 +82,7 @@
/**
* Creates a new ExoCache instance with the relevant parameters
*/
- private ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long timeToLive,
+ private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long timeToLive,
long maxAge, long minTimeToLive) throws ExoCacheInitException
{
final Configuration configuration = cache.getConfiguration();
@@ -115,7 +115,7 @@
/**
* The LRU implementation of an ExoCache
*/
- public static class LRUExoCache extends AbstractExoCache
+ public static class LRUExoCache extends AbstractExoCache<Serializable, Object>
{
private final LRUAlgorithmConfig lru;
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheCreator.java 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheCreator.java 2009-12-09 10:30:42 UTC (rev 959)
@@ -18,8 +18,6 @@
*/
package org.exoplatform.services.cache.impl.jboss.mru;
-import java.io.Serializable;
-
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
import org.exoplatform.services.cache.ExoCache;
@@ -34,6 +32,8 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.MRUAlgorithmConfig;
+import java.io.Serializable;
+
/**
* The MRU Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
* Created by The eXo Platform SAS
@@ -52,7 +52,7 @@
/**
* {@inheritDoc}
*/
- public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
{
if (config instanceof MRUExoCacheConfig)
{
@@ -69,7 +69,7 @@
/**
* Creates a new ExoCache instance with the relevant parameters
*/
- private ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long minTimeToLive)
+ private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long minTimeToLive)
throws ExoCacheInitException
{
final Configuration configuration = cache.getConfiguration();
@@ -81,7 +81,7 @@
final EvictionConfig evictionConfig = configuration.getEvictionConfig();
evictionConfig.setDefaultEvictionRegionConfig(erc);
- return new AbstractExoCache(config, cache)
+ return new AbstractExoCache<Serializable, Object>(config, cache)
{
public void setMaxSize(int max)
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java 2009-12-09 10:30:42 UTC (rev 959)
@@ -52,7 +52,7 @@
CacheService service;
- AbstractExoCache cache;
+ AbstractExoCache<Serializable, Object> cache;
ExoCacheFactory factory;
@@ -64,7 +64,7 @@
public void setUp() throws Exception
{
this.service = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class);
- this.cache = (AbstractExoCache)service.getCacheInstance("myCache");
+ this.cache = (AbstractExoCache<Serializable, Object>)service.getCacheInstance("myCache");
this.factory = (ExoCacheFactory)PortalContainer.getInstance().getComponentInstanceOfType(ExoCacheFactory.class);
}
@@ -130,6 +130,8 @@
assertEquals(2, cache.getCacheSize());
values = new HashMap<Serializable, Object>()
{
+ private static final long serialVersionUID = 1L;
+
public Set<Entry<Serializable, Object>> entrySet()
{
Set<Entry<Serializable, Object>> set = new LinkedHashSet<Entry<Serializable, Object>>(super.entrySet());
@@ -156,14 +158,7 @@
};
values.put(new MyKey("e"), "e");
values.put(new MyKey("d"), "d");
- try
- {
- cache.putMap(values);
- assertTrue("An error was expected", false);
- }
- catch (Exception e)
- {
- }
+ cache.putMap(values);
assertEquals(2, cache.getCacheSize());
}
@@ -202,17 +197,17 @@
cache.put(new MyKey("b"), 2);
cache.put(new MyKey("c"), 3);
final AtomicInteger count = new AtomicInteger();
- CachedObjectSelector selector = new CachedObjectSelector()
+ CachedObjectSelector<Serializable, Object> selector = new CachedObjectSelector<Serializable, Object>()
{
- public void onSelect(ExoCache cache, Serializable key, ObjectCacheInfo ocinfo) throws Exception
+ public void onSelect(ExoCache<? extends Serializable, ? extends Object> cache, Serializable key, ObjectCacheInfo<? extends Object> ocinfo) throws Exception
{
assertTrue(key.equals(new MyKey("a")) || key.equals(new MyKey("b")) || key.equals(new MyKey("c")));
assertTrue(ocinfo.get().equals(1) || ocinfo.get().equals(2) || ocinfo.get().equals(3));
count.incrementAndGet();
}
- public boolean select(Serializable key, ObjectCacheInfo ocinfo)
+ public boolean select(Serializable key, ObjectCacheInfo<? extends Object> ocinfo)
{
return true;
}
@@ -234,6 +229,7 @@
assertEquals(2, cache.getCacheMiss() - misses);
}
+ @SuppressWarnings("unchecked")
public void testDistributedCache() throws Exception
{
ExoCacheConfig config = new ExoCacheConfig();
@@ -246,13 +242,13 @@
config2.setMaxSize(5);
config2.setLiveTime(1000);
config2.setDistributed(true);
- AbstractExoCache cache1 = (AbstractExoCache)factory.createCache(config);
+ AbstractExoCache<Serializable, Object> cache1 = (AbstractExoCache<Serializable, Object>)factory.createCache(config);
MyCacheListener listener1 = new MyCacheListener();
cache1.addCacheListener(listener1);
- AbstractExoCache cache2 = (AbstractExoCache)factory.createCache(config);
+ AbstractExoCache<Serializable, Object> cache2 = (AbstractExoCache<Serializable, Object>)factory.createCache(config);
MyCacheListener listener2 = new MyCacheListener();
cache2.addCacheListener(listener2);
- AbstractExoCache cache3 = (AbstractExoCache)factory.createCache(config2);
+ AbstractExoCache<Serializable, Object> cache3 = (AbstractExoCache<Serializable, Object>)factory.createCache(config2);
MyCacheListener listener3 = new MyCacheListener();
cache3.addCacheListener(listener3);
try
@@ -351,6 +347,8 @@
assertEquals(0, listener3.clearCache);
values = new HashMap<Serializable, Object>()
{
+ private static final long serialVersionUID = 1L;
+
public Set<Entry<Serializable, Object>> entrySet()
{
Set<Entry<Serializable, Object>> set = new LinkedHashSet<Entry<Serializable, Object>>(super.entrySet());
@@ -377,14 +375,7 @@
};
values.put(new MyKey("e"), "e");
values.put(new MyKey("d"), "d");
- try
- {
- cache1.putMap(values);
- assertTrue("An error was expected", false);
- }
- catch (Exception e)
- {
- }
+ cache1.putMap(values);
assertEquals(2, cache1.getCacheSize());
assertEquals(2, cache2.getCacheSize());
assertEquals(5, listener1.put);
@@ -410,7 +401,8 @@
public void testMultiThreading() throws Exception
{
- final ExoCache cache = service.getCacheInstance("test-multi-threading");
+ long time = System.currentTimeMillis();
+ final ExoCache<Serializable, Object> cache = service.getCacheInstance("test-multi-threading");
final int totalElement = 100;
final int totalTimes = 100;
int reader = 20;
@@ -444,12 +436,15 @@
}
sleep(50);
}
- doneSignal.countDown();
}
catch (Exception e)
{
errors.add(e);
}
+ finally
+ {
+ doneSignal.countDown();
+ }
}
};
thread.start();
@@ -472,12 +467,15 @@
}
sleep(50);
}
- doneSignal.countDown();
}
catch (Exception e)
{
errors.add(e);
}
+ finally
+ {
+ doneSignal.countDown();
+ }
}
};
thread.start();
@@ -499,12 +497,15 @@
}
sleep(50);
}
- doneSignal.countDown();
}
catch (Exception e)
{
errors.add(e);
}
+ finally
+ {
+ doneSignal.countDown();
+ }
}
};
thread.start();
@@ -534,12 +535,15 @@
}
sleep(50);
}
- doneSignal2.countDown();
}
catch (Exception e)
{
errors.add(e);
}
+ finally
+ {
+ doneSignal2.countDown();
+ }
}
};
thread.start();
@@ -558,12 +562,15 @@
sleep(150);
cache.clearCache();
}
- doneSignal2.countDown();
}
catch (Exception e)
{
errors.add(e);
}
+ finally
+ {
+ doneSignal2.countDown();
+ }
}
};
thread.start();
@@ -578,10 +585,10 @@
}
throw errors.get(0);
}
-
+ System.out.println("Total Time = " + (System.currentTimeMillis() - time));
}
- public static class MyCacheListener implements CacheListener
+ public static class MyCacheListener implements CacheListener<Serializable, Object>
{
public int clearCache;
@@ -594,27 +601,27 @@
public int remove;
- public void onClearCache(ExoCache cache) throws Exception
+ public void onClearCache(ExoCache<Serializable, Object> cache) throws Exception
{
clearCache++;
}
- public void onExpire(ExoCache cache, Serializable key, Object obj) throws Exception
+ public void onExpire(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
{
expire++;
}
- public void onGet(ExoCache cache, Serializable key, Object obj) throws Exception
+ public void onGet(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
{
get++;
}
- public void onPut(ExoCache cache, Serializable key, Object obj) throws Exception
+ public void onPut(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
{
put++;
}
- public void onRemove(ExoCache cache, Serializable key, Object obj) throws Exception
+ public void onRemove(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
{
remove++;
}
@@ -647,6 +654,7 @@
public static class MyKey implements Serializable
{
+ private static final long serialVersionUID = 1L;
public String value;
public MyKey(String value)
Modified: kernel/trunk/pom.xml
===================================================================
--- kernel/trunk/pom.xml 2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/pom.xml 2009-12-09 10:30:42 UTC (rev 959)
@@ -53,7 +53,7 @@
<module>exo.kernel.component.common</module>
<module>exo.kernel.component.remote</module>
<module>exo.kernel.component.cache</module>
- <!--module>exo.kernel.component.ext.cache</module-->
+ <module>exo.kernel.component.ext.cache.impl.jboss.v3</module>
<module>exo.kernel.component.command</module>
<module>packaging/module</module>
</modules>
16 years, 7 months
exo-jcr SVN: r958 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-09 04:10:18 -0500 (Wed, 09 Dec 2009)
New Revision: 958
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
Log:
EXOJCR-291: Io mode message added
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-09 09:09:09 UTC (rev 957)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-09 09:10:18 UTC (rev 958)
@@ -2650,6 +2650,7 @@
*/
public void setIndexerIoMode(IndexerIoMode ioMode) throws IOException, RepositoryException
{
+ log.info("Indexer io mode=" + ioMode);
this.ioMode = ioMode;
}
16 years, 7 months
exo-jcr SVN: r957 - in jcr/branches/1.12.0-JBC/component/core/src: main/java/org/exoplatform/services/jcr/impl/core/query/lucene and 1 other directories.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-09 04:09:09 -0500 (Wed, 09 Dec 2009)
New Revision: 957
Added:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerIoMode.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/SlowQueryHandler.java
Log:
EXOJCR-291: Io mode added
Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerIoMode.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerIoMode.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerIoMode.java 2009-12-09 09:09:09 UTC (rev 957)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public enum IndexerIoMode {
+ /**
+ * Only query
+ */
+ READ_ONLY,
+ /**
+ * query on index and write changes
+ */
+ READ_WRITE
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerIoMode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2009-12-09 09:06:55 UTC (rev 956)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2009-12-09 09:09:09 UTC (rev 957)
@@ -110,22 +110,7 @@
*/
void logErrorChanges(Set<String> removed, Set<String> added) throws IOException;
- // /**
- // * Creates a new query by specifying the query object model. If the query
- // * object model is considered invalid for the implementing class, an
- // * InvalidQueryException is thrown.
- // *
- // * @param session the session of the current user creating the query
- // * object.
- // * @param itemMgr the item manager of the current user.
- // * @param qomTree query query object model tree.
- // * @return A <code>Query</code> object.
- // * @throws InvalidQueryException if the query object model tree is invalid.
- // */
- // ExecutableQuery createExecutableQuery(SessionImpl session,
- // ItemManager itemMgr,
- // QueryObjectModelTree qomTree)
- // throws InvalidQueryException;
+ void setIndexerIoMode(IndexerIoMode ioMode) throws IOException, RepositoryException;
/**
* @return the name of the query class to use.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-09 09:06:55 UTC (rev 956)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-09 09:09:09 UTC (rev 957)
@@ -52,6 +52,7 @@
import org.exoplatform.services.jcr.impl.core.query.DefaultQueryNodeFactory;
import org.exoplatform.services.jcr.impl.core.query.ErrorLog;
import org.exoplatform.services.jcr.impl.core.query.ExecutableQuery;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.QueryHandlerContext;
import org.exoplatform.services.jcr.impl.core.query.SearchIndexConfigurationHelper;
@@ -415,6 +416,11 @@
private final ConfigurationManager cfm;
/**
+ * Indexer io mode
+ */
+ private IndexerIoMode ioMode;
+
+ /**
* Working constructor.
*
* @throws RepositoryConfigurationException
@@ -2639,4 +2645,13 @@
return new LuceneQueryHits(reader, searcher, query);
}
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.query.QueryHandler#setIndexerIoMode(org.exoplatform.services.jcr.impl.core.query.IndexerIoMode)
+ */
+ public void setIndexerIoMode(IndexerIoMode ioMode) throws IOException, RepositoryException
+ {
+ this.ioMode = ioMode;
+
+ }
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/SlowQueryHandler.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/SlowQueryHandler.java 2009-12-09 09:06:55 UTC (rev 956)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/SlowQueryHandler.java 2009-12-09 09:09:09 UTC (rev 957)
@@ -22,6 +22,7 @@
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.query.AbstractQueryHandler;
import org.exoplatform.services.jcr.impl.core.query.ExecutableQuery;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.jcr.impl.core.query.QueryHandlerContext;
import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
@@ -38,6 +39,8 @@
public class SlowQueryHandler extends AbstractQueryHandler
{
+ private IndexerIoMode ioMode;
+
protected void doInit() throws IOException, RepositoryException
{
// sleep for 10 seconds then try to read from the item state manager
@@ -93,4 +96,13 @@
return null;
}
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.query.QueryHandler#setIndexerIoMode(org.exoplatform.services.jcr.impl.core.query.IndexerIoMode)
+ */
+ public void setIndexerIoMode(IndexerIoMode ioMode) throws IOException, RepositoryException
+ {
+ this.ioMode = ioMode;
+
+ }
+
}
16 years, 7 months
exo-jcr SVN: r956 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-12-09 04:06:55 -0500 (Wed, 09 Dec 2009)
New Revision: 956
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
Log:
EXOJCR-293 : Store the nodes id in attribute of node LOCKS. Theis is need for optimization the method getLocksData in JBossCacheStorageConnection.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-12-09 08:55:06 UTC (rev 955)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-12-09 09:06:55 UTC (rev 956)
@@ -59,6 +59,8 @@
public static final String USER_ID = "$userId".intern();
public static final String LOCK_DATA = "$lock".intern();
+
+ public static final String LOCK_NODE_ID = "$lockId".intern();
protected final Node<Serializable, Object> nodesRoot;
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-12-09 08:55:06 UTC (rev 955)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-12-09 09:06:55 UTC (rev 956)
@@ -1312,7 +1312,21 @@
*/
public List<LockData> getLocksData() throws RepositoryException
{
- Set<Node<Serializable, Object>> lockSet = locksRoot.getChildren()/*getNodes(locksRoot)*/;
+// Set<Node<Serializable, Object>> lockSet = getNodes(locksRoot);
+
+ // TODO Store the id of nodes in attributes of node $Locks. EXOJCR-293
+ Set<Node<Serializable, Object>> lockSet = new HashSet<Node<Serializable,Object>>();
+
+ for (Serializable nodeId : locksRoot.getKeys())
+ {
+ Node<Serializable, Object> node = locksRoot.getChild(makeNodeFqn((String) nodeId));
+
+ if (node != null)
+ {
+ lockSet.add(node);
+ }
+ }
+
List<LockData> locksData = new ArrayList<LockData>();
for (Node<Serializable, Object> node : lockSet)
{
@@ -1348,7 +1362,7 @@
for (Node<Serializable, Object> childNode : childNodes)
{
- if (childNode.getChildrenNames().size() == 0)
+ if (childNode.isLeaf())
{
resultSet.add(childNode);
} else
@@ -1371,6 +1385,10 @@
}
// addChild will add if absent or return old if present
Node<Serializable, Object> node = locksRoot.addChild(makeNodeFqn(lockData.getNodeIdentifier()));
+
+ //TODO Need for optimization getLocksData. EXOJCR-293
+ locksRoot.put(lockData.getNodeIdentifier(), JBossCacheStorage.LOCK_NODE_ID);
+
// this will prevent from deleting by eviction.
node.setResident(true);
@@ -1411,6 +1429,9 @@
throw new RepositoryException("Item ID to clear lock can't be null!");
}
locksRoot.removeChild(makeNodeFqn(identifier));
+
+ //TODO Need for optimization getLocksData. EXOJCR-293
+ locksRoot.remove(identifier);
}
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-12-09 08:55:06 UTC (rev 955)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-12-09 09:06:55 UTC (rev 956)
@@ -254,6 +254,10 @@
*/
private void doUpdate(Modification m, JDBCStorageConnection conn) throws IllegalStateException, RepositoryException
{
+ // TODO We not persist locks. EXOJCR-293
+ if (m.getFqn().get(0).equals(JBossCacheStorage.LOCKS))
+ return;
+
Fqn fqn = IdTreeHelper.buildFqn(m.getFqn());
if (fqn.size() == 2 && m.getValue() instanceof TransientItemData)
@@ -490,6 +494,9 @@
*/
public boolean exists(Fqn fqn) throws Exception
{
+ if (fqn.get(0).equals(JBossCacheStorage.LOCKS) && IdTreeHelper.isSubFqn(fqn))
+ return false;
+
Fqn name = (fqn.size() > 1 ? IdTreeHelper.buildFqn(fqn) : fqn);
boolean exists;
@@ -654,8 +661,8 @@
// return child nodes names
//to sub Fqn (example /$LOCKS/5/4/3)
- // if (IdTreeHelper.isSubFqn(fqn))
- // return null;
+ if (IdTreeHelper.isSubFqn(fqn))
+ return null;
Fqn name = (fqn.size() >= 2 ? IdTreeHelper.buildFqn(fqn) : fqn);
16 years, 7 months
exo-jcr SVN: r955 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-09 03:55:06 -0500 (Wed, 09 Dec 2009)
New Revision: 955
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
Log:
EXOJCR-291: Skip empty logs
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2009-12-09 08:48:35 UTC (rev 954)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2009-12-09 08:55:06 UTC (rev 955)
@@ -377,18 +377,22 @@
*/
public void onSaveItems(ItemStateChangesLog itemStates)
{
- //Check if SearchManager started
- if (changesFilter == null)
+ //skip empty
+ if (itemStates.getSize() > 0)
{
- changesLogBuffer.add(itemStates);
+ //Check if SearchManager started and filter configured
+ if (changesFilter == null)
+ {
+ changesLogBuffer.add(itemStates);
+ }
+ else
+ {
+ changesFilter.onSaveItems(itemStates);
+ }
}
- else
- {
- changesFilter.onSaveItems(itemStates);
- }
-
}
+ @Deprecated
public void onSaveItems(List<WriteCommand> modifications) throws RepositoryException
{
try
16 years, 7 months