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.runtime.common.driver.evaluator.pojos.State;
022import org.apache.reef.util.BuilderUtils;
023import org.apache.reef.util.Optional;
024
025/**
026 * Default POJO implementation of ResourceStatusEvent.
027 * Use newBuilder to construct an instance.
028 */
029public final class ResourceStatusEventImpl implements ResourceStatusEvent {
030
031  private final String identifier;
032  private final State state;
033  private final Optional<String> diagnostics;
034  private final Optional<Integer> exitCode;
035  private final String runtimeName;
036
037  private ResourceStatusEventImpl(final Builder builder) {
038    this.identifier = BuilderUtils.notNull(builder.identifier);
039    this.state = BuilderUtils.notNull(builder.state);
040    this.diagnostics = Optional.ofNullable(builder.diagnostics);
041    this.exitCode = Optional.ofNullable(builder.exitCode);
042    this.runtimeName = BuilderUtils.notNull(builder.identifier);
043  }
044
045  @Override
046  public String toString() {
047    return String.format(
048        "ResourceStatusEventImpl:{id:%s, runtime:%s, state:%s, diag:%s, exit:%s}",
049        identifier, runtimeName, state, diagnostics, exitCode);
050  }
051
052  @Override
053  public String getIdentifier() {
054    return identifier;
055  }
056
057  @Override
058  public String getRuntimeName() {
059    return runtimeName;
060  }
061
062  @Override
063  public State getState() {
064    return state;
065  }
066
067  @Override
068  public Optional<String> getDiagnostics() {
069    return diagnostics;
070  }
071
072  @Override
073  public Optional<Integer> getExitCode() {
074    return exitCode;
075  }
076
077  public static Builder newBuilder() {
078    return new Builder();
079  }
080
081  /**
082   * Builder used to create ResourceStatusEvent instances.
083   */
084  public static final class Builder implements org.apache.reef.util.Builder<ResourceStatusEvent> {
085
086    private String identifier;
087    private String runtimeName;
088    private State state;
089    private String diagnostics;
090    private Integer exitCode;
091
092    /**
093     * @see ResourceStatusEvent#getIdentifier()
094     */
095    public Builder setIdentifier(final String identifier) {
096      this.identifier = identifier;
097      return this;
098    }
099
100    /**
101     * @see ResourceStatusEvent#getIdentifier()
102     */
103    public Builder setRuntimeName(final String runtimeName) {
104      this.runtimeName = runtimeName;
105      return this;
106    }
107    /**
108     * @see ResourceStatusEvent#getState()
109     */
110    public Builder setState(final State state) {
111      this.state = state;
112      return this;
113    }
114
115    /**
116     * @see ResourceStatusEvent#getDiagnostics()
117     */
118    public Builder setDiagnostics(final String diagnostics) {
119      this.diagnostics = diagnostics;
120      return this;
121    }
122
123    /**
124     * @see ResourceStatusEvent#getExitCode()
125     */
126    public Builder setExitCode(final int exitCode) {
127      this.exitCode = exitCode;
128      return this;
129    }
130
131    @Override
132    public ResourceStatusEvent build() {
133      return new ResourceStatusEventImpl(this);
134    }
135  }
136}