Namespaces
Variants
Actions

Message handling in Java Platfrom, Micro Edition (Java ME)

Jump to: navigation, search
SignpostIcon Messages 52.png
Article Metadata

Article
Created: arunjyothiskp (21 Nov 2007)
Last edited: hamishwillee (06 Feb 2012)

Introduction

Sending and receiving messages are carried out by the messaging API, JSR 120. The messaging API is based on the Generic Connection Framework (GCF), which is defined in the Connected Limited Device Configuration (CLDC) 1.0 specification. The package javax.microedition.io defines the framework and supports input/output and networking functionality in J2ME profiles. It provides a coherent way to access and organize data in a resource-constrained environment.

Code Sample 1 – A simplified version of the message handling classes

class MessageListenerImpl implements MessageListener
{
public void notifyIncomingMessage(MessageConnection mCon)
{
messageReader.handleMessage();
}
}
 
class WirelessMessageReader implements Runnable
{
 
private boolean readMessages = true;
 
private int pendingMessages;
 
private MessageConnection msgConn = null;
 
 
public void run()
{
while(readMessages)
{
synchronized(this)
{
if(pendingMessages == 0)
{
try
{
wait();
}
catch(InterruptedException ie) {}
}
pendingMessages--;
}
Message message = null;
try
{
Message message = msgConn.receive();
/* parse payload */
}
catch(IOException ioe) {}
}
}
 
synchronized void handleMessage()
{
pendingMessages++;
notify();
}
}
This page was last modified on 6 February 2012, at 06:33.
102 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved