Package org.jpos.transaction
Class TransactionManager
- java.lang.Object
-
- org.jpos.q2.QBeanSupport
-
- org.jpos.transaction.TransactionManager
-
- All Implemented Interfaces:
java.lang.Runnable
,Configurable
,QBean
,QBeanSupportMBean
,QPersist
,TransactionConstants
,TransactionManagerMBean
,Loggeable
,MetricsProvider
public class TransactionManager extends QBeanSupport implements java.lang.Runnable, TransactionConstants, TransactionManagerMBean, Loggeable, MetricsProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
TransactionManager.InputQueueMonitor
static class
TransactionManager.PausedMonitor
class
TransactionManager.RetryTask
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Integer
COMMITTING
static java.lang.String
CONTEXT
static java.lang.String
DEFAULT_GROUP
static java.lang.Integer
DONE
protected java.util.Map<java.lang.String,java.util.List<TransactionParticipant>>
groups
static java.lang.String
GROUPS
static java.lang.String
HEAD
static long
MAX_PARTICIPANTS
static long
MAX_WAIT
static java.lang.Integer
PREPARING
static java.lang.String
RETRY_QUEUE
static java.lang.String
STATE
static java.lang.String
TAIL
static java.lang.String
TAILLOCK
static long
TIMER_PURGE_INTERVAL
-
Fields inherited from class org.jpos.q2.QBeanSupport
cfg, log, scheduledThreadPoolExecutor
-
-
Constructor Summary
Constructors Constructor Description TransactionManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
abort(int session, long id, java.io.Serializable context, java.util.List<TransactionParticipant> members, boolean recover, LogEvent evt, Profiler prof)
protected void
abort(TransactionParticipant p, long id, java.io.Serializable context)
protected void
addGroup(long id, java.lang.String groupName)
void
addListener(TransactionStatusListener l)
protected void
checkRetryTask()
protected void
checkTail()
protected void
commit(int session, long id, java.io.Serializable context, java.util.List<TransactionParticipant> members, boolean recover, LogEvent evt, Profiler prof)
protected void
commit(TransactionParticipant p, long id, java.io.Serializable context)
protected void
commitOff(Space sp)
protected void
commitOn(Space sp)
TransactionParticipant
createParticipant(org.jdom2.Element e)
void
dump(java.io.PrintStream ps, java.lang.String indent)
protected FrozenLogEvent
freeze(java.io.Serializable context, LogEvent evt, Profiler prof)
This method gives the opportunity to decorate a LogEvent right before it gets logged.int
getActiveSessions()
int
getActiveTransactions()
static <T extends java.io.Serializable>
TgetContext()
boolean
getDebug()
boolean
getDebugContext()
long
getHead()
static java.lang.Long
getId()
Space
getInputSpace()
long
getInTransit()
protected java.lang.String
getKey(java.lang.String prefix, long id)
int
getMaxSessions()
Metrics
getMetrics()
int
getOutstandingTransactions()
protected java.util.List<TransactionParticipant>
getParticipants(long id)
protected java.util.List<TransactionParticipant>
getParticipants(java.lang.String groupName)
int
getPausedCounter()
Space
getPersistentSpace()
java.lang.String
getQueueName()
static java.io.Serializable
getSerializable()
protected int
getSessionsToStandUp()
This method returns the number of sessions that can be started at this point in timeSpace
getSpace()
long
getTail()
TPS
getTPS()
java.lang.String
getTPSAsString()
float
getTPSAvg()
long
getTPSElapsed()
int
getTPSPeak()
java.util.Date
getTPSPeakWhen()
protected long
initCounter(java.lang.String name, long defValue)
protected java.util.List<TransactionParticipant>
initGroup(org.jdom2.Element e)
protected void
initParticipants(org.jdom2.Element config)
void
initService()
protected void
initStatusListeners(org.jdom2.Element config)
protected void
initTailLock()
protected boolean
isSessionToStandDown()
This method returns true if current session should stop working on more messagesprotected long
nextId()
protected int
prepare(int session, long id, java.io.Serializable context, java.util.List<TransactionParticipant> members, java.util.Iterator<TransactionParticipant> iter, boolean abort, LogEvent evt, Profiler prof)
protected int
prepare(TransactionParticipant p, long id, java.io.Serializable context)
protected int
prepareForAbort(TransactionParticipant p, long id, java.io.Serializable context)
protected void
purge(long id, boolean full)
void
push(java.io.Serializable context)
void
queue(java.io.Serializable context)
protected void
recover()
protected void
recover(int session, long id)
void
removeListener(TransactionStatusListener l)
void
resetTPS()
void
run()
void
setConfiguration(Configuration cfg)
void
setDebug(boolean debug)
void
setDebugContext(boolean debugContext)
protected void
setState(long id, java.lang.Integer state)
protected void
snapshot(long id, java.io.Serializable context)
protected void
snapshot(long id, java.io.Serializable context, java.lang.Integer status)
void
startService()
void
stopService()
protected void
syncTail()
protected boolean
tailDone()
-
Methods inherited from class org.jpos.q2.QBeanSupport
addAttr, close, createElement, destroy, destroyService, getAttrs, getAttrs, getConfiguration, getDump, getFactory, getLoader, getLoaderURLS, getLog, getLogger, getName, getPersist, getProperties, getProperty, getRealm, getScheduledThreadPoolExecutor, getServer, getState, getStateAsString, init, isModified, running, setAttr, setLogger, setModified, setName, setPersist, setProperty, setRealm, setServer, setState, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jpos.q2.QBean
destroy, getState, getStateAsString, init, start, stop
-
Methods inherited from interface org.jpos.q2.QBeanSupportMBean
getDump, getLoader, getLoaderURLS, getLogger, getName, getRealm, getServer, setLogger, setName, setPersist, setRealm, setServer
-
Methods inherited from interface org.jpos.q2.QPersist
getPersist, isModified
-
-
-
-
Field Detail
-
HEAD
public static final java.lang.String HEAD
- See Also:
- Constant Field Values
-
TAIL
public static final java.lang.String TAIL
- See Also:
- Constant Field Values
-
CONTEXT
public static final java.lang.String CONTEXT
- See Also:
- Constant Field Values
-
STATE
public static final java.lang.String STATE
- See Also:
- Constant Field Values
-
GROUPS
public static final java.lang.String GROUPS
- See Also:
- Constant Field Values
-
TAILLOCK
public static final java.lang.String TAILLOCK
- See Also:
- Constant Field Values
-
RETRY_QUEUE
public static final java.lang.String RETRY_QUEUE
- See Also:
- Constant Field Values
-
PREPARING
public static final java.lang.Integer PREPARING
-
COMMITTING
public static final java.lang.Integer COMMITTING
-
DONE
public static final java.lang.Integer DONE
-
DEFAULT_GROUP
public static final java.lang.String DEFAULT_GROUP
- See Also:
- Constant Field Values
-
MAX_PARTICIPANTS
public static final long MAX_PARTICIPANTS
- See Also:
- Constant Field Values
-
MAX_WAIT
public static final long MAX_WAIT
- See Also:
- Constant Field Values
-
TIMER_PURGE_INTERVAL
public static final long TIMER_PURGE_INTERVAL
- See Also:
- Constant Field Values
-
groups
protected java.util.Map<java.lang.String,java.util.List<TransactionParticipant>> groups
-
-
Constructor Detail
-
TransactionManager
public TransactionManager()
-
-
Method Detail
-
initService
public void initService() throws ConfigurationException
- Overrides:
initService
in classQBeanSupport
- Throws:
ConfigurationException
-
startService
public void startService() throws java.lang.Exception
- Overrides:
startService
in classQBeanSupport
- Throws:
java.lang.Exception
-
stopService
public void stopService()
- Overrides:
stopService
in classQBeanSupport
-
queue
public void queue(java.io.Serializable context)
-
push
public void push(java.io.Serializable context)
-
getQueueName
public java.lang.String getQueueName()
-
getInputSpace
public Space getInputSpace()
-
getPersistentSpace
public Space getPersistentSpace()
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
getTail
public long getTail()
- Specified by:
getTail
in interfaceTransactionManagerMBean
-
getHead
public long getHead()
- Specified by:
getHead
in interfaceTransactionManagerMBean
-
getInTransit
public long getInTransit()
-
setConfiguration
public void setConfiguration(Configuration cfg) throws ConfigurationException
- Specified by:
setConfiguration
in interfaceConfigurable
- Overrides:
setConfiguration
in classQBeanSupport
- Parameters:
cfg
- Configuration object- Throws:
ConfigurationException
-
addListener
public void addListener(TransactionStatusListener l)
-
removeListener
public void removeListener(TransactionStatusListener l)
-
getTPSAsString
public java.lang.String getTPSAsString()
- Specified by:
getTPSAsString
in interfaceTransactionManagerMBean
-
getTPSAvg
public float getTPSAvg()
- Specified by:
getTPSAvg
in interfaceTransactionManagerMBean
-
getTPSPeak
public int getTPSPeak()
- Specified by:
getTPSPeak
in interfaceTransactionManagerMBean
-
getTPSPeakWhen
public java.util.Date getTPSPeakWhen()
- Specified by:
getTPSPeakWhen
in interfaceTransactionManagerMBean
-
getTPSElapsed
public long getTPSElapsed()
- Specified by:
getTPSElapsed
in interfaceTransactionManagerMBean
-
resetTPS
public void resetTPS()
- Specified by:
resetTPS
in interfaceTransactionManagerMBean
-
getMetrics
public Metrics getMetrics()
- Specified by:
getMetrics
in interfaceMetricsProvider
-
dump
public void dump(java.io.PrintStream ps, java.lang.String indent)
-
commit
protected void commit(int session, long id, java.io.Serializable context, java.util.List<TransactionParticipant> members, boolean recover, LogEvent evt, Profiler prof)
-
abort
protected void abort(int session, long id, java.io.Serializable context, java.util.List<TransactionParticipant> members, boolean recover, LogEvent evt, Profiler prof)
-
prepareForAbort
protected int prepareForAbort(TransactionParticipant p, long id, java.io.Serializable context)
-
prepare
protected int prepare(TransactionParticipant p, long id, java.io.Serializable context)
-
commit
protected void commit(TransactionParticipant p, long id, java.io.Serializable context)
-
abort
protected void abort(TransactionParticipant p, long id, java.io.Serializable context)
-
prepare
protected int prepare(int session, long id, java.io.Serializable context, java.util.List<TransactionParticipant> members, java.util.Iterator<TransactionParticipant> iter, boolean abort, LogEvent evt, Profiler prof)
-
getParticipants
protected java.util.List<TransactionParticipant> getParticipants(java.lang.String groupName)
-
getParticipants
protected java.util.List<TransactionParticipant> getParticipants(long id)
-
initStatusListeners
protected void initStatusListeners(org.jdom2.Element config) throws ConfigurationException
- Throws:
ConfigurationException
-
initParticipants
protected void initParticipants(org.jdom2.Element config) throws ConfigurationException
- Throws:
ConfigurationException
-
initGroup
protected java.util.List<TransactionParticipant> initGroup(org.jdom2.Element e) throws ConfigurationException
- Throws:
ConfigurationException
-
createParticipant
public TransactionParticipant createParticipant(org.jdom2.Element e) throws ConfigurationException
- Throws:
ConfigurationException
-
getOutstandingTransactions
public int getOutstandingTransactions()
- Specified by:
getOutstandingTransactions
in interfaceTransactionManagerMBean
-
getKey
protected java.lang.String getKey(java.lang.String prefix, long id)
-
initCounter
protected long initCounter(java.lang.String name, long defValue)
-
syncTail
protected void syncTail()
-
initTailLock
protected void initTailLock()
-
checkTail
protected void checkTail()
-
tailDone
protected boolean tailDone()
-
nextId
protected long nextId()
-
snapshot
protected void snapshot(long id, java.io.Serializable context)
-
snapshot
protected void snapshot(long id, java.io.Serializable context, java.lang.Integer status)
-
setState
protected void setState(long id, java.lang.Integer state)
-
addGroup
protected void addGroup(long id, java.lang.String groupName)
-
purge
protected void purge(long id, boolean full)
-
recover
protected void recover()
-
recover
protected void recover(int session, long id)
-
checkRetryTask
protected void checkRetryTask()
-
freeze
protected FrozenLogEvent freeze(java.io.Serializable context, LogEvent evt, Profiler prof)
This method gives the opportunity to decorate a LogEvent right before it gets logged. When overriding it, unless you know what you're doing, you should return a FrozenLogEvent in order to prevent concurrency issues.- Parameters:
context
- current Contextevt
- current LogEventprof
- profiler (may be null)- Returns:
- FrozenLogEvent
-
setDebug
public void setDebug(boolean debug)
- Specified by:
setDebug
in interfaceTransactionManagerMBean
-
getDebugContext
public boolean getDebugContext()
- Specified by:
getDebugContext
in interfaceTransactionManagerMBean
-
setDebugContext
public void setDebugContext(boolean debugContext)
- Specified by:
setDebugContext
in interfaceTransactionManagerMBean
-
getDebug
public boolean getDebug()
- Specified by:
getDebug
in interfaceTransactionManagerMBean
-
getSessionsToStandUp
protected int getSessionsToStandUp()
This method returns the number of sessions that can be started at this point in time- Returns:
- number of sessions
-
isSessionToStandDown
protected boolean isSessionToStandDown()
This method returns true if current session should stop working on more messages- Returns:
-
getActiveSessions
public int getActiveSessions()
- Specified by:
getActiveSessions
in interfaceTransactionManagerMBean
-
getPausedCounter
public int getPausedCounter()
- Specified by:
getPausedCounter
in interfaceTransactionManagerMBean
-
getActiveTransactions
public int getActiveTransactions()
- Specified by:
getActiveTransactions
in interfaceTransactionManagerMBean
-
getMaxSessions
public int getMaxSessions()
- Specified by:
getMaxSessions
in interfaceTransactionManagerMBean
-
getSerializable
public static java.io.Serializable getSerializable()
-
getContext
public static <T extends java.io.Serializable> T getContext()
-
getId
public static java.lang.Long getId()
-
-