01: package dalma.impl;
02:
03: /**
04: * Designates the current mode of serialization.
05: *
06: * <p>
07: * There are two different serializations.
08: *
09: * 1. serialization of the continuation
10: * 2. serialization of the conversation state
11: *
12: * @author Kohsuke Kawaguchi
13: */
14: final class SerializationContext {
15: final EngineImpl engine;
16: final Mode mode;
17:
18: private SerializationContext(EngineImpl engine, Mode mode) {
19: this .mode = mode;
20: this .engine = engine;
21: }
22:
23: public static enum Mode {
24: /**
25: * De-hydration of the continuation
26: */
27: CONTINUATION,
28: /**
29: * Saving the state of the conversation
30: */
31: CONVERSATION,
32: /**
33: * Saving the state of the engine
34: */
35: ENGINE;
36: }
37:
38: public static SerializationContext get() {
39: return SERIALIZATION_CONTEXT.get();
40: }
41:
42: /*package*/static SerializationContext set(EngineImpl engine,
43: Mode mode) {
44: SerializationContext old = SERIALIZATION_CONTEXT.get();
45: SERIALIZATION_CONTEXT
46: .set(new SerializationContext(engine, mode));
47: return old;
48: }
49:
50: /*package*/static void remove() {
51: SERIALIZATION_CONTEXT.set(null);
52: }
53:
54: /**
55: * While the hydration of the conversation is in progress,
56: * this variable stores the {@link EngineImpl} that owns the conversation.
57: *
58: * <p>
59: * This is used to resolve serialized instances to running instances.
60: */
61: /*package*/static final ThreadLocal<SerializationContext> SERIALIZATION_CONTEXT = new ThreadLocal<SerializationContext>();
62: }
|