|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.oddjob.sql.SQLKeeperService
public class SQLKeeperService
Keeper
that uses a database
table.
The keeper uses a simple 'first to insert' a row wins methodology for deciding winner and looser. This is quite primitive and decides that any exception from the insert operation is a duplicate key exception and therefore a looser.
A LoosingOutcome
will continue to Poll the database (for as long
as it has listeners) until the work is complete. The default polling schedule
polls every 5 seconds indefinitely. The pollSchedule
property
can be used to poll for a limited time, after which it flags an exception
state. This could be used by loosing servers to flag the winner is taking
too long and has possibly crashed.
This is an example of the SQL that would create a suitable table.
CREATE TABLE oddjob_grabbable(
key VARCHAR(32),
instance VARCHAR(32),
winner VARCHAR(32),
complete boolean,
CONSTRAINT oddjob_pk PRIMARY KEY (key, instance))
This service does not tidy up the database so rows will grow indefinitely. A separate tidy job should be implemented.
Field Summary | |
---|---|
static String |
TABLE_NAME
The default table name. |
Constructor Summary | |
---|---|
SQLKeeperService()
|
Method Summary | |
---|---|
protected PreparedStatement |
createInsertStatementFor(Connection connection,
String keeperKey,
String ourIdentifier,
Object instanceIdentifier)
Provide a PreparedStatement for the insert operation. |
protected PreparedStatement |
createQueryStatementFor(Connection connection,
String keeperKey,
Object instanceIdentifier)
Create the PreparedStatement for the query of who won and is work complete yet. |
protected PreparedStatement |
createUpdateStatementFor(Connection connection,
String keeperKey,
Object instanceIdentifier)
Create the PreparedStatemenet for updating won work is complete. |
Keeper |
getKeeper(String keeperKey)
Provide a Keeper . |
String |
getName()
|
int |
getPollerCount()
|
Schedule |
getPollSchedule()
|
String |
getTable()
|
void |
setConnection(Connection connection)
Set the connection. |
void |
setName(String name)
|
void |
setPollSchedule(Schedule schedule)
|
void |
setScheduleExecutorService(ScheduledExecutorService scheduler)
|
void |
setTable(String table)
|
void |
start()
Start the service. |
void |
stop()
Stop the service. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String TABLE_NAME
Constructor Detail |
---|
public SQLKeeperService()
Method Detail |
---|
public void start() throws SQLException
SQLException
public void stop() throws SQLException
SQLException
public Keeper getKeeper(String keeperKey)
Keeper
.
keeperKey
- The keepers key. Must not be null.
public String getName()
public void setName(String name)
public void setConnection(Connection connection) throws SQLException
connection
- The connection.
SQLException
public int getPollerCount()
Property: pollerCount
Description: The number of outstanding loosing outcome's polling of the database that are still in progress.
protected PreparedStatement createInsertStatementFor(Connection connection, String keeperKey, String ourIdentifier, Object instanceIdentifier) throws SQLException
connection
- keeperKey
- ourIdentifier
- instanceIdentifier
-
SQLException
protected PreparedStatement createQueryStatementFor(Connection connection, String keeperKey, Object instanceIdentifier) throws SQLException
connection
- keeperKey
- instanceIdentifier
-
SQLException
protected PreparedStatement createUpdateStatementFor(Connection connection, String keeperKey, Object instanceIdentifier) throws SQLException
connection
- keeperKey
- instanceIdentifier
-
SQLException
public String getTable()
public void setTable(String table)
public Schedule getPollSchedule()
public void setPollSchedule(Schedule schedule)
@Inject public void setScheduleExecutorService(ScheduledExecutorService scheduler)
public String toString()
toString
in class Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |