Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/mpoquet/simgrid
[simgrid.git] / src / bindings / java / org / simgrid / msg / Comm.java
1 /* Copyright (c) 2012-2014. 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 /**
10  * Communication action, representing an ongoing communication
11  * between processes.
12  */
13 public class Comm {
14         /** Indicates if the communication is a receiving communication */
15         protected boolean receiving;
16         /** Indicates if the communication is finished */
17         protected boolean finished = false;
18         /**
19          * Represents the bind between the java comm and the
20          * native C comm. You must never access it, since it is 
21          * automatically set.
22          */
23         private long bind = 0;
24         /** Represents the bind for the task object pointer. Don't touch it. */
25         private long taskBind = 0;
26         /** Task associated with the comm. Beware, it can be null */
27         protected Task task = null;
28         /**
29          * Protected constructor, used by Comm factories
30          * in Task.
31          */
32         protected Comm() {
33
34         }
35         /** Destroy the C communication object, when the GC reclaims the java part. */
36         protected void finalize() throws Throwable{
37                 nativeFinalize();
38         }
39         protected native void nativeFinalize();
40         /**
41          * Returns if the communication is finished or not.
42          * If the communication has finished and there was an error,
43          * raise an exception.
44          */
45         public native boolean test() throws TransferFailureException, HostFailureException, TimeoutException ;
46         /** Wait infinitely for the completion of the communication (infinite timeout) */
47         public void waitCompletion() throws TransferFailureException, HostFailureException, TimeoutException {
48                 waitCompletion(-1);
49         }
50         /**
51          * Wait for the completion of the communication.
52          * Throws an exception if there were an error in the communication.
53          * @param timeout Time before giving up (infinite time if negative)
54          */
55         public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
56
57         /** Wait all of the communications */
58         public static native void waitAll(Comm[] comms, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
59         /** Wait all of the communications, with no maximal delay */
60         public static void waitAll(Comm[] comms) throws TransferFailureException, HostFailureException, TimeoutException {
61                 waitAll(comms, -1.);
62         }
63         /** Wait any of the communications, and return the rank of the terminating comm */
64         public static native void waitAny(Comm[] comms) throws TransferFailureException, HostFailureException, TimeoutException;
65         /**
66          * Returns the task associated with the communication.
67          * if the communication isn't finished yet, will return null.
68          */
69         public Task getTask() {
70                 return task;
71         }
72
73         /** Class initializer, to initialize various JNI stuff */
74         public static native void nativeInit();
75         static {
76                 org.simgrid.NativeLib.nativeInit();
77                 nativeInit();
78         }       
79 }