class EntryRep extends Object implements StorableResource, LeasedResource, Serializable
EntryRep
object contains a packaged
Entry
object for communication between the client and a
JavaSpace
.Modifier and Type | Class and Description |
---|---|
private static class |
EntryRep.FieldComparator
Comparator for sorting fields.
|
Modifier and Type | Field and Description |
---|---|
private static WeakHashMap |
classHashes
Cached hash values for all classes we encounter.
|
private String |
className |
private String |
codebase |
private static EntryRep.FieldComparator |
comparator
Comparator for sorting fields
|
private long |
expires |
private long |
hash |
private long[] |
hashes |
private Uuid |
id |
private boolean |
integrity
true if the last time this object was unmarshalled
integrity was being enforced, false otherwise. |
private static Logger |
logger
Logger for logging information about operations carried out in
the client.
|
private static EntryRep |
matchAnyRep
This object represents the passing of a
null
parameter as a template, which is designed to match any entry. |
private static Class[] |
noArg
Used to look up no-arg constructors.
|
private Class |
realClass
The realClass object is transient because we neither need nor want
it reconstituted on the other side.
|
(package private) static long |
serialVersionUID |
private String[] |
superclasses |
private MarshalledInstance[] |
values
The fields of the entry in marshalled form.
|
Modifier | Constructor and Description |
---|---|
(package private) |
EntryRep()
Used in recovery
|
|
EntryRep(Entry entry)
Create a serialized form of the entry with our object's
relevant fields set.
|
private |
EntryRep(Entry entry,
boolean validate)
Create a serialized form of the entry.
|
Modifier and Type | Method and Description |
---|---|
String |
classFor()
Return the class name for this entry.
|
private static void |
ensureValidClass(Class c)
Ensure that the entry class is valid, that is, that it has appropriate
access.
|
(package private) Entry |
entry()
Return an
Entry object built out of this
EntryRep This is used by the client-side proxy to
convert the EntryRep it gets from the space server
into the actual Entry object it represents. |
boolean |
equals(Object o)
To be equal, the other object must by an
EntryRep for
an object of the same class with the same values for each field. |
private static Long |
findHash(Class clazz,
boolean marshaling)
Lookup the hash value for the given class.
|
Uuid |
getCookie()
Returns the universally unique identifier associated with this
lease.
|
long |
getExpiration()
Returns the expiration time of the lease.
|
private static Field[] |
getFields(Class cl)
Get the entry fields associated with the passed class and put
them in a canonical order.
|
(package private) long |
getHash()
Return the hash of this entry type.
|
(package private) long[] |
getHashes()
Return the array of superclass hashes of this entry type.
|
int |
hashCode() |
(package private) Uuid |
id()
Return the ID.
|
(package private) boolean |
isAtLeastA(String otherClass)
Return
true if this entry represents an object that
is at least the type of the otherClass . |
private static boolean |
isMatchAny(EntryRep rep)
Return
true if the given rep is that ``match any''
EntryRep . |
(package private) static String |
matchAnyClassName()
Return the class name that is used by the ``match any'' EntryRep
|
(package private) static EntryRep |
matchAnyEntryRep()
The
EntryRep that marks a ``match any'' request. |
(package private) boolean |
matches(EntryRep other)
See if the other object matches the template object this
represents.
|
int |
numFields()
Return the number of fields in this kind of entry.
|
(package private) void |
pickID()
Pick a random
Uuid and set our id field to it. |
private void |
readObject(ObjectInputStream in)
Use
readObject method to capture whether or
not integrity was being enforced when this object was
unmarshalled, and to perform basic integrity checks. |
private void |
readObjectNoData()
We should always have data in the stream, if this method
gets called there is something wrong.
|
void |
restore(ObjectInputStream in)
Restore the persistent fields
|
void |
setExpiration(long newExpiration)
Changes the expiration time of the lease.
|
(package private) void |
shareWith(EntryRep other)
Set this entry's generic data to be shared with the
other
object. |
void |
store(ObjectOutputStream out)
Store the persistent fields
|
String[] |
superclasses()
Return the array names of superclasses of this entry type.
|
private static MarshalException |
throwNewMarshalException(String msg,
Exception nested)
Construct, log, and throw a new MarshalException
|
private UnusableEntryException |
throwNewUnusableEntryException(Entry partial,
String[] badFields,
Throwable[] exceptions)
Construct, log, and throw a new UnusableEntryException
|
private static UnusableEntryException |
throwNewUnusableEntryException(String msg,
Exception nested)
Construct, log, and throw a new UnusableEntryException, that
will rap a newly constructed UnmarshalException (that optional
wraps a given exception).
|
private static UnusableEntryException |
throwNewUnusableEntryException(Throwable nested)
Construct, log, and throw a new UnusableEntryException, that
raps a given exception.
|
private static RuntimeException |
throwRuntime(RuntimeException e)
Log and throw a runtime exception
|
String |
toString() |
private static boolean |
usableField(Field field)
Return
true if the field is to be used for the
entry. |
MarshalledInstance |
value(int fieldNum)
Return the
MarshalledObject for the given field. |
static final long serialVersionUID
private MarshalledInstance[] values
null
for null
fields.private String[] superclasses
private long[] hashes
private long hash
private String className
private String codebase
private Uuid id
private transient long expires
private transient boolean integrity
true
if the last time this object was unmarshalled
integrity was being enforced, false
otherwise.private static final EntryRep.FieldComparator comparator
private static final EntryRep matchAnyRep
null
parameter as a template, which is designed to match any entry.
When a null
is passed, it is replaced with this
rep, which is then handled specially in a few relevant places.private transient Class realClass
private static final Logger logger
private static WeakHashMap classHashes
private static Class[] noArg
private EntryRep(Entry entry, boolean validate) throws MarshalException
validate
is
true
, basic sanity checks are done on the class to
ensure that it meets the requirements to be an Entry
.
validate
is false
only when creating the
stand-in object for "match any", which is never actually marshalled
on the wire and so which doesn't need to be "proper".MarshalException
public EntryRep(Entry entry) throws MarshalException
MarshalException
EntryRep()
void shareWith(EntryRep other)
other
object. Those fields that are object references that will be the same
for all objects of the same type are shared this way.
Note that codebase
is not shared. If it were,
then the failure of one codebase could make all entries inaccessible.
Each entry is usable insofar as the codebase under which it was
written is usable.
private static Field[] getFields(Class cl)
private static Long findHash(Class clazz, boolean marshaling) throws MarshalException, UnusableEntryException
private static void ensureValidClass(Class c)
IllegalArgumentException
.static EntryRep matchAnyEntryRep()
EntryRep
that marks a ``match any'' request.
This is used to represent a null
template.private static boolean isMatchAny(EntryRep rep)
true
if the given rep is that ``match any''
EntryRep
.static String matchAnyClassName()
Entry entry() throws UnusableEntryException
Entry
object built out of this
EntryRep
This is used by the client-side proxy to
convert the EntryRep
it gets from the space server
into the actual Entry
object it represents.UnusableEntryException
- One or more fields in the entry cannot be
deserialized, or the class for the entry type
itself cannot be deserialized.public boolean equals(Object o)
EntryRep
for
an object of the same class with the same values for each field.
This is not a template match -- see matches
.equals
in class Object
matches(com.sun.jini.outrigger.EntryRep)
private static boolean usableField(Field field)
true
if the field is to be used for the
entry. That is, return true
if the field isn't
transient
, static
, or final
.IllegalArgumentException
- The field is not transient
,
static
, or final
, but
is primitive and hence not a proper field for
an Entry
.Uuid id()
void pickID()
Uuid
and set our id field to it.IllegalStateException
- if this method has already
been called.public MarshalledInstance value(int fieldNum)
MarshalledObject
for the given field.public int numFields()
public String classFor()
public String[] superclasses()
long getHash()
long[] getHashes()
boolean matches(EntryRep other)
boolean isAtLeastA(String otherClass)
true
if this entry represents an object that
is at least the type of the otherClass
.private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
readObject
method to capture whether or
not integrity was being enforced when this object was
unmarshalled, and to perform basic integrity checks.IOException
ClassNotFoundException
private void readObjectNoData() throws InvalidObjectException
InvalidObjectException
public void setExpiration(long newExpiration)
LeasedResource
setExpiration
in interface LeasedResource
newExpiration
- The new expiration time in milliseconds
since the beginning of the epochpublic long getExpiration()
LeasedResource
getExpiration
in interface LeasedResource
public Uuid getCookie()
LeasedResource
ReferentUuid
should return this object from their
getReferentUuid
method and should base their implementation of equals
on
this object.getCookie
in interface LeasedResource
public void store(ObjectOutputStream out) throws IOException
StorableObject
store
in interface StorableObject
IOException
public void restore(ObjectInputStream in) throws IOException, ClassNotFoundException
StorableObject
restore
in interface StorableObject
IOException
ClassNotFoundException
private static RuntimeException throwRuntime(RuntimeException e)
private static MarshalException throwNewMarshalException(String msg, Exception nested) throws MarshalException
MarshalException
private UnusableEntryException throwNewUnusableEntryException(Entry partial, String[] badFields, Throwable[] exceptions) throws UnusableEntryException
UnusableEntryException
private static UnusableEntryException throwNewUnusableEntryException(Throwable nested) throws UnusableEntryException
UnusableEntryException
private static UnusableEntryException throwNewUnusableEntryException(String msg, Exception nested) throws UnusableEntryException
UnusableEntryException
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.