|
xmlBlaster 2.2.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xmlBlaster.contrib.dbwatcher.DbWatcher
public class DbWatcher
This is the core processor class to handle database observation.
We handle detected changes of the observed target, typically a database table,
and forward them to the I_ChangePublisher
implementation,
typically a message oriented middleware (MoM).
The changes are XML formatted as implemented by the
I_DataConverter
plugin.
This class loads all plugins by reflection and starts them. Each plugin has its specific configuration paramaters. Descriptions thereof you find in the plugins documentation.
To get you quickly going have a look into Example.java
Configuration:I_DbPool
which defaults to org.xmlBlaster.contrib.db.DbPoolI_DataConverter
which defaults to org.xmlBlaster.contrib.dbwatcher.convert.ResultSetToXmlConverterI_ChangePublisher
which defaults to org.xmlBlaster.contrib.dbwatcher.mom.XmlBlasterPublisherI_ChangeDetector
which defaults to org.xmlBlaster.contrib.dbwatcher.detector.MD5ChangeDetectorI_AlertProducer
which defaults to org.xmlBlaster.contrib.dbwatcher.detector.AlertScheduler
Here you can configure multiple classes with a comma separated list.
Each of them can trigger an new check in parallel, for example
alertProducer.class=org.xmlBlaster.contrib.dbwatcher.mom.XmlBlasterPublisher,org.xmlBlaster.contrib.dbwatcher.detector.AlertSchedulery will check regularly via
the AlertScheduler and on message via XmlBlasterPublisher
org.xmlBlaster.contrib.dbwatcher.test.TestResultSetToXmlConverter
Field Summary | |
---|---|
private I_AlertProducer[] |
alertProducerArr
|
private int |
changeCount
|
private I_ChangeDetector |
changeDetector
|
private int |
collectedMessages
|
private I_DataConverter |
dataConverter
|
private I_DbPool |
dbPool
|
private I_Info |
info
|
private static java.util.logging.Logger |
log
|
private int |
maxCollectedMessages
|
private long |
maxMessageSize
|
private I_ChangePublisher |
publisher
|
Constructor Summary | |
---|---|
DbWatcher()
Default constructor, you need to call init(org.xmlBlaster.contrib.I_Info) thereafter. |
|
DbWatcher(I_Info info)
Convenience constructor, creates a processor for changes, calls init(org.xmlBlaster.contrib.I_Info) . |
Method Summary | |
---|---|
private void |
clearMessageAttributesAfterPublish(java.util.Map attributeMap)
|
private void |
doPostStatement()
Convenience Method which executes a post statement if needed. |
I_ChangeDetector |
getChangeDetector()
Access the change detector handele. |
static I_ChangePublisher |
getChangePublisher(I_Info info)
|
static I_DbPool |
getDbInfoPool(I_Info info)
We scan for dbinfo.* properties and replace it with db.* in a second info object to use for the configuration of the DbPool. |
static I_DbPool |
getDbPool(I_Info info)
|
I_ChangePublisher |
getMom()
Access the MoM handele. |
void |
hasChanged(ChangeEvent changeEvent)
Is called for every data source changed. |
private boolean |
hasChanged(ChangeEvent changeEvent,
boolean recursion)
Publishes a message if it has changed and if it has not to be ignored. |
void |
init(I_Info info)
Creates a processor for changes. |
int |
publishMessagesFromStmt(java.lang.String stmt,
boolean useGroupCol,
ChangeEvent changeEvent,
java.sql.Connection conn)
Does a SQL query with stmt and sends all ResultSets to I_ChangePublisher . |
static java.sql.Connection |
releaseWithCommit(java.sql.Connection conn,
I_DbPool pool)
Helper method used for cleanup: invoke conn = DbWatcher. |
static java.lang.String |
replaceVariable(java.lang.String text,
java.lang.String token)
Replace e.g. |
void |
shutdown()
Cleanup resources. |
void |
startAlertProducers()
Start the work. |
void |
stopAlertProducers()
Suspend processing. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.util.logging.Logger log
private I_Info info
private I_DataConverter dataConverter
private I_ChangePublisher publisher
private I_ChangeDetector changeDetector
private I_DbPool dbPool
private I_AlertProducer[] alertProducerArr
private int changeCount
private int collectedMessages
private int maxCollectedMessages
private long maxMessageSize
Constructor Detail |
---|
public DbWatcher()
init(org.xmlBlaster.contrib.I_Info)
thereafter.
public DbWatcher(I_Info info) throws java.lang.Exception
init(org.xmlBlaster.contrib.I_Info)
.
info
- Configuration
java.lang.Exception
- Can be of any typeMethod Detail |
---|
public static I_ChangePublisher getChangePublisher(I_Info info) throws java.lang.Exception
java.lang.Exception
public static I_DbPool getDbPool(I_Info info) throws java.lang.Exception
java.lang.Exception
public static I_DbPool getDbInfoPool(I_Info info) throws java.lang.Exception
info
-
java.lang.Exception
public void init(I_Info info) throws java.lang.Exception
startAlertProducers()
info
- Configuration
java.lang.Exception
- Can be of any typepublic void startAlertProducers()
public void stopAlertProducers()
public I_ChangePublisher getMom()
public I_ChangeDetector getChangeDetector()
public void hasChanged(ChangeEvent changeEvent)
I_ChangeListener
hasChanged
in interface I_ChangeListener
changeEvent
- Transports all needed information about the changeI_ChangeListener.hasChanged(ChangeEvent)
private final void clearMessageAttributesAfterPublish(java.util.Map attributeMap)
private boolean hasChanged(ChangeEvent changeEvent, boolean recursion)
changeEvent
- The event datarecursion
- To detect recursion
private final void doPostStatement()
public int publishMessagesFromStmt(java.lang.String stmt, boolean useGroupCol, ChangeEvent changeEvent, java.sql.Connection conn) throws java.lang.Exception
I_ChangeListener
I_ChangePublisher
.
The messages are formatted by the configured I_DataConverter
plugin.
Note: This is a common convenienve function, in a future refactoring we should have this method in a separate interface.
publishMessagesFromStmt
in interface I_ChangeListener
stmt
- The SQL query string (with/without grouping)useGroupCol
- If true we send a message for each
ChangeEvent.getGroupColName()
changechangeEvent
- The reason to sendconn
- The JDBC connection, if null we get one ourself in auto commit mode
java.lang.Exception
- of any typeI_ChangeListener.publishMessagesFromStmt(java.lang.String, boolean, org.xmlBlaster.contrib.dbwatcher.ChangeEvent, java.sql.Connection)
public static java.lang.String replaceVariable(java.lang.String text, java.lang.String token)
text
- The complete string which may contain zero to many ${...}
variables, if null we return nulltoken
- The replacement token, if null the original text is returned
public void shutdown() throws java.lang.Exception
shutdown
in interface I_ChangeListener
java.lang.Exception
- Can be of any typepublic static java.sql.Connection releaseWithCommit(java.sql.Connection conn, I_DbPool pool) throws java.lang.Exception
conn
- pool
-
java.lang.Exception
|
xmlBlaster 2.2.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |