RTI Connext RTSJ Extension Kit  Version 5.1.0
RtsjSimpleExample.java

Simple Example

This simple class shows how to register RTSJ properties with the domain participant factory. It is not functional by itself; it merely demonstrates the APIs.

Source Code

/* RtsjSimpleExample.java
*/
package com.rti.ndds.rtsj.example.simple;
import javax.realtime.HeapMemory;
import javax.realtime.ImmortalMemory;
import com.rti.dds.domain.DomainParticipant;
import com.rti.dds.domain.DomainParticipantFactory;
import com.rti.dds.infrastructure.RETCODE_INCONSISTENT_POLICY;
import com.rti.dds.infrastructure.StatusKind;
import com.rti.ndds.rtsj.RtsjProperty_t;
import com.rti.ndds.rtsj.RtsjThreadSupport;
import com.rti.ndds.rtsj.ThreadKind;
public class RtsjSimpleExample {
public static void main(String[] args) {
RtsjProperty_t thread_properties = new RtsjProperty_t();
// set the event thread properties
thread_properties.event_thread.memory_area =
ImmortalMemory.instance();
thread_properties.event_thread.thread_kind =
ThreadKind.NO_HEAP_REALTIME_THREAD_KIND;
// set the receive thread properties
thread_properties.receive_thread.memory_area =
ImmortalMemory.instance();
thread_properties.receive_thread.thread_kind =
ThreadKind.NO_HEAP_REALTIME_THREAD_KIND;
// set the database thread properties
thread_properties.database_thread.memory_area = HeapMemory.instance();
thread_properties.database_thread.thread_kind =
ThreadKind.NON_REALTIME_THREAD_KIND;
// Register the properties for the domain participant factory.
DomainParticipantFactory known_factory =
DomainParticipantFactory.get_instance();
try {
RtsjThreadSupport.register(known_factory, thread_properties);
} catch (RETCODE_INCONSISTENT_POLICY e) {
/* This exception is unchecked; if you know that you will
* only ever be running this code on an RTSJ-capable JVM,
* there is no need to explicitly catch it.
*/
System.out.println("RTSJ feature error: incompatible JVM");
}
/* DomainParticipants created subsequently will use the
* registered properties.
*/
DomainParticipant participant = known_factory.create_participant(
/*domain ID*/ 0,
/*QoS*/ DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
/*listener*/ null,
/*listener mask*/ StatusKind.STATUS_MASK_NONE);
// To restore the defaults, register the default properties.
thread_properties = new RtsjProperty_t();
RtsjThreadSupport.register(known_factory, thread_properties);
}
}

RTI Connext RTSJ Extension Kit Version 5.1.0 Copyright © Tue Feb 4 2014 Real-Time Innovations, Inc