PageRenderTime 65ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/messaging/src/main/java/org/jboss/as/messaging/QueueControlHandler.java

#
Java | 229 lines | 162 code | 39 blank | 28 comment | 4 complexity | 807236cb76cabd21f8422940b9fd9f46 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.messaging;
  23. import java.util.EnumSet;
  24. import java.util.Locale;
  25. import org.hornetq.api.core.management.QueueControl;
  26. import org.hornetq.api.core.management.ResourceNames;
  27. import org.hornetq.core.server.HornetQServer;
  28. import org.jboss.as.controller.OperationContext;
  29. import org.jboss.as.controller.OperationFailedException;
  30. import org.jboss.as.controller.descriptions.DescriptionProvider;
  31. import org.jboss.as.controller.operations.validation.ModelTypeValidator;
  32. import org.jboss.as.controller.registry.ManagementResourceRegistration;
  33. import org.jboss.as.controller.registry.OperationEntry;
  34. import org.jboss.dmr.ModelNode;
  35. import org.jboss.dmr.ModelType;
  36. /**
  37. * Handler for runtime operations that invoke on a HornetQ {@link org.hornetq.api.core.management.QueueControl}.
  38. *
  39. * @author Brian Stansberry (c) 2011 Red Hat Inc.
  40. */
  41. public class QueueControlHandler extends AbstractQueueControlHandler<QueueControl> {
  42. public static final QueueControlHandler INSTANCE = new QueueControlHandler();
  43. public static final String LIST_SCHEDULED_MESSAGES = "list-scheduled-messages";
  44. public static final String LIST_SCHEDULED_MESSAGES_AS_JSON = "list-scheduled-messages-as-json";
  45. private QueueControlHandler() {
  46. super(new ModelTypeValidator(ModelType.LONG));
  47. }
  48. @Override
  49. public void registerOperations(ManagementResourceRegistration registry) {
  50. super.registerOperations(registry);
  51. final EnumSet<OperationEntry.Flag> flags = EnumSet.of(OperationEntry.Flag.READ_ONLY, OperationEntry.Flag.RUNTIME_ONLY);
  52. registry.registerOperationHandler(LIST_SCHEDULED_MESSAGES, this, new DescriptionProvider() {
  53. @Override
  54. public ModelNode getModelDescription(Locale locale) {
  55. return MessagingDescriptions.getListScheduledMessages(locale);
  56. }
  57. }, flags);
  58. registry.registerOperationHandler(LIST_SCHEDULED_MESSAGES_AS_JSON, this, new DescriptionProvider() {
  59. @Override
  60. public ModelNode getModelDescription(Locale locale) {
  61. return MessagingDescriptions.getNoArgSimpleReplyOperation(locale, LIST_SCHEDULED_MESSAGES_AS_JSON, "queue", ModelType.STRING, true);
  62. }
  63. }, flags);
  64. }
  65. @Override
  66. protected Object handleAdditionalOperation(String operationName, ModelNode operation, OperationContext context,
  67. QueueControl queueControl) throws OperationFailedException {
  68. try {
  69. if (LIST_SCHEDULED_MESSAGES.equals(operationName)) {
  70. String json = queueControl.listScheduledMessagesAsJSON();
  71. context.getResult().set(ModelNode.fromJSONString(json));
  72. } else if (LIST_SCHEDULED_MESSAGES_AS_JSON.equals(operationName)) {
  73. context.getResult().set(queueControl.listScheduledMessagesAsJSON());
  74. } else {
  75. // Bug
  76. throwUnimplementedOperationException(operationName);
  77. }
  78. } catch (RuntimeException e) {
  79. throw e;
  80. } catch (Exception e) {
  81. context.getFailureDescription().set(e.getLocalizedMessage());
  82. }
  83. return null;
  84. }
  85. @Override
  86. protected void revertAdditionalOperation(String operationName, ModelNode operation, OperationContext context, QueueControl queueControl, Object handback) {
  87. // no-op
  88. }
  89. @Override
  90. public boolean isJMS() {
  91. return false;
  92. }
  93. @Override
  94. protected DelegatingQueueControl<QueueControl> getQueueControl(HornetQServer hqServer, String queueName) {
  95. final QueueControl control = QueueControl.class.cast(hqServer.getManagementService().getResource(ResourceNames.CORE_QUEUE + queueName));
  96. return new DelegatingQueueControl<QueueControl>() {
  97. public QueueControl getDelegate() {
  98. return control;
  99. }
  100. @Override
  101. public String listMessagesAsJSON(String filter) throws Exception {
  102. return control.listMessagesAsJSON(filter);
  103. }
  104. @Override
  105. public long countMessages(String filter) throws Exception {
  106. return control.countMessages(filter);
  107. }
  108. @Override
  109. public boolean removeMessage(ModelNode id) throws Exception {
  110. return control.removeMessage(id.asLong());
  111. }
  112. @Override
  113. public int removeMessages(String filter) throws Exception {
  114. return control.removeMessages(filter);
  115. }
  116. @Override
  117. public int expireMessages(String filter) throws Exception {
  118. return control.expireMessages(filter);
  119. }
  120. @Override
  121. public boolean expireMessage(ModelNode id) throws Exception {
  122. return control.expireMessage(id.asLong());
  123. }
  124. @Override
  125. public boolean sendMessageToDeadLetterAddress(ModelNode id) throws Exception {
  126. return control.sendMessageToDeadLetterAddress(id.asLong());
  127. }
  128. @Override
  129. public int sendMessagesToDeadLetterAddress(String filter) throws Exception {
  130. return control.sendMessagesToDeadLetterAddress(filter);
  131. }
  132. @Override
  133. public boolean changeMessagePriority(ModelNode id, int priority) throws Exception {
  134. return control.changeMessagePriority(id.asLong(), priority);
  135. }
  136. @Override
  137. public int changeMessagesPriority(String filter, int priority) throws Exception {
  138. return control.changeMessagesPriority(filter, priority);
  139. }
  140. @Override
  141. public boolean moveMessage(ModelNode id, String otherQueue) throws Exception {
  142. return control.moveMessage(id.asLong(), otherQueue);
  143. }
  144. @Override
  145. public boolean moveMessage(ModelNode id, String otherQueue, boolean rejectDuplicates) throws Exception {
  146. return control.moveMessage(id.asLong(), otherQueue, rejectDuplicates);
  147. }
  148. @Override
  149. public int moveMessages(String filter, String otherQueue) throws Exception {
  150. return control.moveMessages(filter, otherQueue);
  151. }
  152. @Override
  153. public int moveMessages(String filter, String otherQueue, boolean rejectDuplicates) throws Exception {
  154. return control.moveMessages(filter, otherQueue, rejectDuplicates);
  155. }
  156. @Override
  157. public String listMessageCounter() throws Exception {
  158. return control.listMessageCounter();
  159. }
  160. @Override
  161. public void resetMessageCounter() throws Exception {
  162. control.resetMessageCounter();
  163. }
  164. @Override
  165. public String listMessageCounterAsHTML() throws Exception {
  166. return control.listMessageCounterAsHTML();
  167. }
  168. @Override
  169. public String listMessageCounterHistory() throws Exception {
  170. return control.listMessageCounterHistory();
  171. }
  172. @Override
  173. public String listMessageCounterHistoryAsHTML() throws Exception {
  174. return control.listMessageCounterHistoryAsHTML();
  175. }
  176. @Override
  177. public void pause() throws Exception {
  178. control.pause();
  179. }
  180. @Override
  181. public void resume() throws Exception {
  182. control.resume();
  183. }
  184. @Override
  185. public String listConsumersAsJSON() throws Exception {
  186. return control.listConsumersAsJSON();
  187. }
  188. };
  189. }
  190. }