... | ... | @@ -50,7 +50,7 @@ public class JavaApp { |
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
// Initialise the Cameo application represented by This.
|
|
|
// Initialize the Cameo application represented by This.
|
|
|
This.init(args);
|
|
|
|
|
|
// Infinite printing loop.
|
... | ... | @@ -82,17 +82,20 @@ The application *App1* written in C++ has the following lines: |
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
|
// Define the reference to the Cameo server in B.
|
|
|
cameo::Server server("tcp://B:7000");
|
|
|
std::unique_ptr<cameo::Server> server = cameo::Server::create("tcp://B:7000");
|
|
|
|
|
|
// Initialize the server.
|
|
|
server->init();
|
|
|
|
|
|
// Start the application "App2" and obtain a reference to the running app.
|
|
|
std::unique_ptr<cameo::application::Instance> app2 = server.start("App2");
|
|
|
std::unique_ptr<cameo::App> app2 = server.start("App2");
|
|
|
|
|
|
// Wait for the end of the app and get the terminal state.
|
|
|
cameo::application::State state = app2->waitFor();
|
|
|
cameo::State state = app2->waitFor();
|
|
|
|
|
|
// Print the terminal state.
|
|
|
std::cout << "The application " << *app2
|
|
|
<< " terminated with state " << application::toString(state) << std::endl;
|
|
|
<< " terminated with state " << cameo::toString(state) << std::endl;
|
|
|
|
|
|
return 0;
|
|
|
}
|
... | ... | @@ -106,7 +109,10 @@ The application *App3* written in Python has the following lines: |
|
|
import cameopy
|
|
|
|
|
|
# Define the reference to the Cameo server in B.
|
|
|
server = cameopy.Server("tcp://B:7000")
|
|
|
server = cameopy.Server.create("tcp://B:7000")
|
|
|
|
|
|
# Initialize the server.
|
|
|
server.init()
|
|
|
|
|
|
# Connect the application "App2" that is supposed running.
|
|
|
app2 = server.connect("App2")
|
... | ... | @@ -117,8 +123,7 @@ app2.stop() |
|
|
# Wait for the end of the app and get the terminal state.
|
|
|
state = app.waitFor()
|
|
|
|
|
|
print("The application", app2.getNameId(),
|
|
|
"terminated with state", cameopy.toString(state))
|
|
|
print("The application", app2.toString(), "terminated with state", cameopy.toString(state))
|
|
|
```
|
|
|
|
|
|
On computer *D*, the console connects to *App2* and receives some output before *App2* is stopped:
|
... | ... | @@ -247,10 +252,10 @@ We suppose to have an *App4* application that returns after a certain amount of |
|
|
For example in C++:
|
|
|
```cpp
|
|
|
// Connect the application "App4" and obtain a reference to the running app.
|
|
|
std::unique_ptr<cameo::application::Instance> app4 = server.connect("App4");
|
|
|
std::unique_ptr<cameo::App> app4 = server.connect("App4");
|
|
|
|
|
|
// Wait for the end of the app and get the terminal state.
|
|
|
cameo::application::State state = app4->waitFor();
|
|
|
cameo::State state = app4->waitFor();
|
|
|
|
|
|
// Get the exit code.
|
|
|
int exitCode = app4->getExitCode();
|
... | ... | @@ -264,7 +269,7 @@ The application App4.13 terminated successfully. |
|
|
$ exitCode=$?
|
|
|
```
|
|
|
|
|
|
What you with this code is on your own.
|
|
|
What you do with this code is on your own.
|
|
|
|
|
|
# Stop handler
|
|
|
|
... | ... | @@ -276,17 +281,18 @@ The C++, Java and Python APIs support the stop handler. An example in C++: |
|
|
#include <atomic>
|
|
|
#include <iostream>
|
|
|
|
|
|
// Shared variable.
|
|
|
std::atomic_bool stopping(false);
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
|
// Init the app.
|
|
|
cameo::application::This::init(argc, argv);
|
|
|
cameo::This::init(argc, argv);
|
|
|
|
|
|
// Shared variable.
|
|
|
std::atomic_bool stopping(false);
|
|
|
|
|
|
// Define a stop handler.
|
|
|
cameo::application::This::handleStop([] {
|
|
|
cameo::application::This::handleStop([&] {
|
|
|
std::cout << "Stop handler executed" << std::endl;
|
|
|
stopping.store(true);
|
|
|
});
|
|
|
|
|
|
// Loop until stop is triggered.
|
... | ... | @@ -385,7 +391,7 @@ public class JavaApp { |
|
|
This.init(args);
|
|
|
|
|
|
// Get the starter app.
|
|
|
Instance starter = This.connectToStarter();
|
|
|
App starter = This.connectToStarter();
|
|
|
|
|
|
// Infinite printing loop.
|
|
|
int i = 0;
|
... | ... | @@ -410,11 +416,11 @@ Once you have a reference to the *starter* you can decide to stop it or use it t |
|
|
|
|
|
# Standard error and output
|
|
|
|
|
|
The standard error and output can be printed by the console application or retrieved by the API. For that the attribute *stream* of the application tag must have be set to *yes* in the configuration of the application. See the page [Configure a server](Configure-a-server).
|
|
|
The standard error and output can be printed by the console application or retrieved by the API. For that the attribute *stream* of the application tag must have been set to *yes* in the configuration of the application. See the page [Configure a server](Configure-a-server).
|
|
|
An example with the C++ API:
|
|
|
```cpp
|
|
|
// Start the app with the OUTPUTSTREAM option.
|
|
|
std::unique_ptr<cameo::application::Instance> app = server.start("App2", cameo::OUTPUTSTREAM);
|
|
|
std::unique_ptr<cameo::App> app = server.start("App2", cameo::OUTPUTSTREAM);
|
|
|
|
|
|
// Get the outputstream socket.
|
|
|
std::shared_ptr<cameo::OutputStreamSocket> socket = app->getOutputStreamSocket();
|
... | ... | @@ -448,7 +454,7 @@ Starting the application with the option *OUTPUTSTREAM* creates an output stream |
|
|
Same example in Java:
|
|
|
```java
|
|
|
// Start the app with the OUTPUTSTREAM option.
|
|
|
Instance app = server.start("App2", Option.OUTPUTSTREAM);
|
|
|
App app = server.start("App2", Option.OUTPUTSTREAM);
|
|
|
|
|
|
// Get the outputstream socket.
|
|
|
OutputStreamSocket socket = app.getOutputStreamSocket();
|
... | ... | |