Fields Summary |
---|
protected String | ADDRESS_PREFIXPrefic for addressed message connections. |
protected com.sun.midp.midlet.MIDletSuite | midletSuiteHandle to the MIDlet suite containing this MIDlet. |
protected boolean | openIndicates whether the connection is open or closed. If it is closed,
subsequent operations should throw an exception. |
protected int | connHandleLocal handle to connection |
protected String | appIDConnection parameter from the URL. |
protected int | m_modeConnector mode. |
protected String | hostMachine name - the parsed target address from the URL. |
private static com.sun.midp.security.SecurityToken | classSecurityTokenThis class has a different security domain than the MIDlet suite |
volatile javax.wireless.messaging.MessageListener | m_listenerMessage listener for async notifications. |
Thread | m_listenerThreadListener thread. |
protected Object | closeLockUsed to protect read-modify operation on open field during close() |
protected boolean | openPermissionIndicates whether a trusted application is allowed to open the
message connection. Set to true if the permission check passes.
Note: return true to override Security Permissions |
protected boolean | readPermissionIndicates whether a trusted application is allowed to read from the
message connection. Set to true if the permission check passes.
Note: return true to override Security Permissions |
protected boolean | writePermissionIndicates whether a trusted application is allowed to write to the
message connection. Set to true if the permission check passes.
Note: return true to override Security Permissions |
Methods Summary |
---|
protected abstract void | checkReceivePermission()Checks internal setting of receive permission.
Called from receive and setMessageListener methods.
|
protected abstract int | close00(int connHandle, int deRegister)Close connection.
|
public void | ensureOpen()Ensures that the connection is open.
if (!open) {
throw new IOException("Connection closed");
}
|
protected abstract java.lang.String | getAppID()Gets the connection parameter in string mode.
|
protected void | io2InterruptedIOExc(java.io.IOException ex, java.lang.String name)Generates InterruptedIOException when connection is closed.
try {
ensureOpen();
} catch (IOException ioe) {
throw new InterruptedIOException("Connection closed " +
"during " + name);
}
throw ex;
|
public abstract javax.wireless.messaging.Message | newMessage(java.lang.String type)Construct a new message object from the given type.
|
public abstract javax.wireless.messaging.Message | newMessage(java.lang.String type, java.lang.String addr)Constructs a new message object from the given type and address.
|
public abstract javax.wireless.messaging.Message | receive()Receives the bytes that have been sent over the connection, constructs a
Message object, and returns it.
If there are no Message s waiting on the connection, this
method will block until a message is received, or the
MessageConnection is closed.
|
public abstract void | send(javax.wireless.messaging.Message dmsg)Sends a message over the connection. This method extracts the data
payload from the Message object so that it can be sent as a
datagram.
|
protected abstract void | setAppID(java.lang.String newValue)Sets the connection parameter in string mode.
|
public void | setMessageListener(javax.wireless.messaging.MessageListener listener)Registers a MessageListener object.
The platform will notify this listener object when a message has been
received to this MessageConnection .
If the queue of this MessageConnection 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.
There can be at most one listener object registered for
a MessageConnection object at any given point in time.
Setting a new listener will implicitly de-register the possibly
previously set listener.
Passing null as the parameter de-registers the currently
registered listener, if any.
boolean 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 (this) {
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) {
String save_appID = getAppID();
/* Close thread without deregistering */
close00(connHandle, 0);
setAppID(null);
try {
m_listenerThread.join();
} catch (InterruptedException ie) {
} /* Ignore interrupted exception */
m_listenerThread = null;
setAppID(save_appID);
/* Unblock the low level */
unblock00(MIDletSuite.UNUSED_SUITE_ID);
}
|
private void | startReceiverThread()Start receiver thread
final MessageConnection messageConnection = this;
if (m_listenerThread == null) {
m_listenerThread = new Thread() {
/**
* Run the steps that wait for a new message.
*/
public void run() {
int messageLength = 0;
do {
/* No message, initially. */
messageLength = -1;
try {
messageLength =
waitUntilMessageAvailable00(connHandle);
if (getAppID() == null) {
break;
}
/*
* If a message is available and there are
* listeners, notify all listeners of the
* incoming message.
*/
if (messageLength >= 0) {
synchronized (this) {
if (m_listener != null) {
// Invoke registered listener.
m_listener.notifyIncomingMessage(
messageConnection);
}
}
}
} catch (InterruptedIOException iioe) {
/*
* Terminate, the reader thread has been
* interrupted
*/
break;
} catch (IOException exception) {
break;
} catch (IllegalArgumentException iae) {
/*
* This happens if port has been set to 0;
* which indicates that the connection has been
* closed. So Terminate.
*/
break;
}
/*
* m_iport = 0 on close
*/
} while (getAppID() != null);
}
};
m_listenerThread.start();
}
|
protected abstract int | unblock00(int msid)Unblock the receive thread.
|
protected abstract int | waitUntilMessageAvailable00(int handle)Waits until message available
|