PageRenderTime 74ms CodeModel.GetById 31ms app.highlight 36ms 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
 23package org.jboss.as.messaging;
 24
 25import java.util.EnumSet;
 26import java.util.Locale;
 27
 28import org.hornetq.api.core.management.QueueControl;
 29import org.hornetq.api.core.management.ResourceNames;
 30import org.hornetq.core.server.HornetQServer;
 31import org.jboss.as.controller.OperationContext;
 32import org.jboss.as.controller.OperationFailedException;
 33import org.jboss.as.controller.descriptions.DescriptionProvider;
 34import org.jboss.as.controller.operations.validation.ModelTypeValidator;
 35import org.jboss.as.controller.registry.ManagementResourceRegistration;
 36import org.jboss.as.controller.registry.OperationEntry;
 37import org.jboss.dmr.ModelNode;
 38import org.jboss.dmr.ModelType;
 39
 40/**
 41 * Handler for runtime operations that invoke on a HornetQ {@link org.hornetq.api.core.management.QueueControl}.
 42 *
 43 * @author Brian Stansberry (c) 2011 Red Hat Inc.
 44 */
 45public class QueueControlHandler extends AbstractQueueControlHandler<QueueControl> {
 46
 47    public static final QueueControlHandler INSTANCE = new QueueControlHandler();
 48
 49    public static final String LIST_SCHEDULED_MESSAGES = "list-scheduled-messages";
 50    public static final String LIST_SCHEDULED_MESSAGES_AS_JSON = "list-scheduled-messages-as-json";
 51
 52    private QueueControlHandler() {
 53        super(new ModelTypeValidator(ModelType.LONG));
 54    }
 55
 56    @Override
 57    public void registerOperations(ManagementResourceRegistration registry) {
 58        super.registerOperations(registry);
 59
 60        final EnumSet<OperationEntry.Flag> flags = EnumSet.of(OperationEntry.Flag.READ_ONLY, OperationEntry.Flag.RUNTIME_ONLY);
 61
 62        registry.registerOperationHandler(LIST_SCHEDULED_MESSAGES, this, new DescriptionProvider() {
 63            @Override
 64            public ModelNode getModelDescription(Locale locale) {
 65                return MessagingDescriptions.getListScheduledMessages(locale);
 66            }
 67        }, flags);
 68
 69        registry.registerOperationHandler(LIST_SCHEDULED_MESSAGES_AS_JSON, this, new DescriptionProvider() {
 70            @Override
 71            public ModelNode getModelDescription(Locale locale) {
 72                return MessagingDescriptions.getNoArgSimpleReplyOperation(locale, LIST_SCHEDULED_MESSAGES_AS_JSON, "queue", ModelType.STRING, true);
 73            }
 74        }, flags);
 75    }
 76
 77    @Override
 78    protected Object handleAdditionalOperation(String operationName, ModelNode operation, OperationContext context,
 79                                               QueueControl queueControl) throws OperationFailedException {
 80        try {
 81            if (LIST_SCHEDULED_MESSAGES.equals(operationName)) {
 82                String json = queueControl.listScheduledMessagesAsJSON();
 83                context.getResult().set(ModelNode.fromJSONString(json));
 84            } else if (LIST_SCHEDULED_MESSAGES_AS_JSON.equals(operationName)) {
 85                context.getResult().set(queueControl.listScheduledMessagesAsJSON());
 86            } else {
 87                // Bug
 88                throwUnimplementedOperationException(operationName);
 89            }
 90        } catch (RuntimeException e) {
 91            throw e;
 92        } catch (Exception e) {
 93            context.getFailureDescription().set(e.getLocalizedMessage());
 94        }
 95
 96        return null;
 97    }
 98
 99    @Override
100    protected void revertAdditionalOperation(String operationName, ModelNode operation, OperationContext context, QueueControl queueControl, Object handback) {
101        // no-op
102    }
103
104
105    @Override
106    public boolean isJMS() {
107        return false;
108    }
109
110    @Override
111    protected DelegatingQueueControl<QueueControl> getQueueControl(HornetQServer hqServer, String queueName) {
112        final QueueControl control = QueueControl.class.cast(hqServer.getManagementService().getResource(ResourceNames.CORE_QUEUE + queueName));
113        return new DelegatingQueueControl<QueueControl>() {
114
115            public QueueControl getDelegate() {
116                return control;
117            }
118            @Override
119            public String listMessagesAsJSON(String filter) throws Exception {
120                return control.listMessagesAsJSON(filter);
121            }
122
123            @Override
124            public long countMessages(String filter) throws Exception {
125                return control.countMessages(filter);
126            }
127
128            @Override
129            public boolean removeMessage(ModelNode id) throws Exception {
130                return control.removeMessage(id.asLong());
131            }
132
133            @Override
134            public int removeMessages(String filter) throws Exception {
135                return control.removeMessages(filter);
136            }
137
138            @Override
139            public int expireMessages(String filter) throws Exception {
140                return control.expireMessages(filter);
141            }
142
143            @Override
144            public boolean expireMessage(ModelNode id) throws Exception {
145                return control.expireMessage(id.asLong());
146            }
147
148            @Override
149            public boolean sendMessageToDeadLetterAddress(ModelNode id) throws Exception {
150                return control.sendMessageToDeadLetterAddress(id.asLong());
151            }
152
153            @Override
154            public int sendMessagesToDeadLetterAddress(String filter) throws Exception {
155                return control.sendMessagesToDeadLetterAddress(filter);
156            }
157
158            @Override
159            public boolean changeMessagePriority(ModelNode id, int priority) throws Exception {
160                return control.changeMessagePriority(id.asLong(), priority);
161            }
162
163            @Override
164            public int changeMessagesPriority(String filter, int priority) throws Exception {
165                return control.changeMessagesPriority(filter, priority);
166            }
167
168            @Override
169            public boolean moveMessage(ModelNode id, String otherQueue) throws Exception {
170                return control.moveMessage(id.asLong(), otherQueue);
171            }
172
173            @Override
174            public boolean moveMessage(ModelNode id, String otherQueue, boolean rejectDuplicates) throws Exception {
175                return control.moveMessage(id.asLong(), otherQueue, rejectDuplicates);
176            }
177
178            @Override
179            public int moveMessages(String filter, String otherQueue) throws Exception {
180                return control.moveMessages(filter, otherQueue);
181            }
182
183            @Override
184            public int moveMessages(String filter, String otherQueue, boolean rejectDuplicates) throws Exception {
185                return control.moveMessages(filter, otherQueue, rejectDuplicates);
186            }
187
188            @Override
189            public String listMessageCounter() throws Exception {
190                return control.listMessageCounter();
191            }
192
193            @Override
194            public void resetMessageCounter() throws Exception {
195                control.resetMessageCounter();
196            }
197
198            @Override
199            public String listMessageCounterAsHTML() throws Exception {
200                return control.listMessageCounterAsHTML();
201            }
202
203            @Override
204            public String listMessageCounterHistory() throws Exception {
205                return control.listMessageCounterHistory();
206            }
207
208            @Override
209            public String listMessageCounterHistoryAsHTML() throws Exception {
210                return control.listMessageCounterHistoryAsHTML();
211            }
212
213            @Override
214            public void pause() throws Exception {
215                control.pause();
216            }
217
218            @Override
219            public void resume() throws Exception {
220                control.resume();
221            }
222
223            @Override
224            public String listConsumersAsJSON() throws Exception {
225                return control.listConsumersAsJSON();
226            }
227        };
228    }
229}