# EXAMPLES

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

## Tutorial

- Running of examples in Standalone Mode
- Running of examples in CORBA Cohabitation Mode

### 1) Description

The Tutorial consists of three executables that together make up a primitive chat box

### 2) Design

The 3 executables are:

- Chatter : sends messages to the chat box
- MessageBoard : displays all available chat messages
- UserLoad : keeps track of when users join and leave the chat box

### 3) Scenario

The Chatter and MessageBoard executables support optional command-line parameters. When these parameters are not specified, default values are used instead. The optional parameters and their meaning are:

- Chatter [userid] [username]

- userid: an integer number that uniquely identifies the sender of a message. (Transmit a message with userid = -1 to terminate the MessageBoard.)
- username: the user-name other chatters will see when they receive one of your chat messages.

- MessageBoard [userid]

- userid: block messages from a user identified by this id. You can use this to prevent seeing your own messages appear on your own MessageBoard.

## 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++/ISO C++ 2 Examples
- Java examples

#### C/C++ and ISO C++ Executables

Building the examples is described on the Summary page

Three executables and a library are generated in the standalone or three executables and two libraries in the isocpp2 directory when the example is built:

For C++

- Chatter
- MessageBoard
- UserLoad
- libsacpp_tutorial_types.so

For C

- Chatter
- MessageBoard
- UserLoad
- libsac_tutorial_types.so

For ISO C++ 2

- Chatter
- MessageBoard
- UserLoad
- libISO_Cxx_V2_Tutorial_Impl.so
- libISO_Cxx_V2_Tutorial_Types.so

#### Java executables

Building the examples is described on the Summary page

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

For Java

- saj_tutorial_chatter.jar
- saj_tutorial_messageboard.jar
- saj_tutorial_userload.jar
- saj_tutorial_types.jar

For Java5

- java5_Chatter.jar
- java5_Messageboard.jar
- java5_Userload.jar

#### 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 3 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 3 terminals. In each terminal:
- Setup the environment and go to the example directory as described above
- Set the required configuraton 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

Running the example

- In the first terminal start MessageBoard by running either
  - MessageBoard [userid] & for C/C++/ISO C++ 2
  - java -jar saj_tutorial_messageboard.jar [userid] & for Java
  - java -jar messageboard/java5_Messageboard.jar [userid] & for Java5

        MessageBoard usage:  MessageBoard [userid] - where userid is optional and is a number representing a user whose messages will be blocked

- In the second terminal start UserLoad by running either
  - UserLoad & for C/C++/ISO C++ 2
  - java -jar saj_tutorial_userload.jar & for Java
  - java -jar userload/java5_Userload.jar & for Java5

- In the third terminal start Chatter by running either
  - Chatter [userid] [username] for C/C++/ISO C++ 2
  - java -jar saj_tutorial_chatter.jar [userid] [username] for Java
  - java -jar chatter/java5_Chatter.jar [userid] [username] for Java5

        Chatter usage:  Chatter [userid] [username] - where both are optional, userid is a number representing a user whose messages will be blocked, username is any string

- To terminate the MessageBoard run the Chatter again with the -1 as the input parameter
  - Chatter -1 for C/C++/ISO C++ 2
  - java -jar saj_tutorial_chatter.jar -1 for Java
  - java -jar chatter/java5_Chatter.jar -1 for Java5

### 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#/ISO C++ 2 Examples
- Java examples

#### C/C++/C#/ISO C++ 2 Executables

Building the examples is described on the Summary page

Executables and a libraries are generated in the standalone or isocpp2 directory when the example is built:

For C/C++/ISO C++ 2

- Chatter
- MessageBoard
- UserLoad
- sac_tutorial_types.lib - For C
- sacpp_tutorial_types.lib - For C++
- ISO_Cxx_V2_Tutorial_Impl - For ISO C++ 2
- ISO_Cxx_V2_Tutorial_Types - For ISO C++ 2

For C#

- sacs_tutorial_chatter
- sacs_tutorial_messageboard
- sacs_tutorial_userload

#### Java Executables

Building the examples is described on the Summary page

Four jars are generated in the java\standalone or java5 directory when the example is built:

For Java

- saj_tutorial_chatter.jar
- saj_tutorial_messageboard.jar
- saj_tutorial_userload.jar
- saj_tutorial_types.jar

For Java5

- java5_Chatter.jar
- java5_Messageboard.jar
- java5_Userload.jar

#### Running the C/C++/C#/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 3 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 3 OpenSplice Command Prompts. In each window:
- Go to the example directory as described above
- Set the required configuraton 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

Running the example

- In the first terminal start MessageBoard by running either
  - MessageBoard [userid]$ for C/C++/ISO C++ 2
  - sacs_tutorial_messageboard [userid]$ for C#
  - java -jar saj_tutorial_messageboard.jar [userid] & for Java
  - java -jar messageboard/java5_Messageboard.jar [userid] & for Java5

        MessageBoard usage:  MessageBoard [userid] - where userid is optional and is a number representing a user whose messages will be blocked

- In the second terminal start UserLoad by running either
  - UserLoad & for C/C++/ISO C++ 2
  - sacs_tutorial_userload & for C#
  - java -jar saj_tutorial_userload.jar & for Java
  - java -jar userload/java5_Userload.jar & for Java5

- In the third terminal start Chatter by running either
  - Chatter [userid] [username] for C/C++/ISO C++ 2
  - sacs_tutorial_chatter [userid] [username] for C#
  - java -jar saj_tutorial_chatter.jar -1 for Java
  - java -jar chatter/java5_Chatter.jar -1 for Java5

        Chatter usage:  Chatter [userid] [username] - where both are optional, userid is a number representing a user whose messages will be blocked, username is any string

- To terminate the MessageBoard run the Chatter again with -1 as the input parameter
  - Chatter -1 for C/C++/ISO C++ 2
  - sacs_tutorial_chatter -1 for C#
  - java -jar saj_tutorial_chatter.jar -1 for Java
  - java -jar chatter/java5_Chatter.jar -1 for Java5

## Running in CORBA Cohabitation Mode

Doing the substitution and additional setups described below, everything previously said for Standalone Mode can be applied to CORBA Cohabitation Mode.

#### Environment Setup

Besides OpenSplice environment variables, we need to set

- C/C++

- The TAO environment variable TAO_ROOT to point to the Tao installation directory.

- Java

- The JacORB environment variable JACORB_HOME to point to the JacORB installation directory.

#### Substitution

- standalone is replaced by corba
- the java command is java -Djava.endorsed.dirs=$JACORB_HOME/lib/endorsed -classpath $OSPL_HOME/jar/dcpssaj.jar:classes