All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dm.jrt.core.DefaultStreamingChannel Maven / Gradle / Ivy

There is a newer version: 5.9.0
Show newest version
/*
 * 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.core;

import com.github.dm.jrt.channel.IOChannel;
import com.github.dm.jrt.channel.InputChannel;
import com.github.dm.jrt.channel.OutputChannel;
import com.github.dm.jrt.channel.OutputConsumer;
import com.github.dm.jrt.channel.StreamingChannel;
import com.github.dm.jrt.util.TimeDuration;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * Default implementation of a streaming channel.
 * 

* Created by davide-maestroni on 09/24/2015. * * @param the input data type. * @param the output data type. */ class DefaultStreamingChannel implements StreamingChannel { private final IOChannel mInputChannel; private final OutputChannel mOutputChannel; /** * Constructor. * * @param inputChannel the input channel. * @param outputChannel the output channel. */ @SuppressWarnings("ConstantConditions") DefaultStreamingChannel(@NotNull final IOChannel inputChannel, @NotNull final OutputChannel outputChannel) { if (inputChannel == null) { throw new NullPointerException("the input channel must not be null"); } if (outputChannel == null) { throw new NullPointerException("the output channel must not be null"); } mInputChannel = inputChannel; mOutputChannel = outputChannel; } public boolean abort() { return mInputChannel.abort() || mOutputChannel.abort(); } public boolean abort(@Nullable final Throwable reason) { return mInputChannel.abort(reason) || mOutputChannel.abort(reason); } public boolean isEmpty() { return mInputChannel.isEmpty() && mOutputChannel.isEmpty(); } public boolean isOpen() { return mInputChannel.isOpen(); } @NotNull public StreamingChannel after(@NotNull final TimeDuration delay) { mInputChannel.after(delay); return this; } @NotNull public StreamingChannel after(final long delay, @NotNull final TimeUnit timeUnit) { mInputChannel.after(delay, timeUnit); return this; } @NotNull public StreamingChannel now() { mInputChannel.now(); return this; } @NotNull public StreamingChannel orderByCall() { mInputChannel.orderByCall(); return this; } @NotNull public StreamingChannel orderByChance() { mInputChannel.orderByChance(); return this; } @NotNull public StreamingChannel orderByDelay() { mInputChannel.orderByDelay(); return this; } @NotNull public StreamingChannel pass(@Nullable final OutputChannel channel) { mInputChannel.pass(channel); return this; } @NotNull public StreamingChannel pass(@Nullable final Iterable inputs) { mInputChannel.pass(inputs); return this; } @NotNull public StreamingChannel pass(@Nullable final IN input) { mInputChannel.pass(input); return this; } @NotNull public StreamingChannel pass(@Nullable final IN... inputs) { mInputChannel.pass(inputs); return this; } @NotNull public StreamingChannel afterMax(@NotNull final TimeDuration timeout) { mOutputChannel.afterMax(timeout); return this; } @NotNull public StreamingChannel afterMax(final long timeout, @NotNull final TimeUnit timeUnit) { mOutputChannel.afterMax(timeout, timeUnit); return this; } @NotNull public StreamingChannel allInto(@NotNull final Collection results) { mOutputChannel.allInto(results); return this; } @NotNull public StreamingChannel eventuallyAbort() { mOutputChannel.eventuallyAbort(); return this; } @NotNull public StreamingChannel eventuallyExit() { mOutputChannel.eventuallyExit(); return this; } @NotNull public StreamingChannel eventuallyThrow() { mOutputChannel.eventuallyThrow(); return this; } @NotNull public StreamingChannel immediately() { mOutputChannel.immediately(); return this; } @NotNull public StreamingChannel passTo(@NotNull final OutputConsumer consumer) { mOutputChannel.passTo(consumer); return this; } @NotNull public StreamingChannel skip(final int count) { mOutputChannel.skip(count); return this; } @NotNull public StreamingChannel close() { mInputChannel.close(); return this; } @NotNull public StreamingChannel combine( @NotNull final IOChannel channel) { mInputChannel.pass(channel).close(); return new DefaultStreamingChannel(channel, mOutputChannel); } @NotNull public StreamingChannel concat( @NotNull final IOChannel channel) { mOutputChannel.passTo(channel); return new DefaultStreamingChannel(mInputChannel, channel.close()); } @NotNull public List all() { return mOutputChannel.all(); } public boolean checkComplete() { return mOutputChannel.checkComplete(); } public boolean hasNext() { return mOutputChannel.hasNext(); } public OUT next() { return mOutputChannel.next(); } public boolean isBound() { return mOutputChannel.isBound(); } @NotNull public List next(final int count) { return mOutputChannel.next(count); } @NotNull public > CHANNEL passTo( @NotNull final CHANNEL channel) { return mOutputChannel.passTo(channel); } @NotNull public InputChannel asInput() { return this; } @NotNull public OutputChannel asOutput() { return this; } public Iterator iterator() { return mOutputChannel.iterator(); } public void remove() { mOutputChannel.remove(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy