Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.gh.bmd.jrt.core;
 
 
 import java.util.List;
 
 
 import static com.gh.bmd.jrt.builder.InvocationConfiguration.builder;

Default implementation of a transport channel.

Created by davide-maestroni on 10/24/14.

Parameters:
<DATA> the data type.
 
 class DefaultTransportChannel<DATA> implements TransportChannel<DATA> {
 
     private final DefaultResultChannel<DATA> mInputChannel;
 
     private final OutputChannel<DATA> mOutputChannel;

    
Constructor.

Parameters:
configuration the channel configuration.
 
     DefaultTransportChannel(@Nonnull final ChannelConfiguration configuration) {
 
         final InvocationConfiguration invocationConfiguration =
                 asInvocationConfiguration(configuration);
         final Logger logger = invocationConfiguration.newLogger(this);
         final ChannelAbortHandler abortHandler = new ChannelAbortHandler();
         final DefaultResultChannel<DATA> inputChannel =
                 new DefaultResultChannel<DATA>(invocationConfigurationabortHandler,
                                                invocationConfiguration.getAsyncRunnerOr(
                                                        Runners.sharedRunner()), logger);
         abortHandler.setChannel(inputChannel);
          = inputChannel;
          = inputChannel.getOutput();
         logger.dbg("building transport channel with configuration: %s"configuration);
     }
 
     @Nonnull
             @Nonnull final ChannelConfiguration configuration) {
 
         return builder().withAsyncRunner(configuration.getAsyncRunnerOr(null))
                         .withOutputMaxSize(
                                 configuration.getChannelMaxSizeOr(.))
                         .withOutputOrder(configuration.getChannelOrderTypeOr(null))
                         .withOutputTimeout(configuration.getChannelTimeoutOr(null))
                         .withExecutionTimeout(configuration.getPassTimeoutOr(null))
                         .withExecutionTimeoutAction(configuration.getPassTimeoutActionOr(null))
                         .withLog(configuration.getLogOr(null))
                         .withLogLevel(configuration.getLogLevelOr(null))
                         .set();
     }
 
     public boolean abort() {
 
         return .abort() || .abort();
     }
 
     public boolean abort(@Nullable final Throwable reason) {
 
         return .abort(reason) || .abort(reason);
     }
 
     public boolean isOpen() {
 
        return .isOpen();
    }
    @Nonnull
    public TransportChannel<DATA> after(@Nonnull final TimeDuration delay) {
        .after(delay);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> after(final long delay, @Nonnull final TimeUnit timeUnit) {
        .after(delaytimeUnit);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> now() {
        .now();
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> orderByCall() {
        .orderByCall();
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> orderByChance() {
        .orderByChance();
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> orderByDelay() {
        .orderByDelay();
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> pass(@Nullable final OutputChannel<? extends DATA> channel) {
        .pass(channel);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> pass(@Nullable final Iterable<? extends DATA> inputs) {
        .pass(inputs);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> pass(@Nullable final DATA input) {
        .pass(input);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> pass(@Nullable final DATA... inputs) {
        .pass(inputs);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> afterMax(@Nonnull final TimeDuration timeout) {
        .afterMax(timeout);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> afterMax(final long timeout, @Nonnull final TimeUnit timeUnit) {
        .afterMax(timeouttimeUnit);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> allInto(@Nonnull final Collection<? super DATA> results) {
        .allInto(results);
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> eventually() {
        .eventually();
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> eventuallyAbort() {
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> eventuallyExit() {
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> eventuallyThrow() {
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> immediately() {
        .immediately();
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> passTo(@Nonnull final OutputConsumer<? super DATA> consumer) {
        .passTo(consumer);
        return this;
    }
    @Nonnull
    public InputChannel<DATA> asInput() {
        return this;
    }
    @Nonnull
    public OutputChannel<DATA> asOutput() {
        return this;
    }
    @Nonnull
    public TransportChannel<DATA> close() {
        .close();
        return this;
    }
    @Nonnull
    public List<DATA> all() {
        return .all();
    }
    public boolean checkComplete() {
        return .checkComplete();
    }
    public boolean hasNext() {
        return .hasNext();
    }
    public DATA next() {
        return .next();
    }
    public boolean isBound() {
        return .isBound();
    }
    @Nonnull
    public <INPUT extends InputChannel<? super DATA>> INPUT passTo(@Nonnull final INPUT channel) {
        return .passTo(channel);
    }
    public Iterator<DATA> iterator() {
        return .iterator();
    }
    public void remove() {
        .remove();
    }

    
Abort handler used to close the input channel on abort.
    private static class ChannelAbortHandler implements AbortHandler {
        private DefaultResultChannel<?> mChannel;
        public void onAbort(@Nullable final RoutineException reasonfinal long delay,
                @Nonnull final TimeUnit timeUnit) {
            .close(reason);
        }
        private void setChannel(@Nonnull final DefaultResultChannel<?> channel) {
             = channel;
        }
    }
New to GrepCode? Check out our FAQ X