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