コード例 #1
0
ファイル: DefaultClient.java プロジェクト: jingchan/jh_rogue
  protected void dispatch(Message m) {
    // Pull off the connection management messages we're
    // interested in and then pass on the rest.
    if (m instanceof ClientRegistrationMessage) {
      // Then we've gotten our real id
      this.id = (int) ((ClientRegistrationMessage) m).getId();
      log.log(Level.INFO, "Connection established, id:{0}.", this.id);
      connecting.countDown();
      fireConnected();
      return;
    }
    if (m instanceof DisconnectMessage) {
      // Can't do too much else yet
      String reason = ((DisconnectMessage) m).getReason();
      log.log(Level.SEVERE, "Connection terminated, reason:{0}.", reason);
      DisconnectInfo info = new DisconnectInfo();
      info.reason = reason;
      fireDisconnected(info);
      close();
    }

    // Make sure client MessageListeners are called single-threaded
    // since it could receive messages from the TCP and UDP
    // thread simultaneously.
    synchronized (this) {
      messageListeners.messageReceived(this, m);
    }
  }
コード例 #2
0
ファイル: DefaultClient.java プロジェクト: jingchan/jh_rogue
  protected void waitForConnected() {
    if (isConnected()) return;

    try {
      connecting.await();
    } catch (InterruptedException e) {
      throw new RuntimeException("Interrupted waiting for connect", e);
    }
  }
コード例 #3
0
ファイル: DefaultClient.java プロジェクト: jingchan/jh_rogue
  public void close() {
    checkRunning();

    // Send a close message

    // Tell the thread it's ok to die
    if (fastAdapter != null) {
      fastAdapter.close();
    }
    if (reliableAdapter != null) {
      reliableAdapter.close();
    }

    // Wait for the threads?

    // Just in case we never fully connected
    connecting.countDown();

    fireDisconnected(null);

    isRunning = false;
  }