Commit a8631545 authored by legoc's avatar legoc

Added example for publisher and subscriber applications.

parent 0e8f34e7
......@@ -31,9 +31,11 @@ public class ResponderServer {
System.out.println("Connected");
}
Application.Responder responder = null;
try {
// create the publisher
Application.Responder responder = Application.Responder.create("responder");
// Create the responder.
responder = Application.Responder.create("responder");
System.out.println("Created responder " + responder);
......@@ -58,7 +60,8 @@ public class ResponderServer {
System.out.println("Responder error");
} finally {
// Do not forget to terminate This.
// Do not forget to terminate This and the responder.
responder.terminate();
Application.This.terminate();
}
......
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.examples.publishersubscriber;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.cameo.RemoteException;
public class PublisherApplication {
public static void main(String[] args) {
Application.This.init(args);
if (Application.This.isAvailable()) {
System.out.println("Connected");
}
Application.Publisher publisher = null;
try {
// Create the publisher not synchronized.
publisher = Application.Publisher.create("publisher");
System.out.println("Created publisher " + publisher);
// Set the state.
Application.This.setRunning();
// Loop on the events.
int i = 0;
while (true) {
// Send a message.
publisher.send("message " + i);
i++;
// Sleep for 1s.
Thread.sleep(1000);
}
} catch (RemoteException e) {
System.out.println("Publisher error");
} catch (InterruptedException e) {
} finally {
// Terminate the publisher and This.
publisher.terminate();
Application.This.terminate();
}
System.out.println("Finished the application");
}
}
\ No newline at end of file
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.examples.publishersubscriber;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.cameo.RemoteException;
import fr.ill.ics.cameo.Server;
public class SubscriberApplication {
public static void main(String[] args) {
Application.This.init(args);
// Get the local Cameo server.
Server server = Application.This.getServer();
if (Application.This.isAvailable() && server.isAvailable()) {
System.out.println("Connected server " + server);
} else {
System.exit(-1);
}
try {
// Connect to the publisher application.
Application.Instance publisherApp = server.connect("publisher-app");
System.out.println("Application " + publisherApp + " has state " + Application.State.toString(publisherApp.now()));
// Create a subscriber to the publisher named "publisher".
Application.Subscriber subscriber = Application.Subscriber.create(publisherApp, "publisher");
System.out.println("Created subscriber " + subscriber);
// Receive data.
while (true) {
String message = subscriber.receiveString();
if (message != null) {
System.out.println("Received: " + message);
} else {
break;
}
}
// Terminate the subscriber.
subscriber.terminate();
} finally {
// Do not forget to terminate This.
Application.This.terminate();
}
System.out.println("Finished the application");
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<config port="8000" max_applications="20" debug="ON" polling_time="100">
<applications>
<application name="responder-server" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="java" args="-classpath target/cameo-tests-jeromq-0.0.1-full.jar fr.ill.ics.cameo.examples.clientserver.PublisherApplication"/>
</application>
<application name="requester-client" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="java" args="-classpath target/cameo-tests-jeromq-0.0.1-full.jar fr.ill.ics.cameo.examples.clientserver.SubscriberApplication"/>
</application>
</applications>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config port="8000" max_applications="20" debug="ON" polling_time="100">
<applications>
<application name="publisher-app" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="java" args="-classpath target/cameo-tests-jzmq-0.0.1-full.jar fr.ill.ics.cameo.examples.publishersubscriber.PublisherApplication"/>
</application>
<application name="subscriber-app" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="java" args="-classpath target/cameo-tests-jzmq-0.0.1-full.jar fr.ill.ics.cameo.examples.publishersubscriber.SubscriberApplication"/>
</application>
</applications>
</config>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment