/*
 * Copyright 2017, 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.annotation;

import io.spine.base.EventContext;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Marks a method as a subscriber for the command output.
 *
 * <p>Use it to subscribe to either events or business failures
 *
 * <h2>Subscribing to Events</h2>
 *
 * <p>An event subscriber method:
 * <ul>
 *     <li>is annotated with {@link Subscribe};
 *     <li>is {@code public};
 *     <li>returns {@code void};
 *     <li>accepts an event derived from {@link com.google.protobuf.Message Message}
 *          as the first parameter;
 *     <li>(optional) accepts an {@link EventContext EventContext}
 *          as the second parameter.
 * </ul>
 *
 * <h2>Subscribing to Failures</h2>
 *
 * <p>A failure subscriber method:
 * <ul> // TODO:2017-05-10:dmytro.dashenkov: Update.
 *     <li>is annotated with {@link Subscribe};
 *     <li>is {@code public};
 *     <li>returns {@code void};
 *     <li>accepts a failure derived from {@link com.google.protobuf.Message Message}
 *          as the first parameter;
 *     <li>accepts a command derived from {@link com.google.protobuf.Message Message}
 *          as the second parameter;
 *     <li>(optional) accepts an {@link io.spine.base.CommandContext CommandContext}
 *          as the third parameter.
 * </ul>
 *
 * <p>The type of the command argument specified acts as a filter. I.e.
 * the subscriber receives the failure if:
 * <ul>
 *     <li>the failure type matches the first argument type;
 *     <li>the command, which processing caused the failure, has the same type as the
 *          second argument.
 * </ul>
 *
 *
 * <p>If the annotation is applied to a method which doesn't satisfy any of these requirements,
 * this method is not considered as a subscriber and is not registered for the command output
 * delivery.
 *
 * @author Alexander Yevsyukov
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Subscribe {
}

@@ -1882,53 +1882,8 @@
 %3Cul%3E
- // TODO:2017-05-10:dmytro.dashenkov: Update.
 %0A * 
@@ -2115,32 +2115,43 @@
 ter;%0A *     %3Cli%3E
+(optional) 
 accepts a comman
@@ -2350,16 +2350,26 @@
  as the 
+second or 
 third pa
@@ -2385,24 +2385,297 @@
  * %3C/ul%3E%0A *%0A
+ * %3Cp%3ETherefore, if the subscriber method specifies both the Command message and%0A * the Command Context, it must have the parameters exactly is that order:%0A * %7B@code (FailureMessage, CommandMessage, CommandContext)%7D. Otherwise, an Exception may be thrown%0A * at runtime.%0A *%0A
  * %3Cp%3EThe ty
@@ -2700,16 +2700,20 @@
 argument
+, if
  specifi
@@ -2714,16 +2714,17 @@
 pecified
+,
  acts as
@@ -2732,19 +2732,19 @@
 a filter
-. I
+, i
 .e.%0A * t
@@ -2936,40 +2936,160 @@
 e as
- the%0A *          second argument
+%0A *          the command message argument if it is present;%0A *     %3Cli%3Eif the command message argument is absent, any failure of a matching type will do
 .%0A *
@@ -3098,19 +3098,16 @@
 /ul%3E%0A *%0A
- *%0A
  * %3Cp%3EIf

Update the `@Subscribe` Javadoc.