/*
 * Copyright 2018, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package io.spine.server.procman;

import io.spine.annotation.SPI;
import io.spine.core.ActorMessageEnvelope;
import io.spine.server.delivery.Consumer;
import io.spine.server.delivery.Delivery;
import io.spine.server.delivery.DeliveryTag;
import io.spine.server.delivery.ShardedStream;
import io.spine.server.entity.Repository;

/**
 * A strategy on delivering the messages to the instances of a certain process manager type.
 *
 * <p>Spine users may want to extend this class or any of its framework-provided implementations
 * in order to switch to another delivery mechanism.
 *
 * @param <I> the ID type of process manager, to which messages are being delivered
 * @param <P> the type of process manager
 * @param <M> the type of message envelope, which is used for message delivery
 * @author Alex Tymchenko
 */
@SPI
public abstract class PmDelivery<I,
                        P extends ProcessManager<I, ?, ?>,
                        M extends ActorMessageEnvelope<?, ?, ?>,
                        S extends ShardedStream<I, ?, M>,
                        B extends ShardedStream.AbstractBuilder<I, M, B, S>>
        extends Delivery<I, P, M, S, B> {

    protected PmDelivery(PmMessageConsumer<I, P, M, S, B> consumer) {
        super(consumer);
    }

    protected abstract static class PmMessageConsumer<I,
            P extends ProcessManager<I, ?, ?>,
            M extends ActorMessageEnvelope<?, ?, ?>,
            S extends ShardedStream<I, ?, M>,
            B extends ShardedStream.AbstractBuilder<I, M, B, S>> extends Consumer<I, P, M, S, B> {

        protected PmMessageConsumer(DeliveryTag<M> tag, Repository<I, P> repository) {
            super(tag, repository);
        }

        @Override
        protected abstract PmEndpoint<I, P, M, ?> getEndpoint(M messageEnvelope);

        @Override
        protected ProcessManagerRepository<I, P, ?> repository() {
            return (ProcessManagerRepository<I, P, ?>) super.repository();
        }

        @Override
        protected void passToEndpoint(I id, M envelopeMessage) {
            getEndpoint(envelopeMessage).deliverNowTo(id);
        }
    }
}

@@ -1882,32 +1882,41 @@
                 
+         
 P extends Proces
@@ -1950,32 +1950,41 @@
                 
+      
+   
 M extends ActorM
@@ -2024,32 +2024,41 @@
                 
+         
 S extends Sharde
@@ -2091,32 +2091,41 @@
                 
+  
+       
 B extends Sharde
@@ -2335,16 +2335,20 @@
 t static
+%0A   
  class P
@@ -2371,32 +2371,48 @@
 %3CI,%0A            
+       
+         
 P extends Proces
@@ -2422,32 +2422,48 @@
 nager%3CI, ?, ?%3E,%0A
+                
             M ex
@@ -2491,32 +2491,48 @@
 elope%3C?, ?, ?%3E,%0A
+                
             S ex
@@ -2553,32 +2553,48 @@
 tream%3CI, ?, M%3E,%0A
+                
             B ex
@@ -2641,16 +2641,28 @@
 , B, S%3E%3E
+%0A           
  extends

Fix wrapping of the generic params.