PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/exec/TaskRunner.java

#
Java | 64 lines | 30 code | 11 blank | 23 comment | 0 complexity | 39303efe09e2dd00cdd508eb3b8d43a2 MD5 | raw file
 1/**
 2 * Licensed to the Apache Software Foundation (ASF) under one
 3 * or more contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  The ASF licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.hive.ql.exec;
20
21import java.io.Serializable;
22
23import org.apache.hadoop.hive.ql.session.SessionState;
24
25/**
26 * TaskRunner implementation.
27 **/
28
29public class TaskRunner extends Thread {
30  protected Task<? extends Serializable> tsk;
31  protected TaskResult result;
32  protected SessionState ss;
33
34  public TaskRunner(Task<? extends Serializable> tsk, TaskResult result) {
35    this.tsk = tsk;
36    this.result = result;
37    ss = SessionState.get();
38  }
39
40  public Task<? extends Serializable> getTask() {
41    return tsk;
42  }
43
44  @Override
45  public void run() {
46    SessionState.start(ss);
47    runSequential();
48  }
49
50  /**
51   * Launches a task, and sets its exit value in the result variable.
52   */
53
54  public void runSequential() {
55    int exitVal = -101;
56    try {
57      exitVal = tsk.executeTask();
58    } catch (Throwable t) {
59      t.printStackTrace();
60    }
61    result.setExitVal(exitVal);
62  }
63
64}