home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 1.4 KB | 49 lines |
- // Thread that looks for newly updated entities
-
- // Written by Bernie Roehl, December 1996
-
- package multi;
-
- import java.io.*;
- import java.util.*;
-
- class ChangeMonitor extends Thread {
-
- World world;
-
- static final int PERIOD = 10000; // every 10 seconds
-
- public ChangeMonitor(World wrld) {
- world = wrld;
- setPriority(NORM_PRIORITY-1);
- start();
- }
-
- public void run() {
- while (true) {
- try { sleep(PERIOD); }
- catch (InterruptedException e2) { }
- synchronized(world.registry_socket) {
- world.registry_output.println("LISTNEW " + PERIOD);
- while (true) {
- String response;
- try { response = world.registry_input.readLine(); }
- catch (IOException ex) {
- System.out.println("could not read response to LIST NEW: " + ex);
- break;
- }
- if (response.startsWith("."))
- break;
- int entid = Integer.parseInt(response);
- Entity e = world.getEntity(entid);
- if (e == null)
- e = world.addEntity(entid);
- else
- e.needsAllInfo();
- }
- }
- }
- }
- }
-
-