1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.websocket.jsr356.endpoints;
20
21 import java.util.Map;
22
23 import javax.websocket.CloseReason;
24 import javax.websocket.CloseReason.CloseCode;
25 import javax.websocket.CloseReason.CloseCodes;
26 import javax.websocket.EndpointConfig;
27 import javax.websocket.Session;
28
29 import org.eclipse.jetty.websocket.api.WebSocketPolicy;
30 import org.eclipse.jetty.websocket.api.extensions.Frame;
31 import org.eclipse.jetty.websocket.common.CloseInfo;
32 import org.eclipse.jetty.websocket.common.WebSocketSession;
33 import org.eclipse.jetty.websocket.common.events.AbstractEventDriver;
34 import org.eclipse.jetty.websocket.jsr356.JsrSession;
35 import org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata;
36
37 public abstract class AbstractJsrEventDriver extends AbstractEventDriver
38 {
39 protected final EndpointMetadata metadata;
40 protected final EndpointConfig config;
41 protected JsrSession jsrsession;
42 private boolean hasCloseBeenCalled = false;
43
44 public AbstractJsrEventDriver(WebSocketPolicy policy, EndpointInstance endpointInstance)
45 {
46 super(policy,endpointInstance.getEndpoint());
47 this.config = endpointInstance.getConfig();
48 this.metadata = endpointInstance.getMetadata();
49 }
50
51 public EndpointConfig getConfig()
52 {
53 return config;
54 }
55
56 public Session getJsrSession()
57 {
58 return this.jsrsession;
59 }
60
61 public EndpointMetadata getMetadata()
62 {
63 return metadata;
64 }
65
66 public abstract void init(JsrSession jsrsession);
67
68 @Override
69 public final void onClose(CloseInfo close)
70 {
71 if (hasCloseBeenCalled)
72 {
73
74 return;
75 }
76 hasCloseBeenCalled = true;
77
78 CloseCode closecode = CloseCodes.getCloseCode(close.getStatusCode());
79 CloseReason closereason = new CloseReason(closecode,close.getReason());
80 onClose(closereason);
81 }
82
83 protected abstract void onClose(CloseReason closereason);
84
85 @Override
86 public void onFrame(Frame frame)
87 {
88
89 }
90
91 @Override
92 public final void openSession(WebSocketSession session)
93 {
94
95 this.jsrsession = (JsrSession)session;
96
97
98 this.jsrsession.init(config);
99
100
101 init(jsrsession);
102
103
104 super.openSession(session);
105 }
106
107 public void setEndpointconfig(EndpointConfig endpointconfig)
108 {
109 throw new RuntimeException("Why are you reconfiguring the endpoint?");
110
111 }
112
113 public abstract void setPathParameters(Map<String, String> pathParameters);
114 }