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.util.BuilderUtils;
022import org.apache.reef.util.Optional;
023
024/**
025 * Default POJO implementation of ResourceAllocationEvent.
026 * Use newBuilder to construct an instance.
027 */
028public final class ResourceAllocationEventImpl implements ResourceAllocationEvent {
029  private final String identifier;
030  private final int resourceMemory;
031  private final String nodeId;
032  private final Optional<Integer> virtualCores;
033
034  private ResourceAllocationEventImpl(final Builder builder) {
035    this.identifier = BuilderUtils.notNull(builder.identifier);
036    this.resourceMemory = BuilderUtils.notNull(builder.resourceMemory);
037    this.nodeId = BuilderUtils.notNull(builder.nodeId);
038    this.virtualCores = Optional.ofNullable(builder.virtualCores);
039  }
040
041  @Override
042  public String getIdentifier() {
043    return identifier;
044  }
045
046  @Override
047  public int getResourceMemory() {
048    return resourceMemory;
049  }
050
051  @Override
052  public String getNodeId() {
053    return nodeId;
054  }
055
056  @Override
057  public Optional<Integer> getVirtualCores() {
058    return virtualCores;
059  }
060
061  public static Builder newBuilder() {
062    return new Builder();
063  }
064
065  /**
066   * Builder used to create ResourceAllocationEvent instances.
067   */
068  public static final class Builder implements org.apache.reef.util.Builder<ResourceAllocationEvent> {
069    private String identifier;
070    private Integer resourceMemory;
071    private String nodeId;
072    private Integer virtualCores;
073
074    /**
075     * @see ResourceAllocationEvent#getIdentifier()
076     */
077    public Builder setIdentifier(final String identifier) {
078      this.identifier = identifier;
079      return this;
080    }
081
082    /**
083     * @see ResourceAllocationEvent#getResourceMemory()
084     */
085    public Builder setResourceMemory(final int resourceMemory) {
086      this.resourceMemory = resourceMemory;
087      return this;
088    }
089
090    /**
091     * @see ResourceAllocationEvent#getNodeId()
092     */
093    public Builder setNodeId(final String nodeId) {
094      this.nodeId = nodeId;
095      return this;
096    }
097
098    /**
099     * @see ResourceAllocationEvent#getVirtualCores()
100     */
101    public Builder setVirtualCores(final int virtualCores) {
102      this.virtualCores = virtualCores;
103      return this;
104    }
105
106    @Override
107    public ResourceAllocationEvent build() {
108      return new ResourceAllocationEventImpl(this);
109    }
110  }
111}