package net.morimekta.providence.util;

import net.morimekta.providence.PServiceCall;

import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;

/**
 * Interface handling the instrumentation of service calls.
 */
@FunctionalInterface
public interface ServiceCallInstrumentation {
    /**
     * After each service call this method is called with the duration, call and
     * response objects. Exceptions from the call is ignored, and will not affect
     * the response in any way.
     *
     * @param duration The duration of handling the service call in milliseconds,
     *                 including receiving and sending it. It does not include the
     *                 time receiving the first HTTP packet with the headers, or
     *                 waiting for free worker threads.
     * @param call     The call triggered.
     * @param response The response returned.
     */
    void afterCall(double duration,
                   @Nullable PServiceCall call,
                   @Nullable PServiceCall response);

    /**
     * Handy constant for calculating MS duration.
     */
    long NS_IN_MILLIS = TimeUnit.MILLISECONDS.toNanos(1);
}

@@ -497,24 +497,28 @@
 .%0A     *
+ %3Cp%3E
 %0A     * 
 @param d
@@ -513,188 +513,218 @@
   * 
-@param duration The duration of handling the service call in milliseconds,%0A     *                 including receiving and sending it. It does not include the%0A     *                
+Note that the timing may not include the whole stack time since receiving%0A     * the first packet, that is dependent on the specific implementation and the%0A     * limitations there. E.g. it does not include the
  tim
@@ -744,16 +744,23 @@
 he first
+%0A     *
  HTTP pa
@@ -788,63 +788,237 @@
 , or
-%0A     *        
+ waiting for free worker threads when using%0A     * %3Ccode%3EProvidenceServlet%3C/code%3E.%0A
      
+*%0A
     
-waiting for free worker threads
+ * @param duration The duration of handling the service call in milliseconds,%0A     *                 including receiving and sending it
 .%0A  
@@ -1078,27 +1078,24 @@
 m re
-sponse
+ply   
  The re
-sponse
+ply
  ret
@@ -1237,22 +1237,19 @@
 eCall re
-sponse
+ply
 );%0A%0A    

Fix comment relating HTTP to be more generic.