Class ERequestFeed.Builder

  • Enclosing class:
    ERequestFeed

    public static final class ERequestFeed.Builder
    extends EFeed.Builder<F,​T,​B>
    EREquestFeed.Builder is now the preferred mechanism for creating a ERequestFeed instance. A Builder instance is acquired from ERequestFeed.builder(). The following example shows how to create an ERequestFeed instance using a Builder. The code assumes that the class implements ERequestor interface feedStatus method but uses other methods for reply messages. The example CatalogOrder request message supports two replies besides the generic EReplyMessage: OrderRejectReply and OrderUpdateReply.
    @Override public void startup() {
        final EMessageKey key = new EMessageKey(com.acme.CatalogOrder.class, subject);
    
        final ERequestFeed feed = (ERequestFeed.builder()).target(this)
                                                          .messageKey(key) Message key must be set prior to setting reply callbacks.
                                                          .scope(EFeed.FeedScope.REMOTE_ONLY)
                                                          // Call .statusCallback(lambda expression) to replace feedStatus method
                                                          // Set different callback for each reply message class.
                                                          .replyCallback(EReplyMessage.class, this::genericReply)
                                                          .replyCallback(OrderRejectReply.class, this::orderReject)
                                                          .replyCallback(OrderUpdateReply.class, this::orderUpdate)
                                                          .build();
        ...
    }
    See Also:
    ERequestFeed.builder()
    • Method Detail

      • getSubject

        protected net.sf.eBus.client.ESubject getSubject()
        Returns eBus subject for the configured message key.
        Returns:
        eBus feed subject.
      • validate

        protected Validator validate​(Validator problems)
        Checks if message key is set.
        Parameters:
        problems - place invalid configuration settings in this problems list.
        Returns:
        problems to allow for method chaining.
      • messageKey

        public ERequestFeed.Builder messageKey​(EMessageKey key)
        Sets eBus message key defining this feed. Returns this Builder instance so that configuration methods may be chained.
        Parameters:
        key - eBus message key.
        Returns:
        this Builder instance.
        Throws:
        java.lang.NullPointerException - if target is null.
      • mayClose

        public ERequestFeed.Builder mayClose​(boolean flag)
        Sets "may close" flag to given value. A true means requester has ability to close an active request; false means requester may not cancel an active request and must wait for the request to complete.

        Defaults to true.

        Parameters:
        flag - true means request may be closed.
        Returns:
        this Builder instance.
      • replyCallback

        public ERequestFeed.Builder replyCallback​(java.lang.Class<? extends EReplyMessage> mc,
                                                  ReplyCallback cb)
        Sets the callback for a specific reply message class. If cb is not null, replies will be passed to cb rather than ERequestor.reply(int, EReplyMessage, ERequestFeed.ERequest). A cb results in replies posted to the ERequestor.reply(int, EReplyMessage, ERequestFeed.ERequest) override.

        If the goal is to set a single callback method for all reply message types, then use replyCallback(ReplyCallback). Note that method overrides all previous set reply callbacks.

        The following example shows how to use this method to set a reply callback lambda expression:

        OrderRejectReply.class, this::orderReject
        Parameters:
        mc - the reply message class.
        cb - callback for the reply message.
        Returns:
        this Builder instance.
        Throws:
        java.lang.NullPointerException - if mc is null.
        java.lang.IllegalArgumentException - if mc is not a reply for this request.
        java.lang.IllegalStateException - if messageKey(EMessageKey) was not successfully called prior to setting the reply callback.
        See Also:
        messageKey(EMessageKey), replyCallback(ReplyCallback)