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.server.mux;
20  
21  import java.io.IOException;
22  import java.nio.ByteBuffer;
23  
24  import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
25  import org.eclipse.jetty.io.EofException;
26  import org.eclipse.jetty.server.HttpTransport;
27  import org.eclipse.jetty.util.BlockingCallback;
28  import org.eclipse.jetty.util.Callback;
29  import org.eclipse.jetty.util.log.Log;
30  import org.eclipse.jetty.util.log.Logger;
31  import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
32  import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
33  
34  /**
35   * Take {@link ResponseInfo} objects and convert to bytes for response.
36   */
37  public class HttpTransportOverMux implements HttpTransport
38  {
39      private static final Logger LOG = Log.getLogger(HttpTransportOverMux.class);
40      private final BlockingCallback streamBlocker = new BlockingCallback();
41  
42      public HttpTransportOverMux(Muxer muxer, MuxChannel channel)
43      {
44          // TODO Auto-generated constructor stub
45      }
46  
47      @Override
48      public void completed()
49      {
50          LOG.debug("completed");
51      }
52  
53      /**
54       * Process ResponseInfo object into AddChannelResponse
55       */
56      @Override
57      public void send(ResponseInfo info, ByteBuffer responseBodyContent, boolean lastContent) throws IOException
58      {
59          send(info,responseBodyContent,lastContent,streamBlocker);
60          streamBlocker.block();
61      }
62  
63      @Override
64      public void send(ResponseInfo info, ByteBuffer responseBodyContent, boolean lastContent, Callback callback)
65      {
66          if (lastContent == false)
67          {
68              // throw error
69          }
70  
71          if (info.getContentLength() > 0)
72          {
73              // throw error
74          }
75  
76          // prepare the AddChannelResponse
77          // TODO: look at HttpSender in jetty-client for generator loop logic
78      }
79      
80      @Override
81      public void send(ByteBuffer responseBodyContent, boolean lastContent, Callback callback)
82      {
83          send(null,responseBodyContent, lastContent, callback);
84      }
85  }