|
|
# Introduction
|
|
|
We present a complete simple example where two Cameo applications interact with a publisher/subscriber pattern.
|
|
|
We present a complete simple example where two CAMEO applications interact with a publisher/subscriber pattern.
|
|
|
|
|
|
# Code
|
|
|
We define:
|
|
|
* a C++ publisher application that publishes to a single subscriber.
|
|
|
* a Java subscriber application which starts the publisher application on the local Cameo server and subscribes to it.
|
|
|
* a Java subscriber application which starts the publisher application on the local CAMEO server and subscribes to it.
|
|
|
|
|
|
Code for the C++ Publisher application:
|
|
|
```cpp
|
... | ... | @@ -12,7 +12,7 @@ Code for the C++ Publisher application: |
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
|
// Initialise the Cameo application represented by This.
|
|
|
// Initialise the CAMEO application represented by This.
|
|
|
cameo::This::init(argc, argv);
|
|
|
|
|
|
// Declare a publisher.
|
... | ... | @@ -59,10 +59,10 @@ public class SubscriberApplication { |
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
// Initialise the Cameo application represented by This.
|
|
|
// Initialise the CAMEO application represented by This.
|
|
|
This.init(args);
|
|
|
|
|
|
// Get the local Cameo server (the one that started This).
|
|
|
// Get the local CAMEO server (the one that started This).
|
|
|
Server server = This.getServer();
|
|
|
|
|
|
// Declare the subscriber.
|
... | ... | @@ -112,7 +112,7 @@ public class SubscriberApplication { |
|
|
}
|
|
|
```
|
|
|
|
|
|
You can notice the call to *start()* with the "pubcpp" name that is not already defined. It will done in the configuration file. Indeed define the code is not enough to run Cameo applications. We need to configure a Cameo server.
|
|
|
You can notice the call to *start()* with the "pubcpp" name that is not already defined. It will done in the configuration file. Indeed define the code is not enough to run CAMEO applications. We need to configure a Cameo server.
|
|
|
|
|
|
# Configuration
|
|
|
Here is a possible configuration file *config.xml*:
|
... | ... | @@ -128,25 +128,25 @@ Here is a possible configuration file *config.xml*: |
|
|
</applications>
|
|
|
</config>
|
|
|
```
|
|
|
A Cameo server configuration file contains:
|
|
|
A CAMEO server configuration file contains:
|
|
|
* The base port from which it is accessed i.e. 7000.
|
|
|
* The list of applications that can be started with their name, executable and other attributes. Each application is a mapping between a name and a command including the executable and the fixed arguments. This configuration file supposes:
|
|
|
* The jar *tests.jar* contains the code of the Java application.
|
|
|
|
|
|
# Execution
|
|
|
First we must start the Cameo server. This can be done directly in a shell:
|
|
|
First we must start the CAMEO server. This can be done directly in a shell:
|
|
|
|
|
|
```
|
|
|
$ cameo-server config.xml --log-console
|
|
|
```
|
|
|
|
|
|
Now we have to execute the *subpubjava* application as it is the entry point. That can be done by using the Cameo console on the machine that runs the Cameo server:
|
|
|
Now we have to execute the *subpubjava* application as it is the entry point. That can be done by using the CAMEO console on the machine that runs the Cameo server:
|
|
|
|
|
|
```
|
|
|
$ cmo exec subpubjava
|
|
|
```
|
|
|
|
|
|
If *serverhost* is the hostname of the machine running the Cameo server, you can go on another machine and run *subpubjava* remotely:
|
|
|
If *serverhost* is the hostname of the machine running the CAMEO server, you can go on another machine and run *subpubjava* remotely:
|
|
|
|
|
|
```
|
|
|
$ cmo -e tcp://serverhost:7000 exec subpubjava
|
... | ... | |