/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.console.Main; /* */ import NET.worlds.console.MainCallback; /* */ import NET.worlds.network.URL; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class BackgroundLoader /* */ implements MainCallback, Runnable /* */ { /* 90 */ private static BackgroundLoader bg = new BackgroundLoader(); /* */ /* */ /* */ /* 94 */ private BackgroundLoaderQueue asyncLoadQueue = new BackgroundLoaderQueue(); /* */ /* */ /* 97 */ private Vector syncLoadQueue = new Vector(); /* */ /* */ /* */ /* */ /* */ private Thread asyncLoaderThread; /* */ /* */ /* */ /* */ /* */ public static void get(BGLoaded loader, String remoteName) /* */ { /* 109 */ get(loader, URL.make(remoteName), false); /* */ } /* */ /* 112 */ public static void get(BGLoaded loader, URL remoteName) { get(loader, remoteName, false); } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public static void get(BGLoaded loader, URL remoteName, boolean highPri) /* */ { /* 122 */ new BackgroundLoaderElement(loader, remoteName, highPri); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ static void activeRoomChanged(Room room) /* */ { /* 133 */ bg.asyncLoadQueue.activeRoomChanged(room); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ static void asyncLoad(BackgroundLoaderElement ele) /* */ { /* 142 */ bg.asyncLoadQueue.add(ele); /* */ } /* */ /* */ static void syncLoad(BackgroundLoaderElement ele) { /* 146 */ bg.syncLoadQueue.addElement(ele); /* */ } /* */ /* */ /* */ /* */ /* */ private BackgroundLoader() /* */ { /* 154 */ this.asyncLoaderThread = new Thread(this); /* 155 */ this.asyncLoaderThread.setDaemon(true); /* 156 */ this.asyncLoaderThread.start(); /* */ /* 158 */ Main.register(this); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void run() /* */ { /* 168 */ assert (Thread.currentThread() == this.asyncLoaderThread); /* */ /* */ /* */ /* */ /* */ for (;;) /* */ { /* 175 */ BackgroundLoaderElement ele = this.asyncLoadQueue.getItem(); /* */ /* */ /* 178 */ ele.asyncLoad(); /* */ /* 180 */ synchronized (this) /* */ { /* */ /* */ /* */ /* 185 */ this.syncLoadQueue.addElement(ele); /* 186 */ while (this.syncLoadQueue.size() > 0) /* */ { /* */ try { /* 189 */ wait(); /* */ } /* */ catch (InterruptedException localInterruptedException) {} /* 192 */ if (this.asyncLoadQueue.hasHighPriorityItems()) /* */ break; /* */ } /* */ } /* */ } /* */ } /* */ /* 199 */ int nextSync = 0; /* */ /* */ /* */ /* */ /* */ public synchronized void mainCallback() /* */ { /* 206 */ if (this.syncLoadQueue.size() == 0) { /* 207 */ return; /* */ } /* 209 */ if (this.nextSync >= this.syncLoadQueue.size()) { /* 210 */ this.nextSync = 0; /* */ } /* 212 */ BackgroundLoaderElement ele = /* 213 */ (BackgroundLoaderElement)this.syncLoadQueue.elementAt(this.nextSync); /* */ /* */ /* 216 */ if (!ele.syncLoad()) /* */ { /* */ /* 219 */ this.syncLoadQueue.removeElementAt(this.nextSync); /* */ /* 221 */ if (this.syncLoadQueue.size() == 0) { /* 222 */ notify(); /* */ } /* */ } /* */ else /* */ { /* 227 */ if (this.asyncLoadQueue.hasHighPriorityItems()) { /* 228 */ notify(); /* */ } /* 230 */ this.nextSync += 1; /* */ } /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\BackgroundLoader.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */