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.resourcemanager;
020
021import org.apache.reef.proto.ReefServiceProtos;
022import org.apache.reef.runtime.common.driver.evaluator.pojos.State;
023import org.apache.reef.util.BuilderUtils;
024import org.apache.reef.util.Optional;
025
026import java.util.ArrayList;
027import java.util.List;
028
029/**
030 * Default POJO implementation of RuntimeStatusEvent.
031 * Use newBuilder to construct an instance.
032 */
033public final class RuntimeStatusEventImpl implements RuntimeStatusEvent {
034  private final String name;
035  private final State state;
036  private final List<String> containerAllocationList;
037  private final Optional<ReefServiceProtos.RuntimeErrorProto> error;
038  private final Optional<Integer> outstandingContainerRequests;
039
040  private RuntimeStatusEventImpl(final Builder builder) {
041    this.name = BuilderUtils.notNull(builder.name);
042    this.state = BuilderUtils.notNull(builder.state);
043    this.containerAllocationList = BuilderUtils.notNull(builder.containerAllocationList);
044    this.error = Optional.ofNullable(builder.error);
045    this.outstandingContainerRequests = Optional.ofNullable(builder.outstandingContainerRequests);
046  }
047
048  @Override
049  public String getName() {
050    return name;
051  }
052
053  @Override
054  public State getState() {
055    return state;
056  }
057
058  @Override
059  public List<String> getContainerAllocationList() {
060    return containerAllocationList;
061  }
062
063  @Override
064  public Optional<ReefServiceProtos.RuntimeErrorProto> getError() {
065    return error;
066  }
067
068  @Override
069  public Optional<Integer> getOutstandingContainerRequests() {
070    return outstandingContainerRequests;
071  }
072
073  public static Builder newBuilder() {
074    return new Builder();
075  }
076
077  /**
078   * Builder used to create RuntimeStatusEvent instances.
079   */
080  public static final class Builder implements org.apache.reef.util.Builder<RuntimeStatusEvent> {
081    private String name;
082    private State state;
083    private List<String> containerAllocationList = new ArrayList<>();
084    private ReefServiceProtos.RuntimeErrorProto error;
085    private Integer outstandingContainerRequests;
086
087    /**
088     * @see RuntimeStatusEvent#getName()
089     */
090    public Builder setName(final String name) {
091      this.name = name;
092      return this;
093    }
094
095    /**
096     * @see RuntimeStatusEvent#getState()
097     */
098    public Builder setState(final State state) {
099      this.state = state;
100      return this;
101    }
102
103    /**
104     * Add an entry to containerAllocationList.
105     * @see RuntimeStatusEvent#getContainerAllocationList()
106     */
107    public Builder addContainerAllocation(final String containerAllocation) {
108      this.containerAllocationList.add(containerAllocation);
109      return this;
110    }
111
112    /**
113     * @see RuntimeStatusEvent#getError()
114     */
115    public Builder setError(final ReefServiceProtos.RuntimeErrorProto error) {
116      this.error = error;
117      return this;
118    }
119
120    /**
121     * @see RuntimeStatusEvent#getOutstandingContainerRequests()
122     */
123    public Builder setOutstandingContainerRequests(final int outstandingContainerRequests) {
124      this.outstandingContainerRequests = outstandingContainerRequests;
125      return this;
126    }
127
128    @Override
129    public RuntimeStatusEvent build() {
130      return new RuntimeStatusEventImpl(this);
131    }
132  }
133}