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 {
30 * The channel identifier (as a port number in the TCP protocol.
35 } /* disable the default constructor */
37 * Construct the channel with the specified identifier.
39 * @param id The channel identifier.
40 */ public Channel(int id) {
45 * This static method sets the number of channels for all the hosts
48 * param channelNumber The channel number to set.
50 public static void setNumber(int channelNumber) {
51 Msg.channelSetNumber(channelNumber);
55 * This static method gets the number of channel of the simulation.
57 * @return The channel numbers used in the simulation.
59 public static int getNumber() {
60 return Msg.channelGetNumber();
63 /** Returns the identifier of the channel */
69 * Listen on the channel and wait for receiving a task.
71 * @return The task readed from the channel.
74 public Task get() throws JniException, NativeException {
75 return Msg.channelGet(this);
78 * Listen on the channel and wait for receiving a task with a timeout.
80 * @param timeout The timeout of the listening.
82 * @return The task readed from the channel.
84 * @exception NativeException if the listening operation failed.
86 public Task getWithTimeout(double timeout) throws JniException,
88 return Msg.channelGetWithTimeout(this, timeout);
91 * Listen on the channel and wait for receiving a task from a host.
93 * @param host The host.
95 * @return The task readed from the channel.
97 * @exception InvalidHostException if the specified host is not valid.
98 * MsgException if the listening operation failed.
102 public Task getFromHost(Host host) throws NativeException, JniException {
103 return Msg.channelGetFromHost(this, host);
106 * This method tests whether there is a pending communication on the channel.
108 * @return This method returns true if there is a pending communication
109 * on the channel. Otherwise the method returns false.
111 public boolean hasPendingCommunication() throws NativeException,
113 return Msg.channelHasPendingCommunication(this);
116 * This method tests whether there is a pending communication on a
117 * channel, and who sent it.
119 * @return The method returns -1 if there is no pending
120 * communication and the PID of the process who sent it otherwise
121 */ public int getCommunicatingProcess() throws JniException {
122 return Msg.channelGetCommunicatingProcess(this);
125 * Wait for at most timeout seconds for a task reception
126 * on channel. The PID is updated with the PID of the first process.
128 * @param timeout The maximum time to wait for a task before
130 * @return The PID of the first process to send a task.
132 * @exception MsgException if the reception failed.
134 public int wait(double timeout) throws NativeException, JniException {
135 return Msg.channelWait(this, timeout);
138 * This method returns the number of tasks waiting to be received on a
139 * channel and sent by a host.
141 * @param host The host that is to be watched.
143 * @return The number of tasks waiting to be received on a channel
144 * and sent by a host.
146 * @exception InvalidHostException if the specified host is not valid.
147 */ public int getHostWaitingTasks(Host host) throws JniException {
148 return Msg.channelGetHostWaitingTasks(this, host);
151 * This method puts a task on a channel of an host and waits for the end of the
154 * @param task The task to put.
155 * @param host The destinated host.
157 * @exception InvalidTaskException if the task is not valid.
158 * InvalidHostException if the host is not valid.
159 * MsgException if the operation failed.
161 public void put(Task task, Host host) throws NativeException,
163 Msg.channelPut(this, task, host);
166 * This method puts a task on a channel of an host (with a timeout on the waiting
167 * of the destination host) and waits for the end of the transmission.
169 * @param task The task to put.
170 * @param host The destination where to put the task.
171 * @param timeout The timeout of the transmission.
173 * @exception InvalidTaskException if the task is not valid.
174 * InvalidHostException if the host is not valid.
175 * MsgException if the operation failed.
177 public void putWithTimeout(Task task, Host host,
178 double timeout) throws
179 NativeException, JniException {
180 Msg.channelPutWithTimeout(this, task, host, timeout);
183 * This method does exactly the same as put() but with a bounded transmition
186 * @param task The task to put.
187 * @param host The destination where to put the task.
188 * @param maxRate The bounded transmition rate.
190 * @exception InvalidTaskException if the task is not valid.
191 * InvalidHostException if the host is not valid.
192 * MsgException if the operation failed.
194 public void putBounded(Task task, Host host,
195 double maxRate) throws NativeException,
197 Msg.channelPutBounded(this, task, host, maxRate);