Beispiel #1
0
 public synchronized void clearDebri(Room room, int taskCode) {
   Tick almostTock = null;
   TockClient C = null;
   ItemTicker I = null;
   Iterator<TockClient> roomSet;
   MOB mob = null;
   for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
     almostTock = e.next();
     roomSet = almostTock.getLocalItems(taskCode, room);
     if (roomSet != null)
       for (; roomSet.hasNext(); ) {
         C = (TockClient) roomSet.next();
         if (C.clientObject instanceof ItemTicker) {
           I = (ItemTicker) C.clientObject;
           almostTock.delTicker(C);
           I.setProperLocation(null);
         } else if (C.clientObject instanceof MOB) {
           mob = (MOB) C.clientObject;
           if ((mob.isMonster()) && (!room.isInhabitant(mob))) {
             mob.destroy();
             almostTock.delTicker(C);
           }
         }
       }
   }
 }
Beispiel #2
0
  public Tick getAvailTickThread(Tickable E, long TICK_TIME, int tickID) {
    Tick tock = null;
    Tick almostTock = null;
    ThreadGroup grp = null;
    char threadGroupNum = Thread.currentThread().getThreadGroup().getName().charAt(0);
    for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
      almostTock = e.next();
      if (almostTock != null) {
        if (almostTock.contains(E, tickID)) return null;
        if ((tock == null)
            && (almostTock.TICK_TIME == TICK_TIME)
            && (!almostTock.solitaryTicker)
            && (almostTock.numTickers() < TickableGroup.MAX_TICK_CLIENTS)) {
          grp = almostTock.getThreadGroup();
          if ((grp != null) && (grp.getName().charAt(0) == threadGroupNum)) {
            tock = almostTock;
          }
        }
      }
    }

    if (tock != null) return tock;
    tock = new Tick(TICK_TIME);
    addTickGroup(tock);
    return tock;
  }
Beispiel #3
0
  private final int add(long tick) {
    long[] ticks = _ticks;
    Buff[] buffs = _buffs;

    if (ticks == null || ticks.length == 0) {
      ticks = new long[OpenMap.CAPACITY];
      buffs = new Buff[OpenMap.CAPACITY];
    } else if (Debug.THREADS) Tick.checkSet(ticks);

    int hash = Tick.hashTick(tick);
    int index;

    while ((index = Tick.tryToAdd(ticks, tick, hash)) < 0) {
      long[] previousTicks = ticks;
      Buff[] previousBuffs = buffs;

      for (; ; ) {
        ticks = new long[ticks.length << OpenMap.TIMES_TWO_SHIFT];
        buffs = new Buff[buffs.length << OpenMap.TIMES_TWO_SHIFT];

        if (rehash(previousTicks, ticks, previousBuffs, buffs)) break;
      }
    }

    if (Debug.ENABLED) Tick.checkSet(ticks);

    _ticks = ticks;
    _buffs = buffs;
    return index;
  }
Beispiel #4
0
  @Override
  void onKnown(URI uri, long[] ticks) {
    boolean all = false;
    long[] list = null;
    int count = 0;

    synchronized (this) {
      if (_ticks == null || _ticks.length == 0) all = true;
      else {
        for (int i = 0; i < ticks.length; i++) {
          if (!Tick.isNull(ticks[i])) {
            if (!Tick.contains(_ticks, ticks[i])) {
              if (list == null) list = new long[ticks.length];

              list[count++] = ticks[i];
            }
          }
        }
      }
    }

    if (all) {
      for (int i = 0; i < ticks.length; i++)
        if (!Tick.isNull(ticks[i])) uri.getBlock(this, ticks[i]);
    } else if (list != null) {
      for (int i = 0; i < count; i++) uri.getBlock(this, list[i]);
    }
  }
Beispiel #5
0
  /**
   * fileReader builds a scene from a file
   *
   * @return sceneOfInput
   * @throws IOException
   */
  public static Scene fileReader() throws IOException {
    long startTime = System.currentTimeMillis();

    //		FileReader fr = new FileReader("file/LogManager-short.dat");
    FileReader fr = new FileReader("file/LogManager-live-tool-2.dat");
    //		FileReader fr = new FileReader("file/LogManager-example.dat");
    //		FileReader fr = new FileReader("file/LogManager-long.dat");
    BufferedReader br = new BufferedReader(fr);

    String line = "";
    List<Tick> tmpTickList = new ArrayList<Tick>();

    /*
     * Read file, split lines into Type and Timestamp, generate Ticks
     */
    while ((line = br.readLine()) != null) {

      String[] parts = line.split(";", -1);
      int tmpTimestamp = Integer.parseInt(parts[0]);
      Tick tmpTick = new Tick(tmpTimestamp, parts[1], parts[2]);
      tmpTickList.add(tmpTick);
    }
    br.close();
    /*
     * filtering out special hashmarks and adding their content to mark before
     */
    int lastHashMark = 0;
    for (int i = 0; i < tmpTickList.size(); i++) {
      Tick currentTick = tmpTickList.get(i);

      if (currentTick.getType().compareTo("########") == 0) {

        lastHashMark = i;

      } else if (currentTick.getType().compareTo("#+#+#+#+") == 0) {

        if (lastHashMark == 0) { // if first mark is special hash

          tmpTickList.remove(i); // remove it

        } else {

          tmpTickList.remove(lastHashMark); // otherwise remove last normal hash
          currentTick.setType("########"); // and convert special to normal hash
          // thus adding special object to normal
          lastHashMark = i - 1; // set new hashmark
        }
      }
    }
    List<Sequence> sequenceList = structureCreator(tmpTickList);

    Sequence[] sequenceArray = new Sequence[sequenceList.size()];
    sequenceArray = sequenceList.toArray(sequenceArray);

    Scene sceneFromInput = new Scene(sequenceArray);

    System.out.println((System.currentTimeMillis() - startTime) + " milliseconds to read log");
    return sceneFromInput;
  }
Beispiel #6
0
  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 = almostTock.fetchTickerByIndex(client);
    if (C == null) return "";

    if (which.toLowerCase().startsWith("tickername")) {
      Tickable E = C.clientObject;
      if ((E instanceof Ability) && (E.ID().equals("ItemRejuv"))) E = ((Ability) E).affecting();
      if (E instanceof Room) return CMLib.map().getExtendedRoomID((Room) E);
      if (E != null) return E.name();
      return "!NULL!";
    } else if (which.toLowerCase().startsWith("tickerid")) return "" + C.tickID;
    else if (which.toLowerCase().startsWith("tickerstatus"))
      return ((C.clientObject == null) ? "" : ("" + C.clientObject.getTickStatus()));
    else if (which.toLowerCase().startsWith("tickercodeword"))
      return getTickStatusSummary(C.clientObject);
    else if (which.toLowerCase().startsWith("tickertickdown")) return "" + C.tickDown;
    else if (which.toLowerCase().startsWith("tickerretickdown")) return "" + C.reTickDown;
    else if (which.toLowerCase().startsWith("tickermillitotal")) return "" + C.milliTotal;
    else if (which.toLowerCase().startsWith("tickermilliavg")) {
      if (C.tickTotal == 0) return "0";
      return "" + (C.milliTotal / C.tickTotal);
    } else if (which.toLowerCase().startsWith("tickerlaststartmillis")) return "" + C.lastStart;
    else if (which.toLowerCase().startsWith("tickerlaststopmillis")) return "" + C.lastStop;
    else if (which.toLowerCase().startsWith("tickerlaststartdate"))
      return CMLib.time().date2String(C.lastStart);
    else if (which.toLowerCase().startsWith("tickerlaststopdate"))
      return CMLib.time().date2String(C.lastStop);
    else if (which.toLowerCase().startsWith("tickerlastduration")) {
      if (C.lastStop >= C.lastStart) return CMLib.english().returnTime(C.lastStop - C.lastStart, 0);
      return CMLib.english().returnTime(System.currentTimeMillis() - C.lastStart, 0);
    } else if (which.toLowerCase().startsWith("tickersuspended")) return "" + C.suspended;
    return "";
  }
Beispiel #7
0
  public void startTickDown(Tickable E, int tickID, long TICK_TIME, int numTicks) {
    Tick tock = getAvailTickThread(E, TICK_TIME, tickID);
    if (tock == null) return;

    TockClient client = new TockClient(E, numTicks, tickID);
    if ((tickID & 65536) == 65536) tock.solitaryTicker = true;
    tock.addTicker(client);
  }
Beispiel #8
0
 public boolean isSuspended(Tickable E, int tickID) {
   Tick almostTock = null;
   Iterator set = null;
   for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
     almostTock = e.next();
     set = almostTock.getTickSet(E, tickID);
     if (set.hasNext()) return ((TockClient) set.next()).suspended;
   }
   return false;
 }
Beispiel #9
0
 public boolean isTicking(Tickable E, int tickID) {
   Tick almostTock = null;
   Iterator set;
   for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
     almostTock = e.next();
     set = almostTock.getTickSet(E, tickID);
     if (set.hasNext()) return true;
   }
   return false;
 }
Beispiel #10
0
 public boolean deleteTick(Tickable E, int tickID) {
   Tick almostTock = null;
   Iterator set = null;
   for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
     almostTock = e.next();
     set = almostTock.getTickSet(E, tickID);
     for (; set.hasNext(); ) almostTock.delTicker((TockClient) set.next());
   }
   return false;
 }
Beispiel #11
0
 protected boolean suspendResumeTicking(Tickable E, int tickID, boolean suspend) {
   Tick almostTock = null;
   Iterator set = null;
   for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
     almostTock = e.next();
     set = almostTock.getTickSet(E, tickID);
     for (; set.hasNext(); ) ((TockClient) set.next()).suspended = suspend;
   }
   return false;
 }
Beispiel #12
0
  private final boolean rehash(
      long[] previousTicks, long[] ticks, Buff[] previousBuffs, Buff[] buffs) {
    for (int i = previousTicks.length - 1; i >= 0; i--) {
      if (!Tick.isNull(previousTicks[i])) {
        int index = Tick.tryToAdd(ticks, previousTicks[i], Tick.hashTick(previousTicks[i]));

        if (index < 0) return false;

        buffs[index] = previousBuffs[i];
      }
    }

    return true;
  }
Beispiel #13
0
    public int compareTo(Object otherTick) {
      if (!(otherTick instanceof Tick)) {
        throw new ClassCastException("Not a valid Tick object!");
      }

      Tick tempTick = (Tick) otherTick;

      if (this.getTimeStamp() > tempTick.getTimeStamp()) {
        return 1;
      } else if (this.getTimeStamp() < tempTick.getTimeStamp()) {
        return -1;
      } else {
        return 0;
      }
    }
Beispiel #14
0
 public Vector getNamedTickingObjects(String name) {
   Vector V = new Vector();
   Tick almostTock = null;
   TockClient C = null;
   name = name.toUpperCase().trim();
   for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
     almostTock = e.next();
     for (Iterator i = almostTock.tickers(); i.hasNext(); ) {
       C = (TockClient) i.next();
       if ((C.clientObject != null)
           && (C.clientObject.name().toUpperCase().indexOf(name) >= 0)
           && (!V.contains(C.clientObject))) V.addElement(C.clientObject);
     }
   }
   return V;
 }
Beispiel #15
0
      // displays the timeline box and the ticks.
      public void display() {
        noStroke();
        fill(204);
        // timeline
        rect(xpos, ypos, swidth, sheight);
        if (over || locked) {
          fill(0, 0, 0);
        } else {
          fill(102, 102, 102);
        }
        // scrubber
        // println(spos);
        rect(spos - sheight / 2, ypos, sheight, sheight);

        for (int i = 0; i < tickArr.size(); i++) {
          tickArr.get(i).displayTick();
        }

        prevTick = null;
        nextTick = null;

        for (int i = 0; i < tickArr.size(); i++) {
          if (tickArr.get(i).getXPos() < spos) {
            prevTick = tickArr.get(i);
          } else {
            break;
          }
        }

        for (int i = 0; i < tickArr.size(); i++) {
          if (tickArr.get(i).getXPos() > spos) {
            nextTick = tickArr.get(i);
            break;
          }
        }

        if (prevTick != null) {
          prevTick.changeCamColorPrev();
        }
        if (nextTick != null) {
          nextTick.changeCamColorNext();
        }
      }
Beispiel #16
0
 public void rejuv(Room here, int tickID) {
   Tick almostTock = null;
   TockClient C = null;
   Tickable E2 = null;
   boolean doItems = ((tickID == 0) || (tickID == Tickable.TICKID_ROOM_ITEM_REJUV));
   boolean doMobs = ((tickID == 0) || (tickID == Tickable.TICKID_MOB));
   for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
     almostTock = e.next();
     try {
       for (Iterator i = almostTock.tickers(); i.hasNext(); ) {
         C = (TockClient) i.next();
         E2 = C.clientObject;
         if ((doItems)
             && (E2 instanceof ItemTicker)
             && ((here == null) || (((ItemTicker) E2).properLocation() == here))) {
           C.tickDown = 0;
           if (Tick.tickTicker(C, false)) almostTock.delTicker(C);
         } else if ((doMobs)
             && (E2 instanceof MOB)
             && (((MOB) E2).amDead())
             && ((here == null) || (((MOB) E2).getStartRoom() == here))
             && (((MOB) E2).baseEnvStats().rejuv() > 0)
             && (((MOB) E2).baseEnvStats().rejuv() < Integer.MAX_VALUE)
             && (((MOB) E2).envStats().rejuv() > 0)) {
           C.tickDown = 0;
           ((MOB) E2).envStats().setRejuv(0);
           if (Tick.tickTicker(C, false)) almostTock.delTicker(C);
         }
       }
     } catch (NoSuchElementException ex) {
     }
   }
 }
Beispiel #17
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;
 }
Beispiel #18
0
 public void tickAllTickers(Room here) {
   Tick almostTock = null;
   TockClient C = null;
   Tickable E2 = null;
   for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
     almostTock = e.next();
     try {
       for (Iterator<TockClient> i = almostTock.tickers(); i.hasNext(); ) {
         C = i.next();
         E2 = C.clientObject;
         if (here == null) {
           if (Tick.tickTicker(C, false)) almostTock.delTicker(C);
         } else if (isHere(E2, here)) {
           if (Tick.tickTicker(C, isSuspended)) almostTock.delTicker(C);
         } else if ((E2 instanceof Ability) && (isHere(((Ability) E2).affecting(), here))) {
           if (Tick.tickTicker(C, isSuspended)) almostTock.delTicker(C);
         }
       }
     } catch (NoSuchElementException ex) {
     }
   }
 }
Beispiel #19
0
  private final long readTick() {
    byte[] uid = null;

    if (interrupted()) uid = (byte[]) resume();

    if (uid == null) {
      uid = readBinary();

      if (interrupted()) {
        interrupt(null);
        return 0;
      }
    }

    if (!canReadLong()) {
      interrupt(uid);
      return 0;
    }

    Peer peer = Peer.get(new UID(uid));
    long tick = readLong();
    return Tick.get(peer.index(), tick);
  }
Beispiel #20
0
  @Override
  void getBlock(URI uri, long tick) {
    Buff duplicate = null;

    synchronized (this) {
      if (Debug.THREADS) ThreadAssert.resume(this, false);

      int index = Tick.indexOf(_ticks, tick);

      if (index >= 0) {
        Buff buff = _buffs[index];

        if (buff != null) {
          duplicate = buff.duplicate();

          if (Debug.THREADS) ThreadAssert.exchangeGive(duplicate, duplicate);
        }
      }

      if (Debug.THREADS) ThreadAssert.suspend(this);
    }

    if (duplicate != null) {
      Buff[] duplicates = new Buff[] {duplicate};

      if (Debug.THREADS) {
        ThreadAssert.exchangeTake(duplicate);
        ThreadAssert.exchangeGive(duplicates, duplicate);
      }

      uri.onBlock(this, tick, duplicates, null, true, null, false, null);

      if (Debug.THREADS) ThreadAssert.exchangeTake(duplicates);

      duplicate.recycle();
    }
  }
Beispiel #21
0
  @SuppressWarnings("fallthrough")
  final void read(long tick) {
    for (; ; ) {
      byte code = -1;

      if (interrupted()) code = resumeByte();

      if (code < 0) {
        if (!canReadByte()) {
          interruptByte(code);
          return;
        }

        code = readByte(Writer.DEBUG_TAG_CODE);

        if (Debug.COMMUNICATIONS_LOG) log("Command: " + Writer.getCommandString(code));
      }

      switch (code) {
        case Writer.COMMAND_ROOT_WRITE:
          {
            readRootVersion();

            if (interrupted()) {
              interruptByte(code);
              return;
            }

            break;
          }
        case Writer.COMMAND_ROOT_READ:
          {
            // TODO
            break;
          }
        case Writer.COMMAND_WRITE:
          {
            if (_versions == null) {
              TObject[] objects = readTObject();

              if (interrupted()) {
                interruptByte(code);
                return;
              }

              _versions = new Version[objects.length];

              for (int i = 0; i < objects.length; i++) _versions[i] = objects[i].createVersion_();
            }

            _versions[0].visit(_visitor);

            if (interrupted()) {
              interruptByte(code);
              return;
            }

            for (int i = 0; i < _versions.length; i++) addWrite(i, _versions[i]);

            _versions = null;
            break;
          }
        case Writer.COMMAND_READ:
          {
            // TODO
            break;
          }
        case Writer.COMMAND_DEPENDENCY:
          {
            long dependency = readTick();

            if (interrupted()) {
              interruptByte(code);
              return;
            }

            _dependencies = Tick.add(_dependencies, dependency);
            break;
          }
        case Writer.COMMAND_HAPPENED_BEFORE:
          {
            long happenedBefore = readTick();

            if (interrupted()) {
              interruptByte(code);
              return;
            }

            if (Debug.ENABLED) Debug.assertion(Tick.peer(happenedBefore) != Tick.peer(tick));

            _happenedBefore = Tick.putMax(_happenedBefore, happenedBefore, false);
            break;
          }
        case Writer.COMMAND_TICK:
          {
            for (int i = resources().size() - 1; i >= 0; i--) {
              Version[] writes = _writes[i];
              _writes[i] = null;

              for (int j = writes.length - 1; j >= 0; j--)
                if (writes[j] != null) writes[j].mergeReadOnlyFields();

              resources().get(i).onBlock(new Block(tick, writes, _happenedBefore, _dependencies));
            }

            _happenedBefore = null;
            _dependencies = null;
            // TODO add a checksum at end of each block
            return;
          }
        default:
          throw new IllegalStateException();
      }
    }
  }
Beispiel #22
0
  public String systemReport(String itemCode) {
    long totalMOBMillis = 0;
    long totalMOBTicks = 0;
    long topMOBMillis = 0;
    long topMOBTicks = 0;
    MOB topMOBClient = null;
    for (int s = 0; s < CMLib.sessions().size(); s++) {
      Session S = CMLib.sessions().elementAt(s);
      totalMOBMillis += S.getTotalMillis();
      totalMOBTicks += S.getTotalTicks();
      if (S.getTotalMillis() > topMOBMillis) {
        topMOBMillis = S.getTotalMillis();
        topMOBTicks = S.getTotalTicks();
        topMOBClient = S.mob();
      }
    }

    if (itemCode.equalsIgnoreCase("totalMOBMillis")) return "" + totalMOBMillis;
    else if (itemCode.equalsIgnoreCase("totalMOBMillisTime"))
      return CMLib.english().returnTime(totalMOBMillis, 0);
    else if (itemCode.equalsIgnoreCase("totalMOBMillisTimePlusAverage"))
      return CMLib.english().returnTime(totalMOBMillis, totalMOBTicks);
    else if (itemCode.equalsIgnoreCase("totalMOBTicks")) return "" + totalMOBTicks;
    else if (itemCode.equalsIgnoreCase("topMOBMillis")) return "" + topMOBMillis;
    else if (itemCode.equalsIgnoreCase("topMOBMillisTime"))
      return CMLib.english().returnTime(topMOBMillis, 0);
    else if (itemCode.equalsIgnoreCase("topMOBMillisTimePlusAverage"))
      return CMLib.english().returnTime(topMOBMillis, topMOBTicks);
    else if (itemCode.equalsIgnoreCase("topMOBTicks")) return "" + topMOBTicks;
    else if (itemCode.equalsIgnoreCase("topMOBClient")) {
      if (topMOBClient != null) return topMOBClient.Name();
      return "";
    }

    int totalTickers = 0;
    long totalMillis = 0;
    long totalTicks = 0;
    int topGroupNumber = -1;
    long topGroupMillis = -1;
    long topGroupTicks = 0;
    long topObjectMillis = -1;
    long topObjectTicks = 0;
    int topObjectGroup = 0;
    Tickable topObjectClient = null;
    int num = 0;
    Tick almostTock = null;
    for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
      almostTock = e.next();
      totalTickers += almostTock.numTickers();
      totalMillis += almostTock.milliTotal;
      totalTicks += almostTock.tickTotal;
      if (almostTock.milliTotal > topGroupMillis) {
        topGroupMillis = almostTock.milliTotal;
        topGroupTicks = almostTock.tickTotal;
        topGroupNumber = num;
      }
      try {
        for (Iterator et = almostTock.tickers(); et.hasNext(); ) {
          TockClient C = (TockClient) et.next();
          if (C.milliTotal > topObjectMillis) {
            topObjectMillis = C.milliTotal;
            topObjectTicks = C.tickTotal;
            topObjectClient = C.clientObject;
            topObjectGroup = num;
          }
        }
      } catch (NoSuchElementException ex) {
      }
      num++;
    }
    if (itemCode.equalsIgnoreCase("freeMemory"))
      return "" + (Runtime.getRuntime().freeMemory() / 1000);
    else if (itemCode.equalsIgnoreCase("totalMemory"))
      return "" + (Runtime.getRuntime().totalMemory() / 1000);
    else if (itemCode.equalsIgnoreCase("totalTime"))
      return ""
          + CMLib.english().returnTime(System.currentTimeMillis() - CMSecurity.getStartTime(), 0);
    else if (itemCode.equalsIgnoreCase("startTime"))
      return CMLib.time().date2String(CMSecurity.getStartTime());
    else if (itemCode.equalsIgnoreCase("currentTime"))
      return CMLib.time().date2String(System.currentTimeMillis());
    else if (itemCode.equalsIgnoreCase("totalTickers")) return "" + totalTickers;
    else if (itemCode.equalsIgnoreCase("totalMillis")) return "" + totalMillis;
    else if (itemCode.equalsIgnoreCase("totalMillisTime"))
      return CMLib.english().returnTime(totalMillis, 0);
    else if (itemCode.equalsIgnoreCase("totalMillisTimePlusAverage"))
      return CMLib.english().returnTime(totalMillis, totalTicks);
    else if (itemCode.equalsIgnoreCase("totalTicks")) return "" + totalTicks;
    else if (itemCode.equalsIgnoreCase("tickgroupsize")) return "" + ticks.size();
    else if (itemCode.equalsIgnoreCase("topGroupNumber")) return "" + topGroupNumber;
    else if (itemCode.equalsIgnoreCase("topGroupMillis")) return "" + topGroupMillis;
    else if (itemCode.equalsIgnoreCase("topGroupMillisTime"))
      return CMLib.english().returnTime(topGroupMillis, 0);
    else if (itemCode.equalsIgnoreCase("topGroupMillisTimePlusAverage"))
      return CMLib.english().returnTime(topGroupMillis, topGroupTicks);
    else if (itemCode.equalsIgnoreCase("topGroupTicks")) return "" + topGroupTicks;
    else if (itemCode.equalsIgnoreCase("topObjectMillis")) return "" + topObjectMillis;
    else if (itemCode.equalsIgnoreCase("topObjectMillisTime"))
      return CMLib.english().returnTime(topObjectMillis, 0);
    else if (itemCode.equalsIgnoreCase("topObjectMillisTimePlusAverage"))
      return CMLib.english().returnTime(topObjectMillis, topObjectTicks);
    else if (itemCode.equalsIgnoreCase("topObjectTicks")) return "" + topObjectTicks;
    else if (itemCode.equalsIgnoreCase("topObjectGroup")) return "" + topObjectGroup;
    else if (itemCode.toLowerCase().startsWith("thread")) {
      int xstart = "thread".length();
      int xend = xstart;
      while ((xend < itemCode.length()) && (Character.isDigit(itemCode.charAt(xend)))) xend++;
      int threadNum = CMath.s_int(itemCode.substring(xstart, xend));
      int curThreadNum = 0;
      for (Enumeration e = CMLib.libraries(); e.hasMoreElements(); ) {
        CMLibrary lib = (CMLibrary) e.nextElement();
        ThreadEngine.SupportThread thread = lib.getSupportThread();
        if (thread != null) {
          if (curThreadNum == threadNum) {
            String instrCode = itemCode.substring(xend);
            if (instrCode.equalsIgnoreCase("miliTotal")) return "" + thread.milliTotal;
            if (instrCode.equalsIgnoreCase("milliTotal")) return "" + thread.milliTotal;
            if (instrCode.equalsIgnoreCase("status")) return "" + thread.status;
            if (instrCode.equalsIgnoreCase("name")) return "" + thread.getName();
            if (instrCode.equalsIgnoreCase("MilliTotalTime"))
              return CMLib.english().returnTime(thread.milliTotal, 0);
            if (instrCode.equalsIgnoreCase("MiliTotalTime"))
              return CMLib.english().returnTime(thread.milliTotal, 0);
            if (instrCode.equalsIgnoreCase("MilliTotalTimePlusAverage"))
              return CMLib.english().returnTime(thread.milliTotal, thread.tickTotal);
            if (instrCode.equalsIgnoreCase("MiliTotalTimePlusAverage"))
              return CMLib.english().returnTime(thread.milliTotal, thread.tickTotal);
            if (instrCode.equalsIgnoreCase("TickTotal")) return "" + thread.tickTotal;
            break;
          }
          curThreadNum++;
        }
      }
    }
    if (itemCode.equalsIgnoreCase("topObjectClient")) {
      if (topObjectClient != null) return topObjectClient.name();
      return "";
    }

    return "";
  }
Beispiel #23
0
  @Override
  void onBlock(URI uri, long tick, Buff[] buffs, long[] removals, boolean requested) {
    int capacity = 0;

    if (Debug.THREADS) ThreadAssert.exchangeTake(buffs);

    for (int i = 0; i < buffs.length; i++) capacity += buffs[i].remaining();

    Buff buff = Buff.createCustom(capacity, false);

    if (Stats.ENABLED) Stats.Instance.MemoryBlocksCreated.incrementAndGet();

    for (int i = 0; i < buffs.length; i++) {
      buff.putImmutably(buffs[i]);

      if (Debug.THREADS) ThreadAssert.exchangeGive(buffs, buffs[i]);
    }

    if (Debug.ENABLED) Debug.assertion(buff.remaining() == 0);

    buff.position(0);
    buff.mark();

    List<Buff> recycle = null;

    if (Debug.THREADS) ThreadAssert.exchangeGive(buff, buff);

    synchronized (this) {
      if (Debug.THREADS) {
        ThreadAssert.resume(this, false);
        ThreadAssert.exchangeTake(buff);
      }

      int index = Tick.indexOf(_ticks, tick);

      if (index < 0) {
        index = add(tick);
        _buffs[index] = buff;

        if (Stats.ENABLED) Stats.Instance.MemoryBlocksLive.incrementAndGet();
      } else {
        if (Debug.ENABLED) Debug.assertion(_buffs[index] != null);

        recycle = new List<Buff>();
        recycle.add(buff);
      }

      for (int i = 0; removals != null && i < removals.length; i++) {
        if (!Tick.isNull(removals[i])) {
          index = Tick.remove(_ticks, removals[i]);

          if (index >= 0) {
            if (recycle == null) recycle = new List<Buff>();

            recycle.add(_buffs[index]);
            _buffs[index] = null;

            if (Stats.ENABLED) Stats.Instance.MemoryBlocksLive.decrementAndGet();
          }
        }
      }

      if (Debug.THREADS) {
        for (int i = 0; recycle != null && i < recycle.size(); i++)
          ThreadAssert.exchangeGive(recycle, recycle.get(i));

        ThreadAssert.suspend(this);
      }
    }

    if (!location().isCache()) {
      uri.onAck(this, tick);

      if (Stats.ENABLED) Stats.Instance.AckCreated.incrementAndGet();
    }

    if (recycle != null) {
      if (Debug.THREADS) ThreadAssert.exchangeTake(recycle);

      for (int i = 0; i < recycle.size(); i++) recycle.get(i).recycle();
    }
  }
Beispiel #24
0
  /** @param tmpTickList */
  private static List<Sequence> structureCreator(List<Tick> tmpTickList) {

    /*
     * transform List of Ticks to Frames
     */
    List<Tick> tickList = new ArrayList<Tick>();
    List<Frame> frameList = new ArrayList<Frame>();
    List<Sequence> sequenceList = new ArrayList<Sequence>();

    for (int i = 0; i < tmpTickList.size(); i++) {
      Tick currentTick = tmpTickList.get(i);

      if (currentTick.getType().compareTo("########") == 0) { // currentTick equal to ########
        /*
         * add Frames to frameList
         */
        Tick[] tickArray = new Tick[tickList.size()];
        tickArray = tickList.toArray(tickArray);
        tickList.clear();
        Frame tmpFrame = new Frame(tickArray);
        frameList.add(tmpFrame);

      } else {

        tickList.add(currentTick);
      }
    }

    /*
     * Arrange Frames into Sequences and create a Scene with them
     */
    List<Frame> listOfFrames = new ArrayList<Frame>();

    Frame stopFrame = new Frame();
    listOfFrames.add(frameList.get(0)); // always start the listOfFrames with first frame
    for (int i = 0; i < frameList.size(); i++) {

      Frame frameA = frameList.get(i);
      Frame frameB;
      if (frameList.size() - 1 == i) {
        frameB = stopFrame;
      } else {
        frameB = frameList.get(i + 1);
      }

      if (frameA.equalTo(frameB)) {
        listOfFrames.add(frameB); // add duplicate frames to listOfFrames

      } else {

        int frameSize = frameA.getArrayLength();
        int sequenceLength = listOfFrames.size();
        int[][] timestampArray = new int[sequenceLength][frameSize];

        String[] typeArray = frameA.getConcatenatedTypes();

        for (int j = 0; j < sequenceLength; j++) { // for every Frame on the listOfFrames

          Frame tmpFrame = listOfFrames.get(j); // get the Frame
          timestampArray[j] = tmpFrame.getTimestamps(); // add every Timestamp in this Frame
        }

        Sequence prevSequence;
        if (sequenceList.isEmpty()) {
          prevSequence = new Sequence();
        } else {
          prevSequence = sequenceList.get(sequenceList.size() - 1);
        }
        Sequence tmpSequence =
            new Sequence(
                typeArray, timestampArray, prevSequence); // create Sequence out of Types and Times

        sequenceList.add(tmpSequence); // add Sequence to List

        listOfFrames.clear(); // rinse and repeat
        listOfFrames.add(frameB); // but add FrameB as a startingpoint for the next iteration
      }
    }

    return sequenceList;
  }
Beispiel #25
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");
  }