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.io;
20
21 import org.eclipse.jetty.websocket.api.BatchMode;
22 import org.eclipse.jetty.websocket.api.WriteCallback;
23 import org.eclipse.jetty.websocket.api.extensions.Frame;
24 import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
25 import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
26
27 public class FramePipes
28 {
29 private static class In2Out implements IncomingFrames
30 {
31 private OutgoingFrames outgoing;
32
33 public In2Out(OutgoingFrames outgoing)
34 {
35 this.outgoing = outgoing;
36 }
37
38 @Override
39 public void incomingError(Throwable t)
40 {
41
42 }
43
44 @Override
45 public void incomingFrame(Frame frame)
46 {
47 this.outgoing.outgoingFrame(frame,null, BatchMode.OFF);
48 }
49 }
50
51 private static class Out2In implements OutgoingFrames
52 {
53 private IncomingFrames incoming;
54
55 public Out2In(IncomingFrames incoming)
56 {
57 this.incoming = incoming;
58 }
59
60 @Override
61 public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode)
62 {
63 try
64 {
65 this.incoming.incomingFrame(frame);
66 callback.writeSuccess();
67 }
68 catch (Throwable t)
69 {
70 callback.writeFailed(t);
71 }
72 }
73 }
74
75 public static OutgoingFrames to(final IncomingFrames incoming)
76 {
77 return new Out2In(incoming);
78 }
79
80 public static IncomingFrames to(final OutgoingFrames outgoing)
81 {
82 return new In2Out(outgoing);
83 }
84 }