|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.fhg.igd.atlas.core.MemoryDB
Provides a memory databases which is used to store entries
of type MemoryDBEntry.
The entries are held in a TreeMap what guarantees
efficient management of this database structure. There exist two
indexes to access the entries: one sorted over the implicit names,
the other sorted over the timestamps. The first one is used for
the operations lookup, init, update, delete, refresh. The second
one is used for the implementation of a timeout mechanism, which
is needed to fulfill the requirements of the Location Service
Protocol (LSP), too.
This database can be used as part of a Location Service Server
(LSServer).
MemoryDBEntry,
StorageDB| Field Summary | |
protected SortedMap |
entries_
References to all entries of the database sorted over implicit names (in a TreeMap). |
protected boolean |
eventFlag_
If this flag is set, a StorageDBEvent ia
generated whenever this database is manipulated. |
protected EventReflector |
eventReflector_
The event reflector which is notified, after every successful request, which manipulates this database. |
private Object |
lock_
The internal lock object. |
protected Signals |
signals_
Used for for signaling between database and timeoutThread. |
protected long |
timeout_
Timeout for entries in milli seconds |
protected SortedMap |
timeoutIndex_
References to all entries of the database sorted over timestamps (in a TreeMap). |
protected Thread |
timeoutThread_
Thread that provides the timeout functionality. |
| Constructor Summary | |
MemoryDB(long timeout)
Creates a new instance of the database with the given timeout for its entries. |
|
| Method Summary | |
boolean |
delete(byte[] implicitName)
Deletes an existing entry with the given implicitName. |
boolean |
getEventFlag()
Returns the current state of the eventFlag_. |
EventReflector |
getEventReflector()
Returns the reference to the database's event reflector which is notified with StorageDBEvent objects
incrementally describing the state of the database. |
int |
getSize()
Returns the current number of entries in the database. |
long |
getTimeout()
Returns the timeout of entries in the database. |
protected byte[] |
getTimeoutIndex(MemoryDBEntry entry)
Creates an unique index key for the given entry
that allowes to sort entries over their timestamps. |
boolean |
init(byte[] implicitName,
URL contactAddress,
byte[] cookie)
Initializes a new entry with the given implicitName,
contactAddress and cookie. |
Set |
list(long timestamp)
Returns the content of the database as set of all entries with a timestamp newer then the given one. |
StorageDBImmutableEntry |
lookup(byte[] implicitName)
Returns the result of a lookup with the given implicitName as immutable entry. |
boolean |
refresh(byte[] implicitName)
Refreshes an existing entry with the given implicitName,
by updating the entries timestamp to the current time. |
void |
run()
This method represents the functionality of the timeout daemon. |
void |
setEventFlag(boolean flag)
Sets the eventFlag_ to enable respectively
disable the generation of events. |
void |
setTimeout(long timeout)
Sets the timeout of entries in the database. |
private void |
stop()
Stops the timeoutThread. |
String |
toString()
Returns the string representation of this database as list of its entries sorted over their implicit names. |
String |
toStringTimeout()
Returns the string representation of this database as list of its entries sorted over their timestamps. |
boolean |
update(byte[] implicitName,
URL contactAddress,
byte[] cookie)
Updates an existing entry with the given implicitName. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected EventReflector eventReflector_
protected long timeout_
protected SortedMap entries_
protected SortedMap timeoutIndex_
protected Thread timeoutThread_
protected Signals signals_
timeoutThread.
protected boolean eventFlag_
StorageDBEvent ia
generated whenever this database is manipulated.
private Object lock_
| Constructor Detail |
public MemoryDB(long timeout)
timeout for its entries.
timeout - The timeout in milli seconds.| Method Detail |
protected byte[] getTimeoutIndex(MemoryDBEntry entry)
entry
that allowes to sort entries over their timestamps.
The key is build out of the entry's timestamp and its
unique implicit name. (It's not possible to use only
the timestamp as key, because several different entries
may have the same timestamp, and different entries in a
SortedMap must have different keys too.)
entry - The entry.
public EventReflector getEventReflector()
StorageDBEvent objects
incrementally describing the state of the database.
These envents are triggered every time the content of
the database has changed, iff the eventFlag_
is set.
getEventReflector in interface StorageDBpublic void setEventFlag(boolean flag)
eventFlag_ to enable respectively
disable the generation of events.
setEventFlag in interface StorageDBflag - The event flag to be set.public boolean getEventFlag()
eventFlag_.
getEventFlag in interface StorageDBpublic int getSize()
getSize in interface StorageDBInteger.MAX_VALUE,
iff the number of entries is larger than
Integer.MAX_VALUE.public StorageDBImmutableEntry lookup(byte[] implicitName)
implicitName as immutable entry.
lookup in interface StorageDBimplicitName - The implicit name.
implicitName or null
if the entry was not found.
public boolean init(byte[] implicitName,
URL contactAddress,
byte[] cookie)
implicitName,
contactAddress and cookie.
If an entry with the implicitName already exists,
false is returned.
init in interface StorageDBimplicitName - The implicit name.contactAddress - The contact address.cookie - The cookie.
true if has been created successfully;
false otherwise.
public boolean update(byte[] implicitName,
URL contactAddress,
byte[] cookie)
implicitName.
If no entry with the implicitName exists,
false is returned.
update in interface StorageDBimplicitName - The implicit name.contactAddress - The contact address.cookie - The cookie.
true if has been updated successfully;
false otherwise.public boolean delete(byte[] implicitName)
implicitName.
If no entry with the implicitName exists,
false is returned.
delete in interface StorageDBimplicitName - The implicit name.
true if has been deleted successfully;
false otherwise.public boolean refresh(byte[] implicitName)
implicitName,
by updating the entries timestamp to the current time.
If no entry with the implicitName exists,
false is returned.
refresh in interface StorageDBimplicitName - The implicit name.
true if has been deleted refreshed;
false otherwise.public Set list(long timestamp)
list in interface StorageDBtimestamp - The timestamp in milliseconds
since January 1, 1970, 00:00:00 GMT
StorageDBEntry.public void run()
run in interface Runnableprivate void stop()
timeoutThread.
public long getTimeout()
getTimeout in interface StorageDBpublic void setTimeout(long timeout)
timeoutThread_
is inactive, it will be started.
If the timeout is not 0 and the timeoutThread_
is active, it will be stopped.
setTimeout in interface StorageDBtimeout - The timeout in milli seconds.public String toString()
public String toStringTimeout()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||