com.sun.jini.jeri.internal.runtime
Class ImplRefManager.ImplRef

java.lang.Object
  extended by com.sun.jini.jeri.internal.runtime.ImplRefManager.ImplRef
Enclosing class:
ImplRefManager

final class ImplRefManager.ImplRef
extends Object

A managed reference to a remote object implementation (impl). An ImplRef may be pinned and unpinned with respect to any target that is registered with it. While pinned for at least one target, an ImplRef refers to its impl with a strong reference; otherwise, it refers to the impl with only a weak reference, so that the impl may be locally garbage collected. The getImpl() method can be used to obtain a strong reference to the impl as long as it has not been garbage collected. An ImplRef maintains a set of all targets that are registered with it-- that is, targets passed to ImplRefManager.getImplRef but not passed to the release method. If the impl is detected to have been garbage collected, then all targets in the set will have their collect() method invoked asynchronously.


Field Summary
private  Set pinningTargets
          targets that have pinned this reference; guarded by "this"
private  boolean removed
          removed from table; guarded by "lock"
private  Remote strongRef
          strong reference to impl, when pinned; guarded by "this"
private  Set targets
          targets for all exports of referenced impl; guarded by "this"
private  Reference weakRef
          weak reference to impl
 
Constructor Summary
private ImplRefManager.ImplRef(Reference weakRef)
           
 
Method Summary
private  void addTarget(Target target)
           
(package private)  Remote getImpl()
          Returns the referenced impl, or null if the impl has been garbage collected.
private  void invokeUnreferenced(Target target)
          Asynchronously invokes the Unreferenced.unreferenced method of the impl, if it is an instance of the Unreferenced interface.
private  boolean isPinned()
           
(package private)  void pin(Target target)
          Pins this reference for the specified target, so that the impl will be held with a strong reference.
(package private)  void release(Target target)
          Removes the specified target from the set of targets that are using this ImplRef, allowing the target to be garbage collected (and this ImplRef too, if there are no other targets using it).
private  void remove()
          Removes this ImplRef from the table.
 String toString()
           
(package private)  void unpin(Target target)
          Unpins a previous pin of this reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

weakRef

private final Reference weakRef
weak reference to impl


removed

private boolean removed
removed from table; guarded by "lock"


targets

private final Set targets
targets for all exports of referenced impl; guarded by "this"


pinningTargets

private final Set pinningTargets
targets that have pinned this reference; guarded by "this"


strongRef

private Remote strongRef
strong reference to impl, when pinned; guarded by "this"

Constructor Detail

ImplRefManager.ImplRef

private ImplRefManager.ImplRef(Reference weakRef)
Method Detail

addTarget

private void addTarget(Target target)

getImpl

Remote getImpl()
Returns the referenced impl, or null if the impl has been garbage collected.


pin

void pin(Target target)
Pins this reference for the specified target, so that the impl will be held with a strong reference. This pin will remain in effect until unpin is invoked for the same target, or if the target releases this reference. This method must NOT be invoked if the referenced impl has been garbage collected (i.e. if getImpl() returns null).


unpin

void unpin(Target target)
Unpins a previous pin of this reference. Each invocation of this method must correspond to a previous invocation of the pin method for the same target. If this operation causes the number of pinning targets to transition to zero, the impl's unreferenced() method will be asynchronously invoked (if it implements the Unreferenced interface).


invokeUnreferenced

private void invokeUnreferenced(Target target)
Asynchronously invokes the Unreferenced.unreferenced method of the impl, if it is an instance of the Unreferenced interface. The specified target must be registered with this ImplRef and DGC-enabled; it is used to obtain a context class loader value for the invocation.


isPinned

private boolean isPinned()

release

void release(Target target)
Removes the specified target from the set of targets that are using this ImplRef, allowing the target to be garbage collected (and this ImplRef too, if there are no other targets using it). If this operation causes the number of pinning targets to transition to zero AND there are still targets representing DGC-enabled exports to the referenced impl, then the impl's unreferenced() method will be asynchronously invoked (if it implements the Unreferenced interface).


remove

private void remove()
Removes this ImplRef from the table.


toString

public String toString()
Overrides:
toString in class Object


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