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.io.network.group.impl.config; 020 021import org.apache.reef.io.network.group.api.operators.Reduce.ReduceFunction; 022import org.apache.reef.io.network.group.api.config.OperatorSpec; 023import org.apache.reef.io.network.group.impl.utils.Utils; 024import org.apache.reef.io.serialization.Codec; 025 026/** 027 * The specification for the Reduce operator. 028 */ 029public class ReduceOperatorSpec implements OperatorSpec { 030 031 private final String receiverId; 032 033 /** 034 * Codec to be used to serialize data. 035 */ 036 private final Class<? extends Codec> dataCodecClass; 037 038 /** 039 * The reduce function to be used for operations that do reduction. 040 */ 041 private final Class<? extends ReduceFunction> redFuncClass; 042 043 044 public ReduceOperatorSpec(final String receiverId, 045 final Class<? extends Codec> dataCodecClass, 046 final Class<? extends ReduceFunction> redFuncClass) { 047 super(); 048 this.receiverId = receiverId; 049 this.dataCodecClass = dataCodecClass; 050 this.redFuncClass = redFuncClass; 051 } 052 053 public String getReceiverId() { 054 return receiverId; 055 } 056 057 /** 058 * @return the redFuncClass 059 */ 060 public Class<? extends ReduceFunction> getRedFuncClass() { 061 return redFuncClass; 062 } 063 064 @Override 065 public Class<? extends Codec> getDataCodecClass() { 066 return dataCodecClass; 067 } 068 069 @Override 070 public String toString() { 071 return "Reduce Operator Spec: [receiver=" + receiverId + "] [dataCodecClass=" + Utils.simpleName(dataCodecClass) 072 + "] [reduceFunctionClass=" + Utils.simpleName(redFuncClass) + "]"; 073 } 074 075 public static Builder newBuilder() { 076 return new ReduceOperatorSpec.Builder(); 077 } 078 079 public static class Builder implements org.apache.reef.util.Builder<ReduceOperatorSpec> { 080 081 private String receiverId; 082 083 private Class<? extends Codec> dataCodecClass; 084 085 private Class<? extends ReduceFunction> redFuncClass; 086 087 public Builder setReceiverId(final String receiverId) { 088 this.receiverId = receiverId; 089 return this; 090 } 091 092 public Builder setDataCodecClass(final Class<? extends Codec> codecClazz) { 093 this.dataCodecClass = codecClazz; 094 return this; 095 } 096 097 @SuppressWarnings("checkstyle:hiddenfield") 098 public Builder setReduceFunctionClass(final Class<? extends ReduceFunction> redFuncClass) { 099 this.redFuncClass = redFuncClass; 100 return this; 101 } 102 103 @Override 104 public ReduceOperatorSpec build() { 105 return new ReduceOperatorSpec(receiverId, dataCodecClass, redFuncClass); 106 } 107 } 108}