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.hello; 020 021import org.apache.reef.client.DriverConfiguration; 022import org.apache.reef.client.DriverLauncher; 023import org.apache.reef.client.LauncherStatus; 024import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration; 025import org.apache.reef.tang.Configuration; 026import org.apache.reef.tang.exceptions.InjectionException; 027import org.apache.reef.util.EnvironmentUtils; 028import org.apache.reef.util.ThreadLogger; 029 030import java.util.logging.Level; 031import java.util.logging.Logger; 032 033/** 034 * The Client for Hello REEF example. 035 */ 036public final class HelloREEF { 037 038 private static final Logger LOG = Logger.getLogger(HelloREEF.class.getName()); 039 040 /** Number of milliseconds to wait for the job to complete. */ 041 private static final int JOB_TIMEOUT = 10000; // 10 sec. 042 043 044 /** Configuration of the runtime. */ 045 private static final Configuration RUNTIME_CONFIG = 046 LocalRuntimeConfiguration.CONF 047 .set(LocalRuntimeConfiguration.MAX_NUMBER_OF_EVALUATORS, 2) 048 .build(); 049 050 /** Configuration of the HelloREEF driver. */ 051 private static final Configuration DRIVER_CONFIG = 052 DriverConfiguration.CONF 053 .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF") 054 .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class)) 055 .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class) 056 .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class) 057 .build(); 058 059 /** 060 * Start Hello REEF job with local runtime. 061 * @param args command line parameters. 062 * @throws InjectionException configuration error. 063 */ 064 public static void main(final String[] args) throws InjectionException { 065 066 final LauncherStatus status = DriverLauncher.getLauncher(RUNTIME_CONFIG).run(DRIVER_CONFIG, JOB_TIMEOUT); 067 068 LOG.log(Level.INFO, "REEF job completed: {0}", status); 069 070 ThreadLogger.logThreads(LOG, Level.FINE, "Threads running at the end of HelloREEF:"); 071 } 072 073 /** Empty private constructor to prohibit instantiation of utility class. */ 074 private HelloREEF() { } 075}