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.runtime.common.driver.api;
020
021import org.apache.reef.driver.evaluator.EvaluatorProcess;
022import org.apache.reef.runtime.common.files.FileResource;
023import org.apache.reef.runtime.common.files.FileResourceImpl;
024import org.apache.reef.runtime.common.files.FileType;
025import org.apache.reef.tang.Configuration;
026import org.apache.reef.util.BuilderUtils;
027
028import java.io.File;
029import java.util.HashSet;
030import java.util.Set;
031
032/**
033 * Default POJO implementation of ResourceLaunchEvent.
034 * Use newBuilder to construct an instance.
035 */
036public final class ResourceLaunchEventImpl implements ResourceLaunchEvent {
037
038  private final String identifier;
039  private final String remoteId;
040  private final Configuration evaluatorConf;
041  private final EvaluatorProcess process;
042  private final Set<FileResource> fileSet;
043  private final String runtimeName;
044
045  private ResourceLaunchEventImpl(final Builder builder) {
046    this.identifier = BuilderUtils.notNull(builder.identifier);
047    this.remoteId = BuilderUtils.notNull(builder.remoteId);
048    this.evaluatorConf = BuilderUtils.notNull(builder.evaluatorConf);
049    this.process = BuilderUtils.notNull(builder.process);
050    this.fileSet = BuilderUtils.notNull(builder.fileSet);
051    this.runtimeName = BuilderUtils.notNull(builder.runtimeName);
052  }
053
054  @Override
055  public String getIdentifier() {
056    return identifier;
057  }
058
059  @Override
060  public String getRemoteId() {
061    return remoteId;
062  }
063
064  @Override
065  public Configuration getEvaluatorConf() {
066    return evaluatorConf;
067  }
068
069  @Override
070  public EvaluatorProcess getProcess() {
071    return process;
072  }
073
074  @Override
075  public Set<FileResource> getFileSet() {
076    return fileSet;
077  }
078
079  @Override
080  public String getRuntimeName() {
081    return runtimeName;
082  }
083
084  public static Builder newBuilder() {
085    return new Builder();
086  }
087
088  /**
089   * Builder used to create ResourceLaunchEvent instances.
090   */
091  public static final class Builder implements org.apache.reef.util.Builder<ResourceLaunchEvent> {
092    private String identifier;
093    private String remoteId;
094    private Configuration evaluatorConf;
095    private EvaluatorProcess process;
096    private Set<FileResource> fileSet = new HashSet<>();
097    private String runtimeName;
098
099    /**
100     * @see ResourceLaunchEvent#getIdentifier()
101     */
102    public Builder setIdentifier(final String identifier) {
103      this.identifier = identifier;
104      return this;
105    }
106
107    /**
108     * @see ResourceLaunchEvent#getRuntimeName()
109     */
110    public Builder setRuntimeName(final String runtimeName) {
111      this.runtimeName = runtimeName;
112      return this;
113    }
114
115    /**
116     * @see ResourceLaunchEvent#getRemoteId()
117     */
118    public Builder setRemoteId(final String remoteId) {
119      this.remoteId = remoteId;
120      return this;
121    }
122
123    /**
124     * @see ResourceLaunchEvent#getEvaluatorConf()
125     */
126    public Builder setEvaluatorConf(final Configuration evaluatorConf) {
127      this.evaluatorConf = evaluatorConf;
128      return this;
129    }
130
131    /**
132     * @see ResourceLaunchEvent#getProcess()
133     */
134    public Builder setProcess(final EvaluatorProcess process) {
135      this.process = process;
136      return this;
137    }
138
139    /**
140     * Add an entry to the fileSet.
141     *
142     * @see ResourceLaunchEvent#getFileSet()
143     */
144    public Builder addFile(final FileResource file) {
145      this.fileSet.add(file);
146      return this;
147    }
148
149    /**
150     * Utility method that adds files to the fileSet.
151     *
152     * @param files the files to add.
153     * @return this
154     * @see ResourceLaunchEvent#getFileSet()
155     */
156    public Builder addFiles(final Iterable<File> files) {
157      for (final File file : files) {
158        this.addFile(FileResourceImpl.newBuilder()
159            .setName(file.getName())
160            .setPath(file.getPath())
161            .setType(FileType.PLAIN)
162            .build());
163      }
164      return this;
165    }
166
167    /**
168     * Utility method that adds Libraries to the fileSet.
169     *
170     * @param files the files to add.
171     * @return this
172     * @see ResourceLaunchEvent#getFileSet()
173     */
174    public Builder addLibraries(final Iterable<File> files) {
175      for (final File file : files) {
176        this.addFile(FileResourceImpl.newBuilder()
177            .setName(file.getName())
178            .setPath(file.getPath())
179            .setType(FileType.LIB)
180            .build());
181      }
182      return this;
183    }
184
185    @Override
186    public ResourceLaunchEvent build() {
187      return new ResourceLaunchEventImpl(this);
188    }
189  }
190}