Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc' into mc++
[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         /**
15          * Indicates if the communication is a receiving communication
16          */
17         protected boolean receiving;
18         /**
19          * Indicates if the communication is finished
20          */
21         protected boolean finished = false;
22         /**
23          * Represents the bind between the java comm and the
24          * native C comm. You must never access it, since it is 
25          * automatically set.
26          */
27         private long bind = 0;
28         /**
29          * Represents the bind for the task object pointer. Don't touch it.
30          */
31         private long taskBind = 0;
32         /**
33          * Task associated with the comm. Beware, it can be null 
34          */
35         protected Task task = null;
36         /**
37          * Protected constructor, used by Comm factories
38          * in Task.
39          */
40         protected Comm() {
41
42         }
43         /**
44          * Finalize the communication object, destroying it.
45          */
46         protected void finalize() throws Throwable {
47                 destroy();
48         }
49         /**
50          * Unbind the communication object
51          */
52         protected native void destroy() throws NativeException;
53         /**
54          * Returns if the communication is finished or not.
55          * If the communication has finished and there was an error,
56          * raise an exception.
57          */
58         public native boolean test() throws TransferFailureException, HostFailureException, TimeoutException ;
59         /**
60          * Wait for the complemetion of the communication for an indefinite time
61          */
62         public void waitCompletion() throws TransferFailureException, HostFailureException, TimeoutException {
63                 waitCompletion(-1);
64         }
65         /**
66          * Wait for the completion of the communication.
67          * Throws an exception if there were an error in the communication.
68          * @param timeout Time before giving up
69          */
70         public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
71                 
72         /**
73          * Returns the task associated with the communication.
74          * if the communication isn't finished yet, will return null.
75          */
76         public Task getTask() {
77                 return task;
78         }
79
80         /**
81          * Class initializer, to initialize various JNI stuff
82          */
83         public static native void nativeInit();
84         static {
85                 Msg.nativeInit();
86                 nativeInit();
87         }       
88 }