public interface CopyContext
Context of the single cloning process.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceReceives a clone. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectMarker returned bycopyNow(Object)when the clone cannot be got now. -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a task which is invoked when the whole object graph is copied, e.g.<T> Tcopy(T original) Returns the instant copy of the object.default <T> voidcopy(T original, CopyContext.CloneSetter<? super T> setter) Copies the object and passes the clone to the setter, now or later, seecopyNow(Object).<T> TcopyComplete(T original) Returns the copy of the object with its own state already copied (for a two-phase copier the second phase is done, its referenced objects may still be incomplete).Copies the object if its clone exists or can be created now.booleanisComplete(Object original) Tells whether the clone of the object has its own state copied.<T> Tregister(T clone) Registers clone in the context.<T> voidsubscribe(T original, CopyContext.CloneSetter<? super T> setter) Passes the clone of the object to the setter when it is registered, seecopyNow(Object).voidthenInvoke(Callable<?> task) Invokes task.
-
Field Details
-
PENDING
Marker returned bycopyNow(Object)when the clone cannot be got now.
-
-
Method Details
-
register
<T> T register(T clone) Registers clone in the context.- Type Parameters:
T- object type- Parameters:
clone- clone- Returns:
- clone
-
copy
Returns the instant copy of the object. It can be a copy, saved previously into cache, or fresh copy. The copy may not be the full copy of the original object, the inner state can be processed later.- Type Parameters:
T- object type- Parameters:
original- original- Returns:
- clone
- Throws:
Exception- if something went wrong
-
copyNow
Copies the object if its clone exists or can be created now. ReturnsPENDINGif the object is being created right now (a reference cycle through a single-phase copier, or another thread); then the callersubscribesto the clone. Outside a second phase of a two-phase copier works ascopy(Object)and never returnsPENDING. -
subscribe
Passes the clone of the object to the setter when it is registered, seecopyNow(Object). Until then the object copied by the current second phase is not complete. If the clone is already available, the setter is called at once.- Type Parameters:
T- object type- Parameters:
original- originalsetter- receiver of the clone- Throws:
Exception- if something went wrong
-
copy
Copies the object and passes the clone to the setter, now or later, seecopyNow(Object). Convenient, but allocates the setter for every call, copiers on hot paths should usecopyNow(Object).- Type Parameters:
T- object type- Parameters:
original- originalsetter- receiver of the clone- Throws:
Exception- if something went wrong
-
copyComplete
Returns the copy of the object with its own state already copied (for a two-phase copier the second phase is done, its referenced objects may still be incomplete). Needed by copiers which create the clone from copied values, e.g. canonical constructors of records. If the object is part of a reference cycle with an object being created by the current thread, its clone cannot be completed before that object's clone exists: then the clone is returned incomplete, seeisComplete(Object).- Type Parameters:
T- object type- Parameters:
original- original- Returns:
- clone
- Throws:
Exception- if something went wrong
-
isComplete
Tells whether the clone of the object has its own state copied. A copier which has got an incomplete clone fromcopyComplete(Object)must keep exactly this clone in its own clone: it will be completed after the own clone is registered.- Parameters:
original- original- Returns:
trueif the clone is complete or the object needs no copying
-
thenInvoke
Invokes task. It can be invoked immediately or later depending on the context implementation. The result of callable is ignored.- Parameters:
task- task- Throws:
Exception- if something went wrong
-
afterCopy
Registers a task which is invoked when the whole object graph is copied, e.g. to rebuild a container whose structure depends on hash codes of copied objects. Tasks are invoked in a single thread.- Parameters:
task- task
-