Example usage for java.lang Thread activeCount

List of usage examples for java.lang Thread activeCount

Introduction

In this page you can find the example usage for java.lang Thread activeCount.

Prototype

public static int activeCount() 

Source Link

Document

Returns an estimate of the number of active threads in the current thread's java.lang.ThreadGroup thread group and its subgroups.

Usage

From source file:org.waarp.openr66.protocol.localhandler.Monitoring.java

/**
 * /* w ww. j  a  va 2  s  .  c o m*/
 * @param nbSecond
 *            as specific PastLimit
 * @param detail
 *            as to get detailed information
 */
public void run(long nbSecond, boolean detail) {
    synchronized (trafficCounter) {
        long limitDate = System.currentTimeMillis();
        long nbMs = pastLimit;
        if (nbSecond <= 0) {
            nbMs = pastLimit;
        } else {
            nbMs = nbSecond * 1000;
        }
        if (dbSession != null && dbSession.isDisActive) {
            dbSession.checkConnectionNoException();
        }
        if (dbSession == null || dbSession.isDisActive) {
            nbNetworkConnection = Configuration.configuration.getHttpChannelGroup().size()
                    + Configuration.configuration.getServerChannelGroup().size();
            bandwidthIn = trafficCounter.lastReadThroughput() >> 7;// B/s -> Kb/s
            bandwidthOut = trafficCounter.lastWriteThroughput() >> 7;
            nbThread = Thread.activeCount();
            secondsRunning = (limitDate - startMonitor) / 1000;

            if (!reCompute()) {
                // too early
                return;
            }
            limitDate -= nbMs;
            currentLimit = limitDate;
            // Update value
            // Overall status including past, future and current transfers
            nbCountInfoToSubmit = CommanderNoDb.todoList.size();
            if (Configuration.configuration.getInternalRunner() != null) {
                nbCountInfoRunning = Configuration.configuration.getInternalRunner().nbInternalRunner();
            } else {
                nbCountInfoRunning = Configuration.configuration.getServerChannelGroup().size();
            }
            // Current situation of all transfers, running or not
            nbCountAllRunningStep = nbCountInfoRunning;
        } else {
            nbNetworkConnection = DbAdmin.getNbConnection();
            bandwidthIn = trafficCounter.lastReadThroughput() >> 7;// B/s -> Kb/s
            bandwidthOut = trafficCounter.lastWriteThroughput() >> 7;
            nbThread = Thread.activeCount();
            secondsRunning = (limitDate - startMonitor) / 1000;

            if (!reCompute()) {
                // too early
                return;
            }
            limitDate -= nbMs;
            currentLimit = limitDate;
            // Update value
            try {
                // Overall status including past, future and current transfers
                nbCountInfoUnknown = DbTaskRunner.getResultCountPrepareStatement(countInfo, UpdatedInfo.UNKNOWN,
                        limitDate);
                nbCountInfoNotUpdated = DbTaskRunner.getResultCountPrepareStatement(countInfo,
                        UpdatedInfo.NOTUPDATED, limitDate);
                nbCountInfoInterrupted = DbTaskRunner.getResultCountPrepareStatement(countInfo,
                        UpdatedInfo.INTERRUPTED, limitDate);
                nbCountInfoToSubmit = DbTaskRunner.getResultCountPrepareStatement(countInfo,
                        UpdatedInfo.TOSUBMIT, limitDate);
                nbCountInfoError = DbTaskRunner.getResultCountPrepareStatement(countInfo, UpdatedInfo.INERROR,
                        limitDate);
                nbCountInfoRunning = DbTaskRunner.getResultCountPrepareStatement(countInfo, UpdatedInfo.RUNNING,
                        limitDate);
                nbCountInfoDone = DbTaskRunner.getResultCountPrepareStatement(countInfo, UpdatedInfo.DONE,
                        limitDate);

                // Current situation of all transfers, running or not
                DbTaskRunner.finishSelectOrCountPrepareStatement(countInActiveTransfer, limitDate);
                nbInActiveTransfer = DbTaskRunner.getResultCountPrepareStatement(countInActiveTransfer);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countOutActiveTransfer, limitDate);
                nbOutActiveTransfer = DbTaskRunner.getResultCountPrepareStatement(countOutActiveTransfer);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countInTotalTransfer, limitDate);
                nbInTotalTransfer = DbTaskRunner.getResultCountPrepareStatement(countInTotalTransfer);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countOutTotalTransfer, limitDate);
                nbOutTotalTransfer = DbTaskRunner.getResultCountPrepareStatement(countOutTotalTransfer);

                DbTaskRunner.finishSelectOrCountPrepareStatement(countOutErrorTransfer, limitDate);
                nbOutErrorTransfer = DbTaskRunner.getResultCountPrepareStatement(countOutErrorTransfer);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countInErrorTransfer, limitDate);
                nbInErrorTransfer = DbTaskRunner.getResultCountPrepareStatement(countInErrorTransfer);

                DbTaskRunner.finishSelectOrCountPrepareStatement(countStepAllTransfer, limitDate);
                nbCountStepAllTransfer = DbTaskRunner.getResultCountPrepareStatement(countStepAllTransfer);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countStepNotask, limitDate);
                nbCountStepNotask = DbTaskRunner.getResultCountPrepareStatement(countStepNotask);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countStepPretask, limitDate);
                nbCountStepPretask = DbTaskRunner.getResultCountPrepareStatement(countStepPretask);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countStepTransfer, limitDate);
                nbCountStepTransfer = DbTaskRunner.getResultCountPrepareStatement(countStepTransfer);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countStepPosttask, limitDate);
                nbCountStepPosttask = DbTaskRunner.getResultCountPrepareStatement(countStepPosttask);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countStepAllDone, limitDate);
                nbCountStepAllDone = DbTaskRunner.getResultCountPrepareStatement(countStepAllDone);
                DbTaskRunner.finishSelectOrCountPrepareStatement(countStepError, limitDate);
                nbCountStepError = DbTaskRunner.getResultCountPrepareStatement(countStepError);

                DbTaskRunner.finishSelectOrCountPrepareStatement(countAllRunningStep, limitDate);
                nbCountAllRunningStep = DbTaskRunner.getResultCountPrepareStatement(countAllRunningStep);

                if (detail) {
                    // First on Running Transfers only
                    DbTaskRunner.finishSelectOrCountPrepareStatement(countRunningStep, limitDate);
                    nbCountRunningStep = DbTaskRunner.getResultCountPrepareStatement(countRunningStep);
                    DbTaskRunner.finishSelectOrCountPrepareStatement(countInitOkStep, limitDate);
                    nbCountInitOkStep = DbTaskRunner.getResultCountPrepareStatement(countInitOkStep);
                    DbTaskRunner.finishSelectOrCountPrepareStatement(countPreProcessingOkStep, limitDate);
                    nbCountPreProcessingOkStep = DbTaskRunner
                            .getResultCountPrepareStatement(countPreProcessingOkStep);
                    DbTaskRunner.finishSelectOrCountPrepareStatement(countTransferOkStep, limitDate);
                    nbCountTransferOkStep = DbTaskRunner.getResultCountPrepareStatement(countTransferOkStep);
                    DbTaskRunner.finishSelectOrCountPrepareStatement(countPostProcessingOkStep, limitDate);
                    nbCountPostProcessingOkStep = DbTaskRunner
                            .getResultCountPrepareStatement(countPostProcessingOkStep);
                    DbTaskRunner.finishSelectOrCountPrepareStatement(countCompleteOkStep, limitDate);
                    nbCountCompleteOkStep = DbTaskRunner.getResultCountPrepareStatement(countCompleteOkStep);

                    // Error Status on all transfers
                    nbCountStatusConnectionImpossible = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.ConnectionImpossible, limitDate);
                    nbCountStatusServerOverloaded = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.ServerOverloaded, limitDate);
                    nbCountStatusBadAuthent = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.BadAuthent, limitDate);
                    nbCountStatusExternalOp = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.ExternalOp, limitDate);
                    nbCountStatusTransferError = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.TransferError, limitDate);
                    nbCountStatusMD5Error = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.MD5Error, limitDate);
                    nbCountStatusDisconnection = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.Disconnection, limitDate);
                    nbCountStatusFinalOp = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.FinalOp, limitDate);
                    nbCountStatusUnimplemented = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.Unimplemented, limitDate);
                    nbCountStatusInternal = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.Internal, limitDate);
                    nbCountStatusWarning = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.Warning, limitDate);
                    nbCountStatusQueryAlreadyFinished = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.QueryAlreadyFinished, limitDate);
                    nbCountStatusQueryStillRunning = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.QueryStillRunning, limitDate);
                    nbCountStatusNotKnownHost = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.NotKnownHost, limitDate);
                    nbCountStatusQueryRemotelyUnknown = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.QueryRemotelyUnknown, limitDate);
                    nbCountStatusCommandNotFound = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.CommandNotFound, limitDate);
                    nbCountStatusPassThroughMode = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.PassThroughMode, limitDate);
                    nbCountStatusRemoteShutdown = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.RemoteShutdown, limitDate);
                    nbCountStatusShutdown = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.Shutdown, limitDate);
                    nbCountStatusRemoteError = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.RemoteError, limitDate);
                    nbCountStatusStopped = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.StoppedTransfer, limitDate);
                    nbCountStatusCanceled = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.CanceledTransfer, limitDate);
                    nbCountStatusFileNotFound = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.FileNotFound, limitDate);
                    nbCountStatusUnknown = DbTaskRunner.getResultCountPrepareStatement(countStatus,
                            ErrorCode.Unknown, limitDate);
                }
            } catch (WaarpDatabaseNoConnectionException e) {
            } catch (WaarpDatabaseSqlException e) {
            }
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.SimpleWebTestCase.java

/**
 * Gets the active JavaScript threads./*from   www  . ja v a  2  s  . c o m*/
 * @return the threads
 */
protected List<Thread> getJavaScriptThreads() {
    final Thread[] threads = new Thread[Thread.activeCount() + 10];
    Thread.enumerate(threads);
    final List<Thread> jsThreads = new ArrayList<Thread>();
    for (final Thread t : threads) {
        if (t != null && t.getName().startsWith("JS executor for")) {
            jsThreads.add(t);
        }
    }

    return jsThreads;
}

From source file:com.l2jfree.gameserver.status.GameStatusThread.java

@Override
public void run() {
    String _usrCommand = "";
    try {/*from  w w w. j a va2  s .  c om*/
        while (_usrCommand.compareTo("quit") != 0 && _usrCommand.compareTo("exit") != 0) {
            _usrCommand = readLine();
            if (_usrCommand == null) {
                _cSocket.close();
                break;
            }
            if (_usrCommand.equals("help")) {
                _print.println("The following is a list of all available commands: ");
                _print.println("help            - shows this help.");
                _print.println("status            - displays basic server statistics.");
                _print.println("printmemusage      - displays memory amounts in JVM.");
                _print.println("performance         - shows server performance statistics.");
                _print.println("threads            - dumps thread infos.");
                _print.println("purge            - purges TPM.");
                _print.println("gc               - forced garbage collection.");
                _print.println("clean            - cleans leakmanager mapped objects.");
                _print.println("clear            - clears leakmanager mapped objects.");
                _print.println("class            - dumps TPM-class stats.");
                _print.println("announce <text>      - announces <text> in game.");
                _print.println("msg <nick> <text>   - Sends a whisper to char <nick> with <text>.");
                _print.println("gmchat <text>      - Sends a message to all GMs with <text>.");
                _print.println("gmlist            - lists all gms online.");
                _print.println("ip               - gets IP of player <name>.");
                _print.println("kick            - kick player <name> from server.");
                _print.println("shutdown <time>      - shuts down server in <time> seconds.");
                _print.println("restart <time>      - restarts down server in <time> seconds.");
                _print.println("abort            - aborts shutdown/restart.");
                _print.println("halt            - halts server.");
                _print.println("give <player> <itemid> <amount>");
                _print.println(
                        "enchant <player> <itemType> <enchant> (itemType: 1 - Helmet, 2 - Chest, 3 - Gloves, 4 - Feet, "
                                + "5 - Legs, 6 - Right Hand, 7 - Left Hand, 8 - Left Ear, 9 - Right Ear , 10 - Left Finger, 11 - Right Finger, "
                                + "12- Necklace, 13 - Underwear, 14 - Back, 15 - Belt, 0 - No Enchant)");
                _print.println(
                        "extreload <name>   - reload and initializes the named extension or all if used without argument");
                _print.println(
                        "extinit <name>      - initilizes the named extension or all if used without argument");
                _print.println(
                        "extunload <name>   - unload the named extension or all if used without argument");
                _print.println("debug <cmd>         - executes the debug command (see 'help debug').");
                _print.println("jail <player> [time]");
                _print.println("unjail <player>");
                _print.println("reload <...>");
                _print.println("reload_config <file>");
                if (Config.IRC_ENABLED) {
                    _print.println("ircc <command>     - sends a command to irc");
                    _print.println("ircm <target ><msg> - sends a message to irc");
                }
                _print.println("quit            - closes telnet session.");
            } else if (_usrCommand.equals("help debug")) {
                _print.println("The following is a list of all available debug commands: ");
                _print.println("decay            - prints info about the DecayManager");
            } else if (_usrCommand.equals("status")) {
                int max = LoginServerThread.getInstance().getMaxPlayer();

                int playerCount = L2World.getInstance().getAllPlayersCount();
                int objectCount = L2World.getInstance().getAllVisibleObjectsCount();

                int itemCount = 0;
                int itemVoidCount = 0;
                int monsterCount = 0;
                int minionCount = 0;
                int minionsGroupCount = 0;
                int npcCount = 0;
                int pcCount = 0;
                int doorCount = 0;
                int summonCount = 0;
                int AICount = 0;

                for (L2Object obj : L2World.getInstance().getAllVisibleObjects()) {
                    if (obj == null)
                        continue;
                    if (obj instanceof L2Creature)
                        if (((L2Creature) obj).hasAI())
                            AICount++;

                    if (obj instanceof L2ItemInstance) {
                        if (((L2ItemInstance) obj).getLocation() == L2ItemInstance.ItemLocation.VOID)
                            itemVoidCount++;
                        else
                            itemCount++;
                    } else if (obj instanceof L2MonsterInstance) {
                        monsterCount++;
                        minionCount += ((L2MonsterInstance) obj).getTotalSpawnedMinionsInstances();
                        minionsGroupCount += ((L2MonsterInstance) obj).getTotalSpawnedMinionsGroups();
                    } else if (obj instanceof L2Npc)
                        npcCount++;
                    else if (obj instanceof L2Player)
                        pcCount++;
                    else if (obj instanceof L2Summon)
                        summonCount++;
                    else if (obj instanceof L2DoorInstance)
                        doorCount++;
                }
                _print.println("Server Status: ");
                _print.println("  --->  Player Count: " + playerCount + "/" + max);
                _print.println("  +-->  Object Count: " + objectCount);
                _print.println("  +-->     AI Count: " + AICount);
                _print.println("  +.... L2Item(Void): " + itemVoidCount);
                _print.println("  +.......... L2Item: " + itemCount);
                _print.println("  +....... L2Monster: " + monsterCount);
                _print.println("  +......... Minions: " + minionCount);
                _print.println("  +.. Minions Groups: " + minionsGroupCount);
                _print.println("  +........... L2Npc: " + npcCount);
                _print.println("  +............ L2Pc: " + pcCount);
                _print.println("  +........ L2Summon: " + summonCount);
                _print.println("  +.......... L2Door: " + doorCount);
                _print.println("  --->   Ingame Time: " + GameTimeManager.getInstance().getFormattedGameTime());
                _print.println("  ---> Server Uptime: " + getUptime(_uptime));
                _print.println("  --->     GM Count: " + getOnlineGMS());
                _print.println("  --->      Threads: " + Thread.activeCount());
                _print.println("  RAM Used: "
                        + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
                _print.flush();
            } else if (_usrCommand.equals("printmemusage")) {
                for (String line : Util.getMemUsage()) {
                    _print.println(line);
                }
                _print.flush();
            } else if (_usrCommand.equals("performance")) {
                for (String line : ThreadPoolManager.getInstance().getStats()) {
                    _print.println(line);
                }
                _print.flush();
            } else if (_usrCommand.equals("threads")) {
                L2Thread.dumpThreads();
                _print.println("Threads dumped....");
                _print.flush();
            } else if (_usrCommand.equals("purge")) {
                ThreadPoolManager.getInstance().purge();
                _print.println("STATUS OF THREAD POOLS AFTER PURGE COMMAND:");
                _print.println("");
                for (String line : ThreadPoolManager.getInstance().getStats()) {
                    _print.println(line);
                }
                _print.flush();
            } else if (_usrCommand.startsWith("class")) {
                SortBy sortBy = null;
                try {
                    sortBy = SortBy.valueOf(_usrCommand.substring(6).toUpperCase());
                } catch (Exception e) {
                }

                RunnableStatsManager.dumpClassStats(sortBy);
                _print.println("TPM-Classes dumped....");
                _print.flush();
            } else if (_usrCommand.equals("gc")) {
                for (String line : Util.getMemUsage()) {
                    _print.println(line);
                }
                _print.println("");
                _print.println("##################################");
                _print.print(" Garbage collecting... ");
                _print.flush();
                long act = System.currentTimeMillis();
                System.gc();
                _print.println("Done!");
                _print.println(" Duration: " + (System.currentTimeMillis() - act) + "msec...");
                _print.println("##################################");
                _print.println("");
                for (String line : Util.getMemUsage()) {
                    _print.println(line);
                }
                _print.flush();
            } else if (_usrCommand.equals("clean")) {
                _print.println("================================================================");
                long begin = System.currentTimeMillis();
                LeakTaskManager.getInstance().clean();
                _print.println("'clean' done in " + (System.currentTimeMillis() - begin) + "msec.");
                _print.println("================================================================");
            } else if (_usrCommand.equals("clear")) {
                _print.println("================================================================");
                long begin = System.currentTimeMillis();
                LeakTaskManager.getInstance().clear();
                _print.println("'clear' done in " + (System.currentTimeMillis() - begin) + "msec.");
                _print.println("================================================================");
            } else if (_usrCommand.startsWith("announce")) {
                try {
                    _usrCommand = _usrCommand.substring(9);
                    if (Config.ALT_TELNET && Config.ALT_TELNET_GM_ANNOUNCER_NAME)
                        _usrCommand += " [" + _gm + "(offline)]";
                    Announcements.getInstance().announceToAll(_usrCommand);
                    _print.println("Announcement Sent!");
                } catch (StringIndexOutOfBoundsException e) {
                    _print.println("Please Enter Some Text To Announce!");
                }
            } else if (_usrCommand.startsWith("msg")) {
                try {
                    String val = _usrCommand.substring(4);
                    StringTokenizer st = new StringTokenizer(val);
                    String name = st.nextToken();
                    String message = val.substring(name.length() + 1);
                    L2Player reciever = L2World.getInstance().getPlayer(name);
                    CreatureSay cs = new CreatureSay(0, SystemChatChannelId.Chat_Tell, "Telnet Priv", message);
                    if (Config.ALT_TELNET)
                        cs = new CreatureSay(0, SystemChatChannelId.Chat_Tell, _gm + "(offline)", message);
                    if (reciever != null) {
                        reciever.sendPacket(cs);
                        _print.println("Telnet Priv->" + name + ": " + message);
                        if (Config.ALT_TELNET)
                            _print.println(_gm + "(offline): " + name + ": " + message);
                        _print.println("Message Sent!");
                    } else {
                        _print.println("Unable To Find Username: " + name);
                    }
                } catch (StringIndexOutOfBoundsException e) {
                    _print.println("Please Enter Some Text!");
                }
            } else if (_usrCommand.startsWith("gmchat")) {
                try {
                    _usrCommand = _usrCommand.substring(7);
                    CreatureSay cs = new CreatureSay(0, SystemChatChannelId.Chat_Alliance,
                            "Telnet GM Broadcast from " + _cSocket.getInetAddress().getHostAddress(),
                            _usrCommand);
                    GmListTable.broadcastToGMs(cs);
                    _print.println("Your Message Has Been Sent To " + getOnlineGMS() + " GM(s).");
                } catch (StringIndexOutOfBoundsException e) {
                    _print.println("Please Enter Some Text To Announce!");
                }
            } else if (_usrCommand.equals("gmlist")) {
                int igm = 0;
                String gmList = "";

                for (String player : GmListTable.getAllGmNames(false)) {
                    gmList = gmList + ", " + player;
                    igm++;
                }
                _print.println("There are currently " + igm + " GM(s) online...");
                if (!gmList.isEmpty())
                    _print.println(gmList);
            } else if (_usrCommand.startsWith("ip")) {
                try {
                    _usrCommand = _usrCommand.substring(3);
                    L2Player player = L2World.getInstance().getPlayer(_usrCommand);
                    if (player != null) {
                        try {
                            _print.println("IP of " + player + ": " + player.getClient().getHostAddress());
                        } catch (RuntimeException e) {
                            _print.println(e.toString());
                        }
                    } else {
                        _print.println("No player online with that name!");
                    }
                } catch (StringIndexOutOfBoundsException e) {
                    _print.println("Please enter player name to get IP");
                }
            } else if (_usrCommand.startsWith("kick")) {
                try {
                    _usrCommand = _usrCommand.substring(5);
                    L2Player player = L2World.getInstance().getPlayer(_usrCommand);
                    if (player != null) {
                        new Disconnection(player).defaultSequence(false);
                        _print.println("Player kicked");
                    }
                } catch (StringIndexOutOfBoundsException e) {
                    _print.println("Please enter player name to kick");
                }
            } else if (_usrCommand.startsWith("shutdown")) {
                try {
                    int val = Integer.parseInt(_usrCommand.substring(9));
                    Shutdown.start(_cSocket.getInetAddress().getHostAddress(), val, ShutdownMode.SHUTDOWN);
                    _print.println("Server Will Shutdown In " + val + " Seconds!");
                    _print.println("Type \"abort\" To Abort Shutdown!");
                } catch (StringIndexOutOfBoundsException e) {
                    _print.println("Please Enter * amount of seconds to shutdown!");
                } catch (NumberFormatException e) {
                    _print.println("Numbers Only!");
                }
            } else if (_usrCommand.startsWith("restart")) {
                try {
                    int val = Integer.parseInt(_usrCommand.substring(8));
                    Shutdown.start(_cSocket.getInetAddress().getHostAddress(), val, ShutdownMode.RESTART);
                    _print.println("Server Will Restart In " + val + " Seconds!");
                    _print.println("Type \"abort\" To Abort Restart!");
                } catch (StringIndexOutOfBoundsException e) {
                    _print.println("Please Enter * amount of seconds to restart!");
                } catch (Exception NumberFormatException) {
                    _print.println("Numbers Only!");
                }
            } else if (_usrCommand.startsWith("abort")) {
                Shutdown.abort(_cSocket.getInetAddress().getHostAddress());
                _print.println("OK! - Shutdown/Restart Aborted.");
            } else if (_usrCommand.startsWith("halt")) {
                try {
                    _print.print("Halting...");
                    Shutdown.halt(_cSocket.getInetAddress().getHostAddress());
                } finally {
                    _print.println("\t\t[OK]");
                }
            } else if (_usrCommand.equals("quit")) {
            } else if (_usrCommand.startsWith("give")) {
                StringTokenizer st = new StringTokenizer(_usrCommand.substring(5));

                String playername = st.nextToken();
                try {
                    L2Player player = L2World.getInstance().getPlayer(playername);
                    int itemId = Integer.parseInt(st.nextToken());
                    int amount = Integer.parseInt(st.nextToken());

                    if (player != null) {
                        L2ItemInstance item = player.getInventory().addItem("Status-Give", itemId, amount, null,
                                null);
                        InventoryUpdate iu = new InventoryUpdate();
                        iu.addItem(item);
                        player.sendPacket(iu);
                        SystemMessage sm = new SystemMessage(SystemMessageId.YOU_PICKED_UP_S1_S2);
                        sm.addItemName(item);
                        sm.addNumber(amount);
                        player.sendPacket(sm);
                        _print.println("ok - was online");
                    } else {
                        Integer playerId = CharNameTable.getInstance().getByName(playername);
                        if (playerId != null) {
                            java.sql.Connection con = null;
                            con = L2DatabaseFactory.getInstance().getConnection(con);
                            addItemToInventory(con, playerId, IdFactory.getInstance().getNextId(), itemId,
                                    amount, 0);
                            _print.println("ok - was offline");
                        } else {
                            _print.println("player not found");
                        }
                    }
                } catch (Exception e) {

                }
            } else if (_usrCommand.startsWith("enchant")) {
                StringTokenizer st = new StringTokenizer(_usrCommand.substring(8), " ");
                int enchant = 0, itemType = 0;

                try {
                    L2Player player = L2World.getInstance().getPlayer(st.nextToken());
                    itemType = Integer.parseInt(st.nextToken());
                    enchant = Integer.parseInt(st.nextToken());

                    switch (itemType) {
                    case 1:
                        itemType = Inventory.PAPERDOLL_HEAD;
                        break;
                    case 2:
                        itemType = Inventory.PAPERDOLL_CHEST;
                        break;
                    case 3:
                        itemType = Inventory.PAPERDOLL_GLOVES;
                        break;
                    case 4:
                        itemType = Inventory.PAPERDOLL_FEET;
                        break;
                    case 5:
                        itemType = Inventory.PAPERDOLL_LEGS;
                        break;
                    case 6:
                        itemType = Inventory.PAPERDOLL_RHAND;
                        break;
                    case 7:
                        itemType = Inventory.PAPERDOLL_LHAND;
                        break;
                    case 8:
                        itemType = Inventory.PAPERDOLL_LEAR;
                        break;
                    case 9:
                        itemType = Inventory.PAPERDOLL_REAR;
                        break;
                    case 10:
                        itemType = Inventory.PAPERDOLL_LFINGER;
                        break;
                    case 11:
                        itemType = Inventory.PAPERDOLL_RFINGER;
                        break;
                    case 12:
                        itemType = Inventory.PAPERDOLL_NECK;
                        break;
                    case 13:
                        itemType = Inventory.PAPERDOLL_UNDER;
                        break;
                    case 14:
                        itemType = Inventory.PAPERDOLL_BACK;
                        break;
                    case 15:
                        itemType = Inventory.PAPERDOLL_BELT;
                        break;
                    default:
                        itemType = 0;
                    }

                    if (enchant > 65535)
                        enchant = 65535;
                    else if (enchant < 0)
                        enchant = 0;

                    boolean success = false;

                    if (player != null && itemType > 0) {
                        success = setEnchant(_cSocket, player, enchant, itemType);
                        if (success)
                            _print.println("Item enchanted successfully.");
                    } else if (!success)
                        _print.println("Item failed to enchant.");
                } catch (Exception e) {

                }
            } else if (_usrCommand.startsWith("jail")) {
                StringTokenizer st = new StringTokenizer(_usrCommand.substring(5));
                try {
                    String name = st.nextToken();
                    L2Player playerObj = L2World.getInstance().getPlayer(name);
                    int delay = 0;
                    try {
                        delay = Integer.parseInt(st.nextToken());
                    } catch (NumberFormatException nfe) {
                    } catch (NoSuchElementException nsee) {
                    }
                    // L2Player playerObj =
                    // L2World.getInstance().getPlayer(player);

                    if (playerObj != null) {
                        playerObj.setInJail(true, delay);
                        _print.println("Character " + name + " jailed for "
                                + (delay > 0 ? delay + " minutes." : "ever!"));
                    } else
                        jailOfflinePlayer(name, delay);
                } catch (NoSuchElementException nsee) {
                    _print.println("Specify a character name.");
                } catch (Exception e) {
                    if (_log.isDebugEnabled())
                        _log.error(e.getMessage(), e);
                }
            } else if (_usrCommand.startsWith("unjail")) {
                StringTokenizer st = new StringTokenizer(_usrCommand.substring(7));
                try {
                    String name = st.nextToken();
                    L2Player playerObj = L2World.getInstance().getPlayer(name);

                    if (playerObj != null) {
                        playerObj.stopJailTask(false);
                        playerObj.setInJail(false, 0);
                        _print.println("Character " + name + " removed from jail");
                    } else
                        unjailOfflinePlayer(name);
                } catch (NoSuchElementException nsee) {
                    _print.println("Specify a character name.");
                } catch (Exception e) {
                    if (_log.isDebugEnabled())
                        _log.debug(e.getMessage(), e);
                }
            } else if (_usrCommand.startsWith("ircc")) {
                if (Config.IRC_ENABLED) {
                    _usrCommand = _usrCommand.substring(4);
                    try {
                        IrcManager.getInstance().getConnection().send(_usrCommand);

                    } catch (Exception e) {
                        if (_log.isDebugEnabled())
                            _log.debug(e.getMessage(), e);
                    }
                }
            } else if (_usrCommand.startsWith("ircm")) {
                if (Config.IRC_ENABLED) {
                    String val = _usrCommand.substring(4);
                    try {
                        StringTokenizer st = new StringTokenizer(val);
                        String name = st.nextToken();
                        String message = val.substring(name.length() + 1);
                        IrcManager.getInstance().getConnection().send(name, message);

                    } catch (Exception e) {
                        if (_log.isDebugEnabled())
                            _log.debug(e.getMessage(), e);
                    }
                }
            } else if (_usrCommand.startsWith("debug") && _usrCommand.length() > 6) {
                StringTokenizer st = new StringTokenizer(_usrCommand.substring(6));
                try {
                    String dbg = st.nextToken();

                    if (dbg.equals("decay"))
                        _print.print(DecayTaskManager.getInstance().getStats());
                } catch (Exception e) {
                }
            } else if (_usrCommand.startsWith("reload_config")) {
                StringTokenizer st = new StringTokenizer(_usrCommand);
                st.nextToken();

                try {
                    _print.println(L2AutoInitialization.loadConfig(st.nextToken()));
                } catch (Exception e) {
                    _print.println("Usage:  reload_config <" + L2AutoInitialization.getLoaderNames() + ">");
                }
            } else if (_usrCommand.startsWith("reload")) {
                StringTokenizer st = new StringTokenizer(_usrCommand);
                st.nextToken();
                try {
                    String type = st.nextToken();

                    if (type.equals("multisell")) {
                        _print.print("Reloading multisell... ");
                        MultisellTable.getInstance().reload();
                        _print.println("done");
                    } else if (type.equals("teleport")) {
                        _print.print("Reloading teleports... ");
                        TeleportLocationTable.getInstance().reloadAll();
                        _print.println("done");
                    } else if (type.equals("skill")) {
                        _print.print("Reloading skills... ");
                        SkillTable.reload();
                        _print.println("done");
                    } else if (type.equals("npc")) {
                        _print.print("Reloading npc templates... ");
                        NpcTable.getInstance().cleanUp();
                        NpcTable.getInstance().reloadAll();
                        _print.println("done");
                    } else if (type.equals("htm")) {
                        _print.print("Reloading html cache... ");
                        HtmCache.getInstance().reload(true);
                        _print.println("done");
                    } else if (type.equals("item")) {
                        _print.print("Reloading item templates... ");
                        ItemTable.reload();
                        _print.println("done");
                    } else if (type.equals("instancemanager")) {
                        _print.print("Reloading instance managers... ");
                        Manager.reloadAll();
                        _print.println("done");
                    } else if (type.equals("zone")) {
                        _print.print("Reloading zone tables... ");
                        ZoneManager.getInstance().reload();
                        _print.println("done");
                    } else if (type.equals("tradelist")) {
                        _print.print("Reloading trade lists...");
                        TradeListTable.getInstance().reloadAll();
                        _print.println("done");
                    } else if (type.startsWith("door")) {
                        _print.print("Reloading Doors...");
                        DoorTable.getInstance().reloadAll();
                        _print.println("done");
                    } else {
                        _print.println(
                                "Usage: reload <multisell|teleport|skill|npc|htm|item|instancemanager|tradelist|zone|door>");
                    }
                } catch (Exception e) {
                    _print.println(
                            "Usage: reload <multisell|teleport|skill|npc|htm|item|instancemanager|tradelist|zone|door>");
                }
            } else if (_usrCommand.startsWith("gamestat")) {
                StringTokenizer st = new StringTokenizer(_usrCommand.substring(9));
                try {
                    String type = st.nextToken();

                    // name;type;x;y;itemId:enchant:price...
                    if (type.equals("privatestore")) {
                        for (L2Player player : L2World.getInstance().getAllPlayers()) {
                            if (player.getPrivateStoreType() == 0)
                                continue;

                            TradeList list = null;
                            String content = "";

                            if (player.getPrivateStoreType() == 1) // sell
                            {
                                list = player.getSellList();
                                for (TradeItem item : list.getItems()) {
                                    content += item.getItem().getItemId() + ":" + item.getEnchant() + ":"
                                            + item.getPrice() + ":";
                                }
                                content = player.getName() + ";" + "sell;" + player.getX() + ";" + player.getY()
                                        + ";" + content;
                                _print.println(content);
                                continue;
                            } else if (player.getPrivateStoreType() == 3) // buy
                            {
                                list = player.getBuyList();
                                for (TradeItem item : list.getItems()) {
                                    content += item.getItem().getItemId() + ":" + item.getEnchant() + ":"
                                            + item.getPrice() + ":";
                                }
                                content = player.getName() + ";" + "buy;" + player.getX() + ";" + player.getY()
                                        + ";" + content;
                                _print.println(content);
                                continue;
                            }

                        }
                    }
                } catch (Exception e) {
                }
            } else if (_usrCommand.startsWith("extreload")) {
                String[] args = _usrCommand.split("\\s+");
                if (args.length > 1) {
                    for (int i = 1; i < args.length; i++)
                        DynamicExtension.getInstance().reload(args[i]);
                } else {
                    DynamicExtension.getInstance().reload();
                }
            } else if (_usrCommand.startsWith("extinit")) {
                String[] args = _usrCommand.split("\\s+");
                if (args.length > 1) {
                    for (int i = 1; i < args.length; i++)
                        DynamicExtension.getInstance().initExtension(args[i]);
                } else {
                    DynamicExtension.getInstance().initExtensions();
                }
            } else if (_usrCommand.startsWith("extunload")) {
                String[] args = _usrCommand.split("\\s+");
                if (args.length > 1) {
                    for (int i = 1; i < args.length; i++)
                        DynamicExtension.getInstance().unloadExtension(args[i]);
                } else {
                    DynamicExtension.getInstance().unloadExtensions();
                }
            } else if (_usrCommand.startsWith("get")) {
                Object o = null;
                try {
                    String[] args = _usrCommand.substring(3).split("\\s+");
                    if (args.length == 1)
                        o = DynamicExtension.getInstance().get(args[0], null);
                    else
                        o = DynamicExtension.getInstance().get(args[0], args[1]);
                } catch (Exception ex) {
                    _print.println(ex.toString());
                }
                if (o != null)
                    _print.println(o.toString());
            } else if (_usrCommand.length() > 0) {
                try {
                    String[] args = _usrCommand.split("\\s+");
                    if (args.length == 1)
                        DynamicExtension.getInstance().set(args[0], null, null);
                    else if (args.length == 2)
                        DynamicExtension.getInstance().set(args[0], null, args[1]);
                    else
                        DynamicExtension.getInstance().set(args[0], args[1], args[2]);
                } catch (Exception ex) {
                    _print.print(ex.toString());
                }
            } else if (_usrCommand.length() == 0) {
            }
            _print.print("");
            _print.flush();
        }
        if (!_cSocket.isClosed()) {
            _print.println("Bye Bye!");
            _print.flush();
            _cSocket.close();
        }
        telnetOutput(1,
                "Connection from " + _cSocket.getInetAddress().getHostAddress() + " was closed by client.");
    } catch (IOException e) {
        _log.error(e.getMessage(), e);
    }
}

From source file:org.hyperic.hq.agent.server.AgentDaemon.java

/**
 * MONITOR METHOD:  Get the # of active threads
 *///  www  .  j av  a2 s . com
public double getNumActiveThreads() throws AgentMonitorException {
    return Thread.activeCount();
}

From source file:com.gargoylesoftware.htmlunit.WebTestCase.java

/**
 * Gets the active JavaScript threads.//from  www .j a  v a  2 s.  c  om
 * @return the threads
 */
protected List<Thread> getJavaScriptThreads() {
    final Thread[] threads = new Thread[Thread.activeCount() + 10];
    Thread.enumerate(threads);
    final List<Thread> jsThreads = new ArrayList<>();
    for (final Thread t : threads) {
        if (t != null && t.getName().startsWith("JS executor for")) {
            jsThreads.add(t);
        }
    }

    return jsThreads;
}

From source file:org.waarp.openr66.protocol.localhandler.Monitoring.java

/**
 * Update a value in Global MIB part//from  ww w.  ja va2  s. com
 * 
 * @param nbMs
 * @param entry
 */
protected void run(long nbMs, WaarpGlobalValuesIndex entry) {
    synchronized (trafficCounter) {
        long val = 0;
        long limitDate = System.currentTimeMillis() - nbMs;
        if (dbSession == null || dbSession.isDisActive) {
            switch (entry) {
            case applUptime:
                return;
            case applOperStatus:
                return;
            case applLastChange:
                return;
            case applInboundAssociations:
                updateGlobalValue(entry.ordinal(), nbInActiveTransfer);
                return;
            case applOutboundAssociations:
                updateGlobalValue(entry.ordinal(), nbOutActiveTransfer);
                return;
            case applAccumInboundAssociations:
                updateGlobalValue(entry.ordinal(), nbInTotalTransfer);
                return;
            case applAccumOutboundAssociations:
                updateGlobalValue(entry.ordinal(), nbOutTotalTransfer);
                return;
            case applLastInboundActivity:
                val = (lastInActiveTransfer - this.agent.getUptimeSystemTime()) / 10;
                if (val < 0)
                    val = 0;
                updateGlobalValue(entry.ordinal(), val);
                return;
            case applLastOutboundActivity:
                val = (lastOutActiveTransfer - this.agent.getUptimeSystemTime()) / 10;
                if (val < 0)
                    val = 0;
                updateGlobalValue(entry.ordinal(), val);
                return;
            case applRejectedInboundAssociations:
                updateGlobalValue(entry.ordinal(), nbInErrorTransfer);
                return;
            case applFailedOutboundAssociations:
                updateGlobalValue(entry.ordinal(), nbOutErrorTransfer);
                return;
            case applInboundBandwidthKBS:
                val = trafficCounter.lastReadThroughput() >> 10;// B/s -> KB/s
                updateGlobalValue(entry.ordinal(), val);
                return;
            case applOutboundBandwidthKBS:
                val = trafficCounter.lastWriteThroughput() >> 10;
                updateGlobalValue(entry.ordinal(), val);
                return;
            case nbInfoUnknown:
                updateGlobalValue(entry.ordinal(), nbCountInfoUnknown);
                return;
            case nbInfoNotUpdated:
                updateGlobalValue(entry.ordinal(), nbCountInfoNotUpdated);
                return;
            case nbInfoInterrupted:
                updateGlobalValue(entry.ordinal(), nbCountInfoInterrupted);
                return;
            case nbInfoToSubmit:
                nbCountInfoToSubmit = CommanderNoDb.todoList.size();
                updateGlobalValue(entry.ordinal(), nbCountInfoToSubmit);
                return;
            case nbInfoError:
                updateGlobalValue(entry.ordinal(), nbCountInfoError);
                return;
            case nbInfoRunning:
                nbCountInfoRunning = Configuration.configuration.getInternalRunner().nbInternalRunner();
                updateGlobalValue(entry.ordinal(), nbCountInfoRunning);
                return;
            case nbInfoDone:
                updateGlobalValue(entry.ordinal(), nbCountInfoDone);
                return;
            case nbStepAllTransfer:
                updateGlobalValue(entry.ordinal(), nbCountStepAllTransfer);
                return;
            case memoryTotal:
                return;
            case memoryFree:
                return;
            case memoryUsed:
                return;
            case nbThreads:
                nbThread = Thread.activeCount();
                updateGlobalValue(entry.ordinal(), nbThread);
                return;
            case nbNetworkConnection:
                nbNetworkConnection = Configuration.configuration.getHttpChannelGroup().size()
                        + Configuration.configuration.getServerChannelGroup().size();
                updateGlobalValue(entry.ordinal(), nbNetworkConnection);
                return;
            }
            return;
        }
        // Global
        try {
            switch (entry) {
            case applUptime:
                return;
            case applOperStatus:
                return;
            case applLastChange:
                return;
            case applInboundAssociations:
                DbTaskRunner.finishSelectOrCountPrepareStatement(countInActiveTransfer, limitDate);
                nbInActiveTransfer = DbTaskRunner.getResultCountPrepareStatement(countInActiveTransfer);
                updateGlobalValue(entry.ordinal(), nbInActiveTransfer);
                return;
            case applOutboundAssociations:
                DbTaskRunner.finishSelectOrCountPrepareStatement(countOutActiveTransfer, limitDate);
                nbOutActiveTransfer = DbTaskRunner.getResultCountPrepareStatement(countOutActiveTransfer);
                updateGlobalValue(entry.ordinal(), nbOutActiveTransfer);
                return;
            case applAccumInboundAssociations:
                DbTaskRunner.finishSelectOrCountPrepareStatement(countInTotalTransfer, limitDate);
                nbInTotalTransfer = DbTaskRunner.getResultCountPrepareStatement(countInTotalTransfer);
                updateGlobalValue(entry.ordinal(), nbInTotalTransfer);
                return;
            case applAccumOutboundAssociations:
                DbTaskRunner.finishSelectOrCountPrepareStatement(countOutTotalTransfer, limitDate);
                nbOutTotalTransfer = DbTaskRunner.getResultCountPrepareStatement(countOutTotalTransfer);
                updateGlobalValue(entry.ordinal(), nbOutTotalTransfer);
                return;
            case applLastInboundActivity:
                val = (lastInActiveTransfer - this.agent.getUptimeSystemTime()) / 10;
                if (val < 0)
                    val = 0;
                updateGlobalValue(entry.ordinal(), val);
                return;
            case applLastOutboundActivity:
                val = (lastOutActiveTransfer - this.agent.getUptimeSystemTime()) / 10;
                if (val < 0)
                    val = 0;
                updateGlobalValue(entry.ordinal(), val);
                return;
            case applRejectedInboundAssociations:
                DbTaskRunner.finishSelectOrCountPrepareStatement(countInErrorTransfer, limitDate);
                nbInErrorTransfer = DbTaskRunner.getResultCountPrepareStatement(countInErrorTransfer);
                updateGlobalValue(entry.ordinal(), nbInErrorTransfer);
                return;
            case applFailedOutboundAssociations:
                DbTaskRunner.finishSelectOrCountPrepareStatement(countOutErrorTransfer, limitDate);
                nbOutErrorTransfer = DbTaskRunner.getResultCountPrepareStatement(countOutErrorTransfer);
                updateGlobalValue(entry.ordinal(), nbOutErrorTransfer);
                return;
            case applInboundBandwidthKBS:
                val = trafficCounter.lastReadThroughput() >> 10;// B/s -> KB/s
                updateGlobalValue(entry.ordinal(), val);
                return;
            case applOutboundBandwidthKBS:
                val = trafficCounter.lastWriteThroughput() >> 10;
                updateGlobalValue(entry.ordinal(), val);
                return;
            case nbInfoUnknown:
                nbCountInfoUnknown = DbTaskRunner.getResultCountPrepareStatement(countInfo, UpdatedInfo.UNKNOWN,
                        limitDate);
                updateGlobalValue(entry.ordinal(), nbCountInfoUnknown);
                return;
            case nbInfoNotUpdated:
                nbCountInfoNotUpdated = DbTaskRunner.getResultCountPrepareStatement(countInfo,
                        UpdatedInfo.NOTUPDATED, limitDate);
                updateGlobalValue(entry.ordinal(), nbCountInfoNotUpdated);
                return;
            case nbInfoInterrupted:
                nbCountInfoInterrupted = DbTaskRunner.getResultCountPrepareStatement(countInfo,
                        UpdatedInfo.INTERRUPTED, limitDate);
                updateGlobalValue(entry.ordinal(), nbCountInfoInterrupted);
                return;
            case nbInfoToSubmit:
                nbCountInfoToSubmit = DbTaskRunner.getResultCountPrepareStatement(countInfo,
                        UpdatedInfo.TOSUBMIT, limitDate);
                updateGlobalValue(entry.ordinal(), nbCountInfoToSubmit);
                return;
            case nbInfoError:
                nbCountInfoError = DbTaskRunner.getResultCountPrepareStatement(countInfo, UpdatedInfo.INERROR,
                        limitDate);
                updateGlobalValue(entry.ordinal(), nbCountInfoError);
                return;
            case nbInfoRunning:
                nbCountInfoRunning = DbTaskRunner.getResultCountPrepareStatement(countInfo, UpdatedInfo.RUNNING,
                        limitDate);
                updateGlobalValue(entry.ordinal(), nbCountInfoRunning);
                return;
            case nbInfoDone:
                nbCountInfoDone = DbTaskRunner.getResultCountPrepareStatement(countInfo, UpdatedInfo.DONE,
                        limitDate);
                updateGlobalValue(entry.ordinal(), nbCountInfoDone);
                return;
            case nbStepAllTransfer:
                DbTaskRunner.finishSelectOrCountPrepareStatement(countStepAllTransfer, limitDate);
                nbCountStepAllTransfer = DbTaskRunner.getResultCountPrepareStatement(countStepAllTransfer);
                updateGlobalValue(entry.ordinal(), nbCountStepAllTransfer);
                return;
            case memoryTotal:
                return;
            case memoryFree:
                return;
            case memoryUsed:
                return;
            case nbThreads:
                nbThread = Thread.activeCount();
                updateGlobalValue(entry.ordinal(), nbThread);
                return;
            case nbNetworkConnection:
                nbNetworkConnection = DbAdmin.getNbConnection();
                updateGlobalValue(entry.ordinal(), nbNetworkConnection);
                return;
            }
        } catch (WaarpDatabaseNoConnectionException e) {
        } catch (WaarpDatabaseSqlException e) {
        }
    }
}

From source file:ECallCenter21.java

/**
 *
 *//*from  ww  w .  j a v  a2s . co m*/
public void timedSystemStatsUpdate() {
    Thread timedSystemStatsUpdateThread = new Thread(allThreadsGroup, new Runnable() {
        @Override
        @SuppressWarnings("static-access")
        public void run() {
            String[] status = new String[2];
            // Get CustomerOrder in case of any runtime changes like a changed soundfile
            if ((campaign != null) && (order != null) && (boundMode.equals("Outbound"))
                    && (callCenterStatus == RUNNING)) {
                order = dbClient.selectCustomerOrder(campaign.getOrderId());
                if (lastMessageDuration != order.getMessageDuration()) {
                    soundFileToStream = order.getMessageFilename();
                    filename = "file:" + soundFileToStream;
                    // Make sure the callSpeedSlider adapts to the message length in relation to the Call / Message Duration when message is longer than 10 seconds
                    if (Math.round(
                            order.getMessageDuration() * 100) < (eCallCenterGUI.callSpeedSlider.getMinimum())) // Soundfile results below minimum
                    {
                        eCallCenterGUI.callSpeedSlider.setMaximum(eCallCenterGUI.callSpeedSlider.getMinimum());
                    } else {
                        eCallCenterGUI.callSpeedSlider.setMaximum(order.getMessageDuration() * 50);
                        eCallCenterGUI.callSpeedSlider
                                .setMajorTickSpacing(Math.round((eCallCenterGUI.callSpeedSlider.getMaximum()
                                        - eCallCenterGUI.callSpeedSlider.getMinimum()) / 10));
                        eCallCenterGUI.callSpeedSlider.setPaintLabels(true);
                    }
                    callSpeedInterval = Math.round(eCallCenterGUI.callSpeedSlider.getMaximum() / 2);
                    callSpeedSlider.setValue(callSpeedInterval);
                    lastMessageDuration = order.getMessageDuration();
                }
            }

            memFree = sysMonitor.getPhysMem();
            systemStatsTable.setValueAt(Long.toString(memFree), 2, 1);

            heapMemMax = (Runtime.getRuntime().maxMemory() / (1024 * 1024));
            systemStatsTable.setValueAt(Long.toString(heapMemMax), 3, 1); // KB
            heapMemTot = (Runtime.getRuntime().totalMemory() / (1024 * 1024));
            systemStatsTable.setValueAt(Long.toString(heapMemTot), 4, 1); // KB
            heapMemFree = (Runtime.getRuntime().freeMemory() / (1024 * 1024));
            systemStatsTable.setValueAt(Long.toString(heapMemFree), 5, 1); // KB
            systemStatsTable.setValueAt(Thread.activeCount(), 1, 1);

            // Display time / performance facts
            currentTimeCalendar = Calendar.getInstance(nlLocale);
            difRegStartExpEndCalendar = Calendar.getInstance(nlLocale);
            difRegStartCurTimeCalendar = Calendar.getInstance(nlLocale);
            difCurTimeExpEndCalendar = Calendar.getInstance(nlLocale);

            if ((outboundCallsInProgress) && (campaignStat.getCallingTT() > 0)) {

                // Set & Display the ExpectedEnd timestamp in human readable format
                //                    campaign.setCalendarExpectedEnd(TimeWindow.getEstimatedEndCalendar(Calendar.getInstance(), order, throughputFactor, destination.getDestinationCount())); // The new way
                campaign.setCalendarExpectedEnd(timeTool.getEstimatedEndCalendar(Calendar.getInstance(), order,
                        throughputFactor, destination.getDestinationCount(), order.getTimewindowIndexArray())); // The new way
                dbClient.updateCampaign(campaign);

                difRegStartExpEndCalendar.setTimeInMillis(campaign.getCalendarExpectedEnd().getTimeInMillis()
                        - campaign.getCalendarRegisteredStart().getTimeInMillis());
                difRegStartCurTimeCalendar.setTimeInMillis(currentTimeCalendar.getTimeInMillis()
                        - campaign.getCalendarRegisteredStart().getTimeInMillis());
                difCurTimeExpEndCalendar.setTimeInMillis(campaign.getCalendarExpectedEnd().getTimeInMillis()
                        - currentTimeCalendar.getTimeInMillis());

                // Sets the End Expected Timestamp
                campaignTable.setValueAt(
                        String.format("%04d", campaign.getCalendarExpectedEnd().get(Calendar.YEAR)) + "-"
                                + String.format("%02d",
                                        campaign.getCalendarExpectedEnd().get(Calendar.MONTH) + 1)
                                + "-"
                                + String.format(
                                        "%02d", campaign.getCalendarExpectedEnd().get(Calendar.DAY_OF_MONTH))
                                + " "
                                + String.format("%02d",
                                        campaign.getCalendarExpectedEnd().get(Calendar.HOUR_OF_DAY))
                                + ":"
                                + String.format("%02d", campaign.getCalendarExpectedEnd().get(Calendar.MINUTE))
                                + ":"
                                + String.format("%02d", campaign.getCalendarExpectedEnd().get(Calendar.SECOND)),
                        3, 1);

                // Sets the Past / Elapsed Campaign Time
                campaignTable.setValueAt(
                        String.format("%04d", difRegStartExpEndCalendar.get(Calendar.YEAR) - 1970) + "-"
                                + String.format("%02d", difRegStartExpEndCalendar.get(Calendar.MONTH)) + "-"
                                + String.format("%02d",
                                        difRegStartExpEndCalendar.get(Calendar.DAY_OF_MONTH) - 1)
                                + " "
                                + String.format("%02d", difRegStartExpEndCalendar.get(Calendar.HOUR_OF_DAY) - 1)
                                + ":" + String.format("%02d", difRegStartExpEndCalendar.get(Calendar.MINUTE))
                                + ":" + String.format("%02d", difRegStartExpEndCalendar.get(Calendar.SECOND)),
                        6, 1);

                // Sets the Campaign Ending Countdown Time (ETA)
                campaignTable.setValueAt(String.format("%04d",
                        difRegStartCurTimeCalendar.get(Calendar.YEAR) - 1970) + "-"
                        + String.format("%02d", difRegStartCurTimeCalendar.get(Calendar.MONTH)) + "-"
                        + String.format("%02d", difRegStartCurTimeCalendar.get(Calendar.DAY_OF_MONTH) - 1) + " "
                        + String.format("%02d", difRegStartCurTimeCalendar.get(Calendar.HOUR_OF_DAY) - 1) + ":"
                        + String.format("%02d", difRegStartCurTimeCalendar.get(Calendar.MINUTE)) + ":"
                        + String.format("%02d", difRegStartCurTimeCalendar.get(Calendar.SECOND)), 7, 1);

                campaignTable.setValueAt(
                        String.format("%04d", difCurTimeExpEndCalendar.get(Calendar.YEAR) - 1970) + "-"
                                + String.format("%02d", difCurTimeExpEndCalendar.get(Calendar.MONTH)) + "-"
                                + String.format("%02d", difCurTimeExpEndCalendar.get(Calendar.DAY_OF_MONTH) - 1)
                                + " "
                                + String.format("%02d", difCurTimeExpEndCalendar.get(Calendar.HOUR_OF_DAY) - 1)
                                + ":" + String.format("%02d", difCurTimeExpEndCalendar.get(Calendar.MINUTE))
                                + ":" + String.format("%02d", difCurTimeExpEndCalendar.get(Calendar.SECOND)),
                        8, 1);

                dbClient.updateCampaign(campaign);
            }

            // Display PieGraph & Update CampaignStat
            if ((callCenterIsOutBound) && (callRatioChartData != null) && (callRatioChart != null)
                    && (dbClient != null)
                    && ((callCenterStatus == RUNNING) || (callCenterStatus == RERUNBREAK))) {
                callRatioChartData.setValue("Connecting",
                        (campaignStat.getConnectingTT() - campaignStat.getTryingTT()));
                callRatioChartData.setValue("Trying",
                        (campaignStat.getTryingTT() - campaignStat.getCallingTT()));
                callRatioChartData.setValue("Busy", campaignStat.getRemoteBusyTT());
                callRatioChartData.setValue("Success", campaignStat.getTalkingTT());
                callRatioChart.setTitle("Call Ratio");

                // Store the CampaignStats in database
                dbClient.updateCampaignStat(campaignStat);
            }

            // Only in correct TimeWindow
            //                if ( order != null)
            //                {
            //                    if ((callCenterIsNetManaged) && (callCenterIsOutBound) && (!TimeWindow.getCurrentTimeWindow().equals(order.getTimeWindowCategory())))
            //                    {
            //                        showStatus          (License.PRODUCT + " Shutdown: Running outside " + order.getTimeWindowCategory(), true, true);
            //                        try { Thread.sleep(5000); } catch (InterruptedException ex) { }
            //                        System.exit(0);
            //                    }
            //                }

            if (order != null) {
                boolean legalTimeWindow = false;
                for (int orderTimewindow : order.getTimewindowIndexArray()) {
                    if (orderTimewindow == timeTool.getCurrentTimeWindowIndex()) {
                        legalTimeWindow = true;
                    }
                }

                if (!legalTimeWindow) {
                    showStatus("Self Destructing: " + Vergunning.PRODUCT + " running outside TimeWindow !",
                            true, true);
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException ex) {
                    }
                    System.exit(0);
                }
            }

            // Management Server Heartbeat (Manager heartbeat Lost)
            if (callCenterIsNetManaged) {
                //Exit if no management signal is received in time
                if (selfDestructCounter == 0) {
                    showStatus(Vergunning.PRODUCT + " Shutdown: Management Heartbeat Lost", true, true);
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException ex) {
                    }
                    System.exit(0);
                }

                if (selfDestructCounter > 0) {
                    selfDestructCounter--;
                }
                if (selfDestructCounter < (selfDestructCounterLimit - 2)) // Warning and Restart
                {
                    if (!callCenterIsOutBound) {
                        if (!isRegistering) {
                            showStatus("Restarting Inbound Management Server", true, true);
                            enableInboundNetManagerServer(false);
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException ex) {
                            }
                            enableInboundNetManagerServer(true);
                        }
                    } else// if (getCallCenterStatus() == RUNNING)
                    {
                        showStatus("Restarting Outbound Management Server", true, true);
                        enableOutboundNetManagerServer(false);
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException ex) {
                        }
                        enableOutboundNetManagerServer(true);
                    }
                } else {
                    if (!callCenterIsOutBound) {
                        netManagerInboundServerToggleButton.setForeground(Color.BLACK);
                    } else {
                        netManagerOutboundServerToggleButton.setForeground(Color.BLACK);
                    }
                }
            }
        } // Run
    }); // Thread
    timedSystemStatsUpdateThread.setName("timedSystemStatsUpdateThread");
    timedSystemStatsUpdateThread.setDaemon(runThreadsAsDaemons);
    timedSystemStatsUpdateThread.start();
}