Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
that's misleading
[simgrid.git] / include / simgrid / s4u / actor.hpp
1 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_S4U_ACTOR_HPP
7 #define SIMGRID_S4U_ACTOR_HPP
8
9 #include "simgrid/simix.h"
10
11 namespace simgrid {
12 namespace s4u {
13
14 class Comm;
15 class Host;
16 class Mailbox;
17
18 /** @brief Simulation Agent
19  *
20  * An actor may be defined as a code executing in a location (host).
21  *
22  * All actors should be started from the XML deployment file (using the @link{s4u::Engine::loadDeployment()}),
23  * even if you can also start new actors directly.
24  * Separating the deployment in the XML from the logic in the code is a good habit as it makes your simulation easier
25  * to adapt to new settings.
26  *
27  * The code that you define for a given actor should be placed in the main method that is virtual.
28  * For example, a Worker actor should be declared as follows:
29  *
30  * \verbatim
31  * #include "s4u/actor.hpp"
32  *
33  * class Worker : simgrid::s4u::Actor {
34  *
35  *        int main(int argc, char **argv) {
36  *              printf("Hello s4u");
37  *        }
38  * };
39  * \endverbatim
40  *
41  */
42 class Actor {
43         friend Comm;
44         Actor(smx_process_t smx_proc);
45 public:
46         Actor(const char*name, s4u::Host *host, int argc, char **argv);
47         Actor(const char*name, s4u::Host *host, int argc, char **argv, double killTime);
48         virtual ~Actor() {}
49
50         /** The main method of your agent */
51         int main(int argc, char **argv) {return 0;}
52
53         /** The Actor that is currently running */
54         static Actor *current();
55         /** Retrieves the actor that have the given PID (or NULL if not existing) */
56         static Actor *byPid(int pid);
57
58         /** Retrieves the name of that actor */
59         const char*getName();
60         /** Retrieves the host on which that actor is running */
61         s4u::Host *getHost();
62         /** Retrieves the PID of that actor */
63         int getPid();
64
65         /** If set to true, the actor will automatically restart when its host reboots */
66         void setAutoRestart(bool autorestart);
67         /** Sets the time at which that actor should be killed */
68         void setKillTime(double time);
69         /** Retrieves the time at which that actor will be killed (or -1 if not set) */
70         double getKillTime();
71
72         /** Ask kindly to all actors to die. Only the issuer will survive. */
73         static void killAll();
74         /** Ask the actor to die.
75          *
76          * It will only notice your request when doing a simcall next time (a communication or similar).
77          * SimGrid sometimes have issues when you kill actors that are currently communicating and such. We are working on it to fix the issues.
78          */
79         void kill();
80
81         /** Block the actor sleeping for that amount of seconds (may throws hostFailure) */
82         void sleep(double duration);
83
84         /** Block the actor, computing the given amount of flops */
85         e_smx_state_t execute(double flop);
86
87         /** Block the actor until it gets a message from the given mailbox.
88          *
89          * See \ref Comm for the full communication API (including non blocking communications).
90          */
91         void *recv(Mailbox &chan);
92
93         /** Block the actor until it delivers a message of the given simulated size to the given mailbox
94          *
95          * See \ref Comm for the full communication API (including non blocking communications).
96         */
97         void send(Mailbox &chan, void*payload, size_t simulatedSize);
98
99 protected:
100         smx_process_t getInferior() {return p_smx_process;}
101 private:
102         smx_process_t p_smx_process;
103 };
104 }} // namespace simgrid::s4u
105
106 #endif /* SIMGRID_S4U_ACTOR_HPP */
107
108 #if 0
109
110 public abstract class Actor implements Runnable {
111         /** Suspends the process. See {@link #resume()} to resume it afterward */
112         public native void suspend();
113         /** Resume a process that was suspended by {@link #suspend()}. */
114         public native void resume();    
115         /** Tests if a process is suspended. */
116         public native boolean isSuspended();
117         
118         /**
119          * Returns the value of a given process property. 
120          */
121         public native String getProperty(String name);
122
123
124         /**
125          * Migrates a process to another host.
126          *
127          * @param host                  The host where to migrate the process.
128          *
129          */
130         public native void migrate(Host host);  
131
132         public native void exit();    
133         /**
134          * This static method returns the current amount of processes running
135          *
136          * @return                      The count of the running processes
137          */ 
138         public native static int getCount();
139
140 }
141 #endif