com.gigaspaces.client.transaction.local
Class LocalTransactionManagerImpl

java.lang.Object
  extended by com.j_spaces.core.client.LocalTransactionManager
      extended by com.gigaspaces.client.transaction.local.LocalTransactionManagerImpl
All Implemented Interfaces:
Externalizable, Serializable, Remote, TransactionConstants, TransactionManager

public class LocalTransactionManagerImpl
extends LocalTransactionManager

A Local Transaction Manager acts as a Transaction Manager for transactions that span a single space instance. It has several advantages over a standard distributed transaction manager:

In order to use it, the application generally getInstance of LocalTransactionManager object and then uses it like a distributed transaction manager:


   JavaSpace space = ... // get instance to a GigaSpaces space instance
   TransactionManager tm = LocalTransactionManager.getInstance((IJSpace) space);
   Transaction tr = ... // obtain transaction through TransactionFactory
   space.write(entry, tr, Lease.FOREVER);
   ...
   tr.commit();
   tr = ... // obtain transaction through TransactionFactory
   space.take(entry, tr, JavaSpace.NO_WAIT);
   ...
   tr.commit();
 

It is important to note that all operations inside a local transaction must be directed to the same space instance - the space instance that was given to the LocalTransactionManager.getInstance( space ).

If you are interested to have multiple spaces as part of the same transaction you should use the Jini Transaction manager - See the TransactionManager. The Jini Transaction manager is mainly used with partitioned space.


 TransactionManager tm = (TransactionManager)LookupFinder.find(
                                null,       // service name
                                new Class[] { net.jini.core.transaction.server.TransactionManager.class },
                                null,       // service attributes
                                "localhost", // unicast lookup host
                               null,       // lookup groups
                                    10*1000     // timeout 10 seconds
                               );
 Transaction.Created tCreated =TransactionFactory.create(trManager, 1000 * 60);
 Transaction  tr = tCreated.transaction;
 

See http://www.gigaspaces.com/wiki/display/GS/Jini+Transaction+Manager for more information.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.jini.core.transaction.server.TransactionManager
TransactionManager.Created
 
Field Summary
 
Fields inherited from interface net.jini.core.transaction.server.TransactionConstants
ABORTED, ACTIVE, COMMITTED, NOTCHANGED, PREPARED, VOTING
 
Constructor Summary
LocalTransactionManagerImpl()
          Do not use, externliazable only.
LocalTransactionManagerImpl(IJSpace spaceProxy)
          Deprecated. Use getInstance(IJSpace) or getInstance(IMap) instead
 
Method Summary
 void abort(long id)
          
 void abort(long id, long waitFor)
          
 void abort(Object xid)
          Internal only - used by XA.
 long checkActiveAndGetTimeLimt(long xtnId)
          This API is called from the proxy when a transaction is used in order to verify if the transaction is alive.
 long checkActiveAndGetTimeLimt(Object xtnId)
          This API is called from the proxy when a transaction is used in order to verify if the transaction is alive.
 void commit(long xtnID)
          
 void commit(long xtnID, long waitFor)
          
 void commit(Object xid)
          Internal only - used by XA.
 TransactionManager.Created create(long lease)
          
 TransactionManager.Created create(Object xid, long lease)
          Creates transaction - for internal and XA use.
 void destroy()
          Destroy the LocalTransactionManager instance, including its context to the space.
 boolean equals(Object o)
          Equality between two LocalTransactionManager instances.
static TransactionManager getInstance(IJSpace space)
          Returns single instance of LocalTransactionManager per space.
static TransactionManager getInstance(IMap map)
          Returns single instance of LocalTransactionManager per map.
 String getManagerID()
          Gets the Manager Id.
 IJSpace getProxy()
           
 int getState(long id)
          
 int getState(Object id)
          Get the transaction state.
 int hashCode()
           
 boolean isActiveTransaction(Object id)
           
 void join(long id, TransactionParticipant part, long crashCount)
          
 int prepare(Object xid)
          Prepare transaction - for internal and XA use.
 void readExternal(ObjectInput in)
           
 Xid[] recover()
          Create Xids array of all the prepared transactions.
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalTransactionManagerImpl

public LocalTransactionManagerImpl()
Do not use, externliazable only.


LocalTransactionManagerImpl

@Deprecated
public LocalTransactionManagerImpl(IJSpace spaceProxy)
                            throws RemoteException
Deprecated. Use getInstance(IJSpace) or getInstance(IMap) instead

Initialize LocalTransactionManager.

Parameters:
spaceProxy - The space proxy.
Throws:
RemoteException - Failed to initialize LocalTransactionManager.
Method Detail

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Throws:
IOException

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Throws:
IOException
ClassNotFoundException

getInstance

public static TransactionManager getInstance(IMap map)
                                      throws RemoteException
Returns single instance of LocalTransactionManager per map.


 

<b>Usage:</b> TransactionManager localTxnManager = LocalTransactionManager( (IMap)map ); Transaction.Created tCreated = TransactionFactory.create(localTxnManager, 60000); Transaction tr = tCreated.transaction;

Parameters:
map - The IMap implementation.
Returns:
Returns instance of LocalTransactionManager.
Throws:
RemoteException - Failed to initialize LocalTransactionManager, or if the passed space proxy is null.
See Also:
TransactionManager

getInstance

public static TransactionManager getInstance(IJSpace space)
                                      throws RemoteException
Returns single instance of LocalTransactionManager per space.


 

<b>Usage:</b> TransactionManager localTxnManager = LocalTransactionManager( (IJSpace)space ); Transaction.Created tCreated = TransactionFactory.create(localTxnManager, 60000); Transaction tr = tCreated.transaction;

Parameters:
space - The space proxy.
Returns:
Returns instance of LocalTransactionManager.
Throws:
RemoteException - Failed to initialize LocalTransactionManager, or if the passed space proxy is null.
See Also:
TransactionManager

abort

public void abort(Object xid)
           throws UnknownTransactionException,
                  CannotAbortException,
                  RemoteException
Internal only - used by XA.

Parameters:
xid - XA transaction id
Throws:
UnknownTransactionException
CannotAbortException
RemoteException

abort

public void abort(long id)
           throws UnknownTransactionException,
                  CannotAbortException,
                  RemoteException

Throws:
UnknownTransactionException
CannotAbortException
RemoteException

abort

public void abort(long id,
                  long waitFor)
           throws UnknownTransactionException,
                  CannotAbortException,
                  TimeoutExpiredException,
                  RemoteException

Throws:
UnknownTransactionException
CannotAbortException
TimeoutExpiredException
RemoteException

commit

public void commit(Object xid)
            throws UnknownTransactionException,
                   CannotCommitException,
                   RemoteException
Internal only - used by XA.

Parameters:
xid - XA transaction id
Throws:
UnknownTransactionException
CannotCommitException
RemoteException

commit

public void commit(long xtnID)
            throws UnknownTransactionException,
                   CannotCommitException,
                   RemoteException

Throws:
UnknownTransactionException
CannotCommitException
RemoteException

commit

public void commit(long xtnID,
                   long waitFor)
            throws UnknownTransactionException,
                   CannotCommitException,
                   TimeoutExpiredException,
                   RemoteException

Throws:
UnknownTransactionException
CannotCommitException
TimeoutExpiredException
RemoteException

prepare

public int prepare(Object xid)
            throws UnknownTransactionException,
                   CannotCommitException,
                   RemoteException
Prepare transaction - for internal and XA use.

Parameters:
xid - transaction id
Returns:
Throws:
UnknownTransactionException
CannotCommitException
RemoteException - if a communication error occurs

create

public TransactionManager.Created create(Object xid,
                                         long lease)
Creates transaction - for internal and XA use.


create

public TransactionManager.Created create(long lease)


getState

public int getState(Object id)
             throws UnknownTransactionException
Get the transaction state.

Parameters:
id - transaction id
Returns:
the transaction state
Throws:
UnknownTransactionException - if the transaction is unknown to the transaction manager, either because the transaction ID is incorrect or because the transaction is complete and its state has been discarded by the manager.
See Also:
TransactionConstants

getState

public int getState(long id)
             throws UnknownTransactionException

Throws:
UnknownTransactionException

join

public void join(long id,
                 TransactionParticipant part,
                 long crashCount)


equals

public boolean equals(Object o)
Equality between two LocalTransactionManager instances.

Overrides:
equals in class Object
Parameters:
o - the target manager to compare
Returns:
true if same manager id, false otherwise.

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
the manager hash-code driven from the manager id
See Also:
getManagerID()

getManagerID

public String getManagerID()
Gets the Manager Id.

Returns:
string representation of the Local Transaction Manager Id.

getProxy

public IJSpace getProxy()
Returns:
space proxy reference for this local transaction manager.

checkActiveAndGetTimeLimt

public long checkActiveAndGetTimeLimt(Object xtnId)
                               throws TransactionException
This API is called from the proxy when a transaction is used in order to verify if the transaction is alive.

Parameters:
xtnId - transaction id to check
Returns:
lease time limit
Throws:
TransactionException - throw incase the transaction isn't active

checkActiveAndGetTimeLimt

public long checkActiveAndGetTimeLimt(long xtnId)
                               throws TransactionException
This API is called from the proxy when a transaction is used in order to verify if the transaction is alive.

Parameters:
xtnId - transaction id to check
Returns:
lease time limit
Throws:
TransactionException - throw incase the transaction isn't active

isActiveTransaction

public boolean isActiveTransaction(Object id)
Parameters:
id - transaction id to check
Returns:
true if the transaction is active.

recover

public Xid[] recover()
              throws RemoteException
Create Xids array of all the prepared transactions.

Returns:
prepared Xids
Throws:
RemoteException - if a communication error occurs

destroy

public void destroy()
Destroy the LocalTransactionManager instance, including its context to the space. Subsequent calls to getInstance(..) will return a new instance. Once this method has been called, the instance may reject all other (in-progress and subsequent) calls to its API.