T
- The type of objects to store in the mappublic class SharedPersistentMap<T> extends AbstractPersistentMap<T>
PersistentMap
whose contents are
shared by all users/programs executing in the same context (i.e.,
on the same CloudSpace server, or in the same current working directory
on an end-user machine). Its contents are persistent,
meaning that they will continue to be available from one
program run to the next. Its contents are shared meaning that
everyone using this class on the same CloudSpace server will see the
same set of keys and values--objects stored in this map will be visible
to everyone, as long as the same identifying key is used. Basically, it
is a shared container where you can store information semi-permanently, so
that your program(s) or anyone else's can access it again later.
A Map
is an object that maps keys to values. In a
PersistentMap
, the keys are Strings. You can think of
the keys in a persistent map as being string identifiers that you
can use to identify objects that you save now, and then recall again
in later programs (or separate executions of the same program).
A map cannot have any duplicate keys, and each unique key maps to at
most one value.
Other than the fact that a persistent map keeps its values from one
execution of a program to the next, you use it just like any other
Map
. The most basic operations are illustrated below.
SharedPersistentMap<UserProfile> map = ...; // Use put(key, value) to save a value under a given key map.put("stedwar2", someObject); // Use get(key) to look up the object saved for that key UserProfile profile = map.get("stedwar2");
Note that if you have saved an object under a given key, and later
modify that object in some way, you need to call put()
again in order for those new changes to be recorded in the map.
Modifier and Type | Field and Description |
---|---|
static String |
CONTEXT_OBJECT |
loader, typeAware
Constructor and Description |
---|
SharedPersistentMap(Class<T> genericClass)
Create a new map that associates keys with values of the specified
class.
|
SharedPersistentMap(Class<T> genericClass,
ClassLoader loader)
NOT FOR STUDENT USE.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Remove all of the key/value associations from this map.
|
protected String |
getCacheId(String uniqueId)
Get the ID used to store the context cache in the ZK browser session.
|
containsKey, containsValue, entrySet, get, getPersistentObject, isEmpty, keySet, put, putAll, remove, removePersistentObject, setPersistentObject, size, values
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
public static final String CONTEXT_OBJECT
public SharedPersistentMap(Class<T> genericClass)
Typical usage: if you want a shared persistent map that stores objects
of class Widget
, then:
SharedPersistentMapmap = new SharedPersistentMap (Widget.class);
genericClass
- The Class
object that represents the
generic type T
, the type of values
stored in this map.public SharedPersistentMap(Class<T> genericClass, ClassLoader loader)
genericClass
- Class typeloader
- custom class loader to use to load classespublic void clear()
Because the contents of this map might be shared among many users, you may not use this method in a program running in a multi-user context (i.e., it is forbidden on a CloudSpace server).
clear
in interface Map<String,T>
clear
in interface PersistentMap<T>
clear
in class AbstractPersistentMap<T>
protected String getCacheId(String uniqueId)
getCacheId
in class AbstractPersistentMap<T>