Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / src / bindings / java / org / simgrid / msg / Comm.java
1 /* Copyright (c) 2012-2020. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 package org.simgrid.msg;
8
9 /** Communication action, representing an ongoing communication between processes. */
10 public class Comm {
11         /** Indicates if the communication is a receiving communication */
12         protected boolean receiving;
13         /** Indicates if the communication is finished */
14         protected boolean finished = false;
15         /**
16          * Represents the bind between the java comm and the
17          * native C comm. You must never access it, since it is
18          * automatically set.
19          */
20         private long bind = 0;
21         /** Represents the bind for the task object pointer. Don't touch it. */
22         private long taskBind = 0;
23         /** Task associated with the comm. Beware, it can be null */
24         protected Task task = null;
25         /**
26          * Protected constructor, used by Comm factories
27          * in Task.
28          */
29         protected Comm() {
30
31         }
32         /**
33          * Destroy the C communication object, when the GC reclaims the java part.
34          * @deprecated (from Java9 onwards)
35          */
36         @Deprecated @Override
37         protected void finalize() throws Throwable{
38                 nativeFinalize();
39         }
40         protected native void nativeFinalize();
41         /**
42          * Returns if the communication is finished or not.
43          * If the communication has finished and there was an error,
44          * raise an exception.
45          */
46         public native boolean test() throws TransferFailureException, HostFailureException, TimeoutException ;
47         /** Wait infinitely for the completion of the communication (infinite timeout) */
48         public void waitCompletion() throws TransferFailureException, HostFailureException, TimeoutException {
49                 waitCompletion(-1);
50         }
51         /**
52          * Wait for the completion of the communication.
53          * Throws an exception if there were an error in the communication.
54          * @param timeout Time before giving up (infinite time if negative)
55          */
56         public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
57
58         /** Wait all of the communications */
59         public static native void waitAll(Comm[] comms, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
60         /** Wait all of the communications, with no maximal delay */
61         public static void waitAll(Comm[] comms) throws TransferFailureException, HostFailureException, TimeoutException {
62                 waitAll(comms, -1.);
63         }
64         /** Wait any of the communications, and return the rank of the terminating comm */
65         public static native int waitAny(Comm[] comms) throws TransferFailureException, HostFailureException, TimeoutException;
66         /**
67          * Returns the task associated with the communication.
68          * if the communication isn't finished yet, will return null.
69          */
70         public Task getTask() {
71                 return task;
72         }
73
74         /** Class initializer, to initialize various JNI stuff */
75         public static native void nativeInit();
76         static {
77                 org.simgrid.NativeLib.nativeInit();
78                 nativeInit();
79         }       
80 }