/*
 * Copyright (c) 2010-2016. Axon Framework
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.axonframework.messaging;

import org.axonframework.eventsourcing.eventstore.TrackingToken;

import java.time.Duration;
import java.time.Instant;

/**
 * Interface for a source of {@link Message messages} that processors can track.
 *
 * @author Rene de Waele
 */
public interface StreamableMessageSource<M extends Message<?>> {

    /**
     * Open a stream containing all messages since given tracking token. Pass a {@code trackingToken} of {@code null} to
     * open a stream containing all available messages. Note that the returned stream is <em>infinite</em>, so beware of
     * applying terminal operations to the returned stream.
     *
     * @param trackingToken object containing the position in the stream or {@code null} to open a stream containing all
     *                      messages
     * @return a stream of messages since the given trackingToken
     */
    MessageStream<M> openStream(TrackingToken trackingToken);

    /**
     * Creates the token at the beginning of an event stream. The begging of an event stream in this context means the
     * token of very first event in the stream.
     *
     * @return the token at the beginning of an event stream
     */
    default TrackingToken createTailToken() {
        throw new UnsupportedOperationException();
    }

    /**
     * Creates the token at the end of an event stream. The end of an event stream in this context means the token of
     * very last event in the stream.
     *
     * @return the token at the end of an event stream
     */
    default TrackingToken createHeadToken() {
        throw new UnsupportedOperationException();
    }

    /**
     * Creates a token that tracks all events after given {@code dateTime}. If there is an event exactly at the given
     * {@code dateTime}, it will be tracked too.
     *
     * @param dateTime The date and time for determining criteria how the tracking token should be created. A tracking
     *                 token should point at very first event before this date and time.
     * @return a tracking token at the given {@code dateTime}, if there aren't events matching this criteria {@code
     * null} is returned
     */
    default TrackingToken createTokenAt(Instant dateTime) {
        throw new UnsupportedOperationException();
    }

    /**
     * Creates a token that tracks all events before given {@code duration}. If there is an event exactly at that time
     * (before given {@code duration}), it will be tracked too.
     *
     * @param duration The duration for determining criteria how the tracking token should be created. A tracking token
     *                 should point at very first event before this duration.
     * @return a tracking token that depicts position before given {@code duration}, if there aren't events matching
     * this criteria {@code null} is returned
     */
    default TrackingToken createTokenSince(Duration duration) {
        return createTokenAt(Instant.now().minus(duration));
    }
}

@@ -25,9 +25,9 @@
 -201
-6
+8
 . Ax
@@ -39,16 +39,19 @@
 amework%0A
+ *%0A
  * Licen
@@ -1632,17 +1632,19 @@
  The beg
-g
+inn
 ing of a
@@ -1724,32 +1724,296 @@
  in the stream.%0A
+     * %3Cp%3E%0A     * The default behavior for this method is to return %7B@code null%7D, which always represents the tail position of a%0A     * stream. However, implementations are encouraged to return an instance that explicitly represents the tail%0A     * of the stream.%0A
      *%0A     * @r
@@ -2130,49 +2130,19 @@
     
-throw new UnsupportedOperationException()
+return null
 ;%0A  
@@ -2364,32 +2364,137 @@
 an event stream%0A
+     * @throws UnsupportedOperationException if the implementation does not support creating head tokens%0A
      */%0A    defa
@@ -3112,32 +3112,150 @@
 ll%7D is returned%0A
+     * @throws UnsupportedOperationException if the implementation does not support the creation of time-based tokens%0A
      */%0A    defa
@@ -3418,28 +3418,30 @@
  events 
-before given
+since the last
  %7B@code 
@@ -3921,24 +3921,142 @@
 is returned%0A
+     * @throws UnsupportedOperationException if the implementation does not support the creation of time-based tokens%0A
      */%0A    

Set default 'tail token' implementation to `null` on `StreamableMessageSource`