View Javadoc

1   /*
2    * $Id: TcpProtocol.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.tcp;
12  
13  import org.mule.ResponseOutputStream;
14  
15  import java.io.IOException;
16  import java.io.InputStream;
17  import java.io.OutputStream;
18  import java.net.Socket;
19  
20  /**
21   * The TcpProtocol interface enables to plug different application level protocols on
22   * a TcpConnector.  Note that this interface has lost the direct byte array write method.
23   * Standard callers should (and will, since it matches the same signature, which is why
24   * the method has not been deprecated) use the generic method instead..
25   */
26  public interface TcpProtocol
27  {
28  
29      /**
30       * Reads the input stream and returns a whole message.
31       * 
32       * @param is the input stream
33       * @return an array of byte containing a full message
34       * @throws IOException if an exception occurs
35       */
36      Object read(InputStream is) throws IOException;
37  
38      /**
39       * Write the specified message to the output stream.
40       * 
41       * @param os the output stream to write to
42       * @param data the data to write
43       * @throws IOException if an exception occurs
44       */
45      void write(OutputStream os, Object data) throws IOException;
46  
47      /**
48       * This lets protocols encode a response stream.  If the protocol does not support a
49       * response stream (ie does not support streaming) then the stream should thrown an
50       * exception when used.
51       *
52       * @param socket The destination to write to
53       * @return A stream whose output will be encoded
54       * @throws IOException
55       */
56      ResponseOutputStream createResponse(Socket socket) throws IOException;
57  
58  }