|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
java.util.HashMap
org.jgroups.blocks.TransactionalHashtable
Hashtable which replicates its contents to all members of the group. Reads and writes can optionally be forced to acquire locks (r/w locks) to ensure total serializability between replicas. The update modes can be chosen per method and are (in order of cost)
Nested Class Summary | |
static class |
TransactionalHashtable.Data
Class used to transport updates to all replicas |
static interface |
TransactionalHashtable.Notification
|
Field Summary | |
protected boolean |
auto_commit
|
protected Channel |
channel
|
protected boolean |
default_sync_repl
|
protected long |
default_sync_repl_timeout
|
protected java.lang.String |
groupname
|
protected Address |
local_addr
|
protected long |
lock_acquisition_timeout
|
protected long |
lock_lease_timeout
|
protected Log |
log
|
protected java.util.List |
notifs
|
protected java.lang.String |
properties
|
protected ReplicationManager |
repl_mgr
|
protected java.util.HashMap |
row_locks
|
protected long |
state_timeout
|
protected RWLock |
table_lock
|
protected int |
transaction_mode
|
Constructor Summary | |
TransactionalHashtable(java.lang.String groupname,
java.lang.String properties,
long state_timeout)
|
|
TransactionalHashtable(java.lang.String groupname,
java.lang.String properties,
long state_timeout,
int initialCapacity)
|
|
TransactionalHashtable(java.lang.String groupname,
java.lang.String properties,
long state_timeout,
int initialCapacity,
float loadFactor)
|
|
TransactionalHashtable(java.lang.String groupname,
java.lang.String properties,
long state_timeout,
java.util.Map m)
|
Method Summary | |
void |
addNotifier(TransactionalHashtable.Notification n)
|
void |
begin()
Starts a new transaction and associates it with the current thread. |
void |
begin(int transaction_mode)
Starts a new transaction and associates it with the current thread. |
protected void |
checkResults(RspList rsps)
Checks whether responses from members contain exceptions or timeouts. |
void |
clear()
Replicates the update to all members. |
void |
clear(boolean synchronous,
long timeout)
Replicates the update to all members. |
void |
clear(long sync_timeout,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean commit)
Replicated the update to all members, and use locks at each member to ensure serializability. |
java.lang.Object |
clone()
|
void |
commit()
Commits all modifications done in the current transaction (kept in temporary storage) to the hashtable. |
void |
commit(Xid transaction)
Commit the modifications to the locally replicated data and release all locks. |
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
java.util.Set |
entrySet()
|
java.lang.Object |
get(java.lang.Object key)
|
boolean |
getAutoCommit()
|
static Xid |
getCurrentTransaction()
Returns the transaction associated with the current thread. |
long |
getDefaultSyncReplTimeout()
|
long |
getLockAcquisitionTimeout()
|
long |
getLockLeaseTimeout()
|
byte[] |
getState()
TODO: use read lock on entire hashmap while making copy |
int |
getTransactionMode()
|
protected java.lang.Object |
handleClear(Xid transaction,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean use_locks)
|
protected java.lang.Object |
handlePut(java.io.Serializable key,
java.io.Serializable value,
Xid transaction,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean use_locks)
|
protected java.lang.Object |
handlePutAll(java.util.Map map,
Xid transaction,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean use_locks)
|
protected java.lang.Object |
handleRemove(java.io.Serializable key,
Xid transaction,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean use_locks)
|
protected void |
initChannel(java.lang.String groupname,
java.lang.String properties,
long state_timeout)
|
boolean |
isDefaultSyncRepl()
|
java.util.Set |
keySet()
|
void |
lclear()
|
java.lang.Object |
lput(java.lang.Object key,
java.lang.Object value)
|
void |
lputAll(java.util.Map m)
|
java.lang.Object |
lremove(java.lang.Object key,
java.lang.Object value)
|
static void |
main(java.lang.String[] args)
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Replicates the update to all members. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value,
boolean synchronous,
long timeout)
Replicates the update to all members. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value,
long sync_timeout,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean commit)
Replicates the update to all members, and use locks at each member to ensure serializability. |
void |
putAll(java.util.Map m)
Replicates the update to all members. |
void |
putAll(java.util.Map m,
boolean synchronous,
long timeout)
Replicates the update to all members. |
void |
putAll(java.util.Map m,
long sync_timeout,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean commit)
Replicated the update to all members, and use locks at each member to ensure serializability. |
void |
receive(Message msg)
|
java.lang.Object |
receive(Xid transaction,
byte[] buf,
byte[] lock_info,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean use_locks)
Receives an update. |
java.lang.Object |
remove(java.lang.Object key)
Replicates the update to all members. |
java.lang.Object |
remove(java.lang.Object key,
boolean synchronous,
long timeout)
Replicates the update to all members. |
java.lang.Object |
remove(java.lang.Object key,
long sync_timeout,
long lock_acquisition_timeout,
long lock_lease_timeout,
boolean commit)
Replicated the update to all members, and use locks at each member to ensure serializability. |
void |
rollback()
Discards all changes done within the current transaction. |
void |
rollback(Xid transaction)
Discard all modifications and release all locks. |
void |
setAutoCommit(boolean b)
|
void |
setDefaultSyncRepl(boolean b)
Sets the default replication mode. |
void |
setDefaultSyncReplTimeout(long timeout)
|
void |
setLockAcquisitionTimeout(long l)
|
void |
setLockLeaseTimeout(long l)
|
void |
setMembershipListener(MembershipListener ml)
|
void |
setState(byte[] state)
TODO: use write lock on entire hashmap to set state |
void |
setTransactionMode(int m)
|
void |
stop()
Leaves the group. |
java.util.Collection |
values()
|
Methods inherited from class java.util.HashMap |
isEmpty, size |
Methods inherited from class java.util.AbstractMap |
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
Field Detail |
protected ReplicationManager repl_mgr
protected Channel channel
protected Address local_addr
protected java.lang.String groupname
protected java.lang.String properties
protected long state_timeout
protected boolean default_sync_repl
protected long default_sync_repl_timeout
protected long lock_acquisition_timeout
protected long lock_lease_timeout
protected int transaction_mode
protected RWLock table_lock
protected java.util.HashMap row_locks
protected boolean auto_commit
protected java.util.List notifs
protected Log log
Constructor Detail |
public TransactionalHashtable(java.lang.String groupname, java.lang.String properties, long state_timeout) throws java.lang.Exception
public TransactionalHashtable(java.lang.String groupname, java.lang.String properties, long state_timeout, java.util.Map m) throws java.lang.Exception
public TransactionalHashtable(java.lang.String groupname, java.lang.String properties, long state_timeout, int initialCapacity) throws java.lang.Exception
public TransactionalHashtable(java.lang.String groupname, java.lang.String properties, long state_timeout, int initialCapacity, float loadFactor) throws java.lang.Exception
Method Detail |
public void addNotifier(TransactionalHashtable.Notification n)
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
default_sync_repl_timeout
the update will be sent synchronously or asynchronously
put
in interface java.util.Map
key
- The key to be set. Needs to be serializable. Can be null.value
- The value to be set. Needs to be serializable. Can be null.
public java.lang.Object put(java.lang.Object key, java.lang.Object value, boolean synchronous, long timeout)
key
- The key to be set. Needs to be serializable. Can be null.value
- The value to be set. Needs to be serializable. Can be null.synchronous
- If true the update will be synchronous, ie. the caller will block until all responses
have been received. If timeout
is 0, we will block indefinitely (until all
responses have been received), otherwise the call is guaranteed to return after at most
timeout
milliseconds. If false, the call will be asynchronous.timeout
- The number of milliseconds to wait for a synchronous call. 0 means to wait forever.
This parameter is not used if synchronous
is false.
public java.lang.Object put(java.lang.Object key, java.lang.Object value, long sync_timeout, long lock_acquisition_timeout, long lock_lease_timeout, boolean commit) throws LockingException, TimeoutException
This call can be one of many inside the same transaction, or it may be the only one. In the first case, the
caller is responsible to call commit() or rollback() once the transaction is done. In the latter case, the
transaction can be committed by setting commit
to true.
A transaction (Xid) is always associated with the current thread. If this call is invoked, and there is no
transaction associated with the current thread, a default transaction will be created. Otherwise the current
transaction will be used.
key
- The key to be set. Needs to be serializable. Can be null.value
- The value to be set. Needs to be serializable. Can be null.sync_timeout
- Max number of milliseconds to wait for all responses. Note that this needs to be higher
than lock_acquisition_timeout
. 0 means to wait forever for all responses.lock_acquisition_timeout
- Number of milliseonds to wait until a lock becomes available. Needs to be lower
than sync_timeout
. 0 means to wait forever. 0 will block
forever in case of deadlocks. Once we have deadlock detection in place,
this parameter may be deprecated.lock_lease_timeout
- Number of milliseonds until a lock is released automatically (if not released
before). Not currently used.commit
- If true the transaction will be committed after this call if the call was successful.
LockingException
- Throw when one or more of the members failed acquiring the lock within
lock_acquisition_timeout
milliseconds
TimeoutException
- Thrown when one or more of the members didn't send a response. LockingExceptions
take precedence over TimeoutExceptions, e.g. if we have both locking and timeout
exceptions, a LockingException will be thrown.public java.lang.Object lput(java.lang.Object key, java.lang.Object value) throws LockingException, TimeoutException
LockingException
TimeoutException
public void putAll(java.util.Map m)
default_sync_repl_timeout
the update will be sent synchronously or asynchronously
putAll
in interface java.util.Map
m
- The map to be set. All entries need to be serializable. Cannot be null.public void putAll(java.util.Map m, boolean synchronous, long timeout)
m
- The map to be set. All entries need to be serializable. Cannot be null.synchronous
- If true the update will be synchronous, ie. the caller will block until all responses
have been received. If timeout
is 0, we will block indefinitely (until all
responses have been received), otherwise the call is guaranteed to return after at most
timeout
milliseconds. If false, the call will be asynchronous.timeout
- The number of milliseconds to wait for a synchronous call. 0 means to wait forever.
This parameter is not used if synchronous
is false.public void putAll(java.util.Map m, long sync_timeout, long lock_acquisition_timeout, long lock_lease_timeout, boolean commit) throws LockingException, TimeoutException
This call can be one of many inside the same transaction, or it may be the only one. In the first case, the
caller is responsible to call commit() or rollback() once the transaction is done. In the latter case, the
transaction can be committed by setting commit
to true.
A transaction (Xid) is always associated with the current thread. If this call is invoked, and there is no
transaction associated with the current thread, a default transaction will be created. Otherwise the current
transaction will be used.
m
- The map to be set. All entries need to be serializable. Cannot be null.sync_timeout
- Max number of milliseconds to wait for all responses. Note that this needs to be higher
than lock_acquisition_timeout
. 0 means to wait forever for all responses.lock_acquisition_timeout
- Number of milliseonds to wait until a lock becomes available. Needs to be lower
than sync_timeout
. 0 means to wait forever. 0 will block
forever in case of deadlocks. Once we have deadlock detection in place,
this parameter may be deprecated.lock_lease_timeout
- Number of milliseonds until a lock is released automatically (if not released
before). Not currently used.commit
- If true the transaction will be committed after this call if the call was successful.
LockingException
- Throw when one or more of the members failed acquiring the lock within
lock_acquisition_timeout
milliseconds
TimeoutException
- Thrown when one or more of the members didn't send a response. LockingExceptions
take precedence over TimeoutExceptions, e.g. if we have both locking and timeout
exceptions, a LockingException will be thrown.public void lputAll(java.util.Map m) throws LockingException, TimeoutException
LockingException
TimeoutException
public java.lang.Object remove(java.lang.Object key)
default_sync_repl_timeout
the update will be sent synchronously or asynchronously
remove
in interface java.util.Map
key
- The key to be set. Needs to be serializable. Can be null.
public java.lang.Object remove(java.lang.Object key, boolean synchronous, long timeout)
key
- The key to be set. Needs to be serializable. Can be null.synchronous
- If true the update will be synchronous, ie. the caller will block until all responses
have been received. If timeout
is 0, we will block indefinitely (until all
responses have been received), otherwise the call is guaranteed to return after at most
timeout
milliseconds. If false, the call will be asynchronous.timeout
- The number of milliseconds to wait for a synchronous call. 0 means to wait forever.
This parameter is not used if synchronous
is false.
public java.lang.Object remove(java.lang.Object key, long sync_timeout, long lock_acquisition_timeout, long lock_lease_timeout, boolean commit) throws LockingException, TimeoutException
This call can be one of many inside the same transaction, or it may be the only one. In the first case, the
caller is responsible to call commit() or rollback() once the transaction is done. In the latter case, the
transaction can be committed by setting commit
to true.
A transaction (Xid) is always associated with the current thread. If this call is invoked, and there is no
transaction associated with the current thread, a default transaction will be created. Otherwise the current
transaction will be used.
key
- The key to be set. Needs to be serializable. Can be null.sync_timeout
- Max number of milliseconds to wait for all responses. Note that this needs to be higher
than lock_acquisition_timeout
. 0 means to wait forever for all responses.lock_acquisition_timeout
- Number of milliseonds to wait until a lock becomes available. Needs to be lower
than sync_timeout
. 0 means to wait forever. 0 will block
forever in case of deadlocks. Once we have deadlock detection in place,
this parameter may be deprecated.lock_lease_timeout
- Number of milliseonds until a lock is released automatically (if not released
before). Not currently used.commit
- If true the transaction will be committed after this call if the call was successful.
LockingException
- Throw when one or more of the members failed acquiring the lock within
lock_acquisition_timeout
milliseconds
TimeoutException
- Thrown when one or more of the members didn't send a response. LockingExceptions
take precedence over TimeoutExceptions, e.g. if we have both locking and timeout
exceptions, a LockingException will be thrown.public java.lang.Object lremove(java.lang.Object key, java.lang.Object value) throws LockingException, TimeoutException
LockingException
TimeoutException
public void clear()
default_sync_repl_timeout
the update will be sent synchronously or asynchronously
clear
in interface java.util.Map
public void clear(boolean synchronous, long timeout)
synchronous
- If true the update will be synchronous, ie. the caller will block until all responses
have been received. If timeout
is 0, we will block indefinitely (until all
responses have been received), otherwise the call is guaranteed to return after at most
timeout
milliseconds. If false, the call will be asynchronous.timeout
- The number of milliseconds to wait for a synchronous call. 0 means to wait forever.
This parameter is not used if synchronous
is false.public void clear(long sync_timeout, long lock_acquisition_timeout, long lock_lease_timeout, boolean commit) throws LockingException, TimeoutException
This call can be one of many inside the same transaction, or it may be the only one. In the first case, the
caller is responsible to call commit() or rollback() once the transaction is done. In the latter case, the
transaction can be committed by setting commit
to true.
A transaction (Xid) is always associated with the current thread. If this call is invoked, and there is no
transaction associated with the current thread, a default transaction will be created. Otherwise the current
transaction will be used.
sync_timeout
- Max number of milliseconds to wait for all responses. Note that this needs to be higher
than lock_acquisition_timeout
. 0 means to wait forever for all responses.lock_acquisition_timeout
- Number of milliseonds to wait until a lock becomes available. Needs to be lower
than sync_timeout
. 0 means to wait forever. 0 will block
forever in case of deadlocks. Once we have deadlock detection in place,
this parameter may be deprecated.lock_lease_timeout
- Number of milliseonds until a lock is released automatically (if not released
before). Not currently used.commit
- If true the transaction will be committed after this call if the call was successful.
LockingException
- Throw when one or more of the members failed acquiring the lock within
lock_acquisition_timeout
milliseconds
TimeoutException
- Thrown when one or more of the members didn't send a response. LockingExceptions
take precedence over TimeoutExceptions, e.g. if we have both locking and timeout
exceptions, a LockingException will be thrown.public void lclear() throws LockingException, TimeoutException
LockingException
TimeoutException
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
public java.lang.Object clone()
public java.util.Set keySet()
keySet
in interface java.util.Map
public java.util.Collection values()
values
in interface java.util.Map
public java.util.Set entrySet()
entrySet
in interface java.util.Map
public java.lang.Object receive(Xid transaction, byte[] buf, byte[] lock_info, long lock_acquisition_timeout, long lock_lease_timeout, boolean use_locks) throws LockingException, UpdateException
use_locks
):
receive
in interface ReplicationReceiver
transaction
- The transaction under which all locks will be acquired. Will be null if no locks are used (e.g.
use_locks
is null).buf
- The data to be modified. In case of a database, this data would have to be stored in stable storage,
and would only be applied on a commit()
. In case of a distributed replicated in-memory
data structure, the update might be applied directly and the subsequent commit() or rollback() might
be ignored. Note that this argument may contain the resource to be locked; in this case the
lock_info
parameter might be null.lock_info
- Information about the resource(s) to be locked. Will be null if no locks are used (e.g.
use_locks
is null). Can also be null even if locks are used, e.g. when the resource(s)
to be locked are an implicit part of data
.lock_acquisition_timeout
- If locks are used, the number of milliseconds to wait for a lock to be acquired.
If this time elapses, a TimeoutException will be thrown. A value of 0 means
to wait forever. If use_locks
is false, this value is ignored.lock_lease_timeout
- The number of milliseconds to hold on to the lock, once it is acquired. A value of 0
means to never release the lock until commit() or rollback() are called.use_locks
- Whether to use locking or not. If this value is false, all lock-related arguments will be
ignored, regardless of whether they are non-null.
ReplicationManager.send
and the receiver. If no special value should be returned, null can be returned. Note that in the
latter case, null is still treated as a response (in the synchronous call).
UpdateException
- Thrown when the update fails (application semantics)
LockingException
- Thrown when a lock on a resource cannot be acquiredpublic void commit(Xid transaction)
ReplicationReceiver
commit
in interface ReplicationReceiver
public void rollback(Xid transaction)
ReplicationReceiver
rollback
in interface ReplicationReceiver
public void receive(Message msg)
receive
in interface MessageListener
public byte[] getState()
getState
in interface MessageListener
public void setState(byte[] state)
setState
in interface MessageListener
public void stop()
public void setMembershipListener(MembershipListener ml)
public boolean isDefaultSyncRepl()
public void setDefaultSyncRepl(boolean b)
public long getDefaultSyncReplTimeout()
public void setDefaultSyncReplTimeout(long timeout)
public boolean getAutoCommit()
public void setAutoCommit(boolean b)
public long getLockAcquisitionTimeout()
public void setLockAcquisitionTimeout(long l)
public long getLockLeaseTimeout()
public void setLockLeaseTimeout(long l)
public int getTransactionMode()
public void setTransactionMode(int m)
public void begin() throws java.lang.Exception
java.lang.Exception
public void begin(int transaction_mode) throws java.lang.Exception
transaction_mode
- Mode in which the transaction should run. Possible values are Xid.DIRTY_READS,
Xid.READ_COMMITTED, Xid.REPEATABLE_READ and Xid.SERIALIZABLE
java.lang.Exception
public void commit()
public void rollback()
public static Xid getCurrentTransaction()
protected void initChannel(java.lang.String groupname, java.lang.String properties, long state_timeout) throws java.lang.Exception
java.lang.Exception
protected java.lang.Object handlePut(java.io.Serializable key, java.io.Serializable value, Xid transaction, long lock_acquisition_timeout, long lock_lease_timeout, boolean use_locks) throws LockingException, UpdateException
LockingException
UpdateException
protected java.lang.Object handlePutAll(java.util.Map map, Xid transaction, long lock_acquisition_timeout, long lock_lease_timeout, boolean use_locks) throws LockingException, UpdateException
LockingException
UpdateException
protected java.lang.Object handleRemove(java.io.Serializable key, Xid transaction, long lock_acquisition_timeout, long lock_lease_timeout, boolean use_locks) throws LockingException, UpdateException
LockingException
UpdateException
protected java.lang.Object handleClear(Xid transaction, long lock_acquisition_timeout, long lock_lease_timeout, boolean use_locks) throws LockingException, UpdateException
LockingException
UpdateException
protected void checkResults(RspList rsps) throws LockingException, TimeoutException
LockingException
TimeoutException
public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |