public void run() { long nextStart = System.currentTimeMillis(); try { while (!dead) { long timeToSleep = nextStart - System.currentTimeMillis(); if (timeToSleep > 10) Thread.sleep(timeToSleep); nextStart += Tickable.TIME_TICK; if ((CMProps.Bools.MUDSTARTED.property()) && (!CMLib.threads().isAllSuspended())) { globalTickCount++; for (Iterator<Exit> iter = exits.iterator(); iter.hasNext(); ) { Exit exit = iter.next(); try { if (!exit.tick(globalTickCount)) exits.remove(exit); } catch (Exception e) { Log.errOut("ServiceEngine", e.toString()); } } for (Iterator<TimeClock> iter = clocks.iterator(); iter.hasNext(); ) { TimeClock clock = iter.next(); try { if (!clock.tick(globalTickCount)) clocks.remove(clock); } catch (Exception e) { Log.errOut("ServiceEngine", e.toString()); } } } } } catch (InterruptedException e) { } }
/* public String tickInfo(String which) { int grpstart=-1; for(int i=0;i<which.length();i++) if(Character.isDigit(which.charAt(i))) { grpstart=i; break; } if(which.equalsIgnoreCase("tickGroupSize")) return ""+ticks.size(); else if(which.toLowerCase().startsWith("tickerssize")) { if(grpstart<0) return""; int group=CMath.s_int(which.substring(grpstart)); if((group>=0)&&(group<ticks.size())) return ""+((Tick)ticks.get(group)).numTickers(); return ""; } int group=-1; int client=-1; int clistart=which.indexOf("-"); if((grpstart>=0)&&(clistart>grpstart)) { group=CMath.s_int(which.substring(grpstart,clistart)); client=CMath.s_int(which.substring(clistart+1)); } if((group<0)||(client<0)||(group>=ticks.size())) return ""; Tick almostTock=(Tick)ticks.get(group); if(client>=almostTock.numTickers()) return ""; TockClient C=null; almostTock.fetchTickerByIndex(client); if(C==null) return ""; if(which.toLowerCase().startsWith("tickername")) { Tickable E=C.clientObject; if(E instanceof Room) return E.ID()+((Room)E).saveNum(); if(E!=null) return E.ID(); return "!NULL!"; } else if(which.toLowerCase().startsWith("tickerstatus")) return ((C.clientObject==null)?"":(""+C.clientObject.getTickStatus())); return ""; } */ public boolean shutdown() { // int numTicks=tickGroup.size(); /*while(ticks.size()>0) { //Log.sysOut("ServiceEngine","Shutting down all tick "+which+"/"+numTicks+"..."); Tick tock=ticks.first(); if(tock!=null) { CMProps.Strings.MUDSTATUS.setProperty("Shutting down...shutting down Service Engine: killing Tick#" + tock.tickObjectCounter+": "+tock.getStatus()); tock.shutdown(); } try{Thread.sleep(100);}catch(Exception e){} }*/ while (areas.size() > 0) { TickArea tock = areas.first(); if (tock != null) { CMProps.Strings.MUDSTATUS.setProperty( "Shutting down...shutting down Service Engine: killing Area#" + tock.tickObjectCounter + ": " + tock.clientObject.getTickStatus()); tock.shutdown(); } try { Thread.sleep(100); } catch (Exception e) { } } CMProps.Strings.MUDSTATUS.setProperty( "Shutting down...shutting down Service Engine: " + ID() + ": thread shutdown"); thread.shutdown(); Log.sysOut("ServiceEngine", "Shutdown complete."); return true; }
public void run() { while (isSuspended) try { Thread.sleep(2000); } catch (Exception e) { } if ((!CMSecurity.isDisabled("UTILITHREAD")) && (!CMSecurity.isDisabled("THREADTHREAD"))) { checkHealth(); // Resources.removeResource("SYSTEM_HASHED_MASKS"); // NOTE: Could use a ReferenceQueue to clean up gced references in the SYSTEM_HASHED_MASKS // hashtable still. } }
public void run() { while (true) { try { while (!tickActQueue.isEmpty()) { awake = false; TickActer next = tickActQueue.first(); long timeToSleep = next.nextAct() - System.currentTimeMillis(); if (timeToSleep > 0) Thread.sleep(timeToSleep); awake = true; nextTicker: if ((CMProps.Bools.MUDSTARTED.property()) && (!isSuspended)) { if (!tickActQueue.remove(next)) break nextTicker; CMClass.threadPool.execute(next); } } } /*try { next.tickAct(); } catch(Exception t) { Log.errOut("ServiceEngine",t); }*/ catch (InterruptedException ioe) { } // If it was interrupted, it is most likely because we need to wake up for a new early // ticker, or the previous new ticker got baleeted. // Interruptions will only come if the thread is sleeping though. // NOTE: tickAct() should NEVER call a sleep (nor take any significant amount of time // anyways)! if (dead) { awake = false; break; } synchronized (tickActQueue) { while (tickActQueue.isEmpty()) try { tickActQueue.wait(); } catch (InterruptedException ioe) { } } } }