Enterprise J2ME Developing Mobile Java Applications [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Enterprise J2ME Developing Mobile Java Applications [Electronic resources] - نسخه متنی

Michael Juntao Yuan

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



10.3 Mobile JMS from iBus//Mobile


iBus//Mobile (v3.0) is a JMS-based mobile MOM solution. It contains a standalone JMS server that runs on gateway computers (PCs). The real value of iBus//Mobile is its extensive clientside library that runs on mobile devices and supports all popular mobile network protocols.

iBus//Mobile provides lightweight JMS client libraries for all J2ME platforms and a special JMS-like lightweight client for the MIDP. Nonprogrammable devices with native SMS, email, or WAP clients are also supported.

The iBus//Mobile server manages message queues and topics. It can also serve as a gateway to fully JMS-compatible J2EE application servers. Now, let's look at iBus//Mobile's extensive client library.


10.3.1 J2ME JMS Clients


iBus//Mobile provides JMS client libraries for all J2ME platforms, including CDC, PersonalJava, and MIDP. Since the javax.jms package is supported, any existing JMS application can be ported to mobile devices with minimum effort. However, since the iBus//Mobile client does not run in the J2EE environment, it does not have access to JNDI services. Hence, any JNDI-dependent initialization code must be changed to conform to the iBus//Mobile API.

Listing 10.5 demonstrates how to initialize a JMS connection from the client side. The ProtocolStackRegistry class specifies the protocol-dependent message transport, iBus//Mobile gateway URL, and QoS settings. The code snippet is based on the MIDP Queue Producer sample distributed with iBus//Mobile download.

Listing 10.5. iBus//Mobile JMS connection initialization



private QueueConnectionFactory qcf_;
private QueueConnection connection_;
private QueueSession session_;
private Queue queue_;
private QueueSender sender_;
public TextMessage msg_;
public String url_ = "socket://gatewayIP:8738";
public void initJms() {
try {
ProtocolStackRegistry.registerQos(
"qos-tcp",
url_,
new Hashtable(),
"mySessionId"
);
Hashtable jndiEnv = new Hashtable();
jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY,
"ch.softwired.mobileibus.jndi.InitialContextFactory"
);
jndiEnv.put(
ch.softwired.mobileibus.jndi.Context.QOS_NAME,
"qos-tcp");
Context ctx = new InitialContext(jndiEnv);
QueueConnectionFactory qcf_ =
(QueueConnectionFactory)ctx.lookup(
"QueueConnectionFactory");
connection_ = qcf_.createQueueConnection();
connection_.setClientID("myClientId");
session_ =
connection_.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
queue_ = (Queue)ctx.lookup("queue");
sender_ = session_.createSender(queue_);
connection_.start();
} catch (Exception e) {
System.out.println("Error: " + e.toString());
}
}


10.3.2 The Lightweight Client for MIDP


Although iBus//Mobile's J2ME JMS client libraries run on MIDP, it is still too big for some low-end devices. For those devices, iBus//Mobile provides a lightweight JMS-like API called JmsLc. JmsLc also works on the MIDP platform. The use of JmsLc is very simple if you are familiar with basic concepts of JMS. Code Listings 10.6, 10.7, and 10.8 demonstrate how to initialize a new connection and send and receive messages using JmsLc. All code examples are based on the JmsLc tutorial sample application bundled in the iBus//Mobile download.

Listing 10.6. Initialize a JMS connection using JmsLc



public void initJms() {
try {
jmsLcConnector_ =
new JmsLcConnector(url_, debugMode_);
} catch (JmsLcException ex) {
// Handle the error
}
}

Listing 10.7. Send a message to the queue using JmsLc


public void sendToQueue() {
JmsLcTextMessage aTextMessage = null;
try {
aTextMessage = jmsLcConnector_.createTextMessage();
aTextMessage.setText(MESSAGE_TEXT_ + msgNumber_);
jmsLcConnector_.sendToQueue(DESTINATION_NAME_,
aTextMessage, new Hashtable());
msgNumber_++;
displayMessageTextBox("Send message:", aTextMessage.getText());
} catch (JmsLcException ex) {
// Handle error
}
}

Listing 10.8. Receive a message from the queue using JmsLc


public void receiveFromQueue() {
try {
IJmsLcMessage receivedMessage =
jmsLcConnector_.receiveFromQueue(
DESTINATION_NAME_, 10000, new Hashtable());
if (receivedMessage != null) {
if ( receivedMessage instanceof JmsLcTextMessage) {
JmsLcTextMessage aTextMessage =
(JmsLcTextMessage)receivedMessage;
displayMessageTextBox("Rec. message:", aTextMessage.getText());
} else {
// Handle non-text message
}
} catch (JmsLcException ex) {
// Handle error
}
}


10.3.3 Non-Programmable Clients


In addition to smart J2ME devices, iBus//Mobile middleware server also supports non-programmable devices. Since there is no way to make API calls, those devices use code words buried inside the message content to trigger appropriate delivery actions on the server side. We can define special mappings between message prefixes and message queues in the iBus//Mobile serverside configure file. For example, we can associate the SX prefix to a queue that is connected to a stock quote producer. In this case, if a user sends "SX IBM" in an SMS message, he will receive a return SMS message of the current IBM stock quote. iBus//Mobile server supports the following native messaging clients.

SMS: The iBus//Mobile server connects to an SMS service center operated by the wireless carrier or an SMS-enabled smart phone via a cable.

Email: The iBus//Mobile server connects to SMTP, POP3, and IMAP mail servers.

WAP: Through a WAP servlet residing on a WML server, iBus//Mobile receives messages from WML form submissions and sends messages as WML responses to WAP clients.


For more information on iBus//Mobile's native device/protocol support, please refer to its documentation.


/ 204