OpenSplice examples - Ownership

# EXAMPLES

- Summary
- PingPong
- Tutorial
- HelloWorld
- WaitSet
- Listener
- ContentFilteredTopic
- QueryCondition
- Lifecycle
- Ownership
- BuiltInTopics
- NetworkPartitions
- RoundTrip
- Throughput

## Ownership

- Running of examples in Standalone Mode

### 1) Description

The ownership example is used to illustrate the concept of Shared Ownership, controlled through QoS, in DDS.

### 2) Design

It consists of 4 units :

- CheckStatus : provides return status checking
- DDSEntityManager : implements a class providing operations to setup DCPS entities(creation, deletion)
- Publisher application implements the 2 publishers sharing the same topic.
- Subscriber implements the subscriber.

### 3) Scenario

Two StockQuote Publishers of different ownership strengths publish topics with the same keyfields. The subscriber will receive the topics from the publisher with higher strength. In this example :

- a publisher "pub1" having an ownership strength set to 5 sends periodically 20 StockQuotes at a period of 200ms.
- after 2 seconds a second publisher "pub2" with a higher strength (10) sends 5 StockQuotes at a period of 200ms. When receiving a topic, the subscriber will display the :
- the key field (always "MSFT")
- the price field
- the publisher name ("pub1" or "pub2") The publisher will receive :
- first StockQuotes from "pub1" (during the first 2 seconds)
- then from "pub2"
- then from "pub1" again when "pub2" stops.

## Running of examples in Standalone Mode

- Running examples in Posix
- Running examples in Visual Studio

### Running the examples in a Posix environment

#### Environment Setup

Let's call OpenSplice_install_dir the OpenSplice installation directory.

The OpenSplice environment variables must be set in order for the examples to build/run correctly. To do this, open a terminal and source the "OpenSplice_install_dir/release.com" script supplied with the distribution.

- C/C++ Examples
- Java examples
- ISO C++ 2 examples

#### C and C++ Executables

Building the examples is described on the Summary page

Two executables and a library are generated in the standalone directory when the example is built:

For C++

- sacpp_ownership_pub
- sacpp_ownership_sub
- libsacpp_ownership_types.so

For C

- sac_ownership_pub
- sac_ownership_sub
- libsac_ownership_types.so

#### Java executables

Building the examples is described on the Summary page

Three jars are generated in the java/standalone or java5 directory when the example is built:

For Java

- saj_ownership_sub.jar
- saj_ownership_pub.jar
- saj_ownership_types.jar

For Java5

- saj5_ownership_sub.jar
- saj5_ownership_pub.jar
- saj5_ownership_types.jar

#### ISO C++ 2 Executables

Building the examples is described on the Summary page

Two executables are generated in the isocpp2 directory when the example is built:

- publisher
- subscriber

#### Running the example

Ensure that the environment for OpenSplice is set up correctly as described above for each new terminal used.

It is recommended that you run the subscriber and publisher in separate terminals to avoid mixing the output

Running in single process (heap memory) configuration : the application starts OpenSplice middleware

- OpenSplice is deployed in this mode by default.
- The OpenSplice daemon should not be started manually. Instead the OpenSplice middleware and optional services are implicitly started by the single process applications as required
- Open 2 or more terminals. Set up the environment and go to the example directory as described above

Running in multiple process shared memory configuration

To enable deployment in this mode, an OpenSplice configuration file must be selected that has shared memory support e.g. one of the ospl_shmem xml configuration files found in the OpenSplice_install_dir/etc/config directory.

- Open 2 or more terminals. In each terminal:
- Setup the environment and go to the example directory as described above
- Set the required configuration file e.g. OSPL_URI=file://$OSPL_HOME/etc/config/ospl_shmem_ddsi.xml
- Start the OpenSplice daemon. You can do this by typing ospl start

Starting the subscriber and publisher

- In the first terminal start the subscriber by running either
  - sac_ownership_sub for C
  - sacpp_ownership_sub for C++
  - java -jar saj_ownership_sub.jar for Java
  - java -jar saj5_ownership_sub.jar for Java5
  - subscriber for ISO C++ 2
- In a second terminal start the publisher by running either
  - sac_ownership_pub pub1 5 40 1 for C
  - sacpp_ownership_pub pub1 5 40 1 for C++
  - java -jar saj_ownership_pub.jar pub1 5 40 1 for Java
  - java -jar saj5_ownership_pub.jar pub1 5 40 1 for Java5
  - publisher pub1 5 40 1 for ISO C++ 2

- In another terminal start the publisher by running either
  - sac_ownership_pub pub2 10 5 0 for C
  - sacpp_ownership_pub pub2 10 5 0 for C++
  - java -jar saj_ownership_pub.jar pub2 10 5 0 for Java
  - java -jar saj5_ownership_pub.jar pub2 10 5 0 for Java5
  - publisher pub2 10 5 0 for ISO C++ 2

    Publisher usage, e.g.:
          sac_ownership_pub [publisher_name] [ownership_strength] [nb_iterations] [stop_subscriber_flag]
            publisher_name
            ownership_strength
            nb_iterations : number of sending message iterations
            stop_subscriber_flag : indicates if the publisher has to send a message to tell the subscriber to stop

### Running C/C++/C#/ISO C++ 2/Java examples on Windows

#### Environment Setup

Let's call OpenSplice_install_dir the OpenSplice installation directory.

The OpenSplice environment variables must be set in order for the examples to run correctly. To do this open an OpenSplice Command Prompt which will set up the environment variables for OpenSplice automatically. The OpenSplice Command Prompt can be selected from the start menu. Alternatively, open a windows Command Prompt and execute the "OpenSplice_install_dir\release.bat" batch script supplied with the distribution.

- C/C++/C# Examples
- Java examples
- ISO C++ 2 examples

#### C/C++/C# Executables

Building the examples is described on the Summary page

Two executables are generated in the standalone directory when the example is built:

For C

- sac_ownership_sub.exe
- sac_ownership_pub.exe

For C++

- sacpp_ownership_sub.exe
- sacpp_ownership_pub.exe

For C#

- sacs_ownership_sub.exe
- sacs_ownership_pub.exe

#### Java Executables

Building the examples is described on the Summary page

Three jars are generated in the java/standalone or java5 directory when the example is built:

For Java

- saj_ownership_sub.jar
- saj_ownership_pub.jar
- saj_ownership_types.jar

For Java5

- saj5_ownership_sub.jar
- saj5_ownership_pub.jar
- saj5_ownership_types.jar

#### ISO C++ 2 Executables

Building the examples is described on the Summary page

Two executables are generated in the isocpp2 directory when the example is built:

- publisher.exe
- subscriber.exe

#### Running the C/C++/C#/ISO C++ 2/Java Examples

Ensure that the environment for OpenSplice is set up correctly as described above for each new command prompt used.

The following steps describe how to run the examples:

Running in single process (heap memory) configuration : the application starts OpenSplice middleware

- OpenSplice is deployed in this mode by default.
- The OpenSplice daemon should not be started manually. Instead the OpenSplice middleware and optional services are implicitly started by the single process applications as required
- Open 2 or more OpenSplice Command Prompts and go to the example directory as described above

Running in multiple process shared memory configuration

To enable deployment in this mode, an OpenSplice configuration file must be selected that has shared memory support e.g. one of the ospl_shmem xml configuration files found in the OpenSplice_install_dir\etc\config directory.

- Open 2 or more OpenSplice Command Prompts. In each window:
- Go to the example directory as described above
- Set the required configuration file e.g. set OSPL_URI=file://%OSPL_HOME%\etc\config\ospl_shmem_ddsi.xml
- Start the OpenSplice daemon. You can do this by typing ospl start

Starting the subscriber and publisher

- In the first terminal start the subscriber by running either
  - sac_ownership_sub for C
  - sacpp_ownership_sub for C++
  - sacs_ownership_sub for C#
  - java -jar saj_ownership_sub.jar for Java
  - java -jar saj5_ownership_sub.jar for Java5
  - subscriber for ISO C++ 2
- In a second terminal start the publisher by running either
  - sac_ownership_pub pub1 5 40 1 for C
  - sacpp_ownership_pub pub1 5 40 1 for C++
  - sacs_ownership_pub pub1 5 40 1 for C#
  - java -jar saj_ownership_pub.jar pub1 5 40 1 for Java
  - java -jar saj5_ownership_pub.jar pub1 5 40 1 for Java5
  - publisher pub1 5 40 1 for ISO C++ 2

- In another terminal start the publisher by running either
  - sac_ownership_pub pub2 10 5 0 for C
  - sacpp_ownership_pub pub2 10 5 0 for C++
  - sacs_ownership_pub pub2 10 5 0 for C#
  - java -jar saj_ownership_pub.jar pub2 10 5 0 for Java
  - java -jar saj5_ownership_pub.jar pub2 10 5 0 for Java5
  - publisher pub2 10 5 0 for ISO C++ 2

    Publisher usage, e.g.:
          sac_ownership_pub [publisher_name] [ownership_strength] [nb_iterations] [stop_subscriber_flag]
            publisher_name
            ownership_strength
            nb_iterations : number of sending message iterations
            stop_subscriber_flag : indicates if the publisher has to sent a message to tell the subscriber to stop