This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.examples.data.output;
020
021import org.apache.reef.io.data.output.OutputStreamProvider;
022import org.apache.reef.task.Task;
023
024import javax.inject.Inject;
025import java.io.DataOutputStream;
026import java.io.IOException;
027
028/**
029 * The Task code for the output service demo app.
030 * This task receives an output stream from the output service
031 * and writes "Hello REEF!" on it.
032 */
033public final class OutputServiceTask implements Task {
034
035  /**
036   * Output stream provider object through which tasks create output streams.
037   */
038  private final OutputStreamProvider outputStreamProvider;
039
040  /**
041   * Task constructor - instantiated via TANG.
042   *
043   * @param outputStreamProvider Output stream provider object through which tasks create output streams.
044   */
045  @Inject
046  public OutputServiceTask(final OutputStreamProvider outputStreamProvider) {
047    this.outputStreamProvider = outputStreamProvider;
048  }
049
050  /**
051   * Receives an output stream from the output service and writes "Hello REEF!" on it.
052   *
053   * @param memento the memento objected passed down by the driver.
054   * @return null
055   * @throws java.io.IOException
056   */
057  @Override
058  public byte[] call(final byte[] memento) throws IOException {
059    try (final DataOutputStream outputStream = outputStreamProvider.create("hello")) {
060      outputStream.writeBytes("Hello REEF!");
061    }
062    return null;
063  }
064}