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.network.group.impl.driver;
020
021import org.apache.reef.driver.parameters.DriverIdentifier;
022import org.apache.reef.io.network.group.api.driver.Topology;
023import org.apache.reef.io.network.group.impl.GroupCommunicationMessage;
024import org.apache.reef.io.network.group.impl.config.parameters.*;
025import org.apache.reef.tang.Injector;
026import org.apache.reef.tang.Tang;
027import org.apache.reef.tang.annotations.Name;
028import org.apache.reef.tang.annotations.Parameter;
029import org.apache.reef.tang.exceptions.InjectionException;
030import org.apache.reef.wake.EStage;
031
032import javax.inject.Inject;
033
034/**
035 * A factory used to create Topology instance.
036 * Uses Tang to instantiate new object.
037 */
038public final class TopologyFactory {
039
040  private final Injector injector;
041
042  @Inject
043  private TopologyFactory(@Parameter(GroupCommSenderStage.class) final EStage<GroupCommunicationMessage> senderStage,
044                          @Parameter(CommGroupNameClass.class) final Class<? extends Name<String>> groupName,
045                          @Parameter(DriverIdentifier.class) final String driverId,
046                          @Parameter(CommGroupNumTask.class) final int numberOfTasks,
047                          @Parameter(TreeTopologyFanOut.class) final int fanOut) {
048    injector = Tang.Factory.getTang().newInjector();
049    injector.bindVolatileParameter(GroupCommSenderStage.class, senderStage);
050    injector.bindVolatileParameter(CommGroupNameClass.class, groupName);
051    injector.bindVolatileParameter(DriverIdentifier.class, driverId);
052    injector.bindVolatileParameter(CommGroupNumTask.class, numberOfTasks);
053    injector.bindVolatileParameter(TreeTopologyFanOut.class, fanOut);
054  }
055
056  /**
057   * Instantiates a new Topology instance.
058   * @param operatorName specified name of the operator
059   * @param topologyClass specified topology type
060   * @return Topology instance
061   * @throws InjectionException
062   */
063  public Topology getNewInstance(final Class<? extends Name<String>> operatorName,
064                                 final Class<? extends Topology> topologyClass) throws InjectionException {
065    final Injector newInjector = injector.forkInjector();
066    newInjector.bindVolatileParameter(OperatorNameClass.class, operatorName);
067    return newInjector.getInstance(topologyClass);
068  }
069}