Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge commit '045db1657e870c721be490b411868f4181a12ced' into surf++
[simgrid.git] / src / bindings / java / org / simgrid / msg / Comm.java
1 package org.simgrid.msg;
2 /**
3 * Copyright (c) 2012-2013. The SimGrid Team.
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute 
7 * it and/or modify it under the terms of the license 
8 * (GNU LGPL) which comes with this package.
9 *
10 */
11 /**
12  * Communication action, representing an ongoing communication
13  * between processes.
14  */
15 public class Comm {
16         /**
17          * Indicates if the communication is a receiving communication
18          */
19         protected boolean receiving;
20         /**
21          * Indicates if the communication is finished
22          */
23         protected boolean finished = false;
24         /**
25          * Represents the bind between the java comm and the
26          * native C comm. You must never access it, since it is 
27          * automatically set.
28          */
29         private long bind = 0;
30         /**
31          * Represents the bind for the task object pointer. Don't touch it.
32          */
33         private long taskBind = 0;
34         /**
35          * Task associated with the comm. Beware, it can be null 
36          */
37         protected Task task = null;
38         /**
39          * Protected constructor, used by Comm factories
40          * in Task.
41          */
42         protected Comm() {
43
44         }
45         /**
46          * Finalize the communication object, destroying it.
47          */
48         protected void finalize() throws Throwable {
49                 destroy();
50         }
51         /**
52          * Unbind the communication object
53          */
54         protected native void destroy() throws NativeException;
55         /**
56          * Returns if the communication is finished or not.
57          * If the communication has finished and there was an error,
58          * raise an exception.
59          */
60         public native boolean test() throws TransferFailureException, HostFailureException, TimeoutException ;
61         /**
62          * Wait for the complemetion of the communication for an indefinite time
63          */
64         public void waitCompletion() throws TransferFailureException, HostFailureException, TimeoutException {
65                 waitCompletion(-1);
66         }
67         /**
68          * Wait for the completion of the communication.
69          * Throws an exception if there were an error in the communication.
70          * @param timeout Time before giving up
71          */
72         public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
73                 
74         /**
75          * Returns the task associated with the communication.
76          * if the communication isn't finished yet, will return null.
77          */
78         public Task getTask() {
79                 return task;
80         }
81
82         /**
83          * Class initializer, to initialize various JNI stuff
84          */
85         public static native void nativeInit();
86         static {
87                 Msg.nativeInit();
88                 nativeInit();
89         }       
90 }