|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--omnisockets.OmniEventHandler
The OmniEventHandler enables the OmniSockets framework to asynchronously notify the application that a socket event has occurred. The supported events are: a connection is made (EV_CONNECT), a connection is dropped (EV_DISCONNECT), a message is received (EV_MESSAGE), and an unrecognized message is received (EV_BAD_MESSAGE).
You must subclass OmniEventHandler and either override the run() method to perform whatever actions are desirable on any of the events. Or you can retain the run() method and override one or more of the separate event methods as appropriate for your protocol.
How to use it depends on whether your application is a client or a server. First create an event handler of your subtype. On the client side, then create an OmniSocket and pass the event handler to its constructor. On the server, you would instead create an OmniListener and pass the event handler to its constructor.
Note that you can choose not to use an event handler on the OmniListener if you are willing to accept connections yourself. Simply create the OmniListener without passing an event handler. Subsequently, you have to call OmniListener.accept() to accept new connnections. In this case, the calling thread will block until a connection is made.
OmniListener
Field Summary | |
static int |
EV_BAD_MESSAGE
An unrecognized message type has been received |
static int |
EV_CONNECT
A connection has been established |
static int |
EV_DISCONNECT
A connection has been dropped |
static int |
EV_MESSAGE
A message has been received |
static int |
EV_NONE
Initial event code |
Constructor Summary | |
OmniEventHandler()
Constructs an emply event handler |
|
OmniEventHandler(java.lang.Object cookie)
Constructs an event handler with a cookie. |
Method Summary | |
void |
badMessage()
The default badMessage event handler,
may be overridden in subclass. |
void |
connected()
The default connected event handler,
may be overridden in subclass. |
void |
disconnected()
The default disconnected event handler,
may be overridden in subclass. |
java.lang.Object |
getCookie()
Returns the cookie. |
int |
getEvent()
Returns the event code. |
omnisockets.OmniListener |
getListener()
Returns the listener |
omnisockets.OmniMessage |
getMessage()
Returns the message. |
omnisockets.OmniSocket |
getSocket()
Returns the socket. |
void |
message()
The default message event handler,
may be overridden in subclass. |
void |
run()
Runs the event handler, may be overridden in subclass |
void |
setCookie(java.lang.Object cookie)
Sets the cookie. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int EV_NONE
public static final int EV_CONNECT
public static final int EV_DISCONNECT
public static final int EV_MESSAGE
public static final int EV_BAD_MESSAGE
Constructor Detail |
public OmniEventHandler()
public OmniEventHandler(java.lang.Object cookie)
cookie
- an object for use as a correlatorMethod Detail |
public omnisockets.OmniListener getListener()
public omnisockets.OmniSocket getSocket()
public omnisockets.OmniMessage getMessage()
public int getEvent()
public void setCookie(java.lang.Object cookie)
cookie
- any object used for correlationpublic java.lang.Object getCookie()
public void run()
run
in interface java.lang.Runnable
public void connected()
connected
event handler,
may be overridden in subclass.
public void disconnected()
disconnected
event handler,
may be overridden in subclass.
public void message()
message
event handler,
may be overridden in subclass.
public void badMessage()
badMessage
event handler,
may be overridden in subclass.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |