exo-jcr SVN: r4617 - ws/trunk/exo.ws.frameworks.servlet/src/main/java/org/exoplatform/ws/frameworks/servlet.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-12 10:45:41 -0400 (Tue, 12 Jul 2011)
New Revision: 4617
Modified:
ws/trunk/exo.ws.frameworks.servlet/src/main/java/org/exoplatform/ws/frameworks/servlet/StandaloneContainerInitializedListener.java
Log:
EXOJCR-1416: Get rid of any call to InitialContextInitializer.recall()
Modified: ws/trunk/exo.ws.frameworks.servlet/src/main/java/org/exoplatform/ws/frameworks/servlet/StandaloneContainerInitializedListener.java
===================================================================
--- ws/trunk/exo.ws.frameworks.servlet/src/main/java/org/exoplatform/ws/frameworks/servlet/StandaloneContainerInitializedListener.java 2011-07-12 14:45:11 UTC (rev 4616)
+++ ws/trunk/exo.ws.frameworks.servlet/src/main/java/org/exoplatform/ws/frameworks/servlet/StandaloneContainerInitializedListener.java 2011-07-12 14:45:41 UTC (rev 4617)
@@ -19,10 +19,8 @@
package org.exoplatform.ws.frameworks.servlet;
import org.exoplatform.container.StandaloneContainer;
-import org.exoplatform.container.configuration.ConfigurationManagerImpl;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.exoplatform.services.naming.InitialContextInitializer;
import java.net.MalformedURLException;
@@ -104,16 +102,6 @@
try
{
container = StandaloneContainer.getInstance(Thread.currentThread().getContextClassLoader());
-
- // Patch for tomcat InitialContext
- InitialContextInitializer ic =
- (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
-
- if (ic != null)
- {
- ic.recall();
- }
-
event.getServletContext().setAttribute("org.exoplatform.frameworks.web.eXoContainer", container);
}
catch (Exception e)
12 years, 10 months
exo-jcr SVN: r4616 - in kernel/trunk/exo.kernel.component.common/src: test/java/org/exoplatform/services/naming and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-12 10:45:11 -0400 (Tue, 12 Jul 2011)
New Revision: 4616
Added:
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/ExoContainerContextFactory.java
Modified:
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/SimpleContext.java
kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/naming/InitialContextTest.java
kernel/trunk/exo.kernel.component.common/src/test/resources/conf/portal/test-configuration.xml
Log:
EXOJCR-1416: Get rid of any call to InitialContextInitializer.recall()
Added: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/ExoContainerContextFactory.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/ExoContainerContextFactory.java (rev 0)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/ExoContainerContextFactory.java 2011-07-12 14:45:11 UTC (rev 4616)
@@ -0,0 +1,529 @@
+/*
+ * Copyright (C) 2011 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.naming;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+/**
+ * This implementation of {@link InitialContextFactory} is used to be able to share
+ * all the objects that have been binded thanks to the {@link InitialContextInitializer}
+ * which is required for example to be able to create and bind data sources dynamically
+ *
+ * @author <a href="mailto:nfilotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class ExoContainerContextFactory implements InitialContextFactory
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException
+ {
+ return new ExoContainerCtx(environment);
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private static class ExoContainerCtx extends SimpleContext
+ {
+
+ /**
+ * The map containing all the bindings for all the containers defined
+ */
+ private static volatile Map<ExoContainer, AtomicReference<Map<String, Object>>> ALL_BINDINGS =
+ new HashMap<ExoContainer, AtomicReference<Map<String, Object>>>();
+
+ /**
+ * The environment to use in case we cannot find the object
+ */
+ private final Hashtable env;
+
+ /**
+ * The current eXo container
+ */
+ private final ExoContainer container;
+
+ /**
+ * The nested context
+ */
+ private InitialContext ctx;
+
+ /**
+ * The reference to the bindings corresponding to this context;
+ */
+ private AtomicReference<Map<String, Object>> bindingsRef;
+
+ public ExoContainerCtx(Hashtable<?, ?> env)
+ {
+ this.env = env == null ? null : (Hashtable)env.clone();
+ this.container = ExoContainerContext.getCurrentContainerIfPresent();
+ if (container != null)
+ {
+ AtomicReference<Map<String, Object>> ref = ALL_BINDINGS.get(container);
+ if (ref == null)
+ {
+ synchronized (ExoContainerCtx.class)
+ {
+ if (ref == null)
+ {
+ Map<ExoContainer, AtomicReference<Map<String, Object>>> tempAllBindings =
+ new HashMap<ExoContainer, AtomicReference<Map<String, Object>>>(ALL_BINDINGS);
+ tempAllBindings.put(container, ref =
+ new AtomicReference<Map<String, Object>>(new HashMap<String, Object>()));
+ ALL_BINDINGS = tempAllBindings;
+ }
+ }
+ }
+ this.bindingsRef = ref;
+ }
+ }
+
+ protected Map<String, Object> getBindings()
+ {
+ return bindingsRef.get();
+ }
+
+ protected void setBindings(Map<String, Object> bindings)
+ {
+ bindingsRef.set(bindings);
+ }
+
+ private InitialContext getContext() throws NamingException
+ {
+ if (ctx == null)
+ {
+ Hashtable env;
+ if (this.env == null)
+ {
+ env = new Hashtable();
+ }
+ else
+ {
+ env = new Hashtable(this.env);
+ }
+ env.put(Context.INITIAL_CONTEXT_FACTORY, InitialContextInitializer.DEFAULT_INITIAL_CONTEXT_FACTORY);
+ env.remove(InitialContextInitializer.class.getName());
+ ctx = new InitialContext(env);
+ }
+ return ctx;
+ }
+
+ private boolean isInitialContextInitializerCall()
+ {
+ return container != null && env != null && env.containsKey(InitialContextInitializer.class.getName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object lookup(String name) throws NamingException
+ {
+ if (getBindings().containsKey(name) || isInitialContextInitializerCall())
+ {
+ return super.lookup(name);
+ }
+ return getContext().lookup(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object lookup(Name name) throws NamingException
+ {
+ if (getBindings().containsKey(name) || isInitialContextInitializerCall())
+ {
+ return super.lookup(nameToString(name));
+ }
+ return getContext().lookup(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void bind(String name, Object value) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.bind(name, value);
+ return;
+ }
+ getContext().bind(name, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void bind(Name name, Object value) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.bind(nameToString(name), value);
+ return;
+ }
+ getContext().bind(name, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void rebind(String name, Object value) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.rebind(name, value);
+ return;
+ }
+ getContext().rebind(name, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void rebind(Name name, Object value) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.rebind(nameToString(name), value);
+ return;
+ }
+ getContext().rebind(name, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void unbind(String name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.unbind(name);
+ return;
+ }
+ getContext().unbind(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void unbind(Name name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.unbind(nameToString(name));
+ return;
+ }
+ getContext().unbind(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void rename(String name1, String name2) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.rename(name1, name2);
+ return;
+ }
+ getContext().rename(name1, name2);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void rename(Name name1, Name name2) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.rename(nameToString(name1), nameToString(name2));
+ return;
+ }
+ getContext().rename(name1, name2);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.list(name);
+ }
+ return getContext().list(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.list(name);
+ }
+ return getContext().list(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.listBindings(name);
+ }
+ return getContext().listBindings(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.listBindings(name);
+ }
+ return getContext().listBindings(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void destroySubcontext(Name name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.destroySubcontext(name);
+ return;
+ }
+ getContext().destroySubcontext(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void destroySubcontext(String name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ super.destroySubcontext(name);
+ return;
+ }
+ getContext().destroySubcontext(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Context createSubcontext(Name name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.createSubcontext(name);
+ }
+ return getContext().createSubcontext(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Context createSubcontext(String name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.createSubcontext(name);
+ }
+ return getContext().createSubcontext(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object lookupLink(Name name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.lookupLink(name);
+ }
+ return getContext().lookupLink(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object lookupLink(String name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.lookupLink(name);
+ }
+ return getContext().lookupLink(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NameParser getNameParser(Name name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.getNameParser(name);
+ }
+ return getContext().getNameParser(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NameParser getNameParser(String name) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.getNameParser(name);
+ }
+ return getContext().getNameParser(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name composeName(Name name, Name prefix) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.composeName(name, prefix);
+ }
+ return getContext().composeName(name, prefix);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String composeName(String name, String prefix) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.composeName(name, prefix);
+ }
+ return getContext().composeName(name, prefix);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.addToEnvironment(propName, propVal);
+ }
+ return getContext().addToEnvironment(propName, propVal);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object removeFromEnvironment(String propName) throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.removeFromEnvironment(propName);
+ }
+ return getContext().removeFromEnvironment(propName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Hashtable<?, ?> getEnvironment() throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ if (env == null)
+ {
+ // Must return non-null
+ return new Hashtable(3, 0.75f);
+ }
+ else
+ {
+ return (Hashtable)env.clone();
+ }
+ }
+ return getContext().getEnvironment();
+ }
+
+ protected Hashtable<?, ?> getInternalEnv()
+ {
+ return env;
+ }
+
+ protected Object getMutex()
+ {
+ return bindingsRef;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws NamingException
+ {
+ bindingsRef = null;
+ if (env != null)
+ {
+ env.clear();
+ }
+ if (ctx != null)
+ {
+ ctx.close();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNameInNamespace() throws NamingException
+ {
+ if (isInitialContextInitializerCall())
+ {
+ return super.getNameInNamespace();
+ }
+ return getContext().getNameInNamespace();
+ }
+ }
+}
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2011-07-08 11:31:30 UTC (rev 4615)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2011-07-12 14:45:11 UTC (rev 4616)
@@ -354,7 +354,7 @@
/**
* Class implements Map.Entry interface and used to push/pop entity in stack.
*/
- class RefEntity implements Map.Entry
+ class RefEntity implements Map.Entry<String, Reference>
{
/**
@@ -384,7 +384,6 @@
/**
* {@inheritDoc}
*/
- @Override
public String getKey()
{
return key;
@@ -393,7 +392,6 @@
/**
* {@inheritDoc}
*/
- @Override
public Reference getValue()
{
return value;
@@ -402,11 +400,10 @@
/**
* {@inheritDoc}
*/
- @Override
- public Reference setValue(Object value)
+ public Reference setValue(Reference value)
{
Reference oldValue = this.value;
- this.value = (Reference)value;
+ this.value = value;
return oldValue;
}
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java 2011-07-08 11:31:30 UTC (rev 4615)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java 2011-07-12 14:45:11 UTC (rev 4616)
@@ -32,6 +32,7 @@
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
@@ -52,23 +53,26 @@
public class InitialContextInitializer
{
- final public static String PROPERTIES_DEFAULT = "default-properties";
+ static String DEFAULT_INITIAL_CONTEXT_FACTORY = PrivilegedSystemHelper.getProperty(Context.INITIAL_CONTEXT_FACTORY);
+
+ public static final String PROPERTIES_DEFAULT = "default-properties";
- final public static String PROPERTIES_MANDATORY = "mandatory-properties";
+ public static final String PROPERTIES_MANDATORY = "mandatory-properties";
- final public static String BINDINGS_STORE_PATH = "bindings-store-path";
+ /**
+ * This parameter is used to overload the default initial context factory in order to ensure that binded objects are shared
+ */
+ public static final String OVERLOAD_CONTEXT_FACTORY = "overload-context-factory";
- final public static String DEFAULT_BINDING_STORE_PATH = PrivilegedSystemHelper.getProperty("java.io.tmpdir")
+ public static final String BINDINGS_STORE_PATH = "bindings-store-path";
+
+ public static final String DEFAULT_BINDING_STORE_PATH = PrivilegedSystemHelper.getProperty("java.io.tmpdir")
+ File.separator + "bind-references.xml";
private static Log LOG = ExoLogger.getLogger("exo.kernel.component.common.InitialContextInitializer");
private List<BindReferencePlugin> bindReferencesPlugins;
- private String defaultContextFactory;
-
- private final InitialContext initialContext;
-
private final InitialContextBinder binder;
/**
@@ -110,7 +114,6 @@
}
}
}
- initialContext = new InitialContext();
bindReferencesPlugins = new ArrayList<BindReferencePlugin>();
ValueParam bindingStorePathParam = params.getValueParam(BINDINGS_STORE_PATH);
@@ -124,7 +127,19 @@
{
binder = new InitialContextBinder(this, bindingStorePathParam.getValue());
}
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("The default initial context factory is " + DEFAULT_INITIAL_CONTEXT_FACTORY);
+ }
+ ValueParam overloadContextFactoryParam = params.getValueParam(OVERLOAD_CONTEXT_FACTORY);
+ if (overloadContextFactoryParam != null && overloadContextFactoryParam.getValue() != null
+ && Boolean.valueOf(overloadContextFactoryParam.getValue()))
+ {
+ PrivilegedSystemHelper
+ .setProperty(Context.INITIAL_CONTEXT_FACTORY, ExoContainerContextFactory.class.getName());
+ }
}
private void setSystemProperty(String propName, String propValue, String propParamName)
@@ -132,7 +147,7 @@
PrivilegedSystemHelper.setProperty(propName, propValue);
if (propName.equals(Context.INITIAL_CONTEXT_FACTORY))
{
- defaultContextFactory = propValue;
+ DEFAULT_INITIAL_CONTEXT_FACTORY = PrivilegedSystemHelper.getProperty(Context.INITIAL_CONTEXT_FACTORY);
}
LOG.info("Using mandatory system property: " + propName + " = " + PrivilegedSystemHelper.getProperty(propName));
}
@@ -141,11 +156,8 @@
private InitialContextInitializer(String name, Reference reference) throws NamingException, FileNotFoundException,
XMLStreamException
{
- if (PrivilegedSystemHelper.getProperty(Context.INITIAL_CONTEXT_FACTORY) == null)
- {
- PrivilegedSystemHelper.setProperty(Context.INITIAL_CONTEXT_FACTORY, defaultContextFactory);
- }
- initialContext = new InitialContext();
+ PrivilegedSystemHelper.setProperty(Context.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT_FACTORY);
+ InitialContext initialContext = getInitialContext();
initialContext.rebind(name, reference);
// binder
@@ -157,13 +169,14 @@
* of app using different copy of Context, for example per web app
* InitialContext in Tomcat
*/
+ @deprecated
public void recall()
{
for (BindReferencePlugin plugin : bindReferencesPlugins)
{
try
{
- InitialContext ic = new InitialContext();
+ InitialContext ic = getInitialContext();
ic.bind(plugin.getBindName(), plugin.getReference());
LOG.info("Reference bound (by recall()): " + plugin.getBindName());
}
@@ -185,8 +198,8 @@
BindReferencePlugin brplugin = (BindReferencePlugin)plugin;
try
{
- // initialContext = new InitialContext();
- initialContext.rebind(brplugin.getBindName(), brplugin.getReference());
+ InitialContext ic = getInitialContext();
+ ic.rebind(brplugin.getBindName(), brplugin.getReference());
LOG.info("Reference bound: " + brplugin.getBindName());
bindReferencesPlugins.add((BindReferencePlugin)plugin);
}
@@ -212,15 +225,24 @@
*/
public String getDefaultContextFactory()
{
- return defaultContextFactory;
+ return DEFAULT_INITIAL_CONTEXT_FACTORY;
}
/**
* @return stored InitialContext
*/
- public synchronized InitialContext getInitialContext()
+ public InitialContext getInitialContext()
{
- return initialContext;
+ try
+ {
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put(InitialContextInitializer.class.getName(), "true");
+ return new InitialContext(env);
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException("Cannot create the intial context", e);
+ }
}
// for out-of-container testing
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/SimpleContext.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/SimpleContext.java 2011-07-08 11:31:30 UTC (rev 4615)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/SimpleContext.java 2011-07-12 14:45:11 UTC (rev 4616)
@@ -18,22 +18,29 @@
*/
package org.exoplatform.services.naming;
-import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.security.PrivilegedExceptionAction;
+import java.util.HashMap;
import java.util.Hashtable;
+import java.util.Map;
import javax.naming.Binding;
+import javax.naming.CompositeName;
import javax.naming.Context;
+import javax.naming.InvalidNameException;
+import javax.naming.LinkRef;
import javax.naming.Name;
+import javax.naming.NameAlreadyBoundException;
import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
import javax.naming.Reference;
-import javax.naming.spi.ObjectFactory;
+import javax.naming.Referenceable;
+import javax.naming.spi.NamingManager;
/**
* Created by The eXo Platform SAS.
@@ -45,186 +52,383 @@
public class SimpleContext implements Context
{
-
+
/**
* The logger
*/
private static final Log LOG = ExoLogger.getLogger("org.exoplatform.services.naming.SimpleContext");
- private static Hashtable objects = new Hashtable();
+ private static final NameParser NAME_PARSER = new SimpleNameParser();
+
+ private static volatile Map<String, Object> BINDINGS = new HashMap<String, Object>();
public SimpleContext()
{
}
+ protected Map<String, Object> getBindings()
+ {
+ return BINDINGS;
+ }
+
+ protected void setBindings(Map<String, Object> bindings)
+ {
+ BINDINGS = bindings;
+ }
+
+ /**
+ * Converts a Name to a flat String.
+ */
+ protected String nameToString(Name name) throws NamingException
+ {
+ return name.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Object lookup(Name name) throws NamingException
{
- throw new NamingException("Not supported");
+ return lookup(nameToString(name));
}
+ /**
+ * {@inheritDoc}
+ */
public Object lookup(String name) throws NamingException
{
- Object obj = objects.get(name);
+ if (name.isEmpty())
+ {
+ throw new InvalidNameException("Cannot bind empty name");
+ }
+ Object obj = getBindings().get(name);
if (obj instanceof Reference)
{
- final Reference ref = (Reference)obj;
- String factoryCN = ref.getFactoryClassName();
- try
+ synchronized (obj)
{
- final ObjectFactory factory = (ObjectFactory)Class.forName(factoryCN).newInstance();
- obj = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Object>()
+ obj = getBindings().get(name);
+ if (obj instanceof Reference)
{
- public Object run() throws Exception
+ try
{
- return factory.getObjectInstance(ref, null, null, null);
+ obj = NamingManager.getObjectInstance(obj, NAME_PARSER.parse(name), this, getInternalEnv());
+ // Re-bind with the object with its new value to be able to return the same ins
+ bind(name, obj, false);
}
- });
+ catch (Exception e)
+ {
+ LOG.error(e.getLocalizedMessage(), e);
+ NamingException ne = new NamingException("getObjectInstance failed");
+ ne.setRootCause(e);
+ throw ne;
+ }
+ }
}
- catch (Exception e)
- {
- LOG.error(e.getLocalizedMessage(), e);
- throw new NamingException("Exception: " + e);
- }
}
+ else if (obj == null)
+ {
+ throw new NameNotFoundException("No object has been binded with the name '" + name + "'");
+ }
return obj;
}
+ /**
+ * {@inheritDoc}
+ */
public void bind(Name name, Object value) throws NamingException
{
- throw new NamingException("Not supported");
+ bind(nameToString(name), value);
}
+ /**
+ * {@inheritDoc}
+ */
public void bind(String name, Object value) throws NamingException
{
- // System.out.println("Bind: "+name+" "+value+" "+objects);
- objects.put(name, value);
+ bind(name, value, true);
}
+ private void bind(String name, Object value, boolean checkIfExists) throws NamingException
+ {
+ if (name.isEmpty())
+ {
+ throw new InvalidNameException("Cannot bind empty name");
+ }
+ // Call getStateToBind for using any state factories
+ value = NamingManager.getStateToBind(value, NAME_PARSER.parse(name), this, getInternalEnv());
+
+ if (value instanceof Context)
+ {
+ throw new OperationNotSupportedException("Context not supported");
+ }
+ else if (value instanceof LinkRef)
+ {
+ throw new OperationNotSupportedException("LinkRef not supported");
+ }
+ else if (value instanceof Referenceable)
+ {
+ value = ((Referenceable)value).getReference();
+ }
+ synchronized (getMutex())
+ {
+ Map<String, Object> tmpObjects = new HashMap<String, Object>(getBindings());
+ if (checkIfExists && tmpObjects.containsKey(name))
+ {
+ throw new NameAlreadyBoundException("An object has already been binded with the name '" + name + "'");
+ }
+ tmpObjects.put(name, value);
+ setBindings(tmpObjects);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void rebind(Name name, Object value) throws NamingException
{
- throw new NamingException("Not supported");
+ rebind(nameToString(name), value);
}
+ /**
+ * {@inheritDoc}
+ */
public void rebind(String name, Object value) throws NamingException
{
- objects.put(name, value);
+ bind(name, value, false);
}
+ /**
+ * {@inheritDoc}
+ */
public void unbind(Name name) throws NamingException
{
- throw new NamingException("Not supported");
+ unbind(nameToString(name));
}
+ /**
+ * {@inheritDoc}
+ */
public void unbind(String name) throws NamingException
{
- objects.remove(name);
+ if (name.isEmpty())
+ {
+ throw new InvalidNameException("Cannot bind empty name");
+ }
+ synchronized (getMutex())
+ {
+ Map<String, Object> tmpObjects = new HashMap<String, Object>(getBindings());
+ if (tmpObjects.remove(name) == null)
+ {
+ throw new NameNotFoundException("No object has been binded with the name '" + name + "'");
+ }
+ setBindings(tmpObjects);
+ }
}
+ /**
+ * {@inheritDoc}
+ */
public void rename(Name name1, Name name2) throws NamingException
{
- throw new NamingException("Not supported");
+ rename(nameToString(name1), nameToString(name2));
}
+ /**
+ * {@inheritDoc}
+ */
public void rename(String name1, String name2) throws NamingException
{
- Object val = objects.get(name1);
- objects.remove(name1);
- objects.put(name2, val);
+ if (name1.isEmpty() || name2.isEmpty())
+ {
+ throw new InvalidNameException("Cannot bind empty name");
+ }
+ Object value;
+ synchronized (getMutex())
+ {
+ Map<String, Object> tmpObjects = new HashMap<String, Object>(getBindings());
+ if (tmpObjects.containsKey(name2))
+ {
+ throw new NameAlreadyBoundException("An object has already been binded with the name '" + name2 + "'");
+ }
+ else if ((value = tmpObjects.remove(name1)) == null)
+ {
+ throw new NameNotFoundException("No object has been binded with the name '" + name1 + "'");
+ }
+ tmpObjects.put(name2, value);
+ setBindings(tmpObjects);
+ }
}
- public NamingEnumeration<NameClassPair> list(Name arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public NamingEnumeration<NameClassPair> list(String arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public NamingEnumeration<Binding> listBindings(Name arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public NamingEnumeration<Binding> listBindings(String arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public void destroySubcontext(Name arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public void destroySubcontext(Name name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public void destroySubcontext(String arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public void destroySubcontext(String name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public Context createSubcontext(Name arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public Context createSubcontext(Name name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public Context createSubcontext(String arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public Context createSubcontext(String name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public Object lookupLink(Name arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public Object lookupLink(Name name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public Object lookupLink(String arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public Object lookupLink(String name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public NameParser getNameParser(Name arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public NameParser getNameParser(Name name) throws NamingException
{
- throw new NamingException("Not supported");
+ return getNameParser(nameToString(name));
}
- public NameParser getNameParser(String arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public NameParser getNameParser(String name) throws NamingException
{
- throw new NamingException("Not supported");
+ return NAME_PARSER;
}
- public Name composeName(Name arg0, Name arg1) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public Name composeName(Name nam1, Name name2) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public String composeName(String arg0, String arg1) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public String composeName(String name1, String name2) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public Object addToEnvironment(String arg0, Object arg1) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public Object addToEnvironment(String name1, Object name2) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
- public Object removeFromEnvironment(String arg0) throws NamingException
+ /**
+ * {@inheritDoc}
+ */
+ public Object removeFromEnvironment(String name) throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("rawtypes")
public Hashtable<?, ?> getEnvironment() throws NamingException
{
- throw new NamingException("Not supported");
+ return new Hashtable(3, 0.75f);
}
+ protected Hashtable<?, ?> getInternalEnv()
+ {
+ return null;
+ }
+
+ protected Object getMutex()
+ {
+ return SimpleContext.class;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void close() throws NamingException
{
- objects.clear();
}
+ /**
+ * {@inheritDoc}
+ */
public String getNameInNamespace() throws NamingException
{
- throw new NamingException("Not supported");
+ throw new OperationNotSupportedException("Not supported");
}
-}
+ private static class SimpleNameParser implements NameParser
+ {
+ /**
+ * {@inheritDoc}
+ */
+ public Name parse(String name) throws NamingException
+ {
+ return new CompositeName(name);
+ }
+ }
+}
\ No newline at end of file
Modified: kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/naming/InitialContextTest.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/naming/InitialContextTest.java 2011-07-08 11:31:30 UTC (rev 4615)
+++ kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/naming/InitialContextTest.java 2011-07-12 14:45:11 UTC (rev 4616)
@@ -33,6 +33,8 @@
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Name;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.xml.stream.XMLStreamException;
@@ -90,6 +92,101 @@
assertNotNull(ctx);
ctx.bind("test", "test");
assertEquals("test", ctx.lookup("test"));
+ try
+ {
+ ctx.bind("test", "test2");
+ fail("A NameAlreadyBoundException is expected here");
+ }
+ catch (NameAlreadyBoundException e)
+ {
+ // expected exception
+ }
+ assertEquals("test", ctx.lookup("test"));
+ ctx.rebind("test", "test2");
+ assertEquals("test2", ctx.lookup("test"));
+
+ InitialContextInitializer initializer =
+ (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
+
+ assertNotNull(initializer);
+ initializer.getInitialContext().bind("test", "test3");
+ assertEquals("test3", ctx.lookup("test"));
+ ctx.rebind("test", "test4");
+ assertEquals("test3", ctx.lookup("test"));
+ initializer.getInitialContext().rebind("test", "test5");
+ assertEquals("test5", ctx.lookup("test"));
+ initializer.getInitialContext().unbind("test");
+ try
+ {
+ initializer.getInitialContext().lookup("test");
+ fail("A NameNotFoundException is expected here");
+ }
+ catch (NameNotFoundException e)
+ {
+ // expected exception
+ }
+ assertEquals("test4", ctx.lookup("test"));
+ ctx.unbind("test");
+ try
+ {
+ ctx.lookup("test");
+ fail("A NameNotFoundException is expected here");
+ }
+ catch (NameNotFoundException e)
+ {
+ // expected exception
+ }
+ try
+ {
+ initializer.getInitialContext().unbind("test2");
+ fail("A NameNotFoundException is expected here");
+ }
+ catch (NameNotFoundException e)
+ {
+ // expected exception
+ }
+ initializer.getInitialContext().bind("foo", "foo");
+ assertEquals("foo", ctx.lookup("foo"));
+ initializer.getInitialContext().bind("foo2", "foo2");
+ assertEquals("foo2", ctx.lookup("foo2"));
+ try
+ {
+ initializer.getInitialContext().rename("foo", "foo2");
+ fail("A NameAlreadyBoundException is expected here");
+ }
+ catch (NameAlreadyBoundException e)
+ {
+ // expected exception
+ }
+ assertEquals("foo", ctx.lookup("foo"));
+ assertEquals("foo2", ctx.lookup("foo2"));
+ try
+ {
+ initializer.getInitialContext().rename("foo3", "foo4");
+ fail("A NameNotFoundException is expected here");
+ }
+ catch (NameNotFoundException e)
+ {
+ // expected exception
+ }
+ initializer.getInitialContext().rename("foo", "foo3");
+ assertEquals("foo", ctx.lookup("foo3"));
+ assertEquals("foo2", ctx.lookup("foo2"));
+ try
+ {
+ initializer.getInitialContext().lookup("foo");
+ fail("A NameNotFoundException is expected here");
+ }
+ catch (NameNotFoundException e)
+ {
+ // expected exception
+ }
+
+ // check same instance
+ initializer.getInitialContext().bind("bla", "bla");
+ Object obj1 = initializer.getInitialContext().lookup("bla");
+ Object obj2 = initializer.getInitialContext().lookup("bla");
+ assertTrue(obj1 == obj2);
}
public void testCompositeNameUsing() throws Exception
@@ -102,6 +199,30 @@
{
System.out.println("---- " + en.nextElement());
}
+ InitialContext ctx = new InitialContext();
+ ctx.bind(name, "foo");
+ assertEquals("foo", ctx.lookup(name));
+ try
+ {
+ ctx.bind(name, "foo2");
+ fail("A NameAlreadyBoundException is expected here");
+ }
+ catch (NameAlreadyBoundException e)
+ {
+ // expected exception
+ }
+ assertEquals("foo", ctx.lookup(name));
+ assertEquals("foo", ctx.lookup("java:comp/env/jdbc/jcr"));
+ ctx.unbind(name);
+ try
+ {
+ ctx.lookup(name);
+ fail("A NameNotFoundException is expected here");
+ }
+ catch (NameNotFoundException e)
+ {
+ // expected exception
+ }
}
/*
Modified: kernel/trunk/exo.kernel.component.common/src/test/resources/conf/portal/test-configuration.xml
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/resources/conf/portal/test-configuration.xml 2011-07-08 11:31:30 UTC (rev 4615)
+++ kernel/trunk/exo.kernel.component.common/src/test/resources/conf/portal/test-configuration.xml 2011-07-12 14:45:11 UTC (rev 4616)
@@ -134,7 +134,13 @@
<value-param>
<name>bindings-store-path</name>
<value>target/store-path.xml</value>
- </value-param>
+ </value-param>
+ <!-- This parameter is required in case your AS don't share the objects
+ by default and you need to be able to remove repositories dynamically -->
+ <value-param>
+ <name>overload-context-factory</name>
+ <value>true</value>
+ </value-param>
<properties-param>
<name>default-properties</name>
<description>Default initial context properties</description>
12 years, 10 months
exo-jcr SVN: r4615 - jcr/trunk/applications/product-patches/as/jboss/ds.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-08 07:31:30 -0400 (Fri, 08 Jul 2011)
New Revision: 4615
Modified:
jcr/trunk/applications/product-patches/as/jboss/ds/jcr-ds.xml
Log:
EXOJCR-1435: fix rar name
Modified: jcr/trunk/applications/product-patches/as/jboss/ds/jcr-ds.xml
===================================================================
--- jcr/trunk/applications/product-patches/as/jboss/ds/jcr-ds.xml 2011-07-08 08:01:53 UTC (rev 4614)
+++ jcr/trunk/applications/product-patches/as/jboss/ds/jcr-ds.xml 2011-07-08 11:31:30 UTC (rev 4615)
@@ -8,7 +8,7 @@
<xa-transaction/>
- <rar-name>exo.jcr.ear.ear#exo-jcr.rar</rar-name>
+ <rar-name>exo-jcr-ear.ear#exo-jcr.rar</rar-name>
<adapter-display-name>eXo JCR Adapter</adapter-display-name>
<connection-definition>org.exoplatform.connectors.jcr.adapter.SessionFactory</connection-definition>
12 years, 11 months
exo-jcr SVN: r4614 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: util/io and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2011-07-08 04:01:53 -0400 (Fri, 08 Jul 2011)
New Revision: 4614
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java
Log:
EXOJCR-1132 : The problem with backup configuration in RepositoryServiceConfigurationImpl.retain() on OS Windows was fixed.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java 2011-07-08 04:01:54 UTC (rev 4613)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java 2011-07-08 08:01:53 UTC (rev 4614)
@@ -26,6 +26,7 @@
import org.exoplatform.services.jcr.config.ConfigurationPersister;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryServiceConfiguration;
+import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
import org.exoplatform.services.naming.InitialContextInitializer;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
@@ -175,9 +176,16 @@
File sourceConfig = new File(filePath.toURI());
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
File backUp = new File(sourceConfig.getAbsoluteFile() + "_" + format.format(new Date()));
- if (!PrivilegedFileHelper.renameTo(sourceConfig, backUp))
+ try
+ {
+ DirectoryHelper.renameFile(sourceConfig, backUp);
+ }
+ catch (IOException ioe)
+ {
throw new RepositoryException("Can't back up configuration on path "
- + PrivilegedFileHelper.getAbsolutePath(sourceConfig));
+ + PrivilegedFileHelper.getAbsolutePath(sourceConfig), ioe);
+ }
+
saveStream = PrivilegedFileHelper.fileOutputStream(sourceConfig);
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java 2011-07-08 04:01:54 UTC (rev 4613)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java 2011-07-08 08:01:53 UTC (rev 4614)
@@ -288,4 +288,73 @@
}
}
}
+
+ /**
+ * Rename file.
+ *
+ * @param srcFile
+ * source file
+ * @param dstFile
+ * destination file
+ * @throws IOException
+ * if any exception occurred
+ */
+ public static synchronized void renameFile(File srcFile, File dstFile) throws IOException
+ {
+ /* This is not atomic. If the program crashes between the call to
+ delete() and the call to renameTo() then we're screwed, but I've
+ been unable to figure out how else to do this... */
+
+ if (PrivilegedFileHelper.exists(dstFile))
+ if (!PrivilegedFileHelper.delete(dstFile))
+ throw new IOException("Cannot delete " + dstFile);
+
+ // Rename the srcFile file to the new one. Unfortunately, the renameTo()
+ // method does not work reliably under some JVMs. Therefore, if the
+ // rename fails, we manually rename by copying the srcFile file to the new one
+ if (!PrivilegedFileHelper.renameTo(srcFile, dstFile))
+ {
+ java.io.InputStream in = null;
+ java.io.OutputStream out = null;
+ byte buffer[] = null;
+ try
+ {
+ in = PrivilegedFileHelper.fileInputStream(srcFile);
+ out = PrivilegedFileHelper.fileOutputStream(dstFile);
+ // see if the buffer needs to be initialized. Initialization is
+ // only done on-demand since many VM's will never run into the renameTo
+ // bug and hence shouldn't waste 1K of mem for no reason.
+ if (buffer == null)
+ {
+ buffer = new byte[1024];
+ }
+ int len;
+ while ((len = in.read(buffer)) >= 0)
+ {
+ out.write(buffer, 0, len);
+ }
+
+ // delete the srcFile file.
+ PrivilegedFileHelper.delete(srcFile);
+ }
+ catch (IOException ioe)
+ {
+ IOException newExc = new IOException("Cannot rename " + srcFile + " to " + dstFile);
+ newExc.initCause(ioe);
+ throw newExc;
+ }
+ finally
+ {
+ if (in != null)
+ {
+ in.close();
+ }
+
+ if (out != null)
+ {
+ out.close();
+ }
+ }
+ }
+ }
}
12 years, 11 months
exo-jcr SVN: r4613 - in jcr/branches/1.12.x: patch/1.12.10-GA/JCR-1639 and 1 other directory.
by do-not-reply@jboss.org
Author: paristote
Date: 2011-07-08 00:01:54 -0400 (Fri, 08 Jul 2011)
New Revision: 4613
Added:
jcr/branches/1.12.x/patch/1.12.10-GA/JCR-1639/readme.txt
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
Log:
JCR-1639
What is the problem to fix?
* Delay in replication of Nodes data in JBoss EPP
How is the problem fixed?
* Need to rollback JDBC connection before closing.
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2011-07-07 12:49:29 UTC (rev 4612)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2011-07-08 04:01:54 UTC (rev 4613)
@@ -373,12 +373,17 @@
{
closeStatements();
- // If READ-ONLY status back it to READ-WRITE (we assume it was original state)
+ // If READ-ONLY status back it to READ-WRITE (we assume it was original state)
if (readOnly)
{
dbConnection.setReadOnly(true);
}
+ if (dbConnection.getTransactionIsolation() > Connection.TRANSACTION_READ_COMMITTED)
+ {
+ dbConnection.rollback();
+ }
+
dbConnection.close();
}
catch (SQLException e)
Added: jcr/branches/1.12.x/patch/1.12.10-GA/JCR-1639/readme.txt
===================================================================
--- jcr/branches/1.12.x/patch/1.12.10-GA/JCR-1639/readme.txt (rev 0)
+++ jcr/branches/1.12.x/patch/1.12.10-GA/JCR-1639/readme.txt 2011-07-08 04:01:54 UTC (rev 4613)
@@ -0,0 +1,72 @@
+Summary
+
+ Status: Delay in replication of Nodes data in JBoss EPP
+ CCP Issue: CCP-984, Product Jira Issue: JCR-1639.
+ Complexity: High
+
+The Proposal
+Problem description
+
+What is the problem to fix?
+
+ Delay in replication of Nodes data in JBoss EPP
+
+Fix description
+
+How is the problem fixed?
+
+ * Need to rollback JDBC connection before closing.
+
+Patch information:
+JCR-1639.patch
+
+Tests to perform
+
+Reproduction test
+
+ A folder was created with the name 00480017, and a document inside it named 00480017-test1
+ After few seconds, the folder just disappeared. We tried to access it using its full path /00480017 but, it wasn't there anymore. Message that the folder doesn't exist or something like that.
+ Then, we tried to create a new folder with the name name of the previous, then we got a "Can not save. This node doesn't allow 2 nodes with the same name" message.
+ After ~15 minutes, the folder appeared again.
+
+Tests performed at DevLevel
+ * Functional testing, manual testing in customer env.
+
+Tests performed at QA/Support Level
+*
+
+Documentation changes
+
+Documentation changes:
+ * No
+
+Configuration changes
+
+Configuration changes:
+ * No
+
+Will previous configuration continue to work?
+ * Yes
+
+Risks and impacts
+
+Can this bug fix have any side effects on current client projects?
+
+ No
+
+Is there a performance risk/cost?
+ * it is possible a bit perf decreasion on MySQL with InnoDB engine. See QA reports (two last columns) http://tests.exoplatform.org/JCR/1.12.10-GA/rev.4553/daily-performance-te...;
+
+Validation (PM/Support/QA)
+
+PM Comment
+
+ Patch approved by the PL
+
+Support Comment
+
+ Support review: Patch validated
+
+QA Feedbacks
+*
+
12 years, 11 months
exo-jcr SVN: r4612 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: ext/action and 1 other directory.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2011-07-07 08:49:29 -0400 (Thu, 07 Jul 2011)
New Revision: 4612
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/ext/action/SessionActionInterceptor.java
Log:
EXOJCR-1408: added parent NodeData to postSetProperty method to avoid extra parent traversing
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2011-07-07 09:20:07 UTC (rev 4611)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2011-07-07 12:49:29 UTC (rev 4612)
@@ -603,7 +603,7 @@
prop = (PropertyImpl)dataManager.update(itemState, true);
// launch event: post-set
- session.getActionHandler().postSetProperty(prevProperty, prop, state);
+ session.getActionHandler().postSetProperty(prevProperty, prop, parentNode.nodeData(), state);
}
else
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/ext/action/SessionActionInterceptor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/ext/action/SessionActionInterceptor.java 2011-07-07 09:20:07 UTC (rev 4611)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/ext/action/SessionActionInterceptor.java 2011-07-07 12:49:29 UTC (rev 4612)
@@ -257,7 +257,7 @@
}
}
- public void postSetProperty(PropertyImpl previousProperty, PropertyImpl currentProperty, int state)
+ public void postSetProperty(PropertyImpl previousProperty, PropertyImpl currentProperty, NodeData parent, int state)
throws RepositoryException
{
if (catalog == null)
@@ -289,7 +289,7 @@
Condition conditions = new Condition();
conditions.put(SessionEventMatcher.EVENTTYPE_KEY, event);
conditions.put(SessionEventMatcher.PATH_KEY, currentProperty.getInternalPath());
- conditions.put(SessionEventMatcher.NODETYPES_KEY, readNodeTypeNames(currentProperty.parentData()));
+ conditions.put(SessionEventMatcher.NODETYPES_KEY, readNodeTypeNames(parent));
InvocationContext ctx = new InvocationContext();
ctx.put(InvocationContext.CURRENT_ITEM, currentProperty);
12 years, 11 months
exo-jcr SVN: r4611 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-07 05:20:07 -0400 (Thu, 07 Jul 2011)
New Revision: 4611
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/WorkspaceContainer.java
Log:
EXOJCR-1396: unregister all components from Repository/Workspace container after stop
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2011-07-07 09:19:32 UTC (rev 4610)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2011-07-07 09:20:07 UTC (rev 4611)
@@ -499,6 +499,16 @@
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized void stop()
+ {
+ super.stop();
+ super.unregisterAllComponents();
+ }
+
+ /**
* Initialize worspaces (root node and jcr:system for system workspace).
* <p>
* Runs on container start.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/WorkspaceContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/WorkspaceContainer.java 2011-07-07 09:19:32 UTC (rev 4610)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/WorkspaceContainer.java 2011-07-07 09:20:07 UTC (rev 4611)
@@ -93,4 +93,13 @@
return (WorkspaceInitializer)getComponentInstanceOfType(WorkspaceInitializer.class);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized void stop()
+ {
+ super.stop();
+ super.unregisterAllComponents();
+ }
}
12 years, 11 months
exo-jcr SVN: r4610 - kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-07 05:19:32 -0400 (Thu, 07 Jul 2011)
New Revision: 4610
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
Log:
EXOJCR-1396: unregister all components from Repository/Workspace container after stop
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2011-07-07 09:08:13 UTC (rev 4609)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2011-07-07 09:19:32 UTC (rev 4610)
@@ -29,12 +29,14 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.picocontainer.ComponentAdapter;
import org.picocontainer.PicoContainer;
import org.picocontainer.defaults.ComponentAdapterFactory;
import java.lang.reflect.Constructor;
import java.security.PrivilegedAction;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -426,4 +428,16 @@
ConfigurationManager cm = (ConfigurationManager)getComponentInstanceOfType(ConfigurationManager.class);
return cm == null ? null : cm.getConfiguration();
}
+
+ /**
+ * Unregister all components from container to avoid keeping instances in memory.
+ */
+ protected void unregisterAllComponents()
+ {
+ Collection<ComponentAdapter> adapters = getComponentAdapters();
+ for (ComponentAdapter adapter : adapters)
+ {
+ unregisterComponent(adapter.getComponentKey());
+ }
+ }
}
12 years, 11 months
exo-jcr SVN: r4609 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query: jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-07-07 05:08:13 -0400 (Thu, 07 Jul 2011)
New Revision: 4609
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
Log:
EXOJCR-1068 : fixed JBossCache MBeans unregistration for Indexer.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java 2011-07-07 08:29:27 UTC (rev 4608)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java 2011-07-07 09:08:13 UTC (rev 4609)
@@ -161,6 +161,13 @@
}
/**
+ * Frees resources associated with changes filter
+ */
+ public void close()
+ {
+ }
+
+ /**
* @param removedNodes
* @param addedNodes
* @param updatedNodes
@@ -245,7 +252,7 @@
{
return log;
}
-
+
protected void logErrorChanges(QueryHandler logHandler, Set<String> removedNodes, Set<String> addedNodes)
{
try
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-07-07 08:29:27 UTC (rev 4608)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-07-07 09:08:13 UTC (rev 4609)
@@ -621,6 +621,11 @@
public void stop()
{
handler.close();
+ // ChangesFiler instance is one for both SearchManagers and close() must be invoked only once,
+ if (parentSearchManager != null)
+ {
+ changesFilter.close();
+ }
log.info("Search manager stopped");
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2011-07-07 08:29:27 UTC (rev 4608)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2011-07-07 09:08:13 UTC (rev 4609)
@@ -202,11 +202,11 @@
return true;
}
- /**
- * @see java.lang.Object#finalize()
+ /**
+ * {@inheritDoc}
*/
@Override
- protected void finalize() throws Throwable
+ public void close()
{
try
{
@@ -222,9 +222,8 @@
});
}
}
- finally
- {
- super.finalize();
+ catch (Exception e) {
+ log.warn("Not all JBoss Cache MBeans were unregistered.");
}
}
}
12 years, 11 months
exo-jcr SVN: r4608 - in jcr/trunk/exo.jcr.component.core: src/main/java/org/exoplatform/services/jcr/dataflow/serialization and 2 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-07-07 04:29:27 -0400 (Thu, 07 Jul 2011)
New Revision: 4608
Modified:
jcr/trunk/exo.jcr.component.core/pom.xml
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/serialization/SerializationConstants.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataWriter.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JcrImplSerializationBaseTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationStream.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationVersionRestore.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TesterItemsPersistenceListener.java
Log:
EXOJCR-1407 : Checks in serialization tests should be performed synchronously with Session.Save()
Modified: jcr/trunk/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/pom.xml 2011-07-06 14:14:54 UTC (rev 4607)
+++ jcr/trunk/exo.jcr.component.core/pom.xml 2011-07-07 08:29:27 UTC (rev 4608)
@@ -412,8 +412,6 @@
<exclude>org/exoplatform/services/jcr/**/api/TestAll.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/Base*.java</exclude>
<exclude>org/exoplatform/services/jcr/**/usecases/BaseUsecasesTest.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationStream.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationVersionRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/usecases/common/RemoveSameNameSiblingUnfixedTest.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/SQLBenchmarkTest.java</exclude>
<!-- Implementation Specific Excludes -->
@@ -753,8 +751,6 @@
<exclude>org/exoplatform/services/jcr/**/api/TestAll.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/Base*.java</exclude>
<exclude>org/exoplatform/services/jcr/**/usecases/BaseUsecasesTest.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationStream.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationVersionRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/usecases/common/RemoveSameNameSiblingUnfixedTest.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/SQLBenchmarkTest.java</exclude>
<!-- From TCK -->
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/serialization/SerializationConstants.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/serialization/SerializationConstants.java 2011-07-06 14:14:54 UTC (rev 4607)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/serialization/SerializationConstants.java 2011-07-07 08:29:27 UTC (rev 4608)
@@ -89,6 +89,11 @@
public static final int PERSISTED_VALUE_DATA = 11;
/**
+ * Null file
+ */
+ public static final int NULL_FILE = -1;
+
+ /**
* Null data.
*/
public static final byte NULL_DATA = 0;
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java 2011-07-06 14:14:54 UTC (rev 4607)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java 2011-07-07 08:29:27 UTC (rev 4608)
@@ -93,7 +93,9 @@
// read id
int key;
if ((key = in.readInt()) != SerializationConstants.PERSISTED_VALUE_DATA)
+ {
throw new UnknownClassIdException("There is unexpected class [" + key + "]");
+ }
int orderNumber = in.readInt();
@@ -115,8 +117,12 @@
SerializationSpoolFile sf = holder.get(id);
if (sf == null)
{
+ // Deleted ItemState usecase
+ if (length == SerializationConstants.NULL_FILE)
+ {
+ return new StreamPersistedValueData(orderNumber, (SerializationSpoolFile)null);
+ }
sf = new SerializationSpoolFile(tempDirectory, id, holder);
- // TODO optimize writeToFile - use channels or streams
writeToFile(in, sf, length);
holder.put(id, sf);
return new StreamPersistedValueData(orderNumber, sf);
@@ -130,7 +136,9 @@
// skip data in input stream
if (in.skip(length) != length)
+ {
throw new IOException("Content isn't skipped correctly.");
+ }
return vd;
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataWriter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataWriter.java 2011-07-06 14:14:54 UTC (rev 4607)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataWriter.java 2011-07-07 08:29:27 UTC (rev 4608)
@@ -26,7 +26,6 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
import org.exoplatform.services.jcr.util.IdGenerator;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -74,14 +73,16 @@
if (streamed.getFile() == null && vd instanceof StreamPersistedValueData)
{
- in = PrivilegedFileHelper.fileInputStream(((StreamPersistedValueData)vd).getTempFile());
+ if (((StreamPersistedValueData)vd).getTempFile() != null)
+ {
+ in = PrivilegedFileHelper.fileInputStream(((StreamPersistedValueData)vd).getTempFile());
+ }
}
else
{
in = streamed.getAsStream();
}
- // TODO optimize it, use channels
if (streamed.getFile() instanceof SerializationSpoolFile)
{
SerializationSpoolFile ssf = (SerializationSpoolFile)streamed.getFile();
@@ -94,17 +95,27 @@
String id = IdGenerator.generate();
out.writeString(id);
- out.writeLong(vd.getLength());
- try
+ if (in == null)
{
- byte[] buf = new byte[SerializationConstants.INTERNAL_BUFFER_SIZE];
- int l = 0;
- while ((l = in.read(buf)) >= 0)
- out.write(buf, 0, l);
+ // Deleted state usecase
+ out.writeLong(SerializationConstants.NULL_FILE);
}
- finally
+ else
{
- in.close();
+ out.writeLong(vd.getLength());
+ try
+ {
+ byte[] buf = new byte[SerializationConstants.INTERNAL_BUFFER_SIZE];
+ int l = 0;
+ while ((l = in.read(buf)) >= 0)
+ {
+ out.write(buf, 0, l);
+ }
+ }
+ finally
+ {
+ in.close();
+ }
}
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JcrImplSerializationBaseTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JcrImplSerializationBaseTest.java 2011-07-06 14:14:54 UTC (rev 4607)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JcrImplSerializationBaseTest.java 2011-07-07 08:29:27 UTC (rev 4608)
@@ -18,10 +18,21 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.serialization;
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
+import org.exoplatform.services.jcr.dataflow.serialization.UnknownClassIdException;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.FilePersistedValueData;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
+
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -35,19 +46,6 @@
import java.util.Iterator;
import java.util.List;
-import org.exoplatform.services.jcr.JcrImplBaseTest;
-import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
-import org.exoplatform.services.jcr.dataflow.ItemState;
-import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
-import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
-import org.exoplatform.services.jcr.dataflow.serialization.UnknownClassIdException;
-import org.exoplatform.services.jcr.datamodel.ItemData;
-import org.exoplatform.services.jcr.datamodel.PropertyData;
-import org.exoplatform.services.jcr.datamodel.ValueData;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
-import org.exoplatform.services.jcr.impl.storage.value.fs.operations.ValueFileIOHelper;
-import org.exoplatform.services.jcr.storage.value.ValueIOChannel;
-
/**
* Created by The eXo Platform SAS. <br/>Date: 16.02.2009
*
@@ -86,14 +84,43 @@
List<ValueData> expValDat = expProp.getValues();
List<ValueData> elemValDat = elemProp.getValues();
- assertEquals(expValDat.size(), elemValDat.size());
- for (int j = 0; j < expValDat.size(); j++)
+ // Both value data are null
+ if (expValDat != null && elemValDat != null)
{
- assertTrue(java.util.Arrays
- .equals(expValDat.get(j).getAsByteArray(), elemValDat.get(j).getAsByteArray()));
+ assertEquals(expValDat.size(), elemValDat.size());
+ for (int j = 0; j < expValDat.size(); j++)
+ {
- // check is received property values ReplicableValueData
- // assertTrue(elemValDat.get(j) instanceof ReplicableValueData);
+ // are of the same class
+ assertEquals(expValDat.get(j).getClass(), elemValDat.get(j).getClass());
+ //
+ if (expValDat.get(j) instanceof FilePersistedValueData)
+ {
+ // if files in both instances are null
+ Boolean nullFiles =
+ ((FilePersistedValueData)expValDat.get(j)).getFile() == null
+ && ((FilePersistedValueData)elemValDat.get(j)).getFile() == null;
+ // if there are instances of StreamPersistedValueData
+ if (expValDat.get(j) instanceof StreamPersistedValueData)
+ {
+ // and they both have null spool files
+ nullFiles &=
+ ((StreamPersistedValueData)expValDat.get(j)).getTempFile() == null
+ && ((StreamPersistedValueData)elemValDat.get(j)).getTempFile() == null;
+ }
+ if (nullFiles)
+ {
+ // Both value data are equals
+ continue;
+ }
+ }
+
+ assertTrue(java.util.Arrays.equals(expValDat.get(j).getAsByteArray(), elemValDat.get(j)
+ .getAsByteArray()));
+
+ // check is received property values ReplicableValueData
+ // assertTrue(elemValDat.get(j) instanceof ReplicableValueData);
+ }
}
}
}
@@ -101,6 +128,20 @@
}
+ protected void checkResults(List<TransactionChangesLog> srcLog) throws Exception
+ {
+ File jcrfile = serializeLogs(srcLog);
+
+ List<TransactionChangesLog> destLog = deSerializeLogs(jcrfile);
+
+ assertEquals(srcLog.size(), destLog.size());
+
+ for (int i = 0; i < srcLog.size(); i++)
+ {
+ checkIterator(srcLog.get(i).getAllStates().iterator(), destLog.get(i).getAllStates().iterator());
+ }
+ }
+
protected File serializeLogs(List<TransactionChangesLog> logs) throws IOException, UnknownClassIdException
{
File jcrfile = File.createTempFile("jcr", "test");
@@ -129,7 +170,7 @@
while (true)
{
TransactionChangesLog obj =
- (TransactionChangesLog)(new TransactionChangesLogReader(fileCleaner, maxBufferSize, holder)).read(jcrin);
+ (new TransactionChangesLogReader(fileCleaner, maxBufferSize, holder)).read(jcrin);
// TransactionChangesLog obj = new TransactionChangesLog();
// obj.readObject(jcrin);
readed.add(obj);
@@ -139,8 +180,7 @@
{
// ok
}
-
-
+
//Imitation of save.
imitationSave(readed);
@@ -159,35 +199,41 @@
for (TransactionChangesLog tLog : readed)
{
ChangesLogIterator it = tLog.getLogIterator();
-
- while (it.hasNextLog())
+
+ while (it.hasNextLog())
{
PlainChangesLog pLog = it.nextLog();
-
+
for (ItemState state : pLog.getAllStates())
{
ItemData itemData = state.getData();
-
+
if (!itemData.isNode())
{
PropertyData propData = (PropertyData)itemData;
-
- for(ValueData valueData : propData.getValues())
+ if (propData.getValues() != null)
{
- if (valueData instanceof StreamPersistedValueData) {
- // imitation of JCR save
- if (((StreamPersistedValueData) valueData).getTempFile() != null)
+ for (ValueData valueData : propData.getValues())
+ {
+ if (valueData instanceof StreamPersistedValueData)
{
- ((StreamPersistedValueData) valueData).setPersistedFile(((StreamPersistedValueData) valueData).getTempFile());
+ // imitation of JCR save
+ if (((StreamPersistedValueData)valueData).getTempFile() != null)
+ {
+ ((StreamPersistedValueData)valueData)
+ .setPersistedFile(((StreamPersistedValueData)valueData).getTempFile());
+ }
+ else
+ {
+ File file = File.createTempFile("tempFile", "tmp");
+ file.deleteOnExit();
+ if (((StreamPersistedValueData)valueData).getStream() != null)
+ {
+ copy(((StreamPersistedValueData)valueData).getStream(), new FileOutputStream(file));
+ ((StreamPersistedValueData)valueData).setPersistedFile(file);
+ }
+ }
}
- else
- {
- File file = File.createTempFile("tempFile", "tmp");
- file.deleteOnExit();
-
- copy(((StreamPersistedValueData) valueData).getStream(), new FileOutputStream(file));
- ((StreamPersistedValueData) valueData).setPersistedFile(file);
- }
}
}
}
@@ -195,7 +241,7 @@
}
}
}
-
+
protected long copy(InputStream in, OutputStream out) throws IOException
{
// compare classes as in Java6 Channels.newChannel(), Java5 has a bug in newChannel().
@@ -243,7 +289,9 @@
}
if (outFile)
+ {
((FileChannel)outch).force(true); // force all data to FS
+ }
return size;
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationStream.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationStream.java 2011-07-06 14:14:54 UTC (rev 4607)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationStream.java 2011-07-07 08:29:27 UTC (rev 4608)
@@ -18,12 +18,9 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.serialization;
-import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
-
import java.io.File;
import java.io.FileInputStream;
import java.util.Calendar;
-import java.util.List;
import javax.jcr.Node;
import javax.jcr.Value;
@@ -54,6 +51,7 @@
contentNode.setProperty("jcr:mimeType", "application/octet-stream");
contentNode.setProperty("jcr:lastModified", session.getValueFactory().createValue(Calendar.getInstance()));
session.save();
+ checkResults(pl.getAndReset());
test.setProperty("creator", new String[]{"Creator 1", "Creator 2", "Creator 3"});
@@ -67,21 +65,15 @@
test.setProperty("language", new String[]{"language 1", "language 2", "language3", "language 4", "language5"});
session.save();
+ checkResults(pl.getAndReset());
// delete
Node srcParent = test.getParent();
srcParent.remove();
session.save();
- List<TransactionChangesLog> srcLog = pl.pushChanges();
-
- File jcrfile = super.serializeLogs(srcLog);
-
- List<TransactionChangesLog> destLog = super.deSerializeLogs(jcrfile);
-
- assertEquals(srcLog.size(), destLog.size());
-
- for (int i = 0; i < srcLog.size(); i++)
- checkIterator(srcLog.get(i).getAllStates().iterator(), destLog.get(i).getAllStates().iterator());
+ checkResults(pl.getAndReset());
+ // unregister listener
+ pl.pushChanges();
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationVersionRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationVersionRestore.java 2011-07-06 14:14:54 UTC (rev 4607)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationVersionRestore.java 2011-07-07 08:29:27 UTC (rev 4608)
@@ -18,13 +18,10 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.serialization;
-import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Calendar;
-import java.util.List;
import javax.jcr.Node;
import javax.jcr.version.Version;
@@ -49,24 +46,36 @@
srcVersionNode.addMixin("mix:versionable");
session.save();
+ checkResults(pl.getAndReset());
+
srcVersionNode.checkin();
session.save();
+ checkResults(pl.getAndReset());
+
srcVersionNode.checkout();
srcVersionNode.setProperty("jcr:data", "version 1");
session.save();
+ checkResults(pl.getAndReset());
+
srcVersionNode.checkin();
session.save();
+ checkResults(pl.getAndReset());
+
srcVersionNode.checkout();
srcVersionNode.setProperty("jcr:data", "version 2");
session.save();
+ checkResults(pl.getAndReset());
+
Version baseVersion = srcVersionNode.getBaseVersion();
srcVersionNode.restore(baseVersion, true);
session.save();
+ checkResults(pl.getAndReset());
+
Version baseVersion1 = srcVersionNode.getBaseVersion();
Version[] predesessors = baseVersion1.getPredecessors();
Version restoreToBaseVersion = predesessors[0];
@@ -74,21 +83,15 @@
srcVersionNode.restore(restoreToBaseVersion, true);
session.save();
- List<TransactionChangesLog> srcLog = pl.pushChanges();
-
- File jcrfile = super.serializeLogs(srcLog);
-
- List<TransactionChangesLog> destLog = super.deSerializeLogs(jcrfile);
-
- assertEquals(srcLog.size(), destLog.size());
-
- for (int i = 0; i < srcLog.size(); i++)
- checkIterator(srcLog.get(i).getAllStates().iterator(), destLog.get(i).getAllStates().iterator());
+ checkResults(pl.getAndReset());
+ // unregister listener
+ pl.pushChanges();
}
public void testBigFileRestore() throws Exception
{
TesterItemsPersistenceListener pl = new TesterItemsPersistenceListener(this.session);
+ //List<TransactionChangesLog> srcLog = new ArrayList<TransactionChangesLog>();
File tempFile = File.createTempFile("tempFile", "doc");
File tempFile2 = File.createTempFile("tempFile", "doc");
@@ -129,25 +132,37 @@
session.save();
+ checkResults(pl.getAndReset());
+
Node srcVersion = root.getNode("nt_file_node");
srcVersion.checkin();
session.save();
+ checkResults(pl.getAndReset());
+
srcVersion.checkout();
srcVersionNode.getNode("jcr:content").setProperty("jcr:data", new FileInputStream(tempFile2));
session.save();
+ checkResults(pl.getAndReset());
+
srcVersion.checkin();
session.save();
+ checkResults(pl.getAndReset());
+
srcVersion.checkout();
srcVersionNode.getNode("jcr:content").setProperty("jcr:data", new FileInputStream(tempFile3));
session.save();
+ checkResults(pl.getAndReset());
+
Version baseVersion = srcVersion.getBaseVersion();
srcVersion.restore(baseVersion, true);
session.save();
+ checkResults(pl.getAndReset());
+
Version baseVersion1 = srcVersion.getBaseVersion();
Version[] predesessors = baseVersion1.getPredecessors();
Version restoreToBaseVersion = predesessors[0];
@@ -155,6 +170,8 @@
srcVersion.restore(restoreToBaseVersion, true);
session.save();
+ checkResults(pl.getAndReset());
+
Version baseVersion2 = srcVersion.getBaseVersion();
Version[] predesessors2 = baseVersion2.getSuccessors();
Version restoreToBaseVersion_2 = predesessors2[0];
@@ -162,16 +179,9 @@
srcVersion.restore(restoreToBaseVersion_2, true);
session.save();
- List<TransactionChangesLog> srcLog = pl.pushChanges();
-
- File jcrfile = super.serializeLogs(srcLog);
-
- List<TransactionChangesLog> destLog = super.deSerializeLogs(jcrfile);
-
- assertEquals(srcLog.size(), destLog.size());
-
- for (int i = 0; i < srcLog.size(); i++)
- checkIterator(srcLog.get(i).getAllStates().iterator(), destLog.get(i).getAllStates().iterator());
+ checkResults(pl.getAndReset());
+ // unregister listener
+ pl.pushChanges();
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TesterItemsPersistenceListener.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TesterItemsPersistenceListener.java 2011-07-06 14:14:54 UTC (rev 4607)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TesterItemsPersistenceListener.java 2011-07-07 08:29:27 UTC (rev 4608)
@@ -70,6 +70,18 @@
return logsList;
}
+ /**
+ * Returns collected changes and resets listener without unregistering
+ *
+ * @return List of TransactionChangesLog
+ */
+ public List<TransactionChangesLog> getAndReset()
+ {
+ List<TransactionChangesLog> logs = new ArrayList<TransactionChangesLog>(logsList);
+ logsList.clear();
+ return logs;
+ }
+
public List<TransactionChangesLog> getCurrentLogList()
{
return logsList;
12 years, 11 months