nxt.http

## Class EventWait

- java.lang.Object
- - nxt.http.APIServlet.APIRequestHandler
  - - nxt.http.EventWait

-     public class EventWait
      extends APIServlet.APIRequestHandler

  The EventWait API will wait for one of the server events registered by EventRegister. EventWait will return immediately if one or more events have occurred since the last time EventWait was called. All pending events will be returned in a single response. The events remain registered so successive calls to EventWait can be made without another call to EventRegister.

  Only one EventWait can be outstanding for the same network address. If a second EventWait is issued, the current EventWait will be replaced by the new EventWait.

  Request parameters:

  - timeout - Number of seconds to wait for an event. The EventWait will complete normally if no event is received within the timeout interval. nxt.apiEventTimeout will be used if no timeout value is specified or if the requested timeout is greater than nxt.apiEventTimeout.

  Response parameters:

  - events - An array of event objects

  Error Response parameters:

  - errorCode - API error code
  - errorDescription - API error description

  Event object:

  - name - The event name
  - ids - An array of event object identifiers

  Event names:

  - Block.BLOCK_GENERATED
  - Block.BLOCK_POPPED
  - Block.BLOCK_PUSHED
  - Ledger.ADD_ENTRY.account - The account suffix will be Reed-Solomon identifier of the account associated with the ledger entry.
  - Peer.ADD_INBOUND
  - Peer.ADDED_ACTIVE_PEER
  - Peer.BLACKLIST
  - Peer.CHANGED_ACTIVE_PEER
  - Peer.DEACTIVATE
  - Peer.NEW_PEER
  - Peer.REMOVE
  - Peer.REMOVE_INBOUND
  - Peer.UNBLACKLIST
  - Transaction.ADDED_CONFIRMED_TRANSACTIONS
  - Transaction.ADDED_UNCONFIRMED_TRANSACTIONS
  - Transaction.REJECT_PHASED_TRANSACTION
  - Transaction.RELEASE_PHASED_TRANSACTION
  - Transaction.REMOVE_UNCONFIRMED_TRANSACTIONS

  Event object identifiers:

  - Block string identifier for a Block event
  - Peer network address for a Peer event
  - Transaction string identifier for a Transaction event

- - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `allowRequiredBlockParameters()` No required block parameters
    `protected org.json.simple.JSONStreamAware` | `processRequest(javax.servlet.http.HttpServletRequest req)` Process the EventWait API request The response will be returned immediately if there are any pending events.
    `protected boolean` | `requirePost()`

    - ### Methods inherited from class nxt.http.APIServlet.APIRequestHandler

      `getAPITags, getFileParameter, getParameters, isPassword, isTextArea, processRequest, requireBlockchain, requireFullClient, requirePassword, startDbTransaction`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### processRequest

          protected org.json.simple.JSONStreamAware processRequest(javax.servlet.http.HttpServletRequest req)

      Process the EventWait API request The response will be returned immediately if there are any pending events. Otherwise, an asynchronous context will be created and the response will be returned after the wait has completed. By using an asynchronous context, we avoid tying up the Jetty servlet thread while waiting for an event.
      Specified by:
        `processRequest` in class `APIServlet.APIRequestHandler`
      Parameters:
        `req` - API request
      Returns:
        API response or null

    - #### requirePost

          protected final boolean requirePost()

      Overrides:
        `requirePost` in class `APIServlet.APIRequestHandler`

    - #### allowRequiredBlockParameters

          protected boolean allowRequiredBlockParameters()

      No required block parameters
      Overrides:
        `allowRequiredBlockParameters` in class `APIServlet.APIRequestHandler`
      Returns:
        FALSE to disable the required block parameters