Components References

Weak Reference

Component A sets weak reference to component B if it needs to use classes of B.

Semantics of Weak References

Throughout the life cycle of a component, a weak reference means:

?        If component B exists, a reference from the class loader of A is set to the class loader of B.

?        Component B must be resolved for component A to be resolved.

?        All events that refer to a change of state of component B are sent to component A.

?        If the system has to unload component B, it must first unload component A.

Weak Reference Appliance Matrix

Reference to

Interface

Library

Service

Reference from

Interface

Yes

Yes

No

Library

Yes

Yes

Yes

Service

Yes

Yes

Yes

Even though it is possible to set weak reference from a library to an interface or a service, it is not common practice. Therefore, if you encounter such a situation, you can double-check the design of your library before you set the link.

Strong Reference

Component A sets strong reference to component B if it needs to use classes and runtime objects that B provides.

Semantics of Strong References

Throughout the life cycle of a component, a strong reference means:

?        If component B exists, a reference from the class loader of A is set to the class loader of B.

?        Component B must be resolved for component A to be resolved.

?        All events that refer to a change of state of component B are sent to component A.

?        Component B must be started for component A to be started.

?        If the system has to stop component B, it must first stop component A.

?        If the system has to unload component B, it must first unload component A.

?        If component A has strong reference to component B, then B cannot have strong reference to A.

Strong Reference Appliance Matrix

Reference to

Interface

Library

Service

Reference from

Interface

No

No

No

Library

No

No

No

Service

Yes

No

Yes

In the case of a service component with a strong reference to an interface, the referencing service will be started only if there is another service that implements the referenced interface and this service is started.