... | ... | @@ -13,7 +13,7 @@ Code for the C++ Publisher application: |
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
|
// Initialise the Cameo application represented by This.
|
|
|
cameo::application::This::init(argc, argv);
|
|
|
cameo::This::init(argc, argv);
|
|
|
|
|
|
// Declare a publisher.
|
|
|
std::unique_ptr<cameo::coms::Publisher> publisher;
|
... | ... | @@ -22,19 +22,19 @@ int main(int argc, char *argv[]) { |
|
|
// Create the publisher with name "pub" that accepts a single subscriber.
|
|
|
publisher = cameo::coms::Publisher::create("pub", 1);
|
|
|
|
|
|
// Synchronize with the subscriber.
|
|
|
publisher->waitForSubscribers();
|
|
|
// Initialize the publisher. Synchronize with the subscriber.
|
|
|
publisher->init();
|
|
|
|
|
|
// Once here, we are sure that the subscriber is ready
|
|
|
// and will be able to receive all the messages.
|
|
|
}
|
|
|
catch (const PublisherCreationException& e) {
|
|
|
catch (const cameo::InitException& e) {
|
|
|
// The publisher cannot be created.
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
// Force the state RUNNING.
|
|
|
cameo::application::This::setRunning();
|
|
|
// Set the state RUNNING.
|
|
|
cameo::This::setRunning();
|
|
|
|
|
|
// We can send data to the unique subscriber.
|
|
|
publisher->send("hello");
|
... | ... | @@ -49,8 +49,7 @@ int main(int argc, char *argv[]) { |
|
|
```
|
|
|
Code for the Java Subscriber application:
|
|
|
```java
|
|
|
import fr.ill.ics.cameo.base.Application;
|
|
|
import fr.ill.ics.cameo.base.Instance;
|
|
|
import fr.ill.ics.cameo.base.App;
|
|
|
import fr.ill.ics.cameo.base.Server;
|
|
|
import fr.ill.ics.cameo.base.This;
|
|
|
import fr.ill.ics.cameo.coms.Subscriber;
|
... | ... | @@ -71,15 +70,13 @@ public class SubscriberApplication { |
|
|
try {
|
|
|
// Start the publisher application with name "pubcpp"
|
|
|
// and get a reference to the running application with the Instance object.
|
|
|
Instance publisherApplication = server.start("pubcpp");
|
|
|
|
|
|
// Check that the application really started.
|
|
|
if (!publisherApplication.exists()) {
|
|
|
return;
|
|
|
}
|
|
|
App publisherApp = server.start("pubcpp");
|
|
|
|
|
|
// Subscribe to the publisher with name "pub".
|
|
|
subscriber = publisherApplication.subscribe("pub");
|
|
|
Subscriber subscriber = Subscriber.create(publisherApp, "pub");
|
|
|
|
|
|
// Initialize the subscriber.
|
|
|
subscriber.init();
|
|
|
|
|
|
// We are ready to receive data.
|
|
|
while (true) {
|
... | ... | @@ -95,10 +92,16 @@ public class SubscriberApplication { |
|
|
|
|
|
// Finished to receive the data.
|
|
|
// We can wait for the termination of the "pubcpp" application.
|
|
|
Application.State state = publisherApplication.waitFor();
|
|
|
int state = publisherApp.waitFor();
|
|
|
|
|
|
// At this point, the "pubcpp" application is terminated and its terminal state is state.
|
|
|
}
|
|
|
catch (StartException e) {
|
|
|
System.out.println("cannot start the publisher application");
|
|
|
}
|
|
|
catch (InitException e) {
|
|
|
System.out.println("cannot initialize the subscriber");
|
|
|
}
|
|
|
finally {
|
|
|
// Do not forget to terminate the subscriber and This in Java.
|
|
|
subscriber.terminate();
|
... | ... | @@ -116,10 +119,10 @@ Here is a possible configuration file *config.xml*: |
|
|
<config port="7000">
|
|
|
<applications>
|
|
|
<application name="pubcpp" log_directory="logs">
|
|
|
<start executable="pubcppapp"/>
|
|
|
<start executable="/path/to/pubcppapp"/>
|
|
|
</application>
|
|
|
<application name="subpubjava" log_directory="logs">
|
|
|
<start executable="java" args="-classpath tests.jar test.SubscriberApplication"/>
|
|
|
<start executable="/usr/bin/java" args="-classpath /path/to/tests.jar test.SubscriberApplication"/>
|
|
|
</application>
|
|
|
</applications>
|
|
|
</config>
|
... | ... | @@ -127,14 +130,13 @@ Here is a possible configuration file *config.xml*: |
|
|
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 *pubcppapp* program is in the *PATH*.
|
|
|
* 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:
|
|
|
|
|
|
```
|
|
|
java -jar java/server/target/cameo-server-1.1.0-full.jar config.xml --log-console
|
|
|
java -jar java/server/target/cameo-server-2.0.0-full.jar 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:
|
... | ... | |