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