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.

Push registrysup

1,228 views

Published on

  • Be the first to comment

  • Be the first to like this

Push registrysup

  1. 1. <ul><li>PushRegistry </li></ul>
  2. 2. Introduction <ul><li>Push registry is introduced in MIDP 2.0 (JSR 118) </li></ul><ul><li>Push Registry maintains a list of inbound connections and associated applications </li></ul><ul><li>The event is triggered by the server and delegated to the mobile device where an application is registered for this event </li></ul><ul><li>With the advent of push registry your application can now be launched in three ways </li></ul><ul><ul><li>Select the application from Application Launcher screen. </li></ul></ul><ul><ul><li>rigger by inbound network request </li></ul></ul><ul><ul><li>Timer based activation </li></ul></ul>
  3. 3. PushRegistry Package <ul><li>The push registry is part of the Generic Connection </li></ul><ul><li>Framework (GCF) and is encapsulated within a single class, </li></ul><ul><li>javax.microedition.io.PushRegistry </li></ul><ul><li>getFilter() </li></ul><ul><li>getMidlet() </li></ul><ul><li>listConnections() PushRegistry Methods </li></ul><ul><li>registerAlarm() </li></ul><ul><li>registerConnection() </li></ul><ul><li>unregisterConnection() </li></ul>
  4. 4. MIDlet Activation and Life Cycle
  5. 5. PushRegistry Overview <ul><li>The MIDlet registers a port along with the protocol name in the </li></ul><ul><li>mobile device such that, if any message arrives in the specified </li></ul><ul><li>port with the protocol mentioned, the AMS delivers it to the MIDlet </li></ul><ul><li>From the server, a message is sent to the specific mobile device using the particular protocol and port where the MIDlet application is registered to listen </li></ul><ul><li>After the message is delivered to the mobile device, the AMS calls the MIDlet application, which has registered to listen to that particular port and particular protocol </li></ul><ul><li>Once the message is delivered to the MIDlet, it is the application's responsibility to process the message accordingly </li></ul>
  6. 6. PushRegistry Overview <ul><li>To become push-enabled, MIDlets must register with the push registry, </li></ul><ul><li>using one of two types of registration: </li></ul><ul><li>Static Registration </li></ul><ul><li>Dynamic Connection </li></ul>
  7. 7. Static Registration <ul><li>Registrations of static (well known) connections occur during the installation of the MIDlet suite </li></ul><ul><li>Static registrations are defined by listing one or more MIDlet-Push attributes in the JAD file or JAR manifest </li></ul><ul><li>The installation will fail if you attempt to register an address that's already bound </li></ul><ul><li>Uninstalling a MIDlet suite automatically unregisters the connection </li></ul><ul><li>The format of the MIDlet-Push attribute is... </li></ul><ul><li>MIDlet-Push-<n>: <ConnectionURL>, <MIDletClassName>, <AllowedSender> </li></ul><ul><li>Example: </li></ul><ul><li>MIDlet-Push-1: socket://:79, </li></ul><ul><li>com.j2me.salsa.midletsuite.FirstMIDlet, 200.200.50.1 MIDlet-Push-2: datagram://:50000, </li></ul><ul><li>com.j2me.salsa.midletsuite.SecondMIDlet, * </li></ul>
  8. 8. Dynamic Connection <ul><li>Dynamic registration are used for both inbound network </li></ul><ul><li>connections and timer-based alarms, at runtime </li></ul><ul><li>Example code for dynamic registration: </li></ul><ul><li>PushRegistry.registerConnection(&quot;socket://:79&quot;,&quot;com.FirstMIDlet&quot;, &quot;200.200.50.1&quot;); </li></ul><ul><li>PushRegistry.registerConnection(&quot;datagram://:50000,com.SecondMIDlet&quot;, &quot;*&quot;); </li></ul><ul><li>To unregistered dynamically use unregisterConnection(String connection) Method </li></ul>
  9. 9. Alarm Based Push Registry <ul><li>Only Dynamic Push Registry can be implemented in Alarm Based Push Registry </li></ul><ul><li>Use registerAlarm(String midlet, long time) Method to register your MIDLet </li></ul><ul><li>Example code to register Alarm </li></ul><ul><li>long day = 1000*60*60*24; long t = new Date().getTime() + day; PushRegistry.registerAlarm(&quot;PushDemoMIDlet&quot;, t); </li></ul>
  10. 10. Security Considerations <ul><li>Application signing enables the platform to determine whether to trust another application </li></ul><ul><li>Network and push operations are considered restricted: applications must request permission before using them </li></ul><ul><li>Attempting to use a restricted operation without proper permission causes the system to throw a SecurityException </li></ul><ul><li>Add permissions in the JAD file or the JAR manifest, by creating MIDlet-Permissions property entries </li></ul><ul><li>For example, to request permission to use the PushRegistry and ServerSocketConnection APIs, define the following property entry: </li></ul><ul><li>MIDlet-Permissions: </li></ul><ul><li>javax.microedition.io.PushRegistry, </li></ul><ul><li>javax.microedition.io.Connector.serversocket </li></ul>
  11. 11. <ul><li>To Display List of all Inbound connections </li></ul><ul><li>public void displayConnections() { </li></ul><ul><li>//Passing false in listConnections() method of PushRegistry class return the complete list of registered connections for the current MIDlet suite </li></ul><ul><li>     String[] allConnections = PushRegistry.listConnections(false); </li></ul><ul><li>     StringBuffer sbuf = new StringBuffer(); if (allConnections != null && allConnections.length > 0) {   for (int i = 0; i < allConnections.length; i++ ) { String midlet = PushRegistry.getMIDlet(connections[i]); </li></ul><ul><li>String filter = PushRegistry.getFilter(connections[i]); </li></ul><ul><li>     sbuf.append(“pushInfo=”+allConnections[i]+” ”+midlet+” ”+filter);      sbuf.append(&quot; &quot;);   } } String str = sbf.toString(); </li></ul><ul><li>} </li></ul>List of all Inbound connections
  12. 12. Register or UnRegister An Inbound Connection <ul><li>Way to register or unregister an inbound connection </li></ul><ul><li>public void regConnection() { </li></ul><ul><li>try { String url = &quot;socket://:5000&quot;; String classname = this.getClass.getName(); //Midlet to be launched     if (register) {          PushRegistry.registerConnection(url, classname, &quot;*&quot;);     } else {             PushRegistry.unregisterConnection(url);     } </li></ul><ul><li>} catch (IllegalArgumentException iae) {     </li></ul><ul><li>  } catch (IOException ioe) { </li></ul><ul><li>   } </li></ul><ul><li>} </li></ul>
  13. 13. Discovering Whether a MIDlet was push-Activated <ul><li>The PushRegistry.listConnections() method allows you to discover all the inbound </li></ul><ul><li>connections registered by the MIDlet suite </li></ul><ul><li>Determine if activated due to inbound connection and if so dispatch a PushProcessor to </li></ul><ul><li>handle incoming return true if MIDlet was activated due to inbound connection, false </li></ul><ul><li>otherwise </li></ul><ul><li>private boolean handlePushActivation() { </li></ul><ul><li>// Discover if there are pending push inbound </li></ul><ul><li>// connections and if so, dispatch a </li></ul><ul><li>// PushProcessor for each one. </li></ul><ul><li>String[] connections = PushRegistry.listConnections(true); </li></ul><ul><li>if (connections != null && connections.length > 0) { </li></ul><ul><li>for (int i=0; i < connections.length; i++) { </li></ul><ul><li>PushProcessor pp = new PushProcessor(connections[i]); </li></ul><ul><li>} </li></ul><ul><li>return(true); </li></ul><ul><li>} </li></ul><ul><li>return(false); </li></ul><ul><li>} </li></ul>
  14. 14. Receiving and Processing Push Events <ul><li>Way to process the received push events </li></ul><ul><li>if (url.startsWith(&quot;socket://&quot;)) { </li></ul><ul><li>// &quot;Open&quot; connection. </li></ul><ul><li>ServerSocketConnection ssc = (ServerSocketConnection) Connector.open(url); </li></ul><ul><li>// Wait for (and accept) inbound connection. </li></ul><ul><li>SocketConnection sc = (SocketConnection) ssc.acceptAndOpen(); </li></ul><ul><li>InputStream is = sc.openInputStream(); </li></ul><ul><li>// Read data from inbound connection. </li></ul><ul><li>int ch; </li></ul><ul><li>byte[] data = null; </li></ul><ul><li>ByteArrayOutputStream tmp = new ByteArrayOutputStream(); </li></ul><ul><li>while( ( ch = is.read() ) != -1 ) { </li></ul><ul><li>tmp.write( ch ); </li></ul><ul><li>} </li></ul><ul><li>data = tmp.toByteArray(); </li></ul><ul><li>// Here do something with received data </li></ul><ul><li>System.out.print(new String(data)); </li></ul><ul><li>} </li></ul>
  15. 15. <ul><li>Thank You </li></ul>

×