Skip to content
Permalink
Browse files
GERONIMO-4360 update to connector 1.6 api jar. Implement InflowContex…
…t handling. Implementation of new LazyAssociatableConnectionManager.inactiveConnectionClosed method not done.... I don't see why its necessary yet

git-svn-id: https://svn.apache.org/repos/asf/geronimo/components/txmanager/trunk@705104 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
djencks committed Oct 16, 2008
1 parent 2d3121d commit 1571a01e83219f45e7d8fb3e51e99a19314f6cb7
Showing 10 changed files with 232 additions and 66 deletions.
@@ -51,9 +51,9 @@

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
<artifactId>geronimo-j2ee-connector_1.6_spec</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -111,6 +111,11 @@ public void associateConnection(Object connection,
getStack().getConnection(ci);
}

public void inactiveConnectionClosed(Object connection, ManagedConnectionFactory managedConnectionFactory) {
//TODO If we are tracking connections, we need to stop tracking this one.
//I don't see why we don't get a connectionClosed event for it.
}

ConnectionInterceptor getConnectionInterceptor() {
return getStack();
}
@@ -18,6 +18,8 @@
package org.apache.geronimo.connector.work;

import java.util.concurrent.Executor;
import java.util.List;
import java.util.Collections;

import javax.resource.spi.work.ExecutionContext;
import javax.resource.spi.work.Work;
@@ -30,7 +32,6 @@
import org.apache.geronimo.connector.work.pool.StartWorkExecutor;
import org.apache.geronimo.connector.work.pool.SyncWorkExecutor;
import org.apache.geronimo.connector.work.pool.WorkExecutor;
import org.apache.geronimo.transaction.manager.XAWork;

/**
* WorkManager implementation which uses under the cover three WorkExecutorPool
@@ -64,7 +65,8 @@ public class GeronimoWorkManager implements WorkManager {
*/
private Executor scheduledWorkExecutorPool;

private final XAWork transactionManager;
private final List<InflowContextHandler> inflowContextHandlers;


private final WorkExecutor scheduleWorkExecutor = new ScheduleWorkExecutor();
private final WorkExecutor startWorkExecutor = new StartWorkExecutor();
@@ -77,11 +79,11 @@ public GeronimoWorkManager() {
this(null, null, null, null);
}

public GeronimoWorkManager(Executor sync, Executor start, Executor sched, XAWork xaWork) {
public GeronimoWorkManager(Executor sync, Executor start, Executor sched, List<InflowContextHandler> inflowContextHandlers) {
syncWorkExecutorPool = sync;
startWorkExecutorPool = start;
scheduledWorkExecutorPool = sched;
this.transactionManager = xaWork;
this.inflowContextHandlers = inflowContextHandlers == null? Collections.<InflowContextHandler>emptyList(): inflowContextHandlers;
}

public void doStart() throws Exception {
@@ -114,7 +116,7 @@ public Executor getScheduledWorkExecutorPool() {
* @see javax.resource.spi.work.WorkManager#doWork(javax.resource.spi.work.Work)
*/
public void doWork(Work work) throws WorkException {
executeWork(new WorkerContext(work, transactionManager), syncWorkExecutor, syncWorkExecutorPool);
executeWork(new WorkerContext(work, inflowContextHandlers), syncWorkExecutor, syncWorkExecutorPool);
}

/* (non-Javadoc)
@@ -127,7 +129,7 @@ public void doWork(
WorkListener workListener)
throws WorkException {
WorkerContext workWrapper =
new WorkerContext(work, startTimeout, execContext, transactionManager, workListener);
new WorkerContext(work, startTimeout, execContext, workListener, inflowContextHandlers);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
executeWork(workWrapper, syncWorkExecutor, syncWorkExecutorPool);
}
@@ -136,7 +138,7 @@ public void doWork(
* @see javax.resource.spi.work.WorkManager#startWork(javax.resource.spi.work.Work)
*/
public long startWork(Work work) throws WorkException {
WorkerContext workWrapper = new WorkerContext(work, transactionManager);
WorkerContext workWrapper = new WorkerContext(work, inflowContextHandlers);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
executeWork(workWrapper, startWorkExecutor, startWorkExecutorPool);
return System.currentTimeMillis() - workWrapper.getAcceptedTime();
@@ -152,7 +154,7 @@ public long startWork(
WorkListener workListener)
throws WorkException {
WorkerContext workWrapper =
new WorkerContext(work, startTimeout, execContext, transactionManager, workListener);
new WorkerContext(work, startTimeout, execContext, workListener, inflowContextHandlers);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
executeWork(workWrapper, startWorkExecutor, startWorkExecutorPool);
return System.currentTimeMillis() - workWrapper.getAcceptedTime();
@@ -162,7 +164,7 @@ public long startWork(
* @see javax.resource.spi.work.WorkManager#scheduleWork(javax.resource.spi.work.Work)
*/
public void scheduleWork(Work work) throws WorkException {
WorkerContext workWrapper = new WorkerContext(work, transactionManager);
WorkerContext workWrapper = new WorkerContext(work, inflowContextHandlers);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
executeWork(workWrapper, scheduleWorkExecutor, scheduledWorkExecutorPool);
}
@@ -177,7 +179,7 @@ public void scheduleWork(
WorkListener workListener)
throws WorkException {
WorkerContext workWrapper =
new WorkerContext(work, startTimeout, execContext, transactionManager, workListener);
new WorkerContext(work, startTimeout, execContext, workListener, inflowContextHandlers);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
executeWork(workWrapper, scheduleWorkExecutor, scheduledWorkExecutorPool);
}
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.geronimo.connector.work;

import javax.resource.spi.work.InflowContext;
import javax.resource.spi.work.WorkCompletedException;

/**
* @version $Rev:$ $Date:$
*/
public interface InflowContextHandler<E extends InflowContext> {

void before(E inflowContext) throws WorkCompletedException;

void after(E inflowContext) throws WorkCompletedException;

Class<E> getHandledClass();

}
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.geronimo.connector.work;

import javax.resource.spi.work.TransactionInflowContext;
import javax.resource.spi.work.WorkCompletedException;
import javax.transaction.xa.XAException;
import javax.transaction.InvalidTransactionException;
import javax.transaction.SystemException;

import org.apache.geronimo.transaction.manager.XAWork;
import org.apache.geronimo.transaction.manager.ImportedTransactionActiveException;

/**
* @version $Rev:$ $Date:$
*/
public class TransactionInflowContextHandler implements InflowContextHandler<TransactionInflowContext>{

private final XAWork xaWork;

public TransactionInflowContextHandler(XAWork xaWork) {
this.xaWork = xaWork;
}

public void before(TransactionInflowContext inflowContext) throws WorkCompletedException {
if (inflowContext.getXid() != null) {
try {
long transactionTimeout = inflowContext.getTransactionTimeout();
//translate -1 value to 0 to indicate default transaction timeout.
xaWork.begin(inflowContext.getXid(), transactionTimeout < 0 ? 0 : transactionTimeout);
} catch (XAException e) {
throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e);
} catch (InvalidTransactionException e) {
throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e);
} catch (SystemException e) {
throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e);
} catch (ImportedTransactionActiveException e) {
throw (WorkCompletedException)new WorkCompletedException("Transaction already active for xid " + inflowContext.getXid(), WorkCompletedException.TX_CONCURRENT_WORK_DISALLOWED).initCause(e);
}
}
}

public void after(TransactionInflowContext inflowContext) throws WorkCompletedException {
if (inflowContext.getXid() != null) {
try {
xaWork.end(inflowContext.getXid());
} catch (XAException e) {
throw (WorkCompletedException)new WorkCompletedException("Transaction end failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e);
} catch (SystemException e) {
throw (WorkCompletedException)new WorkCompletedException("Transaction end failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e);
}
}
}

public Class<TransactionInflowContext> getHandledClass() {
return TransactionInflowContext.class;
}
}

0 comments on commit 1571a01

Please sign in to comment.