Search in sources :

Example 6 with Agent

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++;
}
Also used : Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent)

Example 7 with Agent

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
    }
}
Also used : Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent)

Example 8 with Agent

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);
    }
}
Also used : Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent) CommBroker(com.sun.messaging.jmq.jmsserver.comm.CommBroker) BrokerEvent(com.sun.messaging.jmq.jmsservice.BrokerEvent)

Example 9 with Agent

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;
}
Also used : Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent) MBeanException(javax.management.MBeanException)

Example 10 with Agent

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);
}
Also used : Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException)

Aggregations

Agent (com.sun.messaging.jmq.jmsserver.management.agent.Agent)23 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)6 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)3 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)3 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)3 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)3 CacheHashMap (com.sun.messaging.jmq.util.CacheHashMap)3 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)2 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)2 BaseTransaction (com.sun.messaging.jmq.jmsserver.data.BaseTransaction)2 LocalTransaction (com.sun.messaging.jmq.jmsserver.data.LocalTransaction)2 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)2 BrokerDownException (com.sun.messaging.jmq.jmsserver.util.BrokerDownException)2 MaxConsecutiveRollbackException (com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException)2