uka.patch
Class PatchAdapterImpl

java.lang.Object
  extended byuka.patch.PatchAdapter
      extended byuka.patch.PatchAdapterImpl
All Implemented Interfaces:
Printable, java.io.Serializable

public class PatchAdapterImpl
extends PatchAdapter
implements Printable, java.io.Serializable

Default implementation of the PatchAdapter interface.

See Also:
Serialized Form

Nested Class Summary
(package private)  class PatchAdapterImpl.Output
           
 
Field Summary
private  java.lang.Object[] ARGS_this
           
(package private)  SimpleObjectSpace copies
           
(package private) static java.util.HashMap descriptors
           
(package private)  ReferenceFilter filter
           
(package private)  SharedObjectSpace objects
           
(package private)  java.lang.Object root
           
private static java.lang.Class[] TYPES_PatchAdapter
           
 
Constructor Summary
PatchAdapterImpl(java.lang.Object root)
           
PatchAdapterImpl(SharedObjectSpace objects, java.lang.Object root, ReferenceFilter filter)
          Create a patch adapter with a custom object space.
 
Method Summary
 void appendTo(ToString s)
          This method should append the contents of each instance variable of the current object to the given ToString object.
 void applyPatch(PatchReader reader)
          Applies a patch read from the passed input stream to the own monitored object.
 void checkConsistency(java.util.logging.Logger log)
           
 void createPatch(AbstractPatchWriter writer)
          API: Create a patch and write it to the given output stream.
 AbstractPatchWriter createPatch(MarshalStream marshal)
          Convenience method.
 PatchReader createPatchReader(UnmarshalStream unmarshal)
           
 PatchReader createPatchReader(UnmarshalStream unmarshal, int fromRank)
          API: Read a patch from the given input stream and apply it to the root object associated with this patch adapter.
private  void doApplyPatch(PatchReader reader, java.lang.Object orig, java.lang.Object copy)
           
private static java.lang.Object doClone(java.lang.Object orig)
           
private static void doDescend(java.lang.Object orig, ReferenceConsumer consumer)
           
private static void doFilterReferences(java.lang.Object orig, ReferenceFilter filter)
           
private  boolean enterCopy(int id)
           
 ObjectSpace getObjectSpace()
          Returns the object space of original objects.
private static PatchDescriptor getPatchDescriptor(java.lang.Class origClass)
           
 java.lang.Object getRoot()
           
private  void readObject(java.io.ObjectInputStream in)
          Make sure transient fields are restored after unmarshaling.
private  void restore()
           
private  void restoreAfterUnmarshal()
          Rebuilds transient fields after unmarshaling this object from a stream.
 void updateAfterApplyPatch()
          Create backup copies of new or newly shared objects and remove backup copies of dead or no longer shared objects.
 void updateAfterCreatePatch()
           
 void updateAfterDistributionUpdate()
          Remove backup copies of dead or no longer shared objects.
 
Methods inherited from class uka.patch.PatchAdapter
newInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

java.lang.Object root

descriptors

static final java.util.HashMap descriptors

objects

SharedObjectSpace objects

filter

ReferenceFilter filter

copies

transient SimpleObjectSpace copies

TYPES_PatchAdapter

private static java.lang.Class[] TYPES_PatchAdapter

ARGS_this

private java.lang.Object[] ARGS_this
Constructor Detail

PatchAdapterImpl

public PatchAdapterImpl(java.lang.Object root)
                 throws java.io.IOException

PatchAdapterImpl

public PatchAdapterImpl(SharedObjectSpace objects,
                        java.lang.Object root,
                        ReferenceFilter filter)
                 throws java.io.IOException
Create a patch adapter with a custom object space.

Method Detail

checkConsistency

public void checkConsistency(java.util.logging.Logger log)

restoreAfterUnmarshal

private void restoreAfterUnmarshal()
                            throws java.lang.ClassNotFoundException,
                                   java.io.IOException

Rebuilds transient fields after unmarshaling this object from a stream. When marshaling a PatchAdapter, the backup copies are not marshaled along with their originals. This is done to save bandwidth and to avoid conflicts with backup copies of objects implementing the replicated interface (e.g. the backup copy of the patchable root object). When replicated objects are marshaled during a remote method invocation, they are replaced with their corresponding stubs and resolved at the remote side to the local replica. This is only possible for regular replicated objects that are exported and completely initialized. Backup copies of replicated objects are not exported. Therefore, it is better not to marshal backup copies at all.

This method is called automatically during the unmarshaling process of UnmarshalStream, or called explicitly after unmarshaling through an ObjectInputStream via the readObject(java.io.ObjectInputStream) method.

Throws:
java.lang.ClassNotFoundException
java.io.IOException

restore

private void restore()
              throws java.io.IOException
Throws:
java.io.IOException

doClone

private static java.lang.Object doClone(java.lang.Object orig)
                                 throws java.io.IOException
Throws:
java.io.IOException

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Make sure transient fields are restored after unmarshaling.

Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
restoreAfterUnmarshal()

getRoot

public java.lang.Object getRoot()
Specified by:
getRoot in class PatchAdapter
Returns:
the object the patch adapter was created for. This object was passed as argument to the call to PatchAdapter.newInstance(Object).

getObjectSpace

public ObjectSpace getObjectSpace()
Description copied from class: PatchAdapter
Returns the object space of original objects. This object space is required to create concrete patch writers.

Specified by:
getObjectSpace in class PatchAdapter
See Also:
AbstractPatchWriter

enterCopy

private boolean enterCopy(int id)
                   throws java.io.IOException
Throws:
java.io.IOException

getPatchDescriptor

private static PatchDescriptor getPatchDescriptor(java.lang.Class origClass)
                                           throws java.io.IOException
Throws:
java.io.IOException

createPatch

public AbstractPatchWriter createPatch(MarshalStream marshal)
                                throws java.io.IOException
Convenience method.

Specified by:
createPatch in class PatchAdapter
Parameters:
marshal - the stream, the patch is written to.
Throws:
java.io.IOException
See Also:
createPatch(MarshalStream)

createPatch

public void createPatch(AbstractPatchWriter writer)
                 throws java.io.IOException
API: Create a patch and write it to the given output stream.

Specified by:
createPatch in class PatchAdapter
Throws:
java.io.IOException

createPatchReader

public PatchReader createPatchReader(UnmarshalStream unmarshal)
                              throws java.io.IOException,
                                     java.lang.ClassNotFoundException
Specified by:
createPatchReader in class PatchAdapter
Throws:
java.io.IOException
java.lang.ClassNotFoundException

createPatchReader

public PatchReader createPatchReader(UnmarshalStream unmarshal,
                                     int fromRank)
                              throws java.io.IOException,
                                     java.lang.ClassNotFoundException
API: Read a patch from the given input stream and apply it to the root object associated with this patch adapter.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

applyPatch

public void applyPatch(PatchReader reader)
                throws java.io.IOException,
                       java.lang.ClassNotFoundException
Description copied from class: PatchAdapter
Applies a patch read from the passed input stream to the own monitored object. The patch must be created by a corresponding patch adapter see PatchAdapter.createPatch(MarshalStream).

Specified by:
applyPatch in class PatchAdapter
Throws:
java.io.IOException
java.lang.ClassNotFoundException

doApplyPatch

private void doApplyPatch(PatchReader reader,
                          java.lang.Object orig,
                          java.lang.Object copy)
                   throws java.io.IOException,
                          java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

updateAfterCreatePatch

public void updateAfterCreatePatch()
                            throws java.io.IOException
Specified by:
updateAfterCreatePatch in class PatchAdapter
Throws:
java.io.IOException

updateAfterDistributionUpdate

public void updateAfterDistributionUpdate()
                                   throws java.io.IOException

Remove backup copies of dead or no longer shared objects. This method must be called after creating a patch and after writing the corresponding distribution update (if a partitioned object space is used).

Note: This is somewhat asymmetric to updateAfterApplyPatch(), because backup copy creation must be done immediately after creating the patch and before sending the distribution update. See the lengthy comment at the end of PatchAdapterImpl.Output.createCompletePatch() and the log entry of changeset:2528.

Specified by:
updateAfterDistributionUpdate in class PatchAdapter
Throws:
java.io.IOException

doFilterReferences

private static void doFilterReferences(java.lang.Object orig,
                                       ReferenceFilter filter)
                                throws java.io.IOException
Throws:
java.io.IOException

doDescend

private static void doDescend(java.lang.Object orig,
                              ReferenceConsumer consumer)
                       throws java.io.IOException
Throws:
java.io.IOException

updateAfterApplyPatch

public void updateAfterApplyPatch()
                           throws java.io.IOException
Create backup copies of new or newly shared objects and remove backup copies of dead or no longer shared objects. This method must be called after applying a patch and after reading the corresponding distribution update (if a partitioned object space is used).

Specified by:
updateAfterApplyPatch in class PatchAdapter
Throws:
java.io.IOException
See Also:
applyPatch(uka.patch.PatchReader), PartitionedObjectSpace.readDistributionUpdate(uka.patch.PatchReader)

appendTo

public void appendTo(ToString s)
Description copied from interface: Printable
This method should append the contents of each instance variable of the current object to the given ToString object. The appended data should be labeled with the name of the corresponding instance variable.

Specified by:
appendTo in interface Printable
See Also:
ToString, ToString.append(String, Object), ToString.append(String, boolean), ToString.append(String, byte), ToString.append(String, int)