Commit 40f693a8 authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Add stuff to allow JoramMQ 1.14 compilation.

parent 4c30b913
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2020 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package fr.dyade.aaa.common;
import java.lang.management.ManagementFactory;
import java.util.Timer;
import java.util.TimerTask;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
/**
* This class computes the average CPU use by a thread during last minute.
*/
public final class AverageCPUTask extends TimerTask {
/** logger */
private Logger logger;
long[] cpuTime;
int idx;
int nb;
/** the thread ID of the monitored thread */
private long id;
/** the thread name of the monitored thread */
private String name;
private int average;
public int getAverage() {
return average;
}
/**
* Creates a task that periodically computes the thread load.
*
* @param id thread ID of the monitored thread
* @param nb number of refresh per minute
*/
public AverageCPUTask(long id, int nb) {
this.id = id;
this.name = ManagementFactory.getThreadMXBean().getThreadInfo(id).getThreadName();
logger = Debug.getLogger(AverageCPUTask.class.getName() + '.' + name);
this.nb = nb;
this.cpuTime = new long[nb];
this.idx = 0;
}
/**
* @see java.util.TimerTask#run()
*/
@Override
public void run() {
try {
// Collects the current CPU time.
cpuTime[idx%nb] = ManagementFactory.getThreadMXBean().getThreadCpuTime(id);
// Computes the CPU time used during last minute
average = (int) ((cpuTime[idx%nb] - cpuTime[(idx+1)%nb]) / ((60L *1000000000L) / 100L));
logger.log(BasicLevel.INFO,
"AverageCPUTask: " + name + " CPU Time: " + cpuTime[idx%nb] + "ns -> " + average);
idx += 1;
} catch (Throwable t) {
logger.log(BasicLevel.WARN, "AverageCPUTask.run", t);
}
}
/**
* Starts the resulting task.
*
* @param timer Timer to use to schedule the resulting task.
*/
public void start(Timer timer) {
long period = 60000L / nb;
timer.scheduleAtFixedRate(this, period, period);
}
}
......@@ -218,4 +218,8 @@ public interface AgentEngine extends MessageConsumer {
*/
boolean isNoTxIfTransient();
/**
* Increments the tick counter that reflects activity in server.
*/
void incWorkInProgress();
}
/*
* Copyright (C) 2001 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2020 ScalAgent Distributed Technologies
* Copyright (C) 1996 - 2000 BULL
* Copyright (C) 1996 - 2000 INRIA
*
......@@ -29,6 +29,7 @@ import java.util.Vector;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import fr.dyade.aaa.common.AverageCPUTask;
import fr.dyade.aaa.common.AverageLoadTask;
import fr.dyade.aaa.common.Queue;
......@@ -1041,6 +1042,9 @@ class Engine implements Runnable, AgentEngine, EngineMBean {
long end = 0L;
boolean profiling = false;
averageCPUTask = new AverageCPUTask(Thread.currentThread().getId(), 12);
averageCPUTask.start(AgentServer.getTimer());
main_loop:
while (isRunning) {
agent = null;
......@@ -1060,6 +1064,9 @@ class Engine implements Runnable, AgentEngine, EngineMBean {
canStop = false;
if (! isRunning) break;
// Increment workInProgress counter to indicate that the engine is working.
incWorkInProgress();
if ((msg.from == null) || (msg.to == null) || (msg.not == null)) {
// The notification is malformed.
logmon.log(BasicLevel.ERROR,
......@@ -1327,9 +1334,45 @@ class Engine implements Runnable, AgentEngine, EngineMBean {
AgentServer.getTransaction().release();
}
/** the tick counter that reflects activity in engine. */
long workInProgress = 0L;
/**
* Returns the tick counter that reflects activity in engine.
* @return the tick counter that reflects activity in engine.
*/
@Override
public final long getWorkInProgress() {
return workInProgress;
}
/**
* Increments the tick counter that reflects activity in engine.
* @see #workInProgress
*/
@Override
public final void incWorkInProgress() {
workInProgress++;
}
/** The average use of CPU by the Engine thread during last minute. */
AverageCPUTask averageCPUTask = null;
/**
* Returns the average use of CPU by the Engine thread during last minute.
*
* @return the average use of CPU by the Engine thread during last minute.
*/
@Override
public final int getAverageCPU() {
if (averageCPUTask != null)
return averageCPUTask.getAverage();
return 0;
}
EngineAverageLoadTask averageLoadTask = null;
public void resetAverageLoad() {
public final void resetAverageLoad() {
if (averageLoadTask != null)
averageLoadTask.reset();
}
......@@ -1338,7 +1381,8 @@ class Engine implements Runnable, AgentEngine, EngineMBean {
* Returns the load averages for the last minute.
* @return the load averages for the last minute.
*/
public float getAverageLoad1() {
@Override
public final float getAverageLoad1() {
return averageLoadTask.getAverageLoad1();
}
......@@ -1346,7 +1390,8 @@ class Engine implements Runnable, AgentEngine, EngineMBean {
* Returns the load averages for the past 5 minutes.
* @return the load averages for the past 5 minutes.
*/
public float getAverageLoad5() {
@Override
public final float getAverageLoad5() {
return averageLoadTask.getAverageLoad5();
}
......@@ -1354,7 +1399,8 @@ class Engine implements Runnable, AgentEngine, EngineMBean {
* Returns the load averages for the past 15 minutes.
* @return the load averages for the past 15 minutes.
*/
public float getAverageLoad15() {
@Override
public final float getAverageLoad15() {
return averageLoadTask.getAverageLoad15();
}
......
......@@ -141,6 +141,19 @@ public interface EngineMBean {
*/
public void resetTimer();
/**
* Returns the tick counter that reflects activity in engine.
* @return the tick counter that reflects activity in engine.
*/
public long getWorkInProgress();
/**
* Returns the average use of CPU by the Engine thread during last minute.
*
* @return the average use of CPU by the Engine thread during last minute.
*/
public int getAverageCPU();
/**
* Returns the load averages for the last minute.
* @return the load averages for the last minute.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment