summaryrefslogtreecommitdiff
path: root/qpid/java/perftests/src/main/java/org/apache/qpid/perftests/dlq/client/Create.java
blob: 83d5d58d6dc1c3b4c2189fa7ff9ae71c7bb11cd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.apache.qpid.perftests.dlq.client;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.jms.MessageConsumer;
import javax.jms.Session;

import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.url.AMQBindingURL;
import org.apache.qpid.url.BindingURL;

public class Create extends Client
{
    private MessageConsumer _consumer;
    
    public Create(Properties props)
    {
        super(props);
    }
    
    public void init()
    {
        super.init();
        
        _sessionType = Session.AUTO_ACKNOWLEDGE;
        _transacted = false;
        _clientAck = false;
    }

    public void start() throws Exception
    {
        _connection.start();
        
        BindingURL burl = new AMQBindingURL("direct://amq.direct//" + _queueName + "?maxdeliverycount='" + _maxRedelivery + "'");
        _queue = new AMQQueue(burl);

        final Map<String,Object> arguments = new HashMap<String, Object>();
        arguments.put(AMQQueueFactory.X_QPID_DLQ_ENABLED.asString(), _dlq);
        
        ((AMQSession<?,?>) _session).createQueue(new AMQShortString(_queueName), false, false, false, arguments);
        ((AMQSession<?,?>) _session).declareAndBind((AMQDestination) new AMQQueue("amq.direct", _queueName));
        
        _consumer = _session.createConsumer(_queue);
        while (_consumer.receive(1000) != null);
        _consumer.close();
        
        if (_dlq)
        {
	        _queue = _session.createQueue(_queueName + AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
	        _consumer = _session.createConsumer(_queue);
	        while (_consumer.receive(1000) != null);
        }
    }
}