com.sun.jini.outrigger
Class EntryRep

java.lang.Object
  extended by com.sun.jini.outrigger.EntryRep
All Implemented Interfaces:
LeasedResource, StorableObject, StorableResource, Serializable

 class EntryRep
extends Object
implements StorableResource, LeasedResource, Serializable

An EntryRep object contains a packaged Entry object for communication between the client and a JavaSpace.

Author:
Sun Microsystems, Inc.
See Also:
JavaSpace, Entry

Nested Class Summary
private static class EntryRep.FieldComparator
          Comparator for sorting fields.
 
Field Summary
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.
 
Constructor Summary
(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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

values

private MarshalledInstance[] values
The fields of the entry in marshalled form. Use null for null fields.


superclasses

private String[] superclasses

hashes

private long[] hashes

hash

private long hash

className

private String className

codebase

private String codebase

id

private Uuid id

expires

private transient long expires

integrity

private transient boolean integrity
true if the last time this object was unmarshalled integrity was being enforced, false otherwise.


comparator

private static final EntryRep.FieldComparator comparator
Comparator for sorting fields


matchAnyRep

private static final EntryRep matchAnyRep
This object represents the passing of a 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.


realClass

private transient Class realClass
The realClass object is transient because we neither need nor want it reconstituted on the other side. All we want is to be able to recreate it on the receiving client side. If it were not transient, not only would an unnecessary object creation occur, but it might force the download of the actual class to the server.


logger

private static final Logger logger
Logger for logging information about operations carried out in the client. Note, we hard code "com.sun.jini.outrigger" so we don't drag in OutriggerServerImpl to outrigger-dl.jar.


classHashes

private static WeakHashMap classHashes
Cached hash values for all classes we encounter. Weak hash used in case the class is GC'ed from the client's VM.


noArg

private static Class[] noArg
Used to look up no-arg constructors.

Constructor Detail

EntryRep

private EntryRep(Entry entry,
                 boolean validate)
          throws MarshalException
Create a serialized form of the entry. If 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".

Throws:
MarshalException

EntryRep

public EntryRep(Entry entry)
         throws MarshalException
Create a serialized form of the entry with our object's relevant fields set.

Throws:
MarshalException

EntryRep

EntryRep()
Used in recovery

Method Detail

shareWith

void shareWith(EntryRep other)
Set this entry's generic data to be shared with the 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.


getFields

private static Field[] getFields(Class cl)
Get the entry fields associated with the passed class and put them in a canonical order. The fields are sorted so that fields belonging to a superclasses are before fields belonging to subclasses and within a class fields are ordered lexicographically by their name.


findHash

private static Long findHash(Class clazz,
                             boolean marshaling)
                      throws MarshalException,
                             UnusableEntryException
Lookup the hash value for the given class. If it is not found in the cache, generate the hash for the class and save it.

Throws:
MarshalException
UnusableEntryException

ensureValidClass

private static void ensureValidClass(Class c)
Ensure that the entry class is valid, that is, that it has appropriate access. If not, throw IllegalArgumentException.


matchAnyEntryRep

static EntryRep matchAnyEntryRep()
The EntryRep that marks a ``match any'' request. This is used to represent a null template.


isMatchAny

private static boolean isMatchAny(EntryRep rep)
Return true if the given rep is that ``match any'' EntryRep.


matchAnyClassName

static String matchAnyClassName()
Return the class name that is used by the ``match any'' EntryRep


entry

Entry entry()
      throws UnusableEntryException
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.

Throws:
UnusableEntryException - One or more fields in the entry cannot be deserialized, or the class for the entry type itself cannot be deserialized.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public 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. This is not a template match -- see matches.

Overrides:
equals in class Object
See Also:
matches(com.sun.jini.outrigger.EntryRep)

usableField

private static boolean usableField(Field field)
Return true if the field is to be used for the entry. That is, return true if the field isn't transient, static, or final.

Throws:
IllegalArgumentException - The field is not transient, static, or final, but is primitive and hence not a proper field for an Entry.

id

Uuid id()
Return the ID.


pickID

void pickID()
Pick a random Uuid and set our id field to it.

Throws:
IllegalStateException - if this method has already been called.

value

public MarshalledInstance value(int fieldNum)
Return the MarshalledObject for the given field.


numFields

public int numFields()
Return the number of fields in this kind of entry.


classFor

public String classFor()
Return the class name for this entry.


superclasses

public String[] superclasses()
Return the array names of superclasses of this entry type.


getHash

long getHash()
Return the hash of this entry type.


getHashes

long[] getHashes()
Return the array of superclass hashes of this entry type.


matches

boolean matches(EntryRep other)
See if the other object matches the template object this represents. (Note that even though "this" is a template, it may have no wildcards -- a template can have all values.)


toString

public String toString()
Overrides:
toString in class Object

isAtLeastA

boolean isAtLeastA(String otherClass)
Return true if this entry represents an object that is at least the type of the otherClass.


readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
Use readObject method to capture whether or not integrity was being enforced when this object was unmarshalled, and to perform basic integrity checks.

Throws:
IOException
ClassNotFoundException

readObjectNoData

private void readObjectNoData()
                       throws InvalidObjectException
We should always have data in the stream, if this method gets called there is something wrong.

Throws:
InvalidObjectException

setExpiration

public void setExpiration(long newExpiration)
Description copied from interface: LeasedResource
Changes the expiration time of the lease.

Specified by:
setExpiration in interface LeasedResource
Parameters:
newExpiration - The new expiration time in milliseconds since the beginning of the epoch

getExpiration

public long getExpiration()
Description copied from interface: LeasedResource
Returns the expiration time of the lease.

Specified by:
getExpiration in interface LeasedResource
Returns:
The expiration time in milliseconds since the beginning of the epoch

getCookie

public Uuid getCookie()
Description copied from interface: LeasedResource
Returns the universally unique identifier associated with this lease. Any proxies for this lease that implement ReferentUuid should return this object from their getReferentUuid method and should base their implementation of equals on this object.

Specified by:
getCookie in interface LeasedResource

store

public void store(ObjectOutputStream out)
           throws IOException
Description copied from interface: StorableObject
Store the persistent fields

Specified by:
store in interface StorableObject
Throws:
IOException

restore

public void restore(ObjectInputStream in)
             throws IOException,
                    ClassNotFoundException
Description copied from interface: StorableObject
Restore the persistent fields

Specified by:
restore in interface StorableObject
Throws:
IOException
ClassNotFoundException

throwRuntime

private static RuntimeException throwRuntime(RuntimeException e)
Log and throw a runtime exception


throwNewMarshalException

private static MarshalException throwNewMarshalException(String msg,
                                                         Exception nested)
                                                  throws MarshalException
Construct, log, and throw a new MarshalException

Throws:
MarshalException

throwNewUnusableEntryException

private UnusableEntryException throwNewUnusableEntryException(Entry partial,
                                                              String[] badFields,
                                                              Throwable[] exceptions)
                                                       throws UnusableEntryException
Construct, log, and throw a new UnusableEntryException

Throws:
UnusableEntryException

throwNewUnusableEntryException

private static UnusableEntryException throwNewUnusableEntryException(Throwable nested)
                                                              throws UnusableEntryException
Construct, log, and throw a new UnusableEntryException, that raps a given exception.

Throws:
UnusableEntryException

throwNewUnusableEntryException

private static UnusableEntryException throwNewUnusableEntryException(String msg,
                                                                     Exception nested)
                                                              throws UnusableEntryException
Construct, log, and throw a new UnusableEntryException, that will rap a newly constructed UnmarshalException (that optional wraps a given exception).

Throws:
UnusableEntryException


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.