* @return the old delegate
* @throws IllegalStateException if cyclic swapping action is detected
* @since 0.1
*/
protected Object hotswap(final Object newDelegate) {
ObjectReference ref = getDelegateReference();
Object result = ref.get();
// Note, for the cycle detection the delegate have to be set first
delegate.set(newDelegate);
ref.set(newDelegate);
if (newDelegate instanceof CycleCheck) {
((CycleCheck)newDelegate).checkForCycle();
}
return result;
}