4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
7 * This program is free software; you can redistribute
8 * it and/or modify it under the terms of the license
9 *(GNU LGPL) which comes with this package.
15 * For convenience, the simulator provides the notion of
16 * channel that is close to the tag notion in MPI. A channel
17 * is not a socket. It doesn't need to be opened neither closed.
18 * It rather corresponds to the ports opened on the different
21 * @author Abdelmalek Cherier
22 * @author Martin Quinson
28 public final class Channel
31 * The channel identifier (as a port number in the TCP protocol.
35 private Channel() {} /* disable the default constructor */
38 * Construct the channel with the specified identifier.
40 * @param id The channel identifier.
42 public Channel(int id){
47 * This static method sets the number of channels for all the hosts
50 * param channelNumber The channel number to set.
52 public static void setNumber(int channelNumber) {
53 Msg.channelSetNumber(channelNumber);
57 * This static method gets the number of channel of the simulation.
59 * @return The channel numbers used in the simulation.
61 public static int getNumber() {
62 return Msg.channelGetNumber();
65 /** Returns the identifier of the channel */
71 * Listen on the channel and wait for receiving a task.
73 * @return The task readed from the channel.
76 public Task get() throws JniException,NativeException {
77 return Msg.channelGet(this);
81 * Listen on the channel and wait for receiving a task with a timeout.
83 * @param timeout The timeout of the listening.
85 * @return The task readed from the channel.
87 * @exception NativeException if the listening operation failed.
89 public Task getWithTimeout(double timeout) throws JniException, NativeException{
90 return Msg.channelGetWithTimeout(this,timeout);
94 * Listen on the channel and wait for receiving a task from a host.
96 * @param host The host.
98 * @return The task readed from the channel.
100 * @exception InvalidHostException if the specified host is not valid.
101 * MsgException if the listening operation failed.
105 public Task getFromHost(Host host) throws NativeException, JniException{
106 return Msg.channelGetFromHost(this,host);
110 * This method tests whether there is a pending communication on the channel.
112 * @return This method returns true if there is a pending communication
113 * on the channel. Otherwise the method returns false.
115 public boolean hasPendingCommunication() throws NativeException, JniException{
116 return Msg.channelHasPendingCommunication(this);
120 * This method tests whether there is a pending communication on a
121 * channel, and who sent it.
123 * @return The method returns -1 if there is no pending
124 * communication and the PID of the process who sent it otherwise
126 public int getCommunicatingProcess() throws JniException{
127 return Msg.channelGetCommunicatingProcess(this) ;
131 * Wait for at most timeout seconds for a task reception
132 * on channel. The PID is updated with the PID of the first process.
134 * @param timeout The maximum time to wait for a task before
136 * @return The PID of the first process to send a task.
138 * @exception MsgException if the reception failed.
140 public int wait(double timeout) throws NativeException, JniException{
141 return Msg.channelWait(this,timeout);
145 * This method returns the number of tasks waiting to be received on a
146 * channel and sent by a host.
148 * @param host The host that is to be watched.
150 * @return The number of tasks waiting to be received on a channel
151 * and sent by a host.
153 * @exception InvalidHostException if the specified host is not valid.
155 public int getHostWaitingTasks(Host host) throws JniException{
156 return Msg.channelGetHostWaitingTasks(this,host);
160 * This method puts a task on a channel of an host and waits for the end of the
163 * @param task The task to put.
164 * @param host The destinated host.
166 * @exception InvalidTaskException if the task is not valid.
167 * InvalidHostException if the host is not valid.
168 * MsgException if the operation failed.
170 public void put(Task task,Host host) throws NativeException, JniException {
171 Msg.channelPut(this,task,host);
175 * This method puts a task on a channel of an host (with a timeout on the waiting
176 * of the destination host) and waits for the end of the transmission.
178 * @param task The task to put.
179 * @param host The destination where to put the task.
180 * @param timeout The timeout of the transmission.
182 * @exception InvalidTaskException if the task is not valid.
183 * InvalidHostException if the host is not valid.
184 * MsgException if the operation failed.
186 public void putWithTimeout(Task task,Host host,double timeout) throws NativeException, JniException {
187 Msg.channelPutWithTimeout(this,task,host,timeout);
191 * This method does exactly the same as put() but with a bounded transmition
194 * @param task The task to put.
195 * @param host The destination where to put the task.
196 * @param maxRate The bounded transmition rate.
198 * @exception InvalidTaskException if the task is not valid.
199 * InvalidHostException if the host is not valid.
200 * MsgException if the operation failed.
202 public void putBounded(Task task,Host host,double maxRate) throws NativeException, JniException {
203 Msg.channelPutBounded(this,task,host,maxRate);