This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void on_data_available(DataReader reader) { | |
// Method Parameter of Type DataReader must be cast to Data Type of DataReader for this Topic | |
StringDataReader stringReader = (StringDataReader) reader; | |
SampleInfo info = new SampleInfo(); | |
for (;;) { | |
try { | |
String sample = stringReader.take_next_sample(info); | |
if (info.valid_data) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the data reader using the default publisher | |
StringDataReader dataReader = (StringDataReader) participant.create_datareader( | |
topic, //Topic | |
Subscriber.DATAREADER_QOS_DEFAULT, // QoS | |
new HelloSubscriber(), // Listener | |
StatusKind.DATA_AVAILABLE_STATUS); // mask | |
if (dataReader == null) { | |
System.err.println("Unable to create DDS Data Reader"); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloSubscriber extends DataReaderAdapter { | |
// For clean shutdown sequence | |
private static boolean shutdown_flag = false; | |
public static final void main(String[] args) { | |
// Create the DDS Domain participant on domain ID 0 | |
DomainParticipant participant = DomainParticipantFactory.get_instance().create_participant( | |
0, // Domain ID = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.out.println("Ready to write data."); | |
System.out.println("When the subscriber is ready, you can start writing."); | |
System.out.print("Press CTRL+C to terminate or enter an empty line to do a clean shutdown.\n\n"); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
try | |
{ | |
while (true) { | |
System.out.print("Please type a message> "); | |
String toWrite = reader.readLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the data writer using the default publisher | |
StringDataWriter dataWriter = (StringDataWriter)participant.create_datawriter( | |
helloWorldTopic, // Topic | |
Publisher.DATAWRITER_QOS_DEFAULT, // QoS | |
null, // listener | |
StatusKind.STATUS_MASK_NONE); // mask | |
if (dataWriter == null) { | |
System.err.println("Unable to create data writer\n"); | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the topic "Hello World" with the built-in String type | |
Topic helloWorldTopic = participant.create_topic( | |
"Hello, World", //topic_name | |
StringTypeSupport.get_type_name(), //type_name | |
DomainParticipant.TOPIC_QOS_DEFAULT, //QoS | |
null, //listener | |
StatusKind.STATUS_MASK_NONE); //mask | |
if (topic == null) { | |
System.err.println("Unable to create topic."); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the DDS Domain participant on domain ID 0 | |
DomainParticipant participant = DomainParticipantFactory.get_instance().create_participant( | |
0, // Domain ID = 0 | |
DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT, // QoS Settings = Default | |
null, // listener | |
StatusKind.STATUS_MASK_NONE); // mask | |
if (participant == null) { | |
System.err.println("Unable to create domain participant"); | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloPublisher { | |
public static final void main(String[] args) { |