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.config.OperatorSpec;
022import org.apache.reef.io.network.group.impl.utils.Utils;
023import org.apache.reef.io.serialization.Codec;
024
025/**
026 * The specification for the Scatter operator.
027 */
028public class ScatterOperatorSpec implements OperatorSpec {
029
030  private final String senderId;
031  private final Class<? extends Codec> dataCodecClass;
032
033  public ScatterOperatorSpec(final String senderId,
034                             final Class<? extends Codec> dataCodecClass) {
035    this.senderId = senderId;
036    this.dataCodecClass = dataCodecClass;
037  }
038
039  public String getSenderId() {
040    return senderId;
041  }
042
043  @Override
044  public Class<? extends Codec> getDataCodecClass() {
045    return dataCodecClass;
046  }
047
048  @Override
049  public String toString() {
050    final StringBuilder sb = new StringBuilder("Scatter Operator Spec: [sender=")
051        .append(senderId)
052        .append("] [dataCodecClass=")
053        .append(Utils.simpleName(dataCodecClass))
054        .append("]");
055    return sb.toString();
056  }
057
058  public static Builder newBuilder() {
059    return new ScatterOperatorSpec.Builder();
060  }
061
062  public static class Builder implements org.apache.reef.util.Builder<ScatterOperatorSpec> {
063
064    private String senderId;
065    private Class<? extends Codec> dataCodecClass;
066
067    public Builder setSenderId(final String senderId) {
068      this.senderId = senderId;
069      return this;
070    }
071
072    public Builder setDataCodecClass(final Class<? extends Codec> dataCodecClass) {
073      this.dataCodecClass = dataCodecClass;
074      return this;
075    }
076
077    @Override
078    public ScatterOperatorSpec build() {
079      return new ScatterOperatorSpec(senderId, dataCodecClass);
080    }
081  }
082}
083