01: package dalma.impl;
02:
03: import dalma.Conversation;
04: import dalma.EndPoint;
05: import dalma.Engine;
06:
07: import java.io.Serializable;
08:
09: /**
10: * @author Kohsuke Kawaguchi
11: */
12: public abstract class EndPointImpl extends EndPoint {
13: protected EndPointImpl(String name) {
14: super (name);
15: }
16:
17: /**
18: * Called when {@link Engine#start()} is invoked.
19: *
20: * <p>
21: * This method is invoked once and only once.
22: * {@link EndPoint} can start accepting incoming messages.
23: */
24: protected abstract void start();
25:
26: /**
27: * Called when {@link Engine#stop()} is invoked.
28: *
29: * <p>
30: * {@link EndPoint} should release resources that are used to listen to incoming events.
31: * Note that it's possible for new {@link Conversation}s to part to the {@link EndPoint}
32: * even after this method is called, due to the synchronization issue.
33: *
34: * <p>
35: * Once this method is called, the end point must not awake conversations.
36: */
37: protected abstract void stop();
38:
39: protected Object writeReplace() {
40: return new Moniker(getName());
41: }
42:
43: private static final class Moniker implements Serializable {
44: private final String name;
45:
46: public Moniker(String name) {
47: this .name = name;
48: }
49:
50: private Object readResolve() {
51: EndPoint endPoint = SerializationContext.get().engine
52: .getEndPoint(name);
53: if (endPoint == null)
54: throw new Error("no endpoint of the name " + name
55: + " exists in the engine");
56: return endPoint;
57: }
58:
59: private static final long serialVersionUID = 1L;
60: }
61:
62: }
|