Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more consistant identifier names around Java objects' finalization
[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         /** Destroy the C communication object, when the GC reclaims the java part. */
44         @Override
45         protected void finalize() {
46                 try {
47                         nativeFinalize();
48                 } catch (Throwable e) {
49                         e.printStackTrace();
50                 }
51         }
52         protected native void nativeFinalize();
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         /** Wait infinitely for the completion of the communication (infinite timeout) */
60         public void waitCompletion() throws TransferFailureException, HostFailureException, TimeoutException {
61                 waitCompletion(-1);
62         }
63         /**
64          * Wait for the completion of the communication.
65          * Throws an exception if there were an error in the communication.
66          * @param timeout Time before giving up (infinite time if negative)
67          */
68         public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
69
70         /**
71          * Returns the task associated with the communication.
72          * if the communication isn't finished yet, will return null.
73          */
74         public Task getTask() {
75                 return task;
76         }
77
78         /**
79          * Class initializer, to initialize various JNI stuff
80          */
81         public static native void nativeInit();
82         static {
83                 Msg.nativeInit();
84                 nativeInit();
85         }       
86 }