Package com.iizix.txp.impl
Class TXProcessImpl
- java.lang.Object
- com.iizix.txp.impl.TXProcessImpl
- All Implemented Interfaces:
ITimeoutListener
,ITXProcess
public class TXProcessImpl extends java.lang.Object implements ITXProcess, ITimeoutListener
Basic and crude (for now)ITXProcess
implementation- Author:
- Freggle
Nested Class Summary
Nested classes/interfaces inherited from interface com.iizix.txp.ITXProcess
ITXProcess.State
Constructor Summary
Constructors Modifier Constructor Description protected
TXProcessImpl(ITXPid pid, TXPCoordinatorImpl coordinator)
Constructs a process.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(java.lang.String name, java.lang.Object value)
Adds a named attribute.void
associate(ITXPNode node)
Associate an atomic unit of work (a node) with this process.void
commit()
Called by the process logic/application (not the nodes!)to request that the transactional process gets committed.java.lang.Object
getAttribute(java.lang.String name)
Gets a named attribute.ITXPPolicy
getLocalPolicy()
Return the process local policyITXPid
getPid()
Gets the pid of his processlong
getRemainingTime()
Gets the remaining time before timeout.ITXProcess.State
getState()
Get the state of this process.long
getTimeout()
Returns the nr of milliseconds this process waits for all nodes.protected ITXProcessLogger
log()
void
onTimeout()
Called when timeout is reached.void
ready(ITXPNode node, ITXPNode.State nodeState)
A node will call this method to signal its state after attempting to do the work.java.lang.Object
removeAttribute(java.lang.String name)
Removes a named attribute.void
rollback()
Called by the process logic/application (not the nodes) to request that the transactional process rolls back the work.void
setStartTimeout(long millisecs)
Set the timeout time in milliseconds AND START THE TIMER!.void
timeout(ITXPNode node)
Called by a node indicating it timed out waiting on the process.void
useLocalPolicy(ITXPPolicy policy)
Have the coordinator use the specified local policy for this process.
Constructor Detail
TXProcessImpl
protected TXProcessImpl(ITXPid pid, TXPCoordinatorImpl coordinator)
Constructs a process.- Parameters:
pid
- the pid for this process
Method Detail
useLocalPolicy
public void useLocalPolicy(ITXPPolicy policy)
Description copied from interface:ITXProcess
Have the coordinator use the specified local policy for this process. To stop using a local policy specifynull
.- Specified by:
useLocalPolicy
in interfaceITXProcess
- Parameters:
policy
- the policy
getLocalPolicy
public ITXPPolicy getLocalPolicy()
Description copied from interface:ITXProcess
Return the process local policy- Specified by:
getLocalPolicy
in interfaceITXProcess
- Returns:
- the process local policy or null if none is used
getPid
public ITXPid getPid()
Description copied from interface:ITXProcess
Gets the pid of his process- Specified by:
getPid
in interfaceITXProcess
- Returns:
- the pid
getTimeout
public long getTimeout()
Description copied from interface:ITXProcess
Returns the nr of milliseconds this process waits for all nodes. The timeout is applied when setStartTimeout() is called on the process. It is up to the coordinator (and maybe policy) to decide how to deal with a timeout but the nodes needs to be signalled that the process timed out and the defined behaviour for the node is to stop the work and wait for rollback unless the coordinator decides to CONTINUE or IGNORE the timeout.- Specified by:
getTimeout
in interfaceITXProcess
- Returns:
- the timeout time in milliseconds
associate
public void associate(ITXPNode node)
Description copied from interface:ITXProcess
Associate an atomic unit of work (a node) with this process. This will cause abegin()
call in the node.- Specified by:
associate
in interfaceITXProcess
- Parameters:
node
- the node
getState
public ITXProcess.State getState()
Description copied from interface:ITXProcess
Get the state of this process.- Specified by:
getState
in interfaceITXProcess
- Returns:
- the state
ready
public void ready(ITXPNode node, ITXPNode.State nodeState)
Description copied from interface:ITXProcess
A node will call this method to signal its state after attempting to do the work.- Specified by:
ready
in interfaceITXProcess
- Parameters:
node
- the nodenodeState
- the current state of the node
timeout
public void timeout(ITXPNode node)
Description copied from interface:ITXProcess
Called by a node indicating it timed out waiting on the process. The process (and coordinator) must assume that the node abandoned the process and rolled back any change they made on behalf of it.- Specified by:
timeout
in interfaceITXProcess
- Parameters:
node
- the node
commit
public void commit() throws TXPException
Description copied from interface:ITXProcess
Called by the process logic/application (not the nodes!)to request that the transactional process gets committed.- Specified by:
commit
in interfaceITXProcess
- Throws:
TXPException
- a coordinator and policy dependent exception (today 1 of 3, more details later)
rollback
public void rollback() throws TXPException
Description copied from interface:ITXProcess
Called by the process logic/application (not the nodes) to request that the transactional process rolls back the work.- Specified by:
rollback
in interfaceITXProcess
- Throws:
TXPException
- a coordinator and policy dependent exception (today 1 of 3, more details later)
addAttribute
public void addAttribute(java.lang.String name, java.lang.Object value)
Description copied from interface:ITXProcess
Adds a named attribute.- Specified by:
addAttribute
in interfaceITXProcess
- Parameters:
name
- the attribute namevalue
- the attribute value
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface:ITXProcess
Gets a named attribute.- Specified by:
getAttribute
in interfaceITXProcess
- Parameters:
name
- the attribute name- Returns:
- the attribute value
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
Description copied from interface:ITXProcess
Removes a named attribute.- Specified by:
removeAttribute
in interfaceITXProcess
- Parameters:
name
- the attribute name- Returns:
- the attribute value
setStartTimeout
public void setStartTimeout(long millisecs)
Set the timeout time in milliseconds AND START THE TIMER!. -1L for indefinite (the default so you do not have to call it in that case) You should call this method after you associated all the nodes and all other initialization.- Specified by:
setStartTimeout
in interfaceITXProcess
- Parameters:
millisecs
- the timeout time in milliseconds
onTimeout
public void onTimeout()
Description copied from interface:ITimeoutListener
Called when timeout is reached.- Specified by:
onTimeout
in interfaceITimeoutListener
log
protected ITXProcessLogger log()
getRemainingTime
public long getRemainingTime()
Gets the remaining time before timeout. This value just keeps on counting, even when the timeout has occurred or the task is stopped.- Specified by:
getRemainingTime
in interfaceITXProcess
- Returns:
- A time in milliseconds >= zero indicating the remaining timeout time, or < zero if the task has timed out. The return value is
Long.MAX_VALUE
if the timeout is indefinite or never set.