| java.lang.Object com.sun.midp.io.j2me.ProtocolBase
All known Subclasses: com.sun.midp.io.j2me.sms.Protocol, com.sun.midp.io.j2me.mms.Protocol, com.sun.midp.io.j2me.cbs.Protocol,
ProtocolBase | abstract public class ProtocolBase implements MessageConnection,ConnectionBaseInterface,StreamConnection(Code) | | Base class for SMS/CBS/MMS message connection implementation.
Protocol itself is not instantiated. Instead, the application
calls Connector.open with an URL string and obtains a
javax.wireless.messaging.MessageConnection MessageConnection object. It is an instance of MessageConnection
that is instantiated. The Generic Connection Framework mechanism
in CLDC will return a Protocol object, which is the
implementation of MessageConnection . The
Protocol object represents a connection to a low-level transport
mechanism.
Optional packages, such as Protocol , cannot reside in
small devices.
The Generic Connection Framework allows an application to reach the
optional packages and classes indirectly. For example, an application
can be written with a string that is used to open a connection. Inside
the implementation of Connector , the string is mapped to a
particular implementation: Protocol , in this case. This allows
the implementation to be optional even though
the interface, MessageConnection , is required.
Closing the connection frees an instance of MessageConnection .
The Protocol class contains methods
to open and close the connection to the low-level transport mechanism. The
messages passed on the transport mechanism are defined by the
MessageObject MessageObject class.
Connections can be made in either client mode or server mode.
- Client mode connections are for sending messages only. They are
created by passing a string identifying a destination address to the
Connector.open() method.
- Server mode connections are for receiving and sending messages. They
are created by passing a string that identifies a port, or equivalent,
on the local host to the
Connector.open() method.
The class also contains methods to send, receive, and construct
Message objects.
This class declares that it implements StreamConnection
so it can intercept calls to Connector.open*Stream()
to throw an IllegalArgumentException .
|
Constructor Summary | |
public | ProtocolBase() Creates a message connection protocol handler. |
Method Summary | |
abstract protected void | checkReceivePermission() Checks internal setting of receive permission. | abstract protected int | close00(int connHandle, int deRegister) Close connection.
Parameters: connHandle - handle returned by open0 Parameters: deRegister - Deregistration appID when parameter is 1. | public void | ensureOpen() Ensures that the connection is open. | abstract protected String | getAppID() Gets the connection parameter in string mode. | protected void | io2InterruptedIOExc(IOException ex, String name) Generates InterruptedIOException when connection is closed. | abstract public Message | newMessage(String type) Construct a new message object from the given type.
Parameters: type - MULTIPART_MESSAGE is the only type permitted. | abstract public Message | newMessage(String type, String addr) Constructs a new message object from the given type and address.
Parameters: type - TEXT_MESSAGE orBINARY_MESSAGE . Parameters: addr - the destination address of the message. | abstract public Message | receive() Receives the bytes that have been sent over the connection, constructs a
Message object, and returns it. | abstract public void | send(Message dmsg) Sends a message over the connection. | abstract protected void | setAppID(String newValue) Sets the connection parameter in string mode. | public void | setMessageListener(MessageListener listener) Registers a MessageListener object. | abstract protected int | unblock00(int msid) Unblock the receive thread.
Parameters: msid - The MIDlet suite ID. | abstract protected int | waitUntilMessageAvailable00(int handle) |
ADDRESS_PREFIX | protected String ADDRESS_PREFIX(Code) | | Prefic for addressed message connections.
|
appID | protected String appID(Code) | | Connection parameter from the URL.
|
closeLock | protected Object closeLock(Code) | | Used to protect read-modify operation on open field during close()
|
connHandle | protected int connHandle(Code) | | Local handle to connection
|
host | protected String host(Code) | | Machine name - the parsed target address from the URL.
|
m_listenerThread | Thread m_listenerThread(Code) | | Listener thread.
|
m_mode | protected int m_mode(Code) | | Connector mode.
|
midletSuite | protected MIDletSuite midletSuite(Code) | | Handle to the MIDlet suite containing this MIDlet.
|
open | protected boolean open(Code) | | Indicates whether the connection is open or closed. If it is closed,
subsequent operations should throw an exception.
|
openPermission | protected boolean openPermission(Code) | | Indicates 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
|
readPermission | protected boolean readPermission(Code) | | Indicates 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
|
writePermission | protected boolean writePermission(Code) | | Indicates 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
|
ProtocolBase | public ProtocolBase()(Code) | | Creates a message connection protocol handler.
|
checkReceivePermission | abstract protected void checkReceivePermission() throws InterruptedIOException(Code) | | Checks internal setting of receive permission.
Called from receive and setMessageListener methods.
exception: InterruptedIOException - if permission dialogwas preempted |
close00 | abstract protected int close00(int connHandle, int deRegister)(Code) | | Close connection.
Parameters: connHandle - handle returned by open0 Parameters: deRegister - Deregistration appID when parameter is 1. 0 on success, -1 on failure |
ensureOpen | public void ensureOpen() throws IOException(Code) | | Ensures that the connection is open.
exception: IOException - if the connection is closed |
getAppID | abstract protected String getAppID()(Code) | | Gets the connection parameter in string mode.
string that contains a parameter |
io2InterruptedIOExc | protected void io2InterruptedIOExc(IOException ex, String name) throws IOException, InterruptedIOException(Code) | | Generates InterruptedIOException when connection is closed.
Parameters: ex - input IOException Parameters: name - name of operation: sending or receiving exception: IOException - if the connection is not closed |
newMessage | abstract public Message newMessage(String type)(Code) | | Construct a new message object from the given type.
Parameters: type - MULTIPART_MESSAGE is the only type permitted. A new MMS Message object. |
newMessage | abstract public Message newMessage(String type, String addr)(Code) | | Constructs a new message object from the given type and address.
Parameters: type - TEXT_MESSAGE orBINARY_MESSAGE . Parameters: addr - the destination address of the message. a new Message object. |
receive | abstract public Message receive() throws IOException(Code) | | 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.
a Message object. exception: java.io.IOException - if an error occurs while receiving amessage. exception: java.io.InterruptedIOException - if during this method call thisMessageConnection object is closed. exception: java.lang.SecurityException - if the application doesn't havepermission to receive messages on the given port. |
send | abstract public void send(Message dmsg) throws IOException(Code) | | 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.
Parameters: dmsg - a Message object exception: java.io.IOException - if the message could not be sent orbecause of network failure exception: java.lang.IllegalArgumentException - if the message containsinvalid information or is incomplete, or the message's payloadexceeds the maximal length for the given protocol. exception: java.io.InterruptedIOException - either if thisConnection object is closed during the execution of thissend method or if a timeout occurs while trying to sendthe message. exception: java.lang.NullPointerException - if the parameter isnull . exception: java.lang.SecurityException - if the application doesn't havepermission for sending the message. |
setAppID | abstract protected void setAppID(String newValue)(Code) | | Sets the connection parameter in string mode.
Parameters: newValue - new value of connection parameter |
setMessageListener | public void setMessageListener(MessageListener listener) throws IOException(Code) | | 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.
Parameters: listener - MessageListener object to be registered.If null ,the possibly currently registered listener will bede-registered and will not receive notifications. exception: java.lang.SecurityException - if the application does nothave a permission to receive messages using the given portnumber exception: java.io.IOException - if it is requested to registera listener on a client connection or if the connectionhas been closed |
unblock00 | abstract protected int unblock00(int msid) throws IOException(Code) | | Unblock the receive thread.
Parameters: msid - The MIDlet suite ID. returns handle to the connection. |
waitUntilMessageAvailable00 | abstract protected int waitUntilMessageAvailable00(int handle) throws IOException(Code) | | Waits until message available
Parameters: handle - handle to connection 0 on success, -1 on failure exception: IOException - if an I/O error occurs |
|
|