|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--com.ibm.tspaces.Field
|
+--com.ibm.tspaces.FieldPS
FieldPS is a subclass of the T Spaces Field class that supports PreSerialization of the object.. It modifies the implementation of Field so that the value of a Field that will contain a user defined object is serialized into an array of bytes prior to being sent to the server. This avoids the problem of having to have user defined class object available in the Server classpath.
At the time that the FieldPS object is created or when the value is set using the setValue() method, the user defined object is serialized to a byte[] object and this is stored in the Field theValue instance variable.
When the value is requested, the byte[] in "theValue" is deserialized back to the user defined object and returned to the caller. An Example of usage:
Example4aObj obj = new Example4aObj("User Object 1");
FieldPS f2 = new FieldPS(obj);
Tuple tup = new Tuple("Key1",f2);
ts.write(tup);
At this point, the object is stored on the server only
as a byte[] object. Now we will read it back.
Tuple template = new Tuple("Key1",new FieldPS(Example4aObj.class) );
mytuple = (Tuple)ts.take(template);
Example4aObj objreturned = (Example4aObj)mytuple.getField(1).value();
Because the Server may not know anything about these classes that are represented by the serialized byte array, one can not specify a superclass in the template. If you want to write various subclasses and then retrieve based on the superclass then you must specify the superclass on the original write.
A_child obj = new A_Child"User Object 1");
FieldPS f2 = new FieldPS(A_parent.class,obj);
---
Tuple template = new Tuple("Key1",new FieldPS(A_parent.class) );
There is no reason to believe that if you took 2 equal objects (equality defined by the "equal" method) that the 2 serialized bag of bytes would be equal. Therefore you should not do indexing of a FieldPS or use a FieldPS value in a template. However, you will get no warning if you try this. Don't try it! Perhaps somebody should throw an exception if you even try it.
Field,
Tuple,
TupleSpace, Serialized Form| Fields inherited from class com.ibm.tspaces.Field |
isFormal,
theName,
theType,
theTypeString,
theValue |
| Constructor Summary | |
FieldPS(java.lang.Class t)
Create a FieldPS that has the Class as its type. |
|
FieldPS(java.lang.Class t,
java.io.Serializable v)
Create a FieldPS that has the value Object. |
|
FieldPS(java.io.Serializable v)
Create a FieldPS that has the value Object. |
|
| Method Summary | |
java.lang.Class |
getType()
Return the Class instance that represents the type of the FieldPS. |
java.io.Serializable |
getValue()
Return the value of the FieldPS. |
static void |
main(java.lang.String[] argv)
Test routine for FieldPS |
boolean |
matches(Field f2)
This method is used to determine if the specified FieldPS matches the current FieldPS. |
void |
setValue(java.io.Serializable v)
Set the value of the FieldPS to be any Serializable. |
java.lang.String |
toString()
Return a String that represents the Field. |
| Methods inherited from class com.ibm.tspaces.Field |
assign,
clone,
formal,
getName,
isFormal,
makeField,
name,
setFormal,
setFormal,
setName,
setType,
type,
value |
| Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Constructor Detail |
public FieldPS(java.io.Serializable v)
throws TupleSpaceException
v - The value of the FieldPS
public FieldPS(java.lang.Class t,
java.io.Serializable v)
throws TupleSpaceException
v - The value of the FieldPS
public FieldPS(java.lang.Class t)
throws TupleSpaceException
t - The value of the class| Method Detail |
public void setValue(java.io.Serializable v)
throws TupleSpaceException
v - The value of the FieldPS.public java.lang.Class getType()
public java.io.Serializable getValue()
public boolean matches(Field f2)
Rules for Matching: Field f1.matches(Field f2)
Rule 1: Field f1 is always the Query Field.
Rule 2 - If f1 is Formal and the type Strings are equal
then return true.
if f1.isFormal
if f1.theTypeString.equals(f2.theTypeString) -> true
Because the server may not have any awareness of the represented
class, we can handle derived classes. The class names as String
values must match exactly.
Rule 3 - if both f1 and f2 are null and the types match, then return true
if f1 == null && f2 == null && typeStrings match -> true
Rule 4 - if f1 == null || f2 == null -> false
Rule 5 return f1.getValue().equals(f2.getValue())
Override this method to change the matching behavior.
f2 - The Field to compare against.public java.lang.String toString()
public static void main(java.lang.String[] argv)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||