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.impl; 020 021import org.apache.reef.io.network.Message; 022import org.apache.reef.wake.Identifier; 023 024import java.util.ArrayList; 025import java.util.List; 026 027/** 028 * Network service message that implements the Message interface. 029 * 030 * @param <T> type 031 */ 032public class NSMessage<T> implements Message<T> { 033 private final Identifier srcId; 034 private final Identifier destId; 035 private final List<T> data; 036 037 /** 038 * Constructs a network service message. 039 * 040 * @param srcId a source identifier 041 * @param destId a destination identifier 042 * @param data data of type T 043 */ 044 public NSMessage(final Identifier srcId, final Identifier destId, final T data) { 045 this.srcId = srcId; 046 this.destId = destId; 047 this.data = new ArrayList<>(1); 048 this.data.add(data); 049 } 050 051 /** 052 * Constructs a network service message. 053 * 054 * @param srcId a source identifier 055 * @param destId a destination identifier 056 * @param data a list of data of type T 057 */ 058 public NSMessage(final Identifier srcId, final Identifier destId, final List<T> data) { 059 this.srcId = srcId; 060 this.destId = destId; 061 this.data = data; 062 } 063 064 /** 065 * Gets a source identifier. 066 * 067 * @return an identifier 068 */ 069 public Identifier getSrcId() { 070 return srcId; 071 } 072 073 /** 074 * Gets a destination identifier. 075 * 076 * @return an identifier 077 */ 078 public Identifier getDestId() { 079 return destId; 080 } 081 082 /** 083 * Gets data. 084 * 085 * @return data 086 */ 087 public List<T> getData() { 088 return data; 089 } 090}