com.github.dm.jrt.channel.StreamingChannel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jroutine Show documentation
Show all versions of jroutine Show documentation
Parallel programming on the go
/*
* 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 com.github.dm.jrt.channel;
import com.github.dm.jrt.util.TimeDuration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
/**
* Interface defining a streaming channel, that is, an I/O channel in which data are processed by
* one or more routine invocations.
*
* This type of channel is mainly meant to act as a processing pipeline in which each input produces
* one or more results.
* Streaming channels can be concatenated to form a new channel, or used as inputs for other
* channels or routine invocations.
* Note that a streaming channel must always be closed in order to correctly terminate the lifecycle
* of the involved invocations.
*
* Created by davide-maestroni on 09/24/2015.
*
* @param the input data type.
* @param the output data type.
*/
public interface StreamingChannel extends IOChannel {
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel after(@NotNull TimeDuration delay);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel after(long delay, @NotNull TimeUnit timeUnit);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel now();
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel orderByCall();
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel orderByChance();
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel orderByDelay();
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel pass(@Nullable OutputChannel extends IN> channel);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel pass(@Nullable Iterable extends IN> inputs);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel pass(@Nullable IN input);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel pass(@Nullable IN... inputs);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel afterMax(@NotNull TimeDuration timeout);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel afterMax(long timeout, @NotNull TimeUnit timeUnit);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel allInto(@NotNull Collection super OUT> results);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel eventuallyAbort();
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel eventuallyExit();
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel eventuallyThrow();
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel immediately();
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel passTo(@NotNull OutputConsumer super OUT> consumer);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel skip(int count);
/**
* {@inheritDoc}
*/
@NotNull
StreamingChannel close();
/**
* Creates a new streaming channel which is the concatenation of the specified channel and this
* one.
*
* Note that this channel will be closed as a result of the call.
*
* @param channel the channel after which to concatenate this one.
* @param the concatenation input type.
* @return the concatenated channel.
*/
@NotNull
StreamingChannel combine(
@NotNull IOChannel channel);
/**
* Creates a new streaming channel which is the concatenation of this channel and the specified
* one.
*
* Note that the passed channel will be closed as a result of the call.
*
* @param channel the channel to concatenate after this one.
* @param the concatenation output type.
* @return the concatenated channel.
*/
@NotNull
StreamingChannel concat(@NotNull IOChannel super OUT, AFTER> channel);
}