Lightstreamer - Room-Ball Demo - Java Adapter
This project includes the resources needed to develop the Metadata and Data Adapters for the Room-Ball Demo that is pluggable into Lightstreamer Server.
The Room-Ball Demo implements a simple pure Server-side Mode multiplayer soccer game:
- Physics runs on server side only
- User commands are streamed from clients to server
- Position updates are streamed from server to clients
- Clients are pure renderer (no feedback, no prediction, no interpolation)
For more information, see this slide deck from the HTML5 Developer Conference:
The project is comprised of source code and a deployment example.
Dig the Code
Java Data Adapter and MetaData Adapter
A Java Adapter implementing both the SmartDataProvider interface and the MetadataProviderAdapter interface, to inject data into Lightstreamer server with real-time information about the movement of every player in the room. The adapter accepts also message submission for the chat room.
The adapter receives input commands from Lightstreamer server, which forwards messages arrived from clients to the adapter in relation to:
- Movement commands;
- Changing last message for the player.
The Metadata Adapter inherits from the reusable LiteralBasedProvider and just adds a simple support for message submission. It should not be used as a reference, as no guaranteed delivery and no clustering support is shown.
The Adapter Set Configuration
This Adapter Set is configured and will be referenced by the clients as
adapters.xml file for the Room-Ball Demo, should look like:
<?xml version="1.0"?> <adapters_conf id="ROOMBALL"> <!-- Not all configuration options of an Adapter Set are exposed by this file. You can easily expand your configurations using the generic template, `DOCS-SDKs/sdk_adapter_java_inprocess/doc/adapter_conf_template/adapters.xml`, as a reference. --> <metadata_adapter_initialised_first>Y</metadata_adapter_initialised_first> <metadata_provider> <adapter_class>com.lightstreamer.adapters.RoomBall.RoomBallMetaAdapter</adapter_class> <!-- Optional configuration file for the Adapter's own logging. Logging is managed through log4j. --> <param name="log_config">adapters_log_conf.xml</param> <param name="log_config_refresh_seconds">10</param> <!-- TCP port on which Sun/Oracle's JMXMP connector will be listening. --> <param name="jmxPort">9999</param> <messages_pool> <max_size>1000</max_size> <max_free>10</max_free> </messages_pool> <!-- Dimensions of the world. Any changes to these parameters involves actions on the client side for the drawing of the room. --> <param name="world_size_x">1000</param> <param name="world_size_y">550</param> </metadata_provider> <data_provider> <adapter_class>com.lightstreamer.adapters.RoomBall.RoomBallAdapter</adapter_class> <!-- Frame rate for physics calculations. In milliseconds. --> <param name="frameRate">10</param> <!-- Number of steps for a single frame --> <param name="stepsPerFrame">4</param> </data_provider> </adapters_conf>
Note that the parameter
<metadata_adapter_initialised_first> is mandatory to be set to Y to allow proper initialization of Metadata and Data Adapters respectively.
NOTE: not all configuration options of an Adapter Set are exposed by the file suggested above.
You can easily expand your configurations using the generic template,
DOCS-SDKs/sdk_adapter_java_inprocess/doc/adapter_conf_template/adapters.xml, as a reference.
Please refer here for more details about Lightstreamer Adapters.
If you want to install a version of the Room-Ball Demo in your local Lightstreamer Server, follow these steps:
- Download Lightstreamer Server (Lightstreamer Server comes with a free non-expiring demo license for 20 connected users) from Lightstreamer Download page, and install it, as explained in the
GETTING_STARTED.TXTfile in the installation home directory.
- Make sure that Lightstreamer Server is not running.
- Get the
deploy.zipfile of the proper release, unzip it, and copy the
RoomBallfolder into the
adaptersfolder of your Lightstreamer Server installation.
- [Optional] Customize the specific "LS_RoomDemo_Logger" and "LS_demos_Logger" categories in log4j configuration file
- Launch Lightstreamer Server.
- Test the Adapter, launching the Lightstreamer - Room-Ball Demo - HTML Client listed in Clients Using This Adapter.
To build your own version of
LS_RoomBall_Demo_Adapters.jar instead of using the one provided in the
deploy.zip file from the Install section above, follow these steps:
- Download this project.
- Get the
ls-adapter-interface.jarfile from the latest Lightstreamer distribution, and copy them into the
- Get the
log4j-1.2.17.jarfile from Apache log4j and copy it into the
- Get the
ua-parser-1.2.2.jarfile from ua_parser Java Library and copy it into the
- Get the
snakeyaml-1.11.jarfile from SnakeYAML and copy it into the
- Get the
jbox2d-library-22.214.171.124.jarfile from JBox2D and copy it into the
- Create the
LS_RoomBall_Demo_Adapters.jarwith commands like these:
> mkdir tmp_classes > javac -source 1.7 -target 1.7 -nowarn -g -classpath lib/log4j-1.2.17.jar;lib/ls-adapter-interface.jar;lib/jbox2d-library-126.96.36.199.jar;lib/ua-parser-1.2.2.jar;lib/snakeyaml-1.11.jar -sourcepath src/ -d tmp_classes src/com/lightstreamer/adapters/RoomBall/RoomBallAdapter.java > jar cvf LS_RoomBall_Demo_Adapters.jar -C tmp_classes com
Clients Using This Adapter
- Lightstreamer - Reusable Metadata Adapters - Java Adapter
- Lightstreamer - 3D World Demo - Java Adapter
- Lightstreamer - 3D World Demo - Three.js Client
Lightstreamer Compatibility Notes
- Compatible with Lightstreamer SDK for Java In-Process Adapters since 6.0
- For a version of this example compatible with Lightstreamer SDK for Java Adapters version 5.1, please refer to this tag.