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.runtime.common.files.FileResource;
022import org.apache.reef.runtime.common.launch.ProcessType;
023import org.apache.reef.tang.Configuration;
024import org.apache.reef.util.BuilderUtils;
025
026import java.util.HashSet;
027import java.util.Set;
028
029/**
030 * Default POJO implementation of ResourceLaunchEvent.
031 * Use newBuilder to construct an instance.
032 */
033public final class ResourceLaunchEventImpl implements ResourceLaunchEvent {
034
035  private final String identifier;
036  private final String remoteId;
037  private final Configuration evaluatorConf;
038  private final ProcessType type;
039  private final Set<FileResource> fileSet;
040
041  private ResourceLaunchEventImpl(final Builder builder) {
042    this.identifier = BuilderUtils.notNull(builder.identifier);
043    this.remoteId = BuilderUtils.notNull(builder.remoteId);
044    this.evaluatorConf = BuilderUtils.notNull(builder.evaluatorConf);
045    this.type = BuilderUtils.notNull(builder.type);
046    this.fileSet = BuilderUtils.notNull(builder.fileSet);
047  }
048
049  @Override
050  public String getIdentifier() {
051    return identifier;
052  }
053
054  @Override
055  public String getRemoteId() {
056    return remoteId;
057  }
058
059  @Override
060  public Configuration getEvaluatorConf() {
061    return evaluatorConf;
062  }
063
064  @Override
065  public ProcessType getType() {
066    return type;
067  }
068
069  @Override
070  public Set<FileResource> getFileSet() {
071    return fileSet;
072  }
073
074  public static Builder newBuilder() {
075    return new Builder();
076  }
077
078  /**
079   * Builder used to create ResourceLaunchEvent instances.
080   */
081  public static final class Builder implements org.apache.reef.util.Builder<ResourceLaunchEvent> {
082    private String identifier;
083    private String remoteId;
084    private Configuration evaluatorConf;
085    private ProcessType type;
086    private Set<FileResource> fileSet = new HashSet<>();
087
088    /**
089     * @see ResourceLaunchEvent#getIdentifier()
090     */
091    public Builder setIdentifier(final String identifier) {
092      this.identifier = identifier;
093      return this;
094    }
095
096    /**
097     * @see ResourceLaunchEvent#getRemoteId()
098     */
099    public Builder setRemoteId(final String remoteId) {
100      this.remoteId = remoteId;
101      return this;
102    }
103
104    /**
105     * @see ResourceLaunchEvent#getEvaluatorConf()
106     */
107    public Builder setEvaluatorConf(final Configuration evaluatorConf) {
108      this.evaluatorConf = evaluatorConf;
109      return this;
110    }
111
112    /**
113     * @see ResourceLaunchEvent#getType()
114     */
115    public Builder setType(final ProcessType type) {
116      this.type = type;
117      return this;
118    }
119
120    /**
121     * Add an entry to the fileSet
122     * @see ResourceLaunchEvent#getFileSet()
123     */
124    public Builder addFile(final FileResource file) {
125      this.fileSet.add(file);
126      return this;
127    }
128
129    @Override
130    public ResourceLaunchEvent build() {
131      return new ResourceLaunchEventImpl(this);
132    }
133  }
134}