You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2004/07/26 14:40:52 UTC
cvs commit: jakarta-slide/src/stores/org/apache/slide/store/mem AbstractTransientStore.java
luetzkendorf 2004/07/26 05:40:52
Modified: src/stores/org/apache/slide/store/mem
AbstractTransientStore.java
Log:
moved extra stuff in XAResource-methods to MapXAResource
Revision Changes Path
1.2 +56 -66 jakarta-slide/src/stores/org/apache/slide/store/mem/AbstractTransientStore.java
Index: AbstractTransientStore.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/AbstractTransientStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractTransientStore.java 21 Jul 2004 17:36:29 -0000 1.1
+++ AbstractTransientStore.java 26 Jul 2004 12:40:52 -0000 1.2
@@ -25,7 +25,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
-import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
@@ -40,7 +39,7 @@
import org.apache.commons.transaction.memory.ConflictException;
import org.apache.commons.transaction.memory.TransactionalMapWrapper;
import org.apache.commons.transaction.memory.jca.MapXAResource;
-import org.apache.commons.transaction.util.xa.XidWrapper;
+import org.apache.commons.transaction.util.LoggerFacade;
import org.apache.slide.common.AbstractServiceBase;
import org.apache.slide.common.NamespaceAccessToken;
@@ -52,9 +51,23 @@
import org.apache.slide.common.ServiceParameterMissingException;
import org.apache.slide.common.ServiceResetFailedException;
import org.apache.slide.util.logger.Logger;
-
+import org.apache.slide.util.logger.TxLogger;
/**
+ * Base class for the stores that what to store its data transient in a
+ * map.
+ *
+ * <p>Implementations access the backing map only via {@link #put(Object, Object)},
+ * {@link #get(Object)} and {@link #remove(Object)}.
+ *
+ * <p>The backed map can be any class that is derived from
+ * {@link org.apache.commons.transaction.memory.TransactionalMapWrapper}.
+ *
+ * <p>The class may be configured in the <code>domain.xml</code> using the
+ * parameter <code>map-classname</code>.
+ * Default is {@link org.apache.commons.transaction.memory.OptimisticMapWrapper}.
+ *
+ *
* @author Stefan L�tzkendorf
*/
public abstract class AbstractTransientStore extends AbstractServiceBase {
@@ -76,12 +89,6 @@
*/
private MapXAResource xaResource = null;
- private Map suspendedContexts = Collections.synchronizedMap(new HashMap());
-
- public AbstractTransientStore() {
-
- }
-
// ----------------------------------------------------- XAResource Mathods
public void start(Xid xid, int flags)
@@ -89,21 +96,6 @@
{
debug("start {0} {1}", xid, Integer.toString(flags));
this.xaResource.start(xid, flags);
- // >>
- if (flags == XAResource.TMRESUME) {
- Xid key = XidWrapper.wrap(xid);
- TransactionalMapWrapper.TxContext txContext =
- (TransactionalMapWrapper.TxContext)suspendedContexts.get(key);
- if (txContext != null) {
- this.store.resumeTransaction(txContext);
- this.suspendedContexts.remove(key);
- } else {
- throw new XAException("no such suspended txn");
- }
- } else {
- this.store.startTransaction();
- }
- // <<
}
public void commit(Xid xid, boolean onePhase)
@@ -115,9 +107,9 @@
}
catch (ConflictException e) {
this.xaResource.rollback(xid);
- // TODO it would be great if we could if we could throw something
+ // TODO it would be great if we could throw something
// that would (on the webdav layer) leads to a 409 Conflict
- // instead of 500 Internal Server Erroe
+ // instead of 500 Internal Server Error
throw new XAException(XAException.XA_RBOTHER); // ??
}
}
@@ -126,17 +118,6 @@
throws XAException
{
debug("prepare {0}", xid);
- // >>
- // resume if suspended, because the transactional map throws an exception
- // if we call prepare on suspended txns
- Xid key = XidWrapper.wrap(xid);
- TransactionalMapWrapper.TxContext txContext =
- (TransactionalMapWrapper.TxContext)this.suspendedContexts.get(key);
- if (txContext != null) {
- this.store.resumeTransaction(txContext);
- this.suspendedContexts.remove(key);
- }
- // <<
return this.xaResource.prepare(xid);
}
@@ -145,30 +126,12 @@
{
debug("end {0} {1}", xid, Integer.toString(flags));
this.xaResource.end(xid, flags);
- // >>
- if (flags == XAResource.TMSUSPEND) {
- TransactionalMapWrapper.TxContext txContext =
- this.store.suspendTransaction();
- this.suspendedContexts.put(XidWrapper.wrap(xid), txContext);
- }
- // <<
}
public void rollback(Xid xid)
throws XAException
{
debug("rollback {0}", xid);
- // >>
- // resume if suspended, because the transactional map throws an exception
- // if we call prepare on suspended txns
- Xid key = XidWrapper.wrap(xid);
- TransactionalMapWrapper.TxContext txContext =
- (TransactionalMapWrapper.TxContext)this.suspendedContexts.get(key);
- if (txContext != null) {
- this.store.resumeTransaction(txContext);
- this.suspendedContexts.remove(key);
- }
- // <<
this.xaResource.rollback(xid);
}
@@ -242,6 +205,8 @@
{
super.initialize(token);
+ TxLogger txLogger = new TxLogger(getLogger(), LogChannel());
+
String param = (String)this.parameters.get(MAP_IMPL_PARAMETER);
if (param == null) {
param = MAP_IMPL_PARAMETER_DEFAULT;
@@ -250,34 +215,53 @@
info("Initializing {0} using {1}.", getClass().getName(), param);
Map toBeWrapped = new HashMap();
Class mapClass = Class.forName(param);
- Class[] ctorFormalArgs = { Map.class };
- Constructor ctor = mapClass.getConstructor(ctorFormalArgs);
- Object[] ctorArgs = { toBeWrapped };
- this.store = (TransactionalMapWrapper)ctor.newInstance(ctorArgs);
+
+ try {
+ Class[] ctorFormalArgs = { Map.class, LoggerFacade.class };
+ Constructor ctor = mapClass.getConstructor(ctorFormalArgs);
+ Object[] ctorArgs = { toBeWrapped, txLogger };
+ this.store = (TransactionalMapWrapper)ctor.newInstance(ctorArgs);
+ }
+ catch (NoSuchMethodException e) {
+ // try next
+ try {
+ Class[] ctorFormalArgs = { Map.class };
+ Constructor ctor = mapClass.getConstructor(ctorFormalArgs);
+ Object[] ctorArgs = { toBeWrapped };
+ this.store = (TransactionalMapWrapper)ctor.newInstance(ctorArgs);
+ }
+ catch (NoSuchMethodException ee) {
+ error("Initialization error: ", ee);
+ throw new ServiceInitializationFailedException(this, ee);
+ }
+ }
}
catch (ClassNotFoundException e) {
+ error("Initialization error: ", e);
throw new ServiceInitializationFailedException(this, e);
}
catch (InstantiationException e) {
+ error("Initialization error: ", e);
throw new ServiceInitializationFailedException(this, e);
}
catch (IllegalAccessException e) {
- throw new ServiceInitializationFailedException(this, e);
- }
- catch (NoSuchMethodException e) {
+ error("Initialization error: ", e);
throw new ServiceInitializationFailedException(this, e);
}
catch (InvocationTargetException e) {
+ error("Initialization error: ", e);
throw new ServiceInitializationFailedException(this, e);
}
catch (ClassCastException e) {
+ error("Initialization error: ", e);
throw new ServiceInitializationFailedException(this,
"class in parameter '" + MAP_IMPL_PARAMETER + "' must " +
"be derived from TransactionalMapWrapper");
}
this.xaResource = new MapXAResource(this.store);
- // FIXME logging
+ // FIXME can't set logging because methods are not public, and
+ // ctor doesn't take a loggerFacade
}
public void connect() throws ServiceConnectionFailedException {
@@ -317,6 +301,12 @@
if (this.getLogger().isEnabled(Logger.INFO)) {
Object[] args = { o1, o2 };
this.getLogger().log(MessageFormat.format(msg, args),
+ LogChannel(), Logger.INFO);
+ }
+ }
+ private void error(String msg, Throwable t) {
+ if (this.getLogger().isEnabled(Logger.INFO)) {
+ this.getLogger().log(msg, t,
LogChannel(), Logger.INFO);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org