1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.websocket.common.extensions;
20
21 import java.io.IOException;
22
23 import org.eclipse.jetty.io.ByteBufferPool;
24 import org.eclipse.jetty.util.annotation.ManagedAttribute;
25 import org.eclipse.jetty.util.annotation.ManagedObject;
26 import org.eclipse.jetty.util.component.ContainerLifeCycle;
27 import org.eclipse.jetty.util.log.Log;
28 import org.eclipse.jetty.util.log.Logger;
29 import org.eclipse.jetty.websocket.api.BatchMode;
30 import org.eclipse.jetty.websocket.api.WebSocketPolicy;
31 import org.eclipse.jetty.websocket.api.WriteCallback;
32 import org.eclipse.jetty.websocket.api.extensions.Extension;
33 import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
34 import org.eclipse.jetty.websocket.api.extensions.Frame;
35 import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
36 import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
37 import org.eclipse.jetty.websocket.common.LogicalConnection;
38
39 @ManagedObject("Abstract Extension")
40 public abstract class AbstractExtension extends ContainerLifeCycle implements Extension
41 {
42 private final Logger log;
43 private WebSocketPolicy policy;
44 private ByteBufferPool bufferPool;
45 private ExtensionConfig config;
46 private LogicalConnection connection;
47 private OutgoingFrames nextOutgoing;
48 private IncomingFrames nextIncoming;
49
50 public AbstractExtension()
51 {
52 log = Log.getLogger(this.getClass());
53 }
54
55 @Override
56 public void dump(Appendable out, String indent) throws IOException
57 {
58 super.dump(out, indent);
59
60 dumpWithHeading(out, indent, "incoming", this.nextIncoming);
61 dumpWithHeading(out, indent, "outgoing", this.nextOutgoing);
62 }
63
64 protected void dumpWithHeading(Appendable out, String indent, String heading, Object bean) throws IOException
65 {
66 out.append(indent).append(" +- ");
67 out.append(heading).append(" : ");
68 out.append(bean.toString());
69 }
70
71 public ByteBufferPool getBufferPool()
72 {
73 return bufferPool;
74 }
75
76 @Override
77 public ExtensionConfig getConfig()
78 {
79 return config;
80 }
81
82 public LogicalConnection getConnection()
83 {
84 return connection;
85 }
86
87 @Override
88 public String getName()
89 {
90 return config.getName();
91 }
92
93 @ManagedAttribute(name = "Next Incoming Frame Handler", readonly = true)
94 public IncomingFrames getNextIncoming()
95 {
96 return nextIncoming;
97 }
98
99 @ManagedAttribute(name = "Next Outgoing Frame Handler", readonly = true)
100 public OutgoingFrames getNextOutgoing()
101 {
102 return nextOutgoing;
103 }
104
105 public WebSocketPolicy getPolicy()
106 {
107 return policy;
108 }
109
110 @Override
111 public void incomingError(Throwable e)
112 {
113 nextIncomingError(e);
114 }
115
116
117
118
119
120
121
122
123 @Override
124 public boolean isRsv1User()
125 {
126 return false;
127 }
128
129
130
131
132
133
134
135
136 @Override
137 public boolean isRsv2User()
138 {
139 return false;
140 }
141
142
143
144
145
146
147
148
149 @Override
150 public boolean isRsv3User()
151 {
152 return false;
153 }
154
155 protected void nextIncomingError(Throwable e)
156 {
157 this.nextIncoming.incomingError(e);
158 }
159
160 protected void nextIncomingFrame(Frame frame)
161 {
162 log.debug("nextIncomingFrame({})",frame);
163 this.nextIncoming.incomingFrame(frame);
164 }
165
166 protected void nextOutgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode)
167 {
168 log.debug("nextOutgoingFrame({})",frame);
169 this.nextOutgoing.outgoingFrame(frame,callback, batchMode);
170 }
171
172 public void setBufferPool(ByteBufferPool bufferPool)
173 {
174 this.bufferPool = bufferPool;
175 }
176
177 public void setConfig(ExtensionConfig config)
178 {
179 this.config = config;
180 }
181
182 public void setConnection(LogicalConnection connection)
183 {
184 this.connection = connection;
185 }
186
187 @Override
188 public void setNextIncomingFrames(IncomingFrames nextIncoming)
189 {
190 this.nextIncoming = nextIncoming;
191 }
192
193 @Override
194 public void setNextOutgoingFrames(OutgoingFrames nextOutgoing)
195 {
196 this.nextOutgoing = nextOutgoing;
197 }
198
199 public void setPolicy(WebSocketPolicy policy)
200 {
201 this.policy = policy;
202 }
203
204 @Override
205 public String toString()
206 {
207 return String.format("%s[%s]",this.getClass().getSimpleName(),config.getParameterizedName());
208 }
209 }