01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.client;
22
23 import javax.jms.InvalidSelectorException;
24 import javax.jms.JMSException;
25
26 import org.apache.qpid.AMQException;
27 import org.apache.qpid.QpidException;
28 import org.apache.qpid.client.failover.FailoverException;
29 import org.apache.qpid.client.message.*;
30 import org.apache.qpid.client.protocol.AMQProtocolHandler;
31 import org.apache.qpid.filter.JMSSelectorFilter;
32 import org.apache.qpid.framing.*;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class BasicMessageConsumer_0_8 extends BasicMessageConsumer<UnprocessedMessage_0_8>
37 {
38 protected final Logger _logger = LoggerFactory.getLogger(getClass());
39
40 protected BasicMessageConsumer_0_8(int channelId, AMQConnection connection, AMQDestination destination,
41 String messageSelector, boolean noLocal, MessageFactoryRegistry messageFactory, AMQSession session,
42 AMQProtocolHandler protocolHandler, FieldTable arguments, int prefetchHigh, int prefetchLow,
43 boolean exclusive, int acknowledgeMode, boolean noConsume, boolean autoClose) throws JMSException
44 {
45 super(channelId, connection, destination,messageSelector,noLocal,messageFactory,session,
46 protocolHandler, arguments, prefetchHigh, prefetchLow, exclusive,
47 acknowledgeMode, noConsume, autoClose);
48 try
49 {
50
51 if (messageSelector != null && messageSelector.length() > 0)
52 {
53 JMSSelectorFilter _filter = new JMSSelectorFilter(messageSelector);
54 }
55 }
56 catch (QpidException e)
57 {
58 throw new InvalidSelectorException("cannot create consumer because of selector issue");
59 }
60 }
61
62 void sendCancel() throws AMQException, FailoverException
63 {
64 BasicCancelBody body = getSession().getMethodRegistry().createBasicCancelBody(new AMQShortString(String.valueOf(_consumerTag)), false);
65
66 final AMQFrame cancelFrame = body.generateFrame(_channelId);
67
68 _protocolHandler.syncWrite(cancelFrame, BasicCancelOkBody.class);
69
70 if (_logger.isDebugEnabled())
71 {
72 _logger.debug("CancelOk'd for consumer:" + debugIdentity());
73 }
74 }
75
76 public AbstractJMSMessage createJMSMessageFromUnprocessedMessage(AMQMessageDelegateFactory delegateFactory, UnprocessedMessage_0_8 messageFrame)throws Exception
77 {
78
79 return _messageFactory.createMessage(messageFrame.getDeliveryTag(),
80 messageFrame.isRedelivered(), messageFrame.getExchange(),
81 messageFrame.getRoutingKey(), messageFrame.getContentHeader(), messageFrame.getBodies());
82
83 }
84
85 }
|