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 NodeDescriptorEvent. 026 * Use newBuilder to construct an instance. 027 */ 028public final class NodeDescriptorEventImpl implements NodeDescriptorEvent { 029 private final String identifier; 030 private final String hostName; 031 private final int port; 032 private final int memorySize; 033 private final Optional<String> rackName; 034 035 private NodeDescriptorEventImpl(final Builder builder) { 036 this.identifier = BuilderUtils.notNull(builder.identifier); 037 this.hostName = BuilderUtils.notNull(builder.hostName); 038 this.port = BuilderUtils.notNull(builder.port); 039 this.memorySize = BuilderUtils.notNull(builder.memorySize); 040 this.rackName = Optional.ofNullable(builder.rackName); 041 } 042 043 @Override 044 public String getIdentifier() { 045 return identifier; 046 } 047 048 @Override 049 public String getHostName() { 050 return hostName; 051 } 052 053 @Override 054 public int getPort() { 055 return port; 056 } 057 058 @Override 059 public int getMemorySize() { 060 return memorySize; 061 } 062 063 @Override 064 public Optional<String> getRackName() { 065 return rackName; 066 } 067 068 public static Builder newBuilder() { 069 return new Builder(); 070 } 071 072 /** 073 * Builder used to create NodeDescriptorEvent instances. 074 */ 075 public static final class Builder implements org.apache.reef.util.Builder<NodeDescriptorEvent> { 076 private String identifier; 077 private String hostName; 078 private Integer port; 079 private Integer memorySize; 080 private String rackName; 081 082 /** 083 * @see NodeDescriptorEvent#getIdentifier() 084 */ 085 public Builder setIdentifier(final String identifier) { 086 this.identifier = identifier; 087 return this; 088 } 089 090 /** 091 * @see NodeDescriptorEvent#getHostName() 092 */ 093 public Builder setHostName(final String hostName) { 094 this.hostName = hostName; 095 return this; 096 } 097 098 /** 099 * @see NodeDescriptorEvent#getPort() 100 */ 101 public Builder setPort(final int port) { 102 this.port = port; 103 return this; 104 } 105 106 /** 107 * @see NodeDescriptorEvent#getMemorySize() 108 */ 109 public Builder setMemorySize(final int memorySize) { 110 this.memorySize = memorySize; 111 return this; 112 } 113 114 /** 115 * @see NodeDescriptorEvent#getRackName() 116 */ 117 public Builder setRackName(final String rackName) { 118 this.rackName = rackName; 119 return this; 120 } 121 122 @Override 123 public NodeDescriptorEvent build() { 124 return new NodeDescriptorEventImpl(this); 125 } 126 } 127}