Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

DDS + Android = OpenSplice Mobile


Published on

Mobile platforms such as Android/iOS based smart phones, phablets , and tablets are swiftly establishing as the target client platform for a large class of consumer as well as enterprise and mission/business critical applications. OpenSplice Mobile is a pure Java DDS implementation optimized for Android and the JVM that provides effective and efficient DDS connectivity to Android based devices – as well as any JVM enabled device.

OpenSplice Mobile is the first peer-to-peer middleware infrastructure designed for Android that allow seamless interoperability with existing DDS systems and provides a powerful infrastructure for next generation peer-to-peer Android applications.

This presentation introduces OpenSplice Mobile, provides and overview of its architecture and performances and gets you started writing DDS applications for Android!

Published in: Technology, Education
  • Be the first to comment

DDS + Android = OpenSplice Mobile

  1. 1. OpenSpliceDDSAngelo CORSARO, Ph.D.Chief Technology OfficerOMG DDS Sig Co-ChairPrismTechangelo.corsaro@prismtech.comDDS + Android =OpenSplice |Mobile
  2. 2. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSWhat I’ll Cover Today☐ Learn about OpenSplice Mobile☐ Understand OpenSplice Mobile Architecture andPerformance☐ Get started with DDS programming on Android
  3. 3. OpenSpliceDDSIntroducing OpenSplice Mobile
  4. 4. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSDDS Everywhere Platform☐ A DDS-based, interoperableproduct family addressingsystems needs from Embeddedand Mobile to Enterprise andCloud☐ An Open Source core providingfree access to the OpenSpliceEcosystem, security of supply anda vibrant, innovative communityOpenSpliceCommunityOpenSpliceCloudOpenSpliceEmbeddedOpenSpliceOpenSpliceEnterprise
  5. 5. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSKey Highlights☐ Brings DDS on mobiledevices powered byAndroid/iOS☐ Enables DDS-basedCloud Messaging forhigher scalability,throughout and minimalcost per messageOpenSpliceCommunityOpenSpliceCloudOpenSpliceEmbeddedOpenSpliceOpenSpliceEnterpriseOpenSpliceMobileOpenSpliceGateway
  6. 6. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSOpenSplice Mobile☐ Pure Java version ofOpenSplice targeting the JVM☐ DDSI Protocol Stack optimizedfor mobility and Android OS☐ Only DDS on the marketdesigned and Engineered forAndroid and the JVMDCPS Java 5 / Scala APIDDSI(Optimized for Mobility)OpenSplice Mobile brings Peer-2-Peer, infrastructure-less communicationto the Android platform
  7. 7. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSOpenSplice Mobile
  8. 8. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSIn Action...
  9. 9. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSDDS ComplianceDDS Profiles☐ Minimum☐ Ownership☐ Durability (only Transient Local)API☐ Java 5 DDS PSM (i.e. latest Java 5 API for DDS)DDSI☐ Full implementation of DDSI v2.1 with support for large data (i.e.fragmentation)☐ Interoperability demonstrated with other vendors at the DDS Info Dayin March 2013
  10. 10. OpenSpliceDDSOpenSplice MobileArchitecture
  11. 11. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSA Staged Event Driven Architecture☐ OpenSplice Mobile has a Staged Event Driven Architecture (SEDA)that allows it to be easily configured to trade off betweenthroughput and latency
  12. 12. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSSEDA☐ Aims at decomposing a complex, event-driven application into a set of stagesconnected by queues☐ Avoids the high overhead associated with thread-based concurrency models,and decouples event and thread scheduling from application logic.☐ Through admission control on each event queue, SEDAs can be well-conditionedto load, preventing resources from being overcommitted when demandexceeds service capacity[Matt Welsh, David Culler, and Eric Brewer, SEDA:An Architecture for Well-Conditioned, Scalable Internet Services]
  13. 13. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSOpenSplice Mobile ArchitectureThe OpenSplice Mobile architecture isorganize around three stages☐ Packet Processing☐ Message Processing☐ Data ProcessingThe channel that connect each stagecan be configured to be active or passivePacketProcessorMessageProcessorDataProcessorNetwork PacketDDSI MessagesCache Changes
  14. 14. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSConfigurability☐ Channels can be active or passive (and zero-copy). That means that channels can beconfigured with threading resources, or not☐ Messages posted in a passive channel areexecuted in the context of the posting thread☐ This allows to configure OpenSplice Mobile tooptimize the use case at handProcessorChannel
  15. 15. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSSample ConfigurationsSingle Thread per MessagePacketProcessorMessageProcessorDataProcessorNetwork PacketDDSI MessagesCache ChangesFully AsynchronousPacketProcessorMessageProcessorDataProcessorNetwork PacketDDSI MessagesCache Changes
  16. 16. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSConfiguration in Practice☐ OpenSplice Mobile is SEDA architecture as well as all the protocolparameters can be configured through configuration file or viacommand line properties , i.e. providing -D options to the JVM☐ Configuration parameters are listed on the user manual☐ Example:java  -­‐server    -­‐cp  .:./target/jmobile-­‐demo-­‐assembly-­‐2.0.jar    -­‐Ddds.listeners.useTransportThread=true  -­‐Dddsi.writers.heartbeatPeriod=0.001    -­‐Dddsi.writers.nackResponseDelay=0    -­‐Dddsi.readers.heartbeatResponseDelay=0  -­‐Dddsi.timer.threadPool.size=1    -­‐Dddsi.receiver.threadPool.size=0    -­‐Dddsi.dataProcessor.threadPool.size=0  -­‐Dddsi.acknackProcessor.threadPool.size=0  -­‐Dddsi.writers.reliabilityQueue.size=128    org.opensplice.jmobile.demo.perf.RoundTripDemoReader  $*
  17. 17. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSPerformance☐ OpenSplice Mobile v1.0beta features alreadyvery good performance☐ Latency is low and prettystable ~3usec ofdifference from 32 to 1024bytes
  18. 18. OpenSpliceDDSAndroid and OpenSpliceMobile
  19. 19. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSAndroid Fundamentals☐ Android applications are written in the Java programminglanguage☐ Support for native code is available, but this often leads to worseperformance (due to the JNI layer) and worse battery utilization☐ Thus unless you have very good reasons not to, you are stronglyencouraged to write android applications in Java and to leverageon Java libraries!
  20. 20. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSAndroid Application in a Nutshell☐ An Android application runs in its own JVM and (by default) on its ownlinux process☐ An application may be composed of the following elements:☐ Activities: a single screen with a user interface☐ Services: a component that runs in the background to perform long-runningoperations or to perform work for remote processes.☐ Content Providers: a component that manages shared data for a set ofapplications☐ Broadcast Receivers: a component that responds to system-wide broadcastannouncements☐ Android allows any applications to start any other applicationcomponent and potentially consume the data it produces
  21. 21. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSComponent Activation☐ Activities, Services and Broadcast Receivers are activated throughan asynchronous message, called Intent☐ For Activities and Services the intent specifies the action to perform☐ For Broadcast Receivers it specifies the event being broadcasted,e.g. battery-low
  22. 22. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSApplication Manifest☐ The manifest is an XML file containing several important informationabout the application☐ Among, other things, the manifest includes the authorizationnecessary for your application -- for instance, it is in this file that youhave to mention that your application requires access to thenetwork, etc.
  23. 23. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSActivities Lifecycle☐ Notice that Activities are alsodestroyed each time there is ascreen rotation (unless youdon’t explicitly manage it)
  24. 24. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSTasks and Back-Stack
  25. 25. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSDDS-based and Android AppsConsidering the Android application lifecycle, we should askourselves a few questions:☐ When should we create DDS entities and who should hold areference to them?☐ What happens when an application is no more visible?☐ Can I control when my application exits?☐ How do I deal with multi-threading?
  26. 26. OpenSpliceDDSDDS Chat
  27. 27. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSDDS Chat for Android☐ To learn how to write anAndroid Application thatuses OpenSplice Mobilewe’ll develop a verysimple Chat☐ To keep things simple thischat will have a single“chat room”
  28. 28. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSStep 1: Architecture☐ Our Chat application will have a very simple architecture with asingle just a single Activity that will take care of:☐ Posting Chat Messages into the ChatRoom☐ Displaying the Chat Messages Posted in the room since when we joined☐ In terms of information modeling, we’ll have a single topicrepresenting the user poststruct ChatMessage {string user;string msg;};#pragma keylist ChatMessage user
  29. 29. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSStep 2: Lifecycle Management☐ Creating DDS entities, such asDomainParticipants, DataReadersand DataWriters involves networkcommunication, such as discoveryinformation☐ In addition when an a DDS entity isdestroyed it looses its state☐ As such, tying the life-cycle of DDSentities to activities should be donewith great care[1/2]
  30. 30. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSStep 2: Lifecycle Management☐ In general, it is a better idea to tie thelife-cycle of DDS entities to theApplication as opposed to Activities☐ In some cases, it may make sense totie the life-cycle of DataReaders/DataWriters to that of the activitythat relies on them -- Usually thismakes sense for activities that are“one-off”[2/2]
  31. 31. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSApplicationpublic class ChatApplication extends Application {DataReader<ChatMessage> dr;DataWriter <ChatMessage> dw;DomainParticipant dp;@Overridepublic void onCreate() {super.onCreate();// This should be defined via a resource -- but for a small// demo that’s OK.System.setProperty(ServiceEnvironment.IMPLEMENTATION_CLASS_NAME_PROPERTY,"");ServiceEnvironment env = ServiceEnvironment.createInstance(ChatApplication.class.getClassLoader());DomainParticipantFactory dpf =DomainParticipantFactory.getInstance(env);dp = dpf.createParticipant(0);Topic<ChatMessage> topic = dp.createTopic("TChatMessage",ChatMessage.class);Publisher pub = dp.createPublisher();Subscriber sub = dp.createSubscriber();dw = pub.createDataWriter(topic);dr = sub.createDataReader(topic);}
  32. 32. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSApplicationpublic DataReader<ChatMessage> reader() {return this.dr;}public DataWriter<ChatMessage> writer() {return this.dw;}@Overridepublic void onTerminate() {super.onTerminate();this.dp.close();}}
  33. 33. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSManifest...<applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" android:name="ChatApplication" ><activityandroid:name=""android:label="@string/app_name" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application>
  34. 34. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSMore Manifest...☐ When using OpenSplice Mobile you need to grant the properpermissions for networking:<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
  35. 35. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSActivity GUI<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=""xmlns:tools=""android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><TextView android:id="@+id/chatMessages"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="@string/chat_msgs"android:visibility="gone"android:background="#666"android:textColor="#fff"android:paddingLeft="5dp"/><ListViewandroid:id="@+id/messageList"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"/>
  36. 36. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSActivity GUI<LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><EditTextandroid:id="@+id/message"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:hint="@string/edit_message" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="sendChatMessage"android:text="@string/button_send" /></LinearLayout></LinearLayout>
  37. 37. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSActivity12 public class MainActivity extends Activity {34 private static final String TAG = "ChatMainActivity";5 private final Handler handler = new Handler();6 private ArrayAdapter<String> chatMessages;78 public class ChatMessageListener extends ChatMessageDataListener {9 // ...10 }1112 @Override13 protected void onCreate(Bundle savedInstanceState) {14 super.onCreate(savedInstanceState);15 setContentView(R.layout.activity_main);16 chatMessages = new ArrayAdapter<String>(this, R.layout.messages);17 chatMessages.add("Welcome to the DDS Chat Room");18 ListView mview = (ListView) findViewById(;19 mview.setAdapter(chatMessages);20 ChatApplication app = (ChatApplication) getApplication();2122 app.reader().setListener(new ChatMessageListener());2324 }25
  38. 38. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSActivity2526 @Override27 public boolean onCreateOptionsMenu(Menu menu) {28 // Inflate the menu; this adds items to the action bar if it is present.29 getMenuInflater().inflate(, menu);30 return true;31 }
  39. 39. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSActivity3233 public void sendChatMessage(View view) {34 EditText editText = (EditText) findViewById(;35 String msg = editText.getText().toString();36 editText.setText("");37 // chatMessages.add(msg);38 ChatApplication app = (ChatApplication) getApplication();39 try {40 Log.i(TAG, ">>> Sending data " + msg);41 app.writer().write(new ChatMessage(usr, msg));42 } catch (TimeoutException te) {43 }44 }4546 }
  40. 40. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSReceiving Data☐ Receiving data is a bit trickier since in Android only the thread thatruns an activity has the right to change the UI☐ This means, that from a DDS listener it is not possible to change anthe UI directly!☐ The solution in to use an Android Handler  to which we can postRunnable to be executed by the activity thread☐ Let’s see how this works
  41. 41. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSDDS Listener & Android Handler1 public class ChatMessageListener extends ChatMessageDataListener {23 private DataReader<ChatMessage> dr;45 public ChatMessageListener() {6 ChatApplication app = (ChatApplication) getApplication();7 dr = app.reader();8 }9
  42. 42. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSDDS Listener & Android Handler10 @Override11 public void onDataAvailable(DataAvailableEvent<ChatMessage> dae) {12 final Iterator<ChatMessage> i =;1314 Log.i(TAG, ">>> DataReaderListener.onDataAvailable");15 if (i.hasNext()) {16 Runnable dispatcher = new Runnable() {17 public void run() {18 while (i.hasNext()) {19 Sample<ChatMessage> s =;2021 if (s.getSampleState() == SampleState.NOT_READ) {22 ChatMessage cm = s.getData();23 chatMessages.add(cm.user + " > " + cm.msg);24 }25 }26 }27 };28;29 }30 }31 }
  43. 43. OpenSpliceDDSPutting all Together
  44. 44. OpenSpliceDDSFinal Remarks
  45. 45. Copyright  2011,  PrismTech  –    All  Rights  Reserved.OpenSpliceDDSConcluding Remarks☐ OpenSplice Mobile is the only pure Java DDS implementationavailable on the market. This means that it is the best choice forJava-Based DDS applications as well as Android Applications☐ Its performance are very close to native C/C++ DDSimplementations☐ OpenSplice Mobile architecture is very flexible and can be easilyconfigured to deliver extremely low latency as well as extremelyhigh throughput
  46. 46. OpenSpliceDDS
  47. 47. OpenSpliceDDS¥@prismtech¥@acorsaro¥ ¥¥¥¥ ¥¥ ¥ Connect with Us ::