1 10 11 package org.mule.providers.gs; 12 13 import java.rmi.RemoteException ; 14 15 import net.jini.core.transaction.Transaction; 16 import net.jini.core.transaction.TransactionFactory; 17 import net.jini.core.transaction.server.TransactionManager; 18 19 import org.mule.config.i18n.Message; 20 import org.mule.config.i18n.Messages; 21 import org.mule.providers.gs.space.GSSpace; 22 import org.mule.transaction.AbstractSingleResourceTransaction; 23 import org.mule.transaction.IllegalTransactionStateException; 24 import org.mule.transaction.TransactionRollbackException; 25 import org.mule.umo.TransactionException; 26 27 import com.j_spaces.core.IJSpace; 28 import com.j_spaces.core.client.LocalTransactionManager; 29 30 39 public class JiniTransaction extends AbstractSingleResourceTransaction 40 { 41 42 protected TransactionManager txManager; 43 protected long timeout; 44 protected boolean unbound = true; 45 46 public JiniTransaction(long timeout) 47 { 48 this.timeout = timeout; 49 } 50 51 57 public void bindResource(Object key, Object resource) throws TransactionException 58 { 59 60 try 65 { 66 txManager = LocalTransactionManager.getInstance((IJSpace)((GSSpace)resource).getJavaSpace()); 67 } 68 catch (RemoteException e) 69 { 70 throw new TransactionException(e); 71 } 72 try 73 { 74 Transaction.Created tCreated = TransactionFactory.create(txManager, timeout); 75 Transaction transaction = tCreated.transaction; 76 super.bindResource(resource, transaction); 77 unbound = false; 78 } 79 catch (Exception e) 80 { 81 throw new IllegalTransactionStateException(new Message(Messages.TX_CANT_START_X_TRANSACTION, 82 "Jini"), e); 83 } 84 85 } 86 87 92 public void doBegin() throws TransactionException 93 { 94 unbound = true; 96 } 97 98 103 protected void doCommit() throws TransactionException 104 { 105 if (unbound) 106 { 107 return; 108 } 109 try 110 { 111 ((Transaction)resource).commit(); 112 } 113 catch (Exception e) 114 { 115 throw new IllegalTransactionStateException(new Message(Messages.TX_COMMIT_FAILED), e); 116 } 117 } 118 119 124 protected void doRollback() throws TransactionException 125 { 126 try 127 { 128 if (unbound) 129 { 130 return; 131 } 132 ((Transaction)resource).abort(); 133 } 134 catch (Exception e) 135 { 136 throw new TransactionRollbackException(e); 137 } 138 } 139 } 140 | Popular Tags |