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);
}
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);
}
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();
}
}
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;
}
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);
}
}
Aggregations