Search in sources :

Example 11 with IMQConnection

use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.

the class ConnectionUtil method getConnectionInfo.

/**
 * Returns the ConnectionInfo for the passed connection ID.
 */
public static ConnectionInfo getConnectionInfo(long id) {
    ConnectionManager cm = Globals.getConnectionManager();
    ConnectionInfo cxnInfo = null;
    IMQConnection cxn = null;
    cxn = (IMQConnection) cm.getConnection(new ConnectionUID(id));
    if (cxn == null) {
        return (null);
    }
    cxnInfo = cxn.getConnectionInfo();
    return (cxnInfo);
}
Also used : ConnectionManager(com.sun.messaging.jmq.jmsserver.service.ConnectionManager) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) ConnectionInfo(com.sun.messaging.jmq.util.admin.ConnectionInfo)

Example 12 with IMQConnection

use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.

the class ConnectionUtil method getConsumerIDs.

public static List getConsumerIDs(long cxnId) {
    ConnectionManager cm = Globals.getConnectionManager();
    IMQConnection cxn = null;
    List consumerIDs;
    cxn = (IMQConnection) cm.getConnection(new ConnectionUID(cxnId));
    consumerIDs = cxn.getConsumersIDs();
    return (consumerIDs);
}
Also used : ConnectionManager(com.sun.messaging.jmq.jmsserver.service.ConnectionManager) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) List(java.util.List) ArrayList(java.util.ArrayList) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID)

Example 13 with IMQConnection

use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.

the class ConsumerInfoNotifyManager method run.

@Override
public void run() {
    ArrayList pendingEvents = new ArrayList();
    while (!shutdown) {
        boolean dowait = true;
        List list = null;
        synchronized (eventQueue) {
            list = new ArrayList(eventQueue);
        }
        if (list.size() > 0 && pendingEvents.size() > 0) {
            Iterator itr = list.iterator();
            Object e = null;
            while (itr.hasNext()) {
                e = itr.next();
                if (!pendingEvents.contains(e)) {
                    dowait = false;
                    break;
                }
            }
        } else if (pendingEvents.size() == 0) {
            dowait = eventQueue.isEmpty();
        }
        synchronized (this) {
            if (dowait || eventQueue.isEmpty()) {
                try {
                    wait();
                } catch (InterruptedException inte) {
                }
            }
        }
        if (shutdown) {
            return;
        }
        HashMap notifications = new HashMap();
        Object[] events = eventQueue.toArray();
        Object o = null;
        for (int i = 0; i < events.length && !shutdown; i++) {
            o = events[i];
            if (DEBUG) {
                logger.log(logger.INFO, "Processing " + o);
            }
            if (o instanceof ConsumerAddedEvent) {
                ConsumerAddedEvent e = (ConsumerAddedEvent) o;
                IMQConnection conn = (IMQConnection) cm.getConnection(e.connid);
                if (e.dest.getAllActiveConsumerCount() > 0) {
                    if (conn == null || conn.isConnectionStarted()) {
                        notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_READY));
                    } else {
                        pendingEvents.add(o);
                        continue;
                    }
                } else {
                    notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_NOT_READY));
                }
                eventQueue.remove(o);
                pendingEvents.remove(o);
                continue;
            }
            if (o instanceof RemoteConsumerAddedEvent) {
                RemoteConsumerAddedEvent e = (RemoteConsumerAddedEvent) o;
                if (e.dest.getAllActiveConsumerCount() > 0) {
                    notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_READY));
                } else {
                    notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_NOT_READY));
                }
                eventQueue.remove(o);
                continue;
            }
            if (o instanceof ConsumerRemovedEvent) {
                ConsumerRemovedEvent e = (ConsumerRemovedEvent) o;
                if (e.dest.getAllActiveConsumerCount() == 0) {
                    notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_NOT_READY));
                }
                eventQueue.remove(o);
                continue;
            }
            if (o instanceof ConnectionStartedEvent) {
                ConnectionStartedEvent e = (ConnectionStartedEvent) o;
                for (int j = 0; j < events.length && !shutdown; j++) {
                    Object oo = events[j];
                    if (oo instanceof ConsumerAddedEvent) {
                        ConsumerAddedEvent ee = (ConsumerAddedEvent) oo;
                        IMQConnection conn = (IMQConnection) cm.getConnection(ee.connid);
                        if (conn != null && conn == e.conn && ee.dest.getAllActiveConsumerCount() > 0) {
                            notifications.put(ee.dest.getDestinationUID(), new ConsumerInfoNotification(ee.dest.getDestinationUID(), ee.dest.getType(), CONSUMER_READY));
                            pendingEvents.remove(ee);
                        }
                    }
                }
                eventQueue.remove(e);
                continue;
            }
            if (o instanceof ConsumerInfoRequestEvent) {
                boolean foundmatch = false;
                boolean hasconsumer = false;
                boolean notifyadded = false;
                ConsumerInfoRequestEvent e = (ConsumerInfoRequestEvent) o;
                Iterator[] itrs = DestinationList.getAllDestinations(null);
                // PART
                Iterator itr = itrs[0];
                while (itr.hasNext()) {
                    Destination d = (Destination) itr.next();
                    if (d.isInternal()) {
                        continue;
                    }
                    if ((!e.duid.isWildcard() && d.getDestinationUID().equals(e.duid))) {
                        foundmatch = true;
                        if (d.getAllActiveConsumerCount() == 0) {
                            notifications.put(d.getDestinationUID(), new ConsumerInfoNotification(d.getDestinationUID(), d.getType(), CONSUMER_NOT_READY, ((ConsumerInfoRequestEvent) o).infoType, true));
                            notifyadded = true;
                            break;
                        }
                        hasconsumer = true;
                        Iterator itrr = d.getAllActiveConsumers().iterator();
                        while (itrr.hasNext()) {
                            Consumer c = (Consumer) itrr.next();
                            IMQConnection conn = (IMQConnection) cm.getConnection(c.getConnectionUID());
                            BrokerAddress ba = c.getConsumerUID().getBrokerAddress();
                            if ((conn != null && conn.isConnectionStarted()) || (ba != null && ba != Globals.getMyAddress())) {
                                notifications.put(d.getDestinationUID(), new ConsumerInfoNotification(d.getDestinationUID(), d.getType(), CONSUMER_READY, ((ConsumerInfoRequestEvent) o).infoType, true));
                                notifyadded = true;
                                break;
                            }
                        }
                        break;
                    }
                    if (e.duid.isWildcard() && DestinationUID.match(d.getDestinationUID(), e.duid)) {
                        foundmatch = true;
                        if (d.getAllActiveConsumerCount() == 0) {
                            continue;
                        }
                        hasconsumer = true;
                        Iterator itrr = d.getAllActiveConsumers().iterator();
                        while (itrr.hasNext()) {
                            Consumer c = (Consumer) itrr.next();
                            IMQConnection conn = (IMQConnection) cm.getConnection(c.getConnectionUID());
                            BrokerAddress ba = c.getConsumerUID().getBrokerAddress();
                            if ((conn != null && conn.isConnectionStarted()) || (ba != null && ba != Globals.getMyAddress())) {
                                notifications.put(d.getDestinationUID(), new ConsumerInfoNotification(d.getDestinationUID(), e.destType, CONSUMER_READY, ((ConsumerInfoRequestEvent) o).infoType, true));
                                notifyadded = true;
                                break;
                            }
                        }
                        if (notifyadded) {
                            break;
                        }
                    }
                }
                if (!foundmatch || (!hasconsumer && !notifyadded)) {
                    notifications.put(e.duid, new ConsumerInfoNotification(e.duid, e.destType, CONSUMER_NOT_READY, ((ConsumerInfoRequestEvent) o).infoType, true));
                }
                eventQueue.remove(o);
            }
        }
        Iterator itr = notifications.values().iterator();
        ConsumerInfoNotification cin = null;
        while (itr.hasNext()) {
            cin = (ConsumerInfoNotification) itr.next();
            if (DEBUG) {
                logger.log(logger.INFO, "Sending " + cin);
            }
            if (cin.shouldNotify()) {
                cm.sendConsumerInfo(InfoRequestHandler.REQUEST_CONSUMER_INFO, cin.duid, cin.destType, cin.infoType, cin.sendToWildcard);
            }
        }
        notifications.clear();
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) Iterator(java.util.Iterator) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with IMQConnection

use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.

the class MetricManager method getMetricCounters.

/**
 * Get the metric counters for the specified service. If serviceName is null then do it for all services
 */
public synchronized MetricCounters getMetricCounters(String serviceName) {
    ConnectionManager cm = Globals.getConnectionManager();
    MetricCounters totals = new MetricCounters();
    // Add counters for connections that no longer exist
    if (serviceName == null) {
        // Sum values for all services
        Enumeration e;
        for (e = deadTotalsByService.elements(); e.hasMoreElements(); ) {
            totals.update((MetricCounters) e.nextElement());
        }
    } else {
        // Sum values for just the specified service
        MetricCounters deadTotals = (MetricCounters) deadTotalsByService.get(serviceName);
        if (deadTotals != null) {
            totals.update((MetricCounters) deadTotalsByService.get(serviceName));
        }
    }
    // Sum totals for all active connections for this service
    // We synchronize since connections may be comming and going
    int n = 0;
    synchronized (cm) {
        Collection connections = cm.values();
        Iterator itr = connections.iterator();
        while (itr.hasNext()) {
            Connection con = (Connection) itr.next();
            Service svc = con.getService();
            // See if connection belongs to the service
            if (serviceName == null || serviceName.equals(svc.getName())) {
                if (con instanceof IMQConnection) {
                    totals.update(((IMQConnection) con).getMetricCounters());
                } else {
                // XXX handle other counters
                }
                n++;
            }
        }
    }
    // Get thread information
    ServiceManager sm = Globals.getServiceManager();
    Service svc = null;
    Iterator iter = null;
    if (serviceName == null) {
        Set s = sm.getAllActiveServices();
        if (s != null) {
            iter = s.iterator();
        }
    } else {
        Vector v = new Vector(1);
        v.add(serviceName);
        iter = v.iterator();
    }
    while (iter != null && iter.hasNext()) {
        svc = sm.getService((String) iter.next());
        if (svc instanceof IMQService) {
            totals.threadsActive += ((IMQService) svc).getActiveThreadpool();
            totals.threadsHighWater += ((IMQService) svc).getMaxThreadpool();
            totals.threadsLowWater += ((IMQService) svc).getMinThreadpool();
        }
    }
    Runtime rt = Runtime.getRuntime();
    totals.totalMemory = rt.totalMemory();
    totals.freeMemory = rt.freeMemory();
    totals.nConnections = n;
    totals.timeStamp = System.currentTimeMillis();
    return totals;
}
Also used : MetricCounters(com.sun.messaging.jmq.util.MetricCounters) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) IMQService(com.sun.messaging.jmq.jmsserver.service.imq.IMQService) IMQService(com.sun.messaging.jmq.jmsserver.service.imq.IMQService) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)

Example 15 with IMQConnection

use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.

the class ProducerSpi method sendResumeFlow.

public void sendResumeFlow(DestinationUID duid, int size, long bytes, long mbytes, String reason, boolean uselast, int maxbatch) {
    ResumeFlowSizes rfs = null;
    if (uselast) {
        rfs = (ResumeFlowSizes) lastResumeFlowSizes.get(duid);
        if (rfs == null) {
            rfs = new ResumeFlowSizes(maxbatch, -1, Limitable.UNLIMITED_BYTES);
            lastResumeFlowSizes.put(duid, rfs);
        }
    } else {
        rfs = new ResumeFlowSizes(size, bytes, mbytes);
        lastResumeFlowSizes.put(duid, rfs);
    }
    ConnectionUID cuid = getConnectionUID();
    if (cuid == null) {
        logger.log(Logger.DEBUG, "cant resume flow[no con_uid] " + this);
        return;
    }
    IMQConnection con = (IMQConnection) Globals.getConnectionManager().getConnection(cuid);
    if (reason == null) {
        reason = "Resuming " + this;
    }
    Hashtable hm = new Hashtable();
    hm.put("JMQSize", rfs.size);
    hm.put("JMQBytes", Long.valueOf(rfs.bytes));
    hm.put("JMQMaxMsgBytes", Long.valueOf(rfs.mbytes));
    if (con != null) {
        Packet pkt = new Packet(con.useDirectBuffers());
        pkt.setPacketType(PacketType.RESUME_FLOW);
        hm.put("JMQProducerID", Long.valueOf(getProducerUID().longValue()));
        hm.put("JMQDestinationID", duid.toString());
        hm.put("Reason", reason);
        pkt.setProperties(hm);
        con.sendControlMessage(pkt);
    }
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID)

Aggregations

IMQConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)20 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)13 ConnectionManager (com.sun.messaging.jmq.jmsserver.service.ConnectionManager)8 Iterator (java.util.Iterator)7 List (java.util.List)7 ArrayList (java.util.ArrayList)6 Service (com.sun.messaging.jmq.jmsserver.service.Service)4 ConnectionInfo (com.sun.messaging.jmq.util.admin.ConnectionInfo)4 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)3 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)3 IMQBasicConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQBasicConnection)3 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)3 Hashtable (java.util.Hashtable)3 HAMonitorService (com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)2 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)2 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)2 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)2 Session (com.sun.messaging.jmq.jmsserver.core.Session)2 SessionUID (com.sun.messaging.jmq.jmsserver.core.SessionUID)2 Connection (com.sun.messaging.jmq.jmsserver.service.Connection)2