Author: david.lloyd(a)jboss.com
Date: 2009-01-14 20:31:58 -0500 (Wed, 14 Jan 2009)
New Revision: 4811
Added:
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/TxnReply.java
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/TxnRequest.java
Removed:
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/reply/
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/request/
Modified:
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/TransactionalClientImpl.java
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/TransactionalClientSourceImpl.java
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/WrappingRequestHandler.java
Log:
Make the API somewhat less intimidating
Copied: remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/TxnReply.java (from rev
4810,
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/reply/AbstractTxnReply.java)
===================================================================
--- remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/TxnReply.java
(rev 0)
+++ remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/TxnReply.java 2009-01-15
01:31:58 UTC (rev 4811)
@@ -0,0 +1,160 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.remoting.txn;
+
+import javax.transaction.xa.Xid;
+
+/**
+ *
+ */
+public interface TxnReply {
+
+ <I, O> O accept(Visitor<I, O> visitor, I param);
+
+ interface Visitor<I, O> {
+
+ O visit(ResourceManagerId id, I param);
+
+ O visit(Timeout id, I param);
+
+ O visit(Prepared prepared, I param);
+
+ O visit(Recover reply, I param);
+
+ O visit(TimeoutSet reply, I param);
+
+ O visit(TxnSuccessfulReply reply, I param);
+ }
+
+ /**
+ *
+ */
+ final class ResourceManagerId implements TxnReply {
+ private final Object id;
+
+ public ResourceManagerId(final Object id) {
+ this.id = id;
+ }
+
+ public Object getId() {
+ return id;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class Timeout implements TxnReply {
+
+ private final int timeout;
+
+ public Timeout(final int timeout) {
+ this.timeout = timeout;
+ }
+
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class Prepared implements TxnReply {
+ private final int vote;
+
+ public Prepared(final int vote) {
+ this.vote = vote;
+ }
+
+ public int getVote() {
+ return vote;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class Recover implements TxnReply {
+
+ private final Xid[] resources;
+
+ public Recover(final Xid[] resources) {
+ this.resources = resources;
+ }
+
+ public Xid[] getResources() {
+ return resources;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class TimeoutSet implements TxnReply {
+
+ private final boolean success;
+
+ public TimeoutSet(final boolean success) {
+ this.success = success;
+ }
+
+ public boolean getSuccess() {
+ return success;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class TxnSuccessfulReply implements TxnReply {
+ public static final TxnSuccessfulReply INSTANCE = new TxnSuccessfulReply();
+
+ private TxnSuccessfulReply() {
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+}
Copied: remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/TxnRequest.java (from rev
4810,
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/request/AbstractTxnRequest.java)
===================================================================
--- remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/TxnRequest.java
(rev 0)
+++ remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/TxnRequest.java 2009-01-15
01:31:58 UTC (rev 4811)
@@ -0,0 +1,334 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.remoting.txn;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * A request for a transaction operation on a transactional client.
+ */
+public interface TxnRequest {
+ <I, O> O accept(Visitor<I, O> visitor, I param);
+
+ interface Visitor<I, O> {
+
+ O visit(CommitXA request, I param);
+
+ O visit(EndXA request, I param);
+
+ O visit(ForgetXA request, I param);
+
+ O visit(GetTimeout request, I param);
+
+ O visit(PrepareXA request, I param);
+
+ O visit(Recover request, I param);
+
+ O visit(RollbackXA request, I param);
+
+ O visit(SetTimeout request, I param);
+
+ O visit(StartXA request, I param);
+
+ O visit(Wrapped request, I param);
+
+ O visit(GetResourceManagerId request, I param);
+
+ O visit(StartLocal request, I param);
+
+ O visit(CommitLocal request, I param);
+
+ O visit(RollbackLocal request, I param);
+ }
+
+ /**
+ *
+ */
+ final class CommitLocal implements TxnRequest {
+ public static final CommitLocal INSTANCE = new CommitLocal();
+
+ private CommitLocal() {
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class EndXA implements TxnRequest {
+
+ private final Xid xid;
+ private final int flags;
+
+ public EndXA(final Xid xid, final int flags) {
+ this.xid = xid;
+ this.flags = flags;
+ }
+
+ public Xid getXid() {
+ return xid;
+ }
+
+ public int getFlags() {
+ return flags;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class ForgetXA implements TxnRequest {
+
+ private final Xid xid;
+
+ public ForgetXA(final Xid xid) {
+ this.xid = xid;
+ }
+
+ public Xid getXid() {
+ return xid;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class GetResourceManagerId implements TxnRequest {
+
+ public static final GetResourceManagerId INSTANCE = new GetResourceManagerId();
+
+ private GetResourceManagerId() {
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class GetTimeout implements TxnRequest {
+
+ public static final GetTimeout INSTANCE = new GetTimeout();
+
+ private GetTimeout() {
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class SetTimeout implements TxnRequest {
+
+ private final int timeout;
+
+ public SetTimeout(final int timeout) {
+ this.timeout = timeout;
+ }
+
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class PrepareXA implements TxnRequest {
+
+ private final Xid xid;
+
+ public PrepareXA(final Xid xid) {
+ this.xid = xid;
+ }
+
+ public Xid getXid() {
+ return xid;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class Recover implements TxnRequest {
+
+ private final int flag;
+
+ public Recover(final int flag) {
+ this.flag = flag;
+ }
+
+ public int getFlag() {
+ return flag;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class RollbackLocal implements TxnRequest {
+
+ public static RollbackLocal INSTANCE = new RollbackLocal();
+
+ private RollbackLocal() {
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class StartLocal implements TxnRequest {
+
+ public static StartLocal INSTANCE = new StartLocal();
+
+ private StartLocal() {
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class Wrapped implements TxnRequest {
+
+ private final Object wrappedRequest;
+
+ public Wrapped(final Object request) {
+ wrappedRequest = request;
+ }
+
+ public Object getWrappedRequest() {
+ return wrappedRequest;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class CommitXA implements TxnRequest {
+ private final Xid xid;
+ private final boolean onePhase;
+
+ public CommitXA(final Xid xid, final boolean onePhase) {
+ this.xid = xid;
+ this.onePhase = onePhase;
+ }
+
+ public Xid getXid() {
+ return xid;
+ }
+
+ public boolean isOnePhase() {
+ return onePhase;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class RollbackXA implements TxnRequest {
+
+ private final Xid xid;
+
+ public RollbackXA(final Xid xid) {
+ this.xid = xid;
+ }
+
+ public Xid getXid() {
+ return xid;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+
+ /**
+ *
+ */
+ final class StartXA implements TxnRequest {
+
+ private final Xid xid;
+ private final int flags;
+
+ public StartXA(final Xid xid, final int flags) {
+ this.xid = xid;
+ this.flags = flags;
+ }
+
+ public Xid getXid() {
+ return xid;
+ }
+
+ public int getFlags() {
+ return flags;
+ }
+
+ public <I, O> O accept(final Visitor<I, O> visitor, final I param) {
+ return visitor.visit(this, param);
+ }
+ }
+}
Modified:
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/TransactionalClientImpl.java
===================================================================
---
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/TransactionalClientImpl.java 2009-01-15
00:08:49 UTC (rev 4810)
+++
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/TransactionalClientImpl.java 2009-01-15
01:31:58 UTC (rev 4811)
@@ -35,26 +35,8 @@
import org.jboss.remoting.Client;
import org.jboss.remoting.CloseHandler;
import org.jboss.remoting.RemoteExecutionException;
-import org.jboss.remoting.txn.request.TxnEndRequest;
-import org.jboss.remoting.txn.request.TxnRollbackRequest;
-import org.jboss.remoting.txn.request.TxnPrepareRequest;
-import org.jboss.remoting.txn.request.TxnGetResourceManagerIdRequest;
-import org.jboss.remoting.txn.request.TxnGetTimeoutRequest;
-import org.jboss.remoting.txn.request.TxnRecoverRequest;
-import org.jboss.remoting.txn.request.TxnForgetRequest;
-import org.jboss.remoting.txn.request.TxnCommitRequest;
-import org.jboss.remoting.txn.request.AbstractTxnRequest;
-import org.jboss.remoting.txn.request.TxnSetTimeoutRequest;
-import org.jboss.remoting.txn.request.TxnXACommitRequest;
-import org.jboss.remoting.txn.request.TxnXARollbackRequest;
-import org.jboss.remoting.txn.request.TxnXAStartRequest;
-import org.jboss.remoting.txn.request.TxnStartRequest;
-import org.jboss.remoting.txn.reply.AbstractTxnReply;
-import org.jboss.remoting.txn.reply.TxnGetResourceManagerIdReply;
-import org.jboss.remoting.txn.reply.TxnGetTimeoutReply;
-import org.jboss.remoting.txn.reply.TxnPrepareReply;
-import org.jboss.remoting.txn.reply.TxnRecoverReply;
-import org.jboss.remoting.txn.reply.TxnSetTimeoutReply;
+import org.jboss.remoting.txn.TxnRequest;
+import org.jboss.remoting.txn.TxnReply;
import org.jboss.remoting.txn.TransactionalClient;
/**
@@ -63,11 +45,11 @@
public final class TransactionalClientImpl<I, O> implements
TransactionalClient<I, O> {
private final Client<I, O> realClient;
- private final Client<AbstractTxnRequest, AbstractTxnReply> txnClient;
+ private final Client<TxnRequest, TxnReply> txnClient;
private RemotingXAResource remotingXAResource;
- TransactionalClientImpl(final Client<I, O> realClient, final
Client<AbstractTxnRequest, AbstractTxnReply> txnClient) throws IOException {
+ TransactionalClientImpl(final Client<I, O> realClient, final
Client<TxnRequest, TxnReply> txnClient) throws IOException {
this.realClient = realClient;
this.txnClient = txnClient;
remotingXAResource = new RemotingXAResource(txnClient);
@@ -93,7 +75,7 @@
}
}
- private static AbstractTxnReply doInvoke(Client<AbstractTxnRequest,
AbstractTxnReply> txnClient, AbstractTxnRequest request) throws XAException {
+ private static TxnReply doInvoke(Client<TxnRequest, TxnReply> txnClient,
TxnRequest request) throws XAException {
try {
return txnClient.invoke(request);
} catch (IOException e) {
@@ -102,15 +84,15 @@
}
public void start() throws IOException {
- txnClient.invoke(TxnStartRequest.INSTANCE);
+ txnClient.invoke(TxnRequest.StartLocal.INSTANCE);
}
public void commit() throws IOException {
- txnClient.invoke(TxnCommitRequest.INSTANCE);
+ txnClient.invoke(TxnRequest.CommitLocal.INSTANCE);
}
public void rollback() throws IOException {
- txnClient.invoke(TxnRollbackRequest.INSTANCE);
+ txnClient.invoke(TxnRequest.RollbackLocal.INSTANCE);
}
public XAResource getXaResource() {
@@ -150,28 +132,28 @@
*
*/
public static final class RemotingXAResource implements XAResource {
- private final Client<AbstractTxnRequest, AbstractTxnReply> txnClient;
- private final IoFuture<? extends TxnGetResourceManagerIdReply>
futureIdReply;
+ private final Client<TxnRequest, TxnReply> txnClient;
+ private final IoFuture<? extends TxnReply.ResourceManagerId>
futureIdReply;
- public RemotingXAResource(final Client<AbstractTxnRequest,
AbstractTxnReply> client) throws IOException {
+ public RemotingXAResource(final Client<TxnRequest, TxnReply> client) throws
IOException {
txnClient = client;
- futureIdReply =
IoUtils.cast(txnClient.send(TxnGetResourceManagerIdRequest.INSTANCE),
TxnGetResourceManagerIdReply.class);
+ futureIdReply =
IoUtils.cast(txnClient.send(TxnRequest.GetResourceManagerId.INSTANCE),
TxnReply.ResourceManagerId.class);
}
public void commit(final Xid xid, final boolean onePhase) throws XAException {
- doInvoke(txnClient, new TxnXACommitRequest(xid, onePhase));
+ doInvoke(txnClient, new TxnRequest.CommitXA(xid, onePhase));
}
public void end(final Xid xid, final int flags) throws XAException {
- doInvoke(txnClient, new TxnEndRequest(xid, flags));
+ doInvoke(txnClient, new TxnRequest.EndXA(xid, flags));
}
public void forget(final Xid xid) throws XAException {
- doInvoke(txnClient, new TxnForgetRequest(xid));
+ doInvoke(txnClient, new TxnRequest.ForgetXA(xid));
}
public int getTransactionTimeout() throws XAException {
- return ((TxnGetTimeoutReply) doInvoke(txnClient,
TxnGetTimeoutRequest.INSTANCE)).getTimeout();
+ return ((TxnReply.Timeout) doInvoke(txnClient,
TxnRequest.GetTimeout.INSTANCE)).getTimeout();
}
public boolean isSameRM(final XAResource resource) throws XAException {
@@ -188,23 +170,23 @@
}
public int prepare(final Xid xid) throws XAException {
- return ((TxnPrepareReply) doInvoke(txnClient, new
TxnPrepareRequest(xid))).getVote();
+ return ((TxnReply.Prepared) doInvoke(txnClient, new
TxnRequest.PrepareXA(xid))).getVote();
}
public Xid[] recover(final int flag) throws XAException {
- return ((TxnRecoverReply) doInvoke(txnClient, new
TxnRecoverRequest(flag))).getResources();
+ return ((TxnReply.Recover) doInvoke(txnClient, new
TxnRequest.Recover(flag))).getResources();
}
public void rollback(final Xid xid) throws XAException {
- doInvoke(txnClient, new TxnXARollbackRequest(xid));
+ doInvoke(txnClient, new TxnRequest.RollbackXA(xid));
}
public boolean setTransactionTimeout(final int timeout) throws XAException {
- return ((TxnSetTimeoutReply) doInvoke(txnClient, new
TxnSetTimeoutRequest(timeout))).getSuccess();
+ return ((TxnReply.TimeoutSet) doInvoke(txnClient, new
TxnRequest.SetTimeout(timeout))).getSuccess();
}
public void start(final Xid xid, final int flags) throws XAException {
- doInvoke(txnClient, new TxnXAStartRequest(xid, flags));
+ doInvoke(txnClient, new TxnRequest.StartXA(xid, flags));
}
}
}
Modified:
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/TransactionalClientSourceImpl.java
===================================================================
---
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/TransactionalClientSourceImpl.java 2009-01-15
00:08:49 UTC (rev 4810)
+++
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/TransactionalClientSourceImpl.java 2009-01-15
01:31:58 UTC (rev 4811)
@@ -28,8 +28,8 @@
import org.jboss.remoting.Endpoint;
import org.jboss.remoting.Client;
import org.jboss.remoting.CloseHandler;
-import org.jboss.remoting.txn.request.AbstractTxnRequest;
-import org.jboss.remoting.txn.reply.AbstractTxnReply;
+import org.jboss.remoting.txn.TxnRequest;
+import org.jboss.remoting.txn.TxnReply;
import org.jboss.remoting.txn.TransactionalClientSource;
import org.jboss.remoting.txn.TransactionalClient;
import org.jboss.remoting.spi.RequestHandlerSource;
@@ -83,7 +83,7 @@
final RequestHandler requestHandler = handle.getResource();
final Client<I, O> realClient =
endpoint.createClient(WrappingRequestHandler.create(executor, requestHandler),
requestClass, replyClass);
try {
- final Client<AbstractTxnRequest, AbstractTxnReply> txnClient =
endpoint.createClient(requestHandler, AbstractTxnRequest.class, AbstractTxnReply.class);
+ final Client<TxnRequest, TxnReply> txnClient =
endpoint.createClient(requestHandler, TxnRequest.class, TxnReply.class);
try {
handle.close();
final TransactionalClientImpl<I, O> transactionalClient = new
TransactionalClientImpl<I, O>(realClient, txnClient);
Modified:
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/WrappingRequestHandler.java
===================================================================
---
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/WrappingRequestHandler.java 2009-01-15
00:08:49 UTC (rev 4810)
+++
remoting-txn/trunk/src/main/java/org/jboss/remoting/txn/impl/WrappingRequestHandler.java 2009-01-15
01:31:58 UTC (rev 4811)
@@ -28,7 +28,7 @@
import org.jboss.remoting.spi.AbstractAutoCloseable;
import org.jboss.remoting.spi.Handle;
import org.jboss.remoting.CloseHandler;
-import org.jboss.remoting.txn.request.TxnWrappedRequest;
+import org.jboss.remoting.txn.TxnRequest;
import org.jboss.xnio.IoUtils;
import java.util.concurrent.Executor;
import java.io.IOException;
@@ -66,6 +66,6 @@
}
public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler
replyHandler) {
- return handle.getResource().receiveRequest(new TxnWrappedRequest(request),
replyHandler);
+ return handle.getResource().receiveRequest(new TxnRequest.Wrapped(request),
replyHandler);
}
}