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.ClosedContext; 025import org.apache.reef.driver.evaluator.EvaluatorDescriptor; 026import org.apache.reef.util.Optional; 027 028import java.util.logging.Level; 029import java.util.logging.Logger; 030 031/** 032 * The Java-CLR bridge object for {@link org.apache.reef.driver.context.ClosedContext}. 033 */ 034@Private 035@Interop( 036 CppFiles = { "Clr2JavaImpl.h", "ClosedContextClr2Java.cpp" }, 037 CsFiles = { "IClosedContextClr2Java.cs", "ClosedContext.cs" }) 038public final class ClosedContextBridge extends NativeBridge implements ClosedContext { 039 040 private static final Logger LOG = Logger.getLogger(ClosedContextBridge.class.getName()); 041 042 private final ClosedContext jcloseContext; 043 private final ActiveContextBridge parentContext; 044 private final String contextId; 045 private final String evaluatorId; 046 private final EvaluatorDescriptor evaluatorDescriptor; 047 048 public ClosedContextBridge(final ClosedContext closedContext, 049 final ActiveContextBridgeFactory activeContextBridgeFactory) { 050 jcloseContext = closedContext; 051 parentContext = activeContextBridgeFactory.getActiveContextBridge(closedContext.getParentContext()); 052 contextId = closedContext.getId(); 053 evaluatorId = closedContext.getEvaluatorId(); 054 evaluatorDescriptor = closedContext.getEvaluatorDescriptor(); 055 } 056 057 @Override 058 public String getId() { 059 return contextId; 060 } 061 062 @Override 063 public String getEvaluatorId() { 064 return evaluatorId; 065 } 066 067 @Override 068 public Optional<String> getParentId() { 069 return Optional.of(parentContext.getId()); 070 } 071 072 @Override 073 public EvaluatorDescriptor getEvaluatorDescriptor() { 074 return evaluatorDescriptor; 075 } 076 077 @Override 078 public void close() throws Exception { 079 } 080 081 public String getEvaluatorDescriptorString() { 082 final String descriptorString = Utilities.getEvaluatorDescriptorString(evaluatorDescriptor); 083 LOG.log(Level.INFO, "Closed Context - serialized evaluator descriptor: " + descriptorString); 084 return descriptorString; 085 } 086 087 @Override 088 public ActiveContext getParentContext() { 089 return jcloseContext.getParentContext(); 090 } 091}