Esempio n. 1
0
 public boolean shutdown() {
   // int numTicks=tickGroup.size();
   int which = 0;
   while (ticks.size() > 0) {
     // Log.sysOut("ServiceEngine","Shutting down all tick "+which+"/"+numTicks+"...");
     Tick tock = ticks.getFirst();
     if (tock != null) {
       CMProps.setUpAllLowVar(
           CMProps.SYSTEM_MUDSTATUS,
           "Shutting down...shutting down Service Engine: killing Tick#"
               + tock.getCounter()
               + ": "
               + tock.getStatus());
       tock.shutdown();
     }
     try {
       Thread.sleep(100);
     } catch (Exception e) {
     }
     which++;
   }
   CMProps.setUpAllLowVar(
       CMProps.SYSTEM_MUDSTATUS,
       "Shutting down...shutting down Service Engine: " + ID() + ": thread shutdown");
   thread.shutdown();
   // force final time tick!
   Vector timeObjects = new Vector();
   for (Enumeration e = CMLib.map().areas(); e.hasMoreElements(); ) {
     Area A = ((Area) e.nextElement());
     if (!timeObjects.contains(A.getTimeObj())) timeObjects.addElement(A.getTimeObj());
   }
   CMProps.setUpAllLowVar(
       CMProps.SYSTEM_MUDSTATUS,
       "Shutting down...shutting down Service Engine: " + ID() + ": saving time objects");
   for (int t = 0; t < timeObjects.size(); t++) ((TimeClock) timeObjects.elementAt(t)).save();
   Log.sysOut("ServiceEngine", "Shutdown complete.");
   return true;
 }
Esempio n. 2
0
  public void checkHealth() {
    long lastDateTime = System.currentTimeMillis() - (5 * TimeManager.MILI_MINUTE);
    long longerDateTime = System.currentTimeMillis() - (120 * TimeManager.MILI_MINUTE);
    thread.status("checking");

    thread.status("checking tick groups.");
    DVector orderedDeaths = new DVector(3);
    try {
      Tick almostTock = null;
      for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
        almostTock = e.next();
        if ((almostTock.awake) && (almostTock.lastStop < lastDateTime)) {
          TockClient client = almostTock.lastClient;
          if (client == null)
            insertOrderDeathInOrder(
                orderedDeaths,
                0,
                "LOCKED GROUP " + almostTock.getCounter() + "! No further information.",
                almostTock);
          else if ((!CMath.bset(client.tickID, Tickable.TICKID_LONGERMASK))
              || (almostTock.lastStop < longerDateTime)) {
            if (client.clientObject == null)
              insertOrderDeathInOrder(
                  orderedDeaths,
                  0,
                  "LOCKED GROUP "
                      + almostTock.getCounter()
                      + ": NULL @"
                      + CMLib.time().date2String(client.lastStart)
                      + ", tickID "
                      + client.tickID,
                  almostTock);
            else {
              StringBuffer str = null;
              Tickable obj = client.clientObject;
              long code = client.clientObject.getTickStatus();
              String codeWord = CMLib.threads().getTickStatusSummary(client.clientObject);
              String msg = null;
              if (obj instanceof Environmental)
                str =
                    new StringBuffer(
                        "LOCKED GROUP "
                            + almostTock.getCounter()
                            + " : "
                            + obj.name()
                            + " ("
                            + ((Environmental) obj).ID()
                            + ") @"
                            + CMLib.time().date2String(client.lastStart)
                            + ", status("
                            + code
                            + " ("
                            + codeWord
                            + "), tickID "
                            + client.tickID);
              else
                str =
                    new StringBuffer(
                        "LOCKED GROUP "
                            + almostTock.getCounter()
                            + ": "
                            + obj.name()
                            + ", status("
                            + code
                            + " ("
                            + codeWord
                            + ") @"
                            + CMLib.time().date2String(client.lastStart)
                            + ", tickID "
                            + client.tickID);

              if ((obj instanceof MOB) && (((MOB) obj).location() != null))
                msg = str.toString() + " in " + ((MOB) obj).location().roomID();
              else if ((obj instanceof Item)
                  && (((Item) obj).owner() != null)
                  && (((Item) obj).owner() instanceof Room))
                msg = str.toString() + " in " + ((Room) ((Item) obj).owner()).roomID();
              else if ((obj instanceof Item)
                  && (((Item) obj).owner() != null)
                  && (((Item) obj).owner() instanceof MOB))
                msg = str.toString() + " owned by " + ((MOB) ((Item) obj).owner()).name();
              else if (obj instanceof Room) msg = str.toString() + " is " + ((Room) obj).roomID();
              else msg = str.toString();
              insertOrderDeathInOrder(orderedDeaths, client.lastStart, msg, almostTock);
            }
          }
          // no isDEBUGGING check -- just always let her rip.
          thread.debugDumpStack(almostTock);
        }
      }
    } catch (java.util.NoSuchElementException e) {
    }
    for (int i = 0; i < orderedDeaths.size(); i++)
      Log.errOut(thread.getName(), (String) orderedDeaths.elementAt(i, 2));

    thread.status("killing tick groups.");
    for (int x = 0; x < orderedDeaths.size(); x++) {
      Tick almostTock = (Tick) orderedDeaths.elementAt(x, 3);
      Vector objs = new Vector();
      try {
        for (Iterator e = almostTock.tickers(); e.hasNext(); ) objs.addElement(e.next());
      } catch (NoSuchElementException e) {
      }
      almostTock.shutdown();
      if (CMLib.threads() instanceof ServiceEngine)
        ((ServiceEngine) CMLib.threads()).delTickGroup(almostTock);
      for (int i = 0; i < objs.size(); i++) {
        TockClient c = (TockClient) objs.elementAt(i);
        CMLib.threads().startTickDown(c.clientObject, c.tickID, c.reTickDown);
      }
    }

    thread.status("Checking mud threads");
    for (int m = 0; m < CMLib.hosts().size(); m++) {
      Vector badThreads = ((MudHost) CMLib.hosts().elementAt(m)).getOverdueThreads();
      if (badThreads.size() > 0) {
        for (int b = 0; b < badThreads.size(); b++) {
          Thread T = (Thread) badThreads.elementAt(b);
          String threadName = T.getName();
          if (T instanceof Tickable)
            threadName =
                ((Tickable) T).name()
                    + " ("
                    + ((Tickable) T).ID()
                    + "): "
                    + ((Tickable) T).getTickStatus();
          thread.status("Killing " + threadName);
          Log.errOut("Killing stray thread: " + threadName);
          CMLib.killThread(T, 100, 1);
        }
      }
    }

    thread.status("Done checking threads");
  }