KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > gs > JiniTransactionFactory


1 /*
2  * $Id: JiniTransactionFactory.java 3807 2006-11-06 13:13:36Z holger $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.gs;
12
13 import net.jini.core.transaction.server.TransactionManager;
14
15 import org.mule.config.i18n.Message;
16 import org.mule.config.i18n.Messages;
17 import org.mule.umo.TransactionException;
18 import org.mule.umo.UMOTransaction;
19 import org.mule.umo.UMOTransactionFactory;
20
21 /**
22  * Creates a Jini Transaction. This factory needs to have the TransactionManager set
23  * on it before the <code>beginTransaction</code> method is called on it. This
24  * should be set during start up of the Mule server by the resource that will be
25  * sending or receiving events from a JavaSpace.
26  *
27  * @see TransactionManager
28  */

29 public class JiniTransactionFactory implements UMOTransactionFactory
30 {
31
32     protected TransactionManager transactionManager = null;
33     protected long transactionTimeout = 3200 * 1000;
34
35     /**
36      * Create and begins a new transaction
37      *
38      * @return a new Transaction
39      * @throws org.mule.umo.TransactionException if the transaction cannot be created
40      * or begun
41      */

42     public UMOTransaction beginTransaction() throws TransactionException
43     {
44         // if(transactionManager==null) {
45
// throw new TransactionException(new Message(Messages.X_IS_NULL,
46
// "transactionManager"));
47
// }
48
try
49         {
50             JiniTransaction jtx = new JiniTransaction(transactionTimeout);
51             jtx.begin();
52             return jtx;
53         }
54         catch (Exception JavaDoc e)
55         {
56             throw new TransactionException(new Message(Messages.TX_CANT_START_X_TRANSACTION, "Jini"), e);
57         }
58     }
59
60     /**
61      * Determines whether this transaction factory creates transactions that are
62      * really transacted or if they are being used to simulate batch actions, such as
63      * using Jms Client Acknowledge.
64      *
65      * @return
66      */

67     public boolean isTransacted()
68     {
69         return true;
70     }
71
72     public TransactionManager getTransactionManager()
73     {
74         return transactionManager;
75     }
76
77     public void setTransactionManager(TransactionManager transactionManager)
78     {
79         this.transactionManager = transactionManager;
80     }
81
82     public long getTransactionTimeout()
83     {
84         return transactionTimeout;
85     }
86
87     public void setTransactionTimeout(long transactionTimeout)
88     {
89         this.transactionTimeout = transactionTimeout;
90     }
91 }
92
Popular Tags