@SuppressWarnings("unchecked")
public void purge(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
try {
if (destinationInfo.getType().equals(DestinationType.Queue)) {
BrokerInfo brokerInfo = getBrokerInfo(portletRequest, destinationInfo);
if (brokerInfo == null || !isInLocalMBeanServer(brokerInfo)) {
throw new JMSException("Currently, only queue belong to local broker is supported");
}
MBeanServer server = getMBeanServer();
ObjectName destinationObjectName = createDestinationObjectName(brokerInfo.getBrokerName(), destinationInfo.getType().name(), destinationInfo.getPhysicalName());
QueueViewMBean proxy;
if (!server.isRegistered(destinationObjectName)) {
// mbean is not yet registered.Adding the destination to activemq broker.
ObjectName brokerObjectName = createBrokerObjectName(brokerInfo.getBrokerName());
Set set = server.queryMBeans(brokerObjectName, null);
Iterator it = set.iterator();
if (it.hasNext()) {
ObjectInstance instance = (ObjectInstance) it.next();
brokerObjectName = instance.getObjectName();