本文整理汇总了Java中org.apache.activemq.broker.jmx.QueueViewMBean类的典型用法代码示例。如果您正苦于以下问题:Java QueueViewMBean类的具体用法?Java QueueViewMBean怎么用?Java QueueViewMBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueueViewMBean类属于org.apache.activemq.broker.jmx包,在下文中一共展示了QueueViewMBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSendNonPersistentQueueMessagesAMQP
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
@Test
public void testSendNonPersistentQueueMessagesAMQP() throws Exception {
connection = createAmqpConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Destination destination = session.createQueue(getDestinationName());
MessageProducer producer = session.createProducer(destination);
QueueViewMBean queueView = getProxyToQueue(getDestinationName());
// Warm
produceMessages(session, producer);
long totalCycleTime = 0;
for (int i = 0; i < ITERATIONS; i++) {
totalCycleTime += produceMessages(session, producer);
queueView.purge();
}
long smoothedTime = totalCycleTime / ITERATIONS;
LOG.info("Total time for QPid client = {}", TimeUnit.NANOSECONDS.toMillis(smoothedTime));
}
示例2: getBrokerQueues
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
@Override
public Set<BrokerQueue> getBrokerQueues() throws MessageQueueJmxException {
Set<BrokerQueue> res = new HashSet<BrokerQueue>();
ObjectName[] queueObjects = new ObjectName[0];
BrokerViewMBean viewMBean = getMBean(brokerViewBeanObjectName, BrokerViewMBean.class);
if (viewMBean != null) {
queueObjects = viewMBean.getQueues();
}
for (ObjectName objectName : queueObjects) {
QueueViewMBean queue = getMBean(objectName, QueueViewMBean.class);
BrokerQueue brokerQueue = new BrokerQueue();
brokerQueue.setName(queue.getName());
brokerQueue.setDispatchedMessagesCount(queue.getDequeueCount());
brokerQueue.setPendingMessagesCount(queue.getQueueSize());
res.add(brokerQueue);
}
return res;
}
示例3: displayAllDestinations
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
private void displayAllDestinations() throws Exception {
String query = JmxMBeansUtil.createQueryString(queryString, "*");
List<?> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);
final String header = "%-50s %10s %10s %10s %10s %10s %10s";
final String tableRow = "%-50s %10d %10d %10d %10d %10d %10d";
context.print(String.format(Locale.US, header, "Name", "Queue Size", "Producer #", "Consumer #", "Enqueue #", "Dequeue #", "Memory %"));
// Iterate through the queue result
for (Object view : queueList) {
ObjectName queueName = ((ObjectInstance)view).getObjectName();
QueueViewMBean queueView = MBeanServerInvocationHandler.
newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
context.print(String.format(Locale.US, tableRow,
queueView.getName(),
queueView.getQueueSize(),
queueView.getProducerCount(),
queueView.getConsumerCount(),
queueView.getEnqueueCount(),
queueView.getDequeueCount(),
queueView.getMemoryPercentUsage()));
}
}
示例4: displayQueueStats
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
private void displayQueueStats() throws Exception {
String query = JmxMBeansUtil.createQueryString(queryString, "Queue");
List<?> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);
final String header = "%-50s %10s %10s %10s %10s %10s %10s";
final String tableRow = "%-50s %10d %10d %10d %10d %10d %10d";
context.print(String.format(Locale.US, header, "Name", "Queue Size", "Producer #", "Consumer #", "Enqueue #", "Dequeue #", "Memory %"));
// Iterate through the queue result
for (Object view : queueList) {
ObjectName queueName = ((ObjectInstance)view).getObjectName();
QueueViewMBean queueView = MBeanServerInvocationHandler.
newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
context.print(String.format(Locale.US, tableRow,
queueView.getName(),
queueView.getQueueSize(),
queueView.getProducerCount(),
queueView.getConsumerCount(),
queueView.getEnqueueCount(),
queueView.getDequeueCount(),
queueView.getMemoryPercentUsage()));
}
}
示例5: setUp
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
mockJmsSession = mock(Session.class);
mockJmsQueueBrowser = mock(QueueBrowser.class);
mockJmsTemplate = mock(JmsOperations.class);
mockConversionService = mock(ConversionService.class);
mockQueueMBean = mock(QueueViewMBean.class);
mockErrorDao = mock(IVprSyncErrorDao.class);
syncService = new SyncService();
syncService.setConversionService(mockConversionService);
syncService.setErrorDao(mockErrorDao);
syncService.setJmsTemplate(mockJmsTemplate);
syncService.setVprDeadLetterQueueMBean(mockQueueMBean);
when(mockJmsTemplate.browse(eq(MessageDestinations.DEAD_LETTER_QUEUE), any(BrowserCallback.class))).thenAnswer(new ReturnsBrowserCallbackArgument<Object>(mockJmsSession, mockJmsQueueBrowser));
}
示例6: setUp
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
@Before
public void setUp() {
mockJmsTemplate = mock(JmsOperations.class);
mockPatientDao = mock(IPatientDAO.class);
mockConversionService = mock(ConversionService.class);
mockPatientDataService = mock(IVistaVprDataExtractEventStreamDAO.class);
mockClearPatientMessageHandler = mock(ClearPatientMessageHandler.class);
mockQueueMBean = mock(QueueViewMBean.class);
mockPageable = new PageRequest(0, 100);
mockErrorDao = mock(IVprSyncErrorDao.class);
mockSyncStatusDao = mock(IVprSyncStatusDao.class);
syncService = new SyncService();
syncService.setJmsTemplate(mockJmsTemplate);
syncService.setPatientDao(mockPatientDao);
syncService.setConversionService(mockConversionService);
syncService.setMetricRegistry(new MetricRegistry());
syncService.setVprDeadLetterQueueMBean(mockQueueMBean);
syncService.setErrorDao(mockErrorDao);
syncService.setEventStreamDAO(mockPatientDataService);
syncService.setSyncStatusDao(mockSyncStatusDao);
syncService.setClearPatientMessageHandler(mockClearPatientMessageHandler);
}
示例7: getQueueStatistics
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
/**
* Returns queue statistics for the JMS queues.
*
* @return {@link List} of {@link QueueMBean}. One for each queue belonging.
*/
@PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ)
public List<QueueMBean> getQueueStatistics() {
try {
List<QueueMBean> queues = new ArrayList<>();
for (ObjectName name : mBeanServer.getQueues()) {
String destination = name.getKeyProperty(mBeanServer.getDestinationProperty());
QueueViewMBean queueView = mBeanServer.getQueueViewMBean(name);
QueueMBean queue = new QueueMBean(destination);
queue.setEnqueueCount(queueView.getEnqueueCount());
queue.setDequeueCount(queueView.getDequeueCount());
queue.setExpiredCount(queueView.getExpiredCount());
queue.setConsumerCount(queueView.getConsumerCount());
queue.setQueueSize(queueView.getQueueSize());
queues.add(queue);
}
return queues;
} catch (IOException ex) {
throw new MotechException("Could not access MBeans ", ex);
}
}
示例8: getQueueMessages
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
/**
* Retrieves a list of messages for the given JMS queue.
*
* @param queueName The name of the queue for which messages should be retrieved.
* @return {@link List} of messages for the given queue.
*/
@PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ)
public List<QueueMessage> getQueueMessages(String queueName) {
try {
ArrayList<QueueMessage> queueMessages = new ArrayList<>();
QueueViewMBean queueViewMBean = mBeanServer.getQueueViewMBean(queueName);
for (CompositeData compositeData : queueViewMBean.browse()) {
if (compositeData != null) {
String messageId = (String) compositeData.get(JMS_MESSAGE_ID);
Boolean redelivered = (Boolean) compositeData.get(JMS_REDELIVERED);
Date timestamp = (Date) compositeData.get(JMS_TIMESTAMP);
queueMessages.add(new QueueMessage(messageId, redelivered, DateUtil.newDateTime(timestamp)));
}
}
return queueMessages;
} catch (OpenDataException openDataException) {
throw new MotechException(String.format("Could not Browse MBean for queue %s", queueName), openDataException);
} catch (IOException ioException) {
throw new MotechException(String.format("Could not access MBean for queue %s", queueName), ioException);
}
}
示例9: shouldReturnQueues
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
@Test
public void shouldReturnQueues() throws IOException {
ObjectName fooQueue = mock(ObjectName.class);
ObjectName[] queues = {fooQueue};
QueueViewMBean queueViewMBean = mock(QueueViewMBean.class);
given(mBeanServer.getQueueViewMBean(any(ObjectName.class))).willReturn(queueViewMBean);
given(mBeanServer.getQueues()).willReturn(queues);
given(fooQueue.getKeyProperty(mBeanServer.getDestinationProperty())).willReturn("foo_queue");
List<QueueMBean> queueStatistics = mBeanService.getQueueStatistics();
assertThat(queueStatistics.size(), Is.is(1));
assertThat(queueStatistics.get(0).getDestination(), Is.is("foo_queue"));
}
示例10: testBrowseExpiredMessages
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
public void testBrowseExpiredMessages() throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(url, null);
connector.connect();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost," + "destinationType=Queue,destinationName=TEST.Q");
QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
HashMap<String, String> headers = new HashMap<>();
headers.put("timeToLive", Long.toString(2000));
headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT));
queueMbean.sendTextMessage(headers, "test", "system", "manager");
// allow message to expire on the queue
TimeUnit.SECONDS.sleep(4);
Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection("system", "manager");
c.start();
// browser consumer will force expiration check on addConsumer
QueueBrowser browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("TEST.Q"));
assertTrue("no message in the q", !browser.getEnumeration().hasMoreElements());
// verify dlq got the message, no security exception as brokers context is now used
browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ"));
assertTrue("one message in the dlq", browser.getEnumeration().hasMoreElements());
}
示例11: browseQueueWithJmx
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
private Object[] browseQueueWithJmx(BrokerService broker) throws Exception {
Hashtable<String, String> params = new Hashtable<>();
params.put("brokerName", broker.getBrokerName());
params.put("type", "Broker");
params.put("destinationType", "Queue");
params.put("destinationName", queueName);
ObjectName queueObjectName = ObjectName.getInstance(amqDomain, params);
ManagementContext mgmtCtx = broker.getManagementContext();
QueueViewMBean queueView = (QueueViewMBean) mgmtCtx.newProxyInstance(queueObjectName, QueueViewMBean.class, true);
Object[] messages = queueView.browse();
LOG.info("+Browsed with JMX: " + messages.length);
return messages;
}
示例12: testQueueViewMbean
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
/**
* This test ensures that the queueViewMbean will work.
*
* @throws Exception
*/
public void testQueueViewMbean() throws Exception {
try {
addMessages();
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
List<String> tokens = Arrays.asList(new String[]{"*"});
for (String token : tokens) {
List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), "type=Broker,brokerName=localbroker,destinationType=Queue,destinationName=" + token);
for (ObjectInstance queue : queueList) {
ObjectName queueName = queue.getObjectName();
QueueViewMBean proxy = MBeanServerInvocationHandler.newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
int removed = proxy.removeMatchingMessages(MSG_SEL_WITH_PROPERTY);
LOG.info("Removed: " + removed);
}
}
validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
} finally {
purgeAllMessages();
}
}
示例13: testPurgeLargeQueueWithConsumer
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
public void testPurgeLargeQueueWithConsumer() throws Exception {
applyBrokerSpoolingPolicy();
createProducerAndSendMessages(NUM_TO_SEND);
QueueViewMBean proxy = getProxyToQueueViewMBean();
createConsumer();
long start = System.currentTimeMillis();
LOG.info("purging..");
proxy.purge();
LOG.info("purge done: " + (System.currentTimeMillis() - start) + "ms");
assertEquals("Queue size is not zero, it's " + proxy.getQueueSize(), 0, proxy.getQueueSize());
assertEquals("usage goes to duck", 0, proxy.getMemoryPercentUsage());
Message msg;
do {
msg = consumer.receive(1000);
if (msg != null) {
msg.acknowledge();
}
} while (msg != null);
assertEquals("Queue size not valid", 0, proxy.getQueueSize());
}
示例14: testCreateQueueBrowser
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
@Test(timeout = 60000)
public void testCreateQueueBrowser() throws Exception {
connection = createAmqpConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
Queue queue = session.createQueue(name.getMethodName());
session.createConsumer(queue).close();
QueueBrowser browser = session.createBrowser(queue);
assertNotNull(browser);
QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
assertEquals(0, proxy.getQueueSize());
}
示例15: testCreateQueueSender
import org.apache.activemq.broker.jmx.QueueViewMBean; //导入依赖的package包/类
@Test
public void testCreateQueueSender() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI());
QueueConnection connection = factory.createQueueConnection();
assertNotNull(connection);
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
Queue queue = session.createQueue(name.getMethodName());
QueueSender sender = session.createSender(queue);
assertNotNull(sender);
QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
assertEquals(0, proxy.getQueueSize());
connection.close();
}