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.io;
020
021import org.apache.reef.driver.parameters.EvaluatorConfigurationProviders;
022import org.apache.reef.tang.Configuration;
023import org.apache.reef.tang.ConfigurationProvider;
024import org.apache.reef.tang.Tang;
025import org.apache.reef.tang.annotations.Parameter;
026import org.apache.reef.wake.remote.ports.parameters.TcpPortRangeBegin;
027import org.apache.reef.wake.remote.ports.parameters.TcpPortRangeCount;
028import org.apache.reef.wake.remote.ports.parameters.TcpPortRangeTryCount;
029
030import javax.inject.Inject;
031import java.util.logging.Level;
032import java.util.logging.Logger;
033
034/**
035 * Implements ConfigurationProvider for RangeTcpPortProvider.
036 */
037public class TcpPortConfigurationProvider implements ConfigurationProvider {
038  private final int portRangeBegin;
039  private final int portRangeCount;
040  private final int portRangeTryCount;
041  private static final Logger LOG = Logger.getLogger(TcpPortConfigurationProvider.class.getName());
042
043  @Inject
044  TcpPortConfigurationProvider(@Parameter(TcpPortRangeBegin.class) final int portRangeBegin,
045                               @Parameter(TcpPortRangeCount.class) final int portRangeCount,
046                               @Parameter(TcpPortRangeTryCount.class) final int portRangeTryCount) {
047    this.portRangeBegin = portRangeBegin;
048    this.portRangeCount = portRangeCount;
049    this.portRangeTryCount = portRangeTryCount;
050    LOG.log(Level.INFO, "Instantiating " + this.toString());
051  }
052
053  /**
054   * returns a configuration for the class that implements TcpPortProvider so that class can be instantiated.
055   * somewhere else
056   *
057   * @return Configuration.
058   */
059  @Override
060  public Configuration getConfiguration() {
061    return Tang.Factory.getTang().newConfigurationBuilder()
062        .bindNamedParameter(TcpPortRangeBegin.class, String.valueOf(portRangeBegin))
063        .bindNamedParameter(TcpPortRangeCount.class, String.valueOf(portRangeCount))
064        .bindNamedParameter(TcpPortRangeTryCount.class, String.valueOf(portRangeTryCount))
065        .bindSetEntry(EvaluatorConfigurationProviders.class, TcpPortConfigurationProvider.class)
066        .build();
067  }
068
069  @Override
070  public String toString() {
071    return "TcpPortConfigurationProvider{" +
072        "portRangeBegin=" + portRangeBegin +
073        ", portRangeCount=" + portRangeCount +
074        ", portRangeTryCount=" + portRangeTryCount +
075        '}';
076  }
077}