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.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    if (closedContext.getParentContext() != null) {
052      parentContext = activeContextBridgeFactory.getActiveContextBridge(closedContext.getParentContext());
053    } else {
054      parentContext = null;
055    }
056
057    contextId = closedContext.getId();
058    evaluatorId = closedContext.getEvaluatorId();
059    evaluatorDescriptor = closedContext.getEvaluatorDescriptor();
060  }
061
062  @Override
063  public String getId() {
064    return contextId;
065  }
066
067  @Override
068  public String getEvaluatorId() {
069    return evaluatorId;
070  }
071
072  @Override
073  public Optional<String> getParentId() {
074    return Optional.of(parentContext.getId());
075  }
076
077  @Override
078  public EvaluatorDescriptor getEvaluatorDescriptor() {
079    return evaluatorDescriptor;
080  }
081
082  @Override
083  public void close() throws Exception {
084  }
085
086  public String getEvaluatorDescriptorString() {
087    final String descriptorString = Utilities.getEvaluatorDescriptorString(evaluatorDescriptor);
088    LOG.log(Level.INFO, "Closed Context - serialized evaluator descriptor: " + descriptorString);
089    return descriptorString;
090  }
091
092  public ActiveContextBridge getParentContextBridge() {
093    return parentContext;
094  }
095
096  @Override
097  public ActiveContext getParentContext() {
098    return jcloseContext.getParentContext();
099  }
100}