[ictk-cvs] ictk/src/ictk/boardgame/chess/net/ics ICSEventRouter.java,1.5,1.6
chess library in java, PGN, FEN, ICS
Brought to you by:
jvarsoke
|
From: <jva...@us...> - 2003-08-30 04:46:01
|
Update of /cvsroot/ictk/ictk/src/ictk/boardgame/chess/net/ics
In directory sc8-pr-cvs1:/tmp/cvs-serv9493/src/ictk/boardgame/chess/net/ics
Modified Files:
ICSEventRouter.java
Log Message:
added ChannelListenerExample to SimpleICSClient to demonstrate adding a
channel listener and how to make it exclusive.
Index: ICSEventRouter.java
===================================================================
RCS file: /cvsroot/ictk/ictk/src/ictk/boardgame/chess/net/ics/ICSEventRouter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ICSEventRouter.java 29 Aug 2003 08:42:21 -0000 1.5
--- ICSEventRouter.java 30 Aug 2003 04:45:57 -0000 1.6
***************
*** 33,36 ****
--- 33,38 ----
*/
public class ICSEventRouter {
+ /** key offset for integers so they can be put in the hash */
+ protected static int OFFSET = 1000;
/** the default listener receives all events or those not sent to a
** exclusive listener (depending on set options). */
***************
*** 44,60 ****
** the value is a ICSEventListener[] */
protected HashMap chSubscribers,
-
- /** subscribers to individual boards.
- ** the key is the board number.
- ** the value is a 3 element array of
- ** ICSEventListener arrays. The 3 elements
- ** indicate types of events the listener wants*/
- boardSubscribers;
-
- /** a list of which events are exclusively listed to by the
- ** subscriber (event if null) instead of also being sent
- ** to the defaultListener */
- protected boolean[] exclusive;
-
/** determines if the channel(shout, tournament channel, etc)
** events will be sent only to the listener subscribing
--- 46,49 ----
***************
*** 62,68 ****
** the CHANNEL_EVENT or SHOUT_EVENT listener will also
** receive the event. */
! protected boolean exclusiveChannel,
! exclusiveBoard;
--- 51,60 ----
** the CHANNEL_EVENT or SHOUT_EVENT listener will also
** receive the event. */
! chExclusive;
! /** a list of which events are exclusively listed to by the
! ** subscriber (event if null) instead of also being sent
! ** to the defaultListener */
! protected boolean[] exclusive;
***************
*** 70,74 ****
subscribers = new ICSEventListener[ICSEvent.NUM_EVENTS][];
chSubscribers = new HashMap();
! boardSubscribers = new HashMap();
exclusive = new boolean[ICSEvent.NUM_EVENTS];
}
--- 62,66 ----
subscribers = new ICSEventListener[ICSEvent.NUM_EVENTS][];
chSubscribers = new HashMap();
! chExclusive = new HashMap();
exclusive = new boolean[ICSEvent.NUM_EVENTS];
}
***************
*** 97,100 ****
--- 89,93 ----
*/
public void dispatch (ICSEvent evt) {
+ Integer key = null;
int type = evt.getEventType(),
i = 0;
***************
*** 108,117 ****
case ICSEvent.TOURNAMENT_CHANNEL_EVENT:
case ICSEvent.SHOUT_EVENT:
! int[] key = new int[2];
! key[0] = type;
! key[1] = ((ICSChannelEvent) evt).getChannel();
listeners = (ICSEventListener[]) chSubscribers.get(key);
! done = exclusiveChannel;
break;
--- 101,111 ----
case ICSEvent.TOURNAMENT_CHANNEL_EVENT:
case ICSEvent.SHOUT_EVENT:
! key = new Integer(type * OFFSET
! + ((ICSChannelEvent) evt).getChannel());
listeners = (ICSEventListener[]) chSubscribers.get(key);
! done = (listeners != null)
! && isChannelExclusive(type,
! ((ICSChannelEvent) evt).getChannel());
break;
***************
*** 151,156 ****
* @param icsEventNumber an ICSEvent.<FOO>_EVENT
*/
! public void addEventListener (ICSEventListener eh,
! int icsEventNumber) {
}
--- 145,153 ----
* @param icsEventNumber an ICSEvent.<FOO>_EVENT
*/
! public void addEventListener (int icsEventNumber,
! ICSEventListener eh) {
!
! subscribers[icsEventNumber]
! = _addListener(subscribers[icsEventNumber], eh);
}
***************
*** 197,208 ****
* shouts is the type of shout.
*/
! public void addChannelListener (ICSEventListener eh,
! int channelType,
! int channelNumber) {
! int[] key = new int[2];
! ICSEventListener[] list;
! key[0] = channelType;
! key[1] = channelNumber;
list = (ICSEventListener[]) chSubscribers.get(key);
--- 194,203 ----
* shouts is the type of shout.
*/
! public void addChannelListener (int channelType,
! int channelNumber,
! ICSEventListener eh) {
! Integer key = new Integer(channelType * OFFSET + channelNumber);
! ICSEventListener[] list;
list = (ICSEventListener[]) chSubscribers.get(key);
***************
*** 212,224 ****
}
! public void removeChannelListener (ICSEventListener eh,
! int channelType,
! int channelNumber) {
! int[] key = new int[2];
ICSEventListener[] list;
- key[0] = channelType;
- key[1] = channelNumber;
-
list = (ICSEventListener[]) chSubscribers.get(key);
list = _removeListener(list, eh);
--- 207,216 ----
}
! public void removeChannelListener (int channelType,
! int channelNumber,
! ICSEventListener eh) {
! Integer key = new Integer(channelType * OFFSET + channelNumber);
ICSEventListener[] list;
list = (ICSEventListener[]) chSubscribers.get(key);
list = _removeListener(list, eh);
***************
*** 228,231 ****
--- 220,238 ----
else
chSubscribers.put(key, list);
+ }
+
+ public void setChannelExclusive (int channelType,
+ int channelNumber,
+ boolean t) {
+ Integer key = new Integer(channelType * OFFSET + channelNumber);
+ chExclusive.put(key, ((t) ? Boolean.TRUE : Boolean.FALSE));
+ }
+
+ public boolean isChannelExclusive (int channelType,
+ int channelNumber) {
+ Integer key = new Integer(channelType * OFFSET + channelNumber);
+ Boolean b = null;
+ return ((b = (Boolean) chExclusive.get(key)) != null)
+ && b == Boolean.TRUE;
}
|