## HTTPClient
Class IdempotentSequence

    java.lang.Object
      HTTPClient.IdempotentSequence

class IdempotentSequence
extends Object

This class checks whether a sequence of requests is idempotent. This is used to determine which requests may be automatically retried. This class also serves as a central place to record which methods have side effects and which methods are idempotent.

Note: unknown methods (i.e. a method which is not HEAD, GET, POST, PUT, DELETE, OPTIONS, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, or UNLOCK) are treated conservatively, meaning they are assumed to have side effects and are not idempotent.

Usage:

         IdempotentSequence seq = new IdempotentSequence();
         seq.add(r1);
         ...
         if (seq.isIdempotent(r1)) ...
         ...

Constructor Summary
`IdempotentSequence()` Start a new sequence of requests.

Method Summary
`void` `add(Request req)` Add the request to the end of the list of requests.
`boolean` `isIdempotent(Request req)` Is this request part of an idempotent sequence? This method must not be called before all requests have been added to this sequence; similarly, add() must not be called after this method was invoked.
`static void` `main(String[] args)` Test code.
`static boolean` `methodHasSideEffects(String method)`
`static boolean` `methodIsComplete(String method)` A method is complete if any side effects of the request affect the complete resource.
`static boolean` `methodIsIdempotent(String method)` A method is idempotent if the side effects of N identical requests is the same as for a single request (Section 9.1.2 of RFC-????).

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### IdempotentSequence

    public IdempotentSequence()

  Start a new sequence of requests.

Method Detail

### add

    public void add(Request req)

  Add the request to the end of the list of requests. This is used to build the complete sequence of requests before determining whether the sequence is idempotent.

  Parameters:
    `req` - the next request

### isIdempotent

    public boolean isIdempotent(Request req)

  Is this request part of an idempotent sequence? This method must not be called before all requests have been added to this sequence; similarly, add() must not be called after this method was invoked.

  We split up the sequence of requests into individual sub-sequences, or threads, with all requests in a thread having the same request-URI and no two threads having the same request-URI. Each thread is then marked as idempotent or not according to the following rules:

  1. If any method is UNKNOWN then the thread is not idempotent;
  2. else, if no method has side effects then the thread is idempotent;
  3. else, if the first method has side effects and is complete then the thread is idempotent;
  4. else, if the first method has side effects, is not complete, and no other method has side effects then the thread is idempotent;
  5. else the thread is not idempotent.

  The major assumption here is that the side effects of any method only apply to resource specified. E.g. a `"PUT /barbara.html"` will only affect the resource "/barbara.html" and nothing else. This assumption is violated by POST of course; however, POSTs are not pipelined and will therefore never show up here.

  Parameters:
    `req` - the request

### methodIsIdempotent

    public static boolean methodIsIdempotent(String method)

  A method is idempotent if the side effects of N identical requests is the same as for a single request (Section 9.1.2 of RFC-????).

  Returns:
    true if method is idempotent

### methodIsComplete

    public static boolean methodIsComplete(String method)

  A method is complete if any side effects of the request affect the complete resource. For example, a PUT is complete but a PUT with byte-ranges wouldn't be. In essence, if a request uses a method which has side effects and is complete then the state of the resource after the request is independent of the state of the resource before the request.

  Returns:
    true if method is complete

### methodHasSideEffects

    public static boolean methodHasSideEffects(String method)

### main

    public static void main(String[] args)

  Test code.