eu.stratosphere.nephele.taskmanager.transferenvelope.TransferEnvelopeReceiverList Maven / Gradle / Ivy
/***********************************************************************************************************************
* Copyright (C) 2010-2013 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
**********************************************************************************************************************/
package eu.stratosphere.nephele.taskmanager.transferenvelope;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import eu.stratosphere.nephele.io.channels.ChannelID;
import eu.stratosphere.nephele.taskmanager.bytebuffered.ConnectionInfoLookupResponse;
import eu.stratosphere.nephele.taskmanager.bytebuffered.RemoteReceiver;
/**
* A transfer envelope receiver list contains all recipients of a transfer envelope. Their are three different types of
* receivers: Local receivers identified by {@link ChannelID} objects, remote receivers identified by
* {@link InetAddress} objects and finally checkpoints which are identified by
*
* This class is thread-safe.
*
*/
public class TransferEnvelopeReceiverList {
private final List localReceivers;
private final List remoteReceivers;
public TransferEnvelopeReceiverList(final ConnectionInfoLookupResponse cilr) {
this.localReceivers = Collections.unmodifiableList(cilr.getLocalTargets());
this.remoteReceivers = Collections.unmodifiableList(cilr.getRemoteTargets());
}
public TransferEnvelopeReceiverList(final ChannelID localReceiver) {
final List lr = new ArrayList(1);
lr.add(localReceiver);
this.localReceivers = Collections.unmodifiableList(lr);
this.remoteReceivers = Collections.emptyList();
}
public TransferEnvelopeReceiverList(final RemoteReceiver remoteReceiver) {
final List rr = new ArrayList(1);
rr.add(remoteReceiver);
this.localReceivers = Collections.emptyList();
this.remoteReceivers = Collections.unmodifiableList(rr);
}
public boolean hasLocalReceivers() {
return (!this.localReceivers.isEmpty());
}
public boolean hasRemoteReceivers() {
return (!this.remoteReceivers.isEmpty());
}
public int getTotalNumberOfReceivers() {
return (this.localReceivers.size() + this.remoteReceivers.size());
}
public List getRemoteReceivers() {
return this.remoteReceivers;
}
public List getLocalReceivers() {
return this.localReceivers;
}
}