org.chromium.sdk/src/org/chromium/sdk/ConnectionLogger.java
changeset 2 e4420d2515f1
child 52 f577ea64429e
equal deleted inserted replaced
1:ef76fc2ac88c 2:e4420d2515f1
       
     1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
       
     2 // Use of this source code is governed by a BSD-style license that can be
       
     3 // found in the LICENSE file.
       
     4 
       
     5 package org.chromium.sdk;
       
     6 
       
     7 import java.io.Reader;
       
     8 import java.io.Writer;
       
     9 
       
    10 /**
       
    11  * Logger facility for the Chromium debugger connection. It can eavesdrop both
       
    12  * incoming and outgoing streams and log them somewhere. To make other code
       
    13  * less dependent on this interface, it works by wrapping reader/writer and is
       
    14  * only visible at start-up time. This approach has its disadvantages, because
       
    15  * it works with raw data streams, which are not perfectly formatted for human
       
    16  * reading. E.g. adjacent  requests or responses are not separated even
       
    17  * by EOL.
       
    18  */
       
    19 public interface ConnectionLogger {
       
    20   /**
       
    21    * @return new writer that should pass all data to {@code streamWriter} and
       
    22    * silently copy it elsewhere (without additional exceptions).
       
    23    */
       
    24   Writer wrapWriter(Writer streamWriter);
       
    25 
       
    26   /**
       
    27    * @return new reader that should give access to all data
       
    28    * from {@code streamReader} and silently copy it elsewhere (without
       
    29    * additional exceptions).
       
    30    */
       
    31   Reader wrapReader(Reader streamReader);
       
    32 
       
    33   /**
       
    34    * Connection may allow the logger to close it. It is nice for UI, where
       
    35    * user sees logger and the corresponding stop button.
       
    36    * TODO(peter.rybin): consider removing it out of logging.
       
    37    */
       
    38   void setConnectionCloser(ConnectionCloser connectionCloser);
       
    39 
       
    40   /**
       
    41    * Interface that gives you control over underlying connection.
       
    42    */
       
    43   interface ConnectionCloser {
       
    44     void closeConnection();
       
    45   }
       
    46 
       
    47   /**
       
    48    * Notifies logger that actual transmission is starting. After this {@link #handleEos()}
       
    49    * is guaranteed to be called.
       
    50    */
       
    51   void start();
       
    52 
       
    53   /**
       
    54    * Notifies logger that EOS has been received from remote. Technically some
       
    55    * traffic still may go through writer (i.e. be sent to remote) after this.
       
    56    */
       
    57   void handleEos();
       
    58 
       
    59   /**
       
    60    * Factory for connection logger. ConnectionLogger is NOT reconnectable.
       
    61    */
       
    62   interface Factory {
       
    63     /**
       
    64      * Creates new instance of {@link ConnectionLogger}.
       
    65      */
       
    66     ConnectionLogger newConnectionLogger();
       
    67   }
       
    68 }