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.runtime.common.driver.context;
020
021
022import org.apache.reef.annotations.audience.DriverSide;
023import org.apache.reef.annotations.audience.Private;
024import org.apache.reef.common.AbstractFailure;
025import org.apache.reef.driver.context.ActiveContext;
026import org.apache.reef.driver.context.FailedContext;
027import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
028import org.apache.reef.util.Optional;
029
030/**
031 * Driver-Side representation of a failed context.
032 */
033@Private
034@DriverSide
035public final class FailedContextImpl extends AbstractFailure implements FailedContext {
036
037  private final Optional<ActiveContext> parentContext;
038  private final EvaluatorDescriptor evaluatorDescriptor;
039  private final String evaluatorID;
040
041  /**
042   * @param id                  Identifier of the entity that produced the error.
043   * @param message             One-line error message.
044   * @param description         Long error description.
045   * @param cause               Java Exception that caused the error.
046   * @param data                byte array that contains serialized version of the error.
047   * @param parentContext       the parent context, if there is one.
048   * @param evaluatorDescriptor the descriptor of the Evaluator this context failed on.
049   * @param evaluatorID         the id of the Evaluator this context failed on.
050   */
051  public FailedContextImpl(final String id,
052                           final String message,
053                           final Optional<String> description,
054                           final Optional<Throwable> cause,
055                           final Optional<byte[]> data,
056                           final Optional<ActiveContext> parentContext,
057                           final EvaluatorDescriptor evaluatorDescriptor,
058                           final String evaluatorID) {
059    super(id, message, description, cause, data);
060    this.parentContext = parentContext;
061    this.evaluatorDescriptor = evaluatorDescriptor;
062    this.evaluatorID = evaluatorID;
063  }
064
065
066  @Override
067  public Optional<ActiveContext> getParentContext() {
068    return this.parentContext;
069  }
070
071  @Override
072  public String getEvaluatorId() {
073    return this.evaluatorID;
074  }
075
076  @Override
077  public Optional<String> getParentId() {
078    if (this.getParentContext().isPresent()) {
079      return Optional.of(this.getParentContext().get().getId());
080    } else {
081      return Optional.empty();
082    }
083  }
084
085  @Override
086  public EvaluatorDescriptor getEvaluatorDescriptor() {
087    return this.evaluatorDescriptor;
088  }
089
090
091  @Override
092  public String toString() {
093    return "FailedContext{" + "evaluatorID='" + evaluatorID + "', contextID='" + getId() + "'}";
094  }
095}