本文整理汇总了Java中javax.wireless.messaging.MessageListener类的典型用法代码示例。如果您正苦于以下问题:Java MessageListener类的具体用法?Java MessageListener怎么用?Java MessageListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageListener类属于javax.wireless.messaging包,在下文中一共展示了MessageListener类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setMessageListener
import javax.wireless.messaging.MessageListener; //导入依赖的package包/类
public void setMessageListener(MessageListener a0)
throws java.io.IOException
{ }
示例2: setMessageListener
import javax.wireless.messaging.MessageListener; //导入依赖的package包/类
/**
* Registers a <code>MessageListener</code> object.
* <p>
* The platform will notify this listener object when a message has been
* received to this <code>MessageConnection</code>.
* </p>
* <p>If the queue of this <code>MessageConnection</code> contains some
* incoming messages that the application haven't read before the call
* of this method, the newly registered listener will be notified
* immediately exactly once for each such message in the queue.
* </p>
* <p>There can be at most one listener object registered for
* a <code>MessageConnection</code> object at any given point in time.
* Setting a new listener will implicitly de-register the possibly
* previously set listener.
* </p>
* <p>Passing <code>null</code> as the parameter de-registers the currently
* registered listener, if any.
* </p>
* @param listener <code>MessageListener</code> object to be registered.
* If <code>null</code>,
* the possibly currently registered listener will be
* de-registered and will not receive notifications.
* @exception java.lang.SecurityException if the application does not
* have a permission to receive messages using the given port
* number
* @exception java.io.IOException if it is requested to register
* a listener on a client connection or if the connection
* has been closed
*/
public void setMessageListener(MessageListener listener)
throws IOException {
needStopReceiver = false;
if (listener != null) {
/*
* Make sure the connection is still open.
*/
ensureOpen();
/*
* Check if we have permission to recieve.
*/
checkReceivePermission();
/*
* Don't let the application waste time listening on a client
* connection, which can not be used for receive operations.
*/
if (host != null && host.length() > 0) {
throw new IOException("Cannot listen on client connection");
}
}
synchronized (listenerLock) {
if ((m_listener != null) && (listener == null)) {
needStopReceiver = true;
}
m_listener = listener;
/* Start a new receive thread when need */
if ((listener != null) && (m_listenerThread == null)) {
startReceiverThread();
}
}
/* Kill listener when need */
if (needStopReceiver) {
/* Close thread without deregistering */
close00(connHandle, 0);
try {
m_listenerThread.join();
} catch (InterruptedException ie) {
} /* Ignore interrupted exception */
m_listenerThread = null;
/* Unblock the low level */
unblock00(appPackage.UNUSED_APP_ID);
}
}