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 */ 019 020package org.apache.reef.runtime.common.driver.evaluator.pojos; 021 022import org.apache.reef.annotations.audience.DriverSide; 023import org.apache.reef.annotations.audience.Private; 024import org.apache.reef.proto.ReefServiceProtos; 025import org.apache.reef.proto.ReefServiceProtos.TaskStatusProto.TaskMessageProto; 026 027import java.util.ArrayList; 028import java.util.List; 029 030/** 031 * DriverSide representation of TaskStatusProto. 032 */ 033@DriverSide 034@Private 035public final class TaskStatusPOJO { 036 037 private final String taskId; 038 private final String contextId; 039 private final State state; 040 private final byte[] result; 041 private final List<TaskMessagePOJO> taskMessages = new ArrayList<>(); 042 043 public TaskStatusPOJO(final ReefServiceProtos.TaskStatusProto proto, final long sequenceNumber) { 044 045 this.taskId = proto.getTaskId(); 046 this.contextId = proto.getContextId(); 047 this.state = proto.hasState() ? State.fromProto(proto.getState()) : null; 048 this.result = proto.hasResult() ? proto.getResult().toByteArray() : null; 049 050 for (final TaskMessageProto taskMessageProto : proto.getTaskMessageList()) { 051 this.taskMessages.add(new TaskMessagePOJO(taskMessageProto, sequenceNumber)); 052 } 053 } 054 055 /** 056 * @return a list of messages sent by a task. 057 */ 058 public List<TaskMessagePOJO> getTaskMessageList() { 059 return this.taskMessages; 060 } 061 062 /** 063 * @return true, if a completed task returned a non-null value in the 'return' statement. 064 */ 065 public boolean hasResult() { 066 return null != this.result; 067 } 068 069 /** 070 * @return serialized result that a completed task returned to the Driver. 071 */ 072 public byte[] getResult() { 073 return this.result; 074 } 075 076 /** 077 * @return the id of a task. 078 */ 079 public String getTaskId() { 080 return this.taskId; 081 } 082 083 /** 084 * @return the id of a context that this task runs within. 085 */ 086 public String getContextId() { 087 return this.contextId; 088 } 089 090 /** 091 * @return current state of a task. 092 */ 093 public State getState() { 094 return this.state; 095 } 096}