Download Diffusion 5.5 User Guide - Documentation
Transcript
9. Use a Thread.sleep() to hold the client open for a minute while the updates are
received and output.
// Wait for a minute while the stream prints updates
Thread.sleep(60000);
10.Compile and run your client.
We recommend that you run your client using the JDK rather than the JRE. The JDK includes
additional diagnostic capabilities that might be useful.
Results
The client outputs the value to the console every time the value of the foo/counter topic is
updated. You can update the value of the foo/counter topic by creating a publishing client to
update the topic. For more information, see Start publishing with Java on page 357.
Full example
The completed SubscribingClient class contains the following code:
import com.pushtechnology.diffusion.client.Diffusion;
import com.pushtechnology.diffusion.client.content.Content;
import com.pushtechnology.diffusion.client.features.Topics;
import
com.pushtechnology.diffusion.client.features.Topics.TopicStream;
import com.pushtechnology.diffusion.client.session.Session;
import
com.pushtechnology.diffusion.client.types.UpdateContext;
public class SubscribingClient {
public static void main(String... arguments) throws
Exception {
// Connect anonymously
// Replace 'host' with your hostname
Session session =
Diffusion.sessions().open("ws://host:port");
// Get the Topics feature to subscribe to topics
final Topics topics = session.feature(Topics.class);
// Add a new topic stream for 'foo/counter'
topics.addTopicStream(">foo/counter", new
TopicStreamPrintLn());
// Subscribe to the topic 'foo/counter'
topics.subscribe("foo/counter",
new Topics.CompletionCallback.Default());
// Wait for a minute while the stream prints updates
Thread.sleep(60000);
}
/**
* A topic stream that prints updates to the console.
*/
private static class TopicStreamPrintLn extends
TopicStream.Default {
@Override
public void onTopicUpdate(String topic, Content
content,
Diffusion | 356
Related documents
Diffusion 5.1 User Guide - Documentation
User Guide - Documentation
Netgear 782S Quick Start Guide
PRIMECLUSTER Reliant Monitor Services (RMS) with
RTI Routing Service - Community RTI Connext Users
NaviPlan User Manual: Business Administration
Sirius User Guide.book
Supply and Delivery of RS and GIS Laboratory Setup
Chapter 1 Introduction to EverBEEN
Netgear 782S Quick Start Guide
DNP 3.0 LAN/WAN Master (OPC) User`s Manual
HornetQ User Guide - for use with JBoss Enterprise
spring-boot-referenc..
User Manual - barcode
US English
PBPB User Manual - KIT Solutions Support Site
User manual - STMicroelectronics
IX-T01 WiFi - SnelWebshop
LittleDog Robot 1.0 - Computational Learning and Motor Control Lab
Stemming Selector 4 User Guide