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 oz...@apache.org on 2004/07/01 14:59:10 UTC
cvs commit: jakarta-slide/src/share/org/apache/slide/common AbstractXAServiceBase.java XAServiceBase.java
ozeigermann 2004/07/01 05:59:10
Added: src/share/org/apache/slide/common AbstractXAServiceBase.java
XAServiceBase.java
Log:
Introduced new service bases that make used of abstract XA Resource.
Allow for valid suspension and resume of transactions.
Revision Changes Path
1.1 jakarta-slide/src/share/org/apache/slide/common/AbstractXAServiceBase.java
Index: AbstractXAServiceBase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/AbstractXAServiceBase.java,v 1.1 2004/07/01 12:59:10 ozeigermann Exp $
* $Revision: 1.1 $
* $Date: 2004/07/01 12:59:10 $
*
* ====================================================================
*
* Copyright 1999-2002 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.common;
import java.util.Hashtable;
import org.apache.slide.authenticate.CredentialsToken;
import org.apache.slide.transaction.AbstractXAResource;
import org.apache.slide.util.logger.Logger;
import org.apache.slide.util.logger.LoggerFacade;
import org.apache.slide.util.logger.TxLogger;
/**
* Slide Service abstract implementation.
*
* @version $Revision: 1.1 $
*/
public abstract class AbstractXAServiceBase extends AbstractXAResource implements Service {
// -------------------------------------------------------------- Constants
protected String LOG_CHANNEL = this.getClass().getName();
// ----------------------------------------------------- Instance Variables
/**
* Namespace.
*/
protected Namespace namespace;
// the scope of this store as specified in domain.xml
protected Scope scope;
protected LoggerFacade loggerFacade = null;
// -------------------------------------------------------- Service Methods
/**
* Set the scope of the store as specified in domain.xml.
*/
public void setScope(Scope scope) {
this.scope = scope;
}
/**
* Namespace setter.
*/
public void setNamespace(Namespace namespace) {
this.namespace = namespace;
}
/**
* Logger accessor.
*/
public Logger getLogger() {
Logger logger = null;
if (namespace != null) {
logger = this.namespace.getLogger();
}
if (logger == null)
logger = Domain.getLogger();
return logger;
}
protected LoggerFacade getLoggerFacade() {
if (loggerFacade == null) {
loggerFacade = new TxLogger(getLogger(), LOG_CHANNEL);
}
return loggerFacade;
}
/**
* Initializes the service with a set of parameters. Those could be :
* <li>User name, login info
* <li>Host name on which to connect
* <li>Remote port
* <li>JDBC driver whoich is to be used :-)
* <li>Anything else ...
*
* @param parameters Hashtable containing the parameters' names
* and associated values
* @exception ServiceParameterErrorException Incorrect service parameter
* @exception ServiceParameterMissingException Service parameter missing
*/
public abstract void setParameters(Hashtable parameters)
throws ServiceParameterErrorException,
ServiceParameterMissingException;
/**
* Connects to the underlying data source (if any is needed).
* Compatibility implementation for the previous store implementations
*
* @param crdtoken the slide token containing e.g. the credential
* @exception ServiceConnectionFailedException Connection failed
*/
public void connect(CredentialsToken crdtoken) throws ServiceConnectionFailedException {
connect();
}
/**
* Connects to the underlying data source (if any is needed).
*
* @exception ServiceConnectionFailedException Connection failed
*/
public abstract void connect()
throws ServiceConnectionFailedException;
/**
* Disconnects from the underlying data source.
*
* @exception ServiceDisconnectionFailedException Disconnection failed
*/
public abstract void disconnect()
throws ServiceDisconnectionFailedException;
/**
* Initializes service.
*
* @param token Namespace access token, needed if the service needs to
* access objects or data within the namespace during its initialization
* @exception ServiceInitializationFailedException May throw an exception
* if the service has already been initialized before
*/
public void initialize(NamespaceAccessToken token)
throws ServiceInitializationFailedException {
}
/**
* Deletes service underlying data source, if possible (and meaningful).
*
* @exception ServiceResetFailedException Reset failed
*/
public abstract void reset()
throws ServiceResetFailedException;
/**
* This function tells whether or not the service is connected.
*
* @return boolean true if we are connected
* @exception ServiceAccessException Service access error
*/
public abstract boolean isConnected()
throws ServiceAccessException;
/**
* Connects to the service, if we were not previously connected.
*
* @param token the Credeantials token containing e.g. the credential
* @return boolean true if we were not already connected
* @exception ServiceAccessException Unspecified service access error
* @exception ServiceConnectionFailedException Connection failed
*/
public boolean connectIfNeeded(CredentialsToken token)
throws ServiceConnectionFailedException, ServiceAccessException {
boolean result = true;
try {
result = !isConnected();
} catch (ServiceAccessException e) {
// Ignore : Will try to reconnect
}
if (result) {
connect(token);
}
return result;
}
/**
* Connects to the service, if we were not previously connected.
*
* @return boolean true if we were not already connected
* @exception ServiceAccessException Unspecified service access error
* @exception ServiceConnectionFailedException Connection failed
*/
public boolean connectIfNeeded()
throws ServiceConnectionFailedException, ServiceAccessException {
boolean result = true;
try {
result = !isConnected();
} catch (ServiceAccessException e) {
// Ignore : Will try to reconnect
}
if (result) {
connect();
}
return result;
}
/**
* Indicates whether or not the objects managed by this service should be
* cached. Caching is enabled by default.
*
* @return boolean True if results should be cached
*/
public boolean cacheResults() {
return true;
}
// ----------------------------------------------------- XAResource Mathods
}
1.1 jakarta-slide/src/share/org/apache/slide/common/XAServiceBase.java
Index: XAServiceBase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/XAServiceBase.java,v 1.1 2004/07/01 12:59:10 ozeigermann Exp $
* $Revision: 1.1 $
* $Date: 2004/07/01 12:59:10 $
*
* ====================================================================
*
* Copyright 1999-2002 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.common;
import java.util.Hashtable;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.apache.slide.transaction.TransactionalResource;
/**
* Slide Service dummy implementation.
*
* @version $Revision: 1.1 $
*/
public class XAServiceBase extends AbstractXAServiceBase {
protected boolean started = false;
public void setParameters(Hashtable parameters)
throws ServiceParameterErrorException,
ServiceParameterMissingException {
}
public void connect() throws ServiceConnectionFailedException {
started = true;
}
public void disconnect() throws ServiceDisconnectionFailedException {
started = false;
}
public void reset() throws ServiceResetFailedException {
}
public boolean isConnected() throws ServiceAccessException {
return started;
}
public boolean isSameRM(XAResource xares) throws XAException {
return (xares == this);
}
public Xid[] recover(int flag) throws XAException {
return null;
}
public int getTransactionTimeout() throws XAException {
return 0;
}
public boolean setTransactionTimeout(int arg0) throws XAException {
return false;
}
protected TransactionalResource createTransactionResource(Xid xid) {
return new DummyTxResource(xid);
}
protected class DummyTxResource implements TransactionalResource {
Xid xid;
int status;
DummyTxResource(Xid xid) {
this.xid = xid;
status = STATUS_ACTIVE;
}
public void commit() throws XAException {
}
public void rollback() throws XAException {
}
public int prepare() throws XAException {
// no check possible
return XA_OK;
}
public void close() throws XAException {
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public Xid getXid() {
return xid;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org