JMS Conector demo (OC4J 10g R3)

Class Player

java.lang.Object
  extended byPlayer

public final class Player
extends java.lang.Object


Field Summary
private static long delay
           
private static boolean gameOver
           
private static boolean human
           
private static java.util.HashMap map
           
private static java.lang.String player
           
private static boolean tookMyTurn
           
 
Constructor Summary
Player()
           
 
Method Summary
static void main(java.lang.String[] argv)
          main method for app-client
private static int myScore()
          Returns this player's score.
static void play()
          This is the top-level game-play method (called by main).
private static boolean playerIsWinning()
          Indicates if this player is winning.
private static void primeCommunications(MyChannel command, MyChannel response)
          Handle pub/sub latency -- reach a 'steady state'.
private static void processTurn(GameEvent event)
          Process TURN_NOTIFICATION events (decide what to do on this player's turn).
private static void processValue(GameEvent event)
          Process PLAYER_GOT_VALUE events (update local game state and detect end of game).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

player

private static java.lang.String player

delay

private static long delay

human

private static boolean human

map

private static java.util.HashMap map

tookMyTurn

private static boolean tookMyTurn

gameOver

private static boolean gameOver
Constructor Detail

Player

public Player()
Method Detail

main

public static void main(java.lang.String[] argv)
main method for app-client


myScore

private static int myScore()
Returns this player's score.

Returns:
this player's score (1..100)

playerIsWinning

private static boolean playerIsWinning()
Indicates if this player is winning.

Returns:
true iff this player is currently in the lead (or tied for the lead)

processValue

private static void processValue(GameEvent event)
Process PLAYER_GOT_VALUE events (update local game state and detect end of game).

Parameters:
event - the PLAYER_GOT_VALUE event

processTurn

private static void processTurn(GameEvent event)
Process TURN_NOTIFICATION events (decide what to do on this player's turn).

Parameters:
event - the TURN_NOTIFICATION event

primeCommunications

private static void primeCommunications(MyChannel command,
                                        MyChannel response)
                                 throws JMSException
Handle pub/sub latency -- reach a 'steady state'. (See JMS 1.1 spec.)

JMS does not guarantee ordering between two different destinations. It also does not guarantee any ordering between subscriber creation and the first message received. The following sequence represents a perfectly legal JMS 1.1 scenario:

  1. Player sets up a subscriber on ResponseDestination topic.
  2. Player sends request to Dealer via CommandDestination queue.
  3. Dealer reponds to request via ResponseDestination topic.
  4. Player never receives Dealer's response.

One solution is to "ping" the dealer until the ResponseDestination topic has been "primed". Once the player has seen a ping response (or any other message) from the ResponseDestination topic, JMS message ordering guarantees that later messages from that same topic (from the same producing session, with the same delivery mode, and with the same or lower priority) will be seen.

Other solutions are possible (such as allowing a player to repeatedly send PLAYER_JOIN_REQUEST until a response is seen) but tend to be more complicated due to the modification and transference of game state.

Throws:
JMSException

play

public static void play()
This is the top-level game-play method (called by main).


JMS Conector demo (OC4J 10g R3)

Copyright © 2006, Oracle. All rights reserved.