View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.websocket.common.io;
20  
21  import org.eclipse.jetty.websocket.api.WebSocketException;
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(WebSocketException e)
40          {
41              /* cannot send exception on */
42          }
43  
44          @Override
45          public void incomingFrame(Frame frame)
46          {
47              this.outgoing.outgoingFrame(frame,null);
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)
62          {
63              this.incoming.incomingFrame(frame);
64          }
65      }
66  
67      public static OutgoingFrames to(final IncomingFrames incoming)
68      {
69          return new Out2In(incoming);
70      }
71  
72      public static IncomingFrames to(final OutgoingFrames outgoing)
73      {
74          return new In2Out(outgoing);
75      }
76  }