KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > perf > SlowConsumerTopicTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
4  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
5  * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12  * specific language governing permissions and limitations under the License.
13  */

14
15 package org.apache.activemq.perf;
16
17 import javax.jms.ConnectionFactory JavaDoc;
18 import javax.jms.DeliveryMode JavaDoc;
19 import javax.jms.Destination JavaDoc;
20 import javax.jms.JMSException JavaDoc;
21 import org.apache.activemq.ActiveMQConnectionFactory;
22 import org.apache.activemq.ActiveMQPrefetchPolicy;
23 import org.apache.activemq.broker.BrokerService;
24 import org.apache.activemq.xbean.BrokerFactoryBean;
25 import org.springframework.core.io.ClassPathResource;
26 import org.springframework.core.io.Resource;
27
28 /**
29  * @version $Revision: 1.3 $
30  */

31 public class SlowConsumerTopicTest extends SimpleTopicTest{
32
33     protected PerfConsumer[] slowConsumers;
34     protected int NUMBER_OF_SLOW_CONSUMERS=1;
35
36     protected void setUp() throws Exception JavaDoc{
37         NUMBER_OF_CONSUMERS=0;
38         PAYLOAD_SIZE=10 * 1024;
39         super.setUp();
40         slowConsumers=new SlowConsumer[NUMBER_OF_SLOW_CONSUMERS];
41         for(int i=0;i<NUMBER_OF_SLOW_CONSUMERS;i++){
42             slowConsumers[i]=createSlowConsumer(factory,destination,i);
43             slowConsumers[i].start();
44         }
45     }
46
47     protected PerfConsumer createSlowConsumer(ConnectionFactory JavaDoc fac,Destination JavaDoc dest,int number) throws JMSException JavaDoc{
48         return new SlowConsumer(fac,dest);
49     }
50
51     protected PerfProducer createProducer(ConnectionFactory JavaDoc fac,Destination JavaDoc dest,int number,byte[] payload)
52             throws JMSException JavaDoc{
53         PerfProducer result=super.createProducer(fac,dest,number,payload);
54         result.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
55         return result;
56     }
57
58     protected BrokerService createBroker() throws Exception JavaDoc{
59         Resource resource=new ClassPathResource("org/apache/activemq/perf/slowConsumerBroker.xml");
60         BrokerFactoryBean factory=new BrokerFactoryBean(resource);
61         factory.afterPropertiesSet();
62         BrokerService broker=factory.getBroker();
63         broker.start();
64         return broker;
65     }
66     
67     protected ActiveMQConnectionFactory createConnectionFactory() throws Exception JavaDoc{
68         ActiveMQConnectionFactory result = super.createConnectionFactory();
69         ActiveMQPrefetchPolicy policy = new ActiveMQPrefetchPolicy();
70         policy.setTopicPrefetch(1000);
71         result.setPrefetchPolicy(policy);
72         return result;
73     }
74 }
75
Popular Tags