use of com.sun.messaging.jmq.jmsserver.management.agent.Agent in project openmq by eclipse-ee4j.
the class MemoryManager method checkMemoryState.
public void checkMemoryState() {
if (turnOffMemory || !active) {
return;
}
if (DEBUG) {
logger.log(Logger.DEBUG, "checkMemoryState " + memoryCheckCount);
}
boolean notify = false;
int oldLevel = 0;
int newState = 0;
synchronized (stateChangeLock) {
newState = calculateState();
oldLevel = currentLevel;
currentLevel = newState;
}
MemoryLevelHandler currentHandler = levelHandlers[oldLevel];
if (newState != oldLevel) {
MemoryLevelHandler newHandler = levelHandlers[newState];
if (newState > oldLevel) {
// entered new state
gc(newHandler.gcCount());
newState = calculateState();
}
for (int i = oldLevel; i < newState; i++) {
// higher
notify = levelHandlers[i + 1].enter(false);
notify |= levelHandlers[i].leave(true);
}
for (int i = oldLevel; i > newState; i--) {
// lower
notify |= levelHandlers[i - 1].enter(true);
notify |= levelHandlers[i].leave(false);
}
newHandler = levelHandlers[newState];
// update variables
synchronized (valuesObjectLock) {
JMQSizeValue = newHandler.getMessageCount(availMemory, producerCount);
JMQBytesValue = newHandler.getMemory(availMemory, producerCount);
}
if (notify) {
notifyAllOfStateChange(true);
}
currentLevel = newState;
if (newState > oldLevel) {
// cleanup
completedRunningCleanup = false;
cleanupCnt = 0;
completedRunningCleanup = levelHandlers[newState].cleanup(cleanupCnt++);
} else if (newState < oldLevel) {
completedRunningCleanup = true;
cleanupCnt = 0;
}
if (newState != oldLevel) {
String[] args = { levelHandlers[newState].localizedLevelName(), levelHandlers[oldLevel].localizedLevelName(), String.valueOf((allocatedMemory / 1024)), String.valueOf((allocatedMemory * 100 / maxAvailableMemory)) };
logger.log(Logger.INFO, BrokerResources.I_CHANGE_OF_MEMORY_STATE, args);
Agent agent = Globals.getAgent();
if (agent != null) {
agent.notifyResourceStateChange(levelHandlers[oldLevel].localizedLevelName(), levelHandlers[newState].localizedLevelName(), null);
}
currentLevel = newState;
currentHandler = newHandler;
// diags
currentLevelString = currentHandler.levelName();
synchronized (timerObjectLock) {
// set new timer
if (mytimer != null) {
mytimer.cancel();
mytimer = null;
}
mytimer = new MyTimerTask();
long time = currentHandler.getTimeBetweenChecks();
try {
Globals.getTimer(true).schedule(mytimer, time, time);
} catch (IllegalStateException ex) {
logger.log(Logger.DEBUG, "Timer canceled ", ex);
}
}
}
} else {
if (!completedRunningCleanup) {
completedRunningCleanup = levelHandlers[oldLevel].cleanup(cleanupCnt++);
}
// periodically perform gcs on some iterations
if (currentHandler.gcIteration() != 0 && memoryCheckCount % currentHandler.gcIteration() == 0) {
gc();
}
// update variables
synchronized (valuesObjectLock) {
JMQSizeValue = currentHandler.getMessageCount(availMemory, producerCount);
JMQBytesValue = currentHandler.getMemory(availMemory, producerCount);
}
if (JMQSizeValue > 0) {
checkAndNotifyPaused();
}
}
if (allocatedMemory > highestMemUsage) {
highestMemUsage = allocatedMemory;
}
// XXX racer revisit
// we may not want to calculate this on each call
averageMemUsage = ((averageMemUsage * memoryCheckCount) + allocatedMemory) / (memoryCheckCount + 1);
memoryCheckCount++;
}
use of com.sun.messaging.jmq.jmsserver.management.agent.Agent in project openmq by eclipse-ee4j.
the class ServiceManager method pauseService.
/**
* Pause a service by name either stoping just new connections or stopping all interaction
*/
public void pauseService(String servicename, boolean pause_all) throws BrokerException {
ServiceInfo info = (ServiceInfo) services.get(servicename);
if (info != null) {
info.pause(pause_all);
setServiceStateProp(servicename, ServiceState.PAUSED);
Agent agent = Globals.getAgent();
if (agent != null) {
agent.notifyServicePause(servicename);
}
} else {
// handle error
}
}
use of com.sun.messaging.jmq.jmsserver.management.agent.Agent in project openmq by eclipse-ee4j.
the class Broker method destroyBroker.
/**
* Shutdown the broker but don't exit the JVM
*
* @param cleanup Set to true if unused resources should be freed. Should be set to true if the JVM will be left
* running. May be set to false if we intend to exit the JVM later
*/
public static void destroyBroker(boolean cleanup, boolean triggerFailover) {
// we want to cleanup all the statics
if (broker == null) {
return;
}
Object tmp = broker;
if (Globals.getBrokerStateHandler() != null) {
Globals.getBrokerStateHandler().initiateShutdown("BrokerProcess", 0, triggerFailover, 0, false, false, true);
}
if (cleanup) {
BrokerMonitor.shutdownMonitor();
Globals.getCoreLifecycle().cleanup();
LockFile.clearLock();
TLSProtocol.destroy();
// stop JMX connectors
Agent agent = Globals.getAgent();
if (agent != null) {
agent.stop();
agent.unloadMBeans();
}
PortMapper pm = Globals.getPortMapper();
if (pm != null) {
pm.destroy();
}
Globals.cleanup();
synchronized (Broker.class) {
broker = null;
}
}
if (bkrEvtListener != null) {
// L10N-XXX
BrokerEvent event = new BrokerEvent(tmp, BrokerEvent.Type.SHUTDOWN, "Broker has been shutdown");
bkrEvtListener.brokerEvent(event);
setBrokerEventListener(null);
}
}
use of com.sun.messaging.jmq.jmsserver.management.agent.Agent in project openmq by eclipse-ee4j.
the class BrokerConfig method update.
@Override
public boolean update(String name, String value) {
Object newVal = null;
Object oldVal = null;
if (name.equals("imq.portmapper.port")) {
try {
newVal = Integer.valueOf(value);
} catch (NumberFormatException nfe) {
logger.log(Logger.WARNING, "BrokerConfig MBean: cannot parse internal value of Port: " + nfe);
newVal = null;
}
try {
oldVal = getPort();
} catch (MBeanException mbe) {
/*
* A warning message will be logged by getters on error
*/
}
notifyAttrChange(BrokerAttributes.PORT, newVal, oldVal);
Agent agent = Globals.getAgent();
if (agent != null) {
agent.portMapperPortUpdated((Integer) oldVal, (Integer) newVal);
}
}
initProps();
return true;
}
use of com.sun.messaging.jmq.jmsserver.management.agent.Agent in project openmq by eclipse-ee4j.
the class JMSServiceImpl method createDirectConnection.
private IMQConnection createDirectConnection(String username, String password) throws BrokerException {
IMQDirectConnection con = null;
// System.err.println("#### CREATE DIRECT CXN: username: " +username+", passwd: "+password);
con = new IMQDirectConnection(service);
connectionList.addConnection(con);
localConnectionList.put(con.getConnectionUID(), con);
try {
con.authenticate(username, password);
con.setClientProtocolVersion(con.getHighestSupportedProtocol());
// System.err.println("#### CREATE DIRECT CXN: AUTH SUCCESSFULL");
// System.err.println("#### DIRECT CXN authenticated name: " + con.getAuthenticatedName());
} catch (Exception e) {
e.printStackTrace();
String errStr = "Authentication failed for username " + username + " in service " + service.getName() + ": " + e;
logger.log(Logger.WARNING, errStr);
logger.log(Logger.WARNING, BrokerResources.W_LOGIN_FAILED, e);
connectionList.removeConnection(con.getConnectionUID(), true, GoodbyeReason.CON_FATAL_ERROR, errStr);
localConnectionList.remove(con.getConnectionUID());
throw new BrokerException(errStr, BrokerResources.X_FORBIDDEN, e, Status.FORBIDDEN);
}
Agent agent = Globals.getAgent();
if (agent != null) {
agent.registerConnection(con.getConnectionUID().longValue());
agent.notifyConnectionOpen(con.getConnectionUID().longValue());
}
return (con);
}
Aggregations