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.javabridge; 020 021import org.apache.reef.annotations.audience.Interop; 022import org.apache.reef.annotations.audience.Private; 023import org.apache.reef.driver.context.ActiveContext; 024import org.apache.reef.driver.context.ContextBase; 025import org.apache.reef.driver.context.FailedContext; 026import org.apache.reef.driver.evaluator.EvaluatorDescriptor; 027import org.apache.reef.util.Optional; 028 029import java.util.logging.Level; 030import java.util.logging.Logger; 031 032/** 033 * The Java-CLR bridge object for {@link org.apache.reef.driver.context.FailedContext}. 034 */ 035@Private 036@Interop( 037 CppFiles = { "Clr2JavaImpl.h", "FailedContextClr2Java.cpp" }, 038 CsFiles = { "IFailedContextClr2Java.cs", "FailedContext.cs" }) 039public final class FailedContextBridge extends NativeBridge implements ContextBase { 040 041 private static final Logger LOG = Logger.getLogger(FailedContextBridge.class.getName()); 042 043 private final ActiveContextBridge parentContext; 044 private final EvaluatorDescriptor evaluatorDescriptor; 045 private final String evaluatorId; 046 private final String contextId; 047 private final String parentContextId; 048 private final FailedContext jfailedContext; 049 050 public FailedContextBridge(final FailedContext failedContext, final ActiveContextBridgeFactory factory) { 051 jfailedContext = failedContext; 052 evaluatorDescriptor = failedContext.getEvaluatorDescriptor(); 053 evaluatorId = failedContext.getEvaluatorId(); 054 contextId = failedContext.getId(); 055 if (failedContext.getParentContext().isPresent()) { 056 final ActiveContext parent = failedContext.getParentContext().get(); 057 this.parentContextId = parent.getId(); 058 this.parentContext = factory.getActiveContextBridge(parent); 059 } else { 060 this.parentContextId = null; 061 this.parentContext = null; 062 } 063 064 } 065 066 @Override 067 public void close() throws Exception { 068 } 069 070 @Override 071 public String getId() { 072 return contextId; 073 } 074 075 @Override 076 public String getEvaluatorId() { 077 return evaluatorId; 078 } 079 080 @Override 081 public Optional<String> getParentId() { 082 return Optional.ofNullable(this.parentContextId); 083 } 084 085 @Override 086 public EvaluatorDescriptor getEvaluatorDescriptor() { 087 return evaluatorDescriptor; 088 } 089 090 /** 091 * @return the parent {@link ActiveContextBridge}. 092 */ 093 public ActiveContextBridge getParentContext() { 094 return parentContext; 095 } 096 097 public String getEvaluatorDescriptorString() { 098 final String descriptorString = Utilities.getEvaluatorDescriptorString(evaluatorDescriptor); 099 LOG.log(Level.INFO, "Failed Context - serialized evaluator descriptor: " + descriptorString); 100 return descriptorString; 101 } 102}