@@ -27,99 +27,72 @@ public class MulticastSet {
2727 private final String id ;
2828 private final Stats stats ;
2929 private final ConnectionFactory factory ;
30- private final MulticastParams p ;
30+ private final MulticastParams params ;
3131
3232 public MulticastSet (Stats stats , ConnectionFactory factory ,
3333 MulticastParams params ) {
3434 this .id = UUID .randomUUID ().toString ();
3535 this .stats = stats ;
3636 this .factory = factory ;
37- this .p = params ;
37+ this .params = params ;
3838 }
3939
4040 public void run () throws IOException , InterruptedException {
4141 run (false );
4242 }
4343
4444 public void run (boolean announceStartup ) throws IOException , InterruptedException {
45- Thread [] consumerThreads = new Thread [p . consumerCount ];
46- Connection [] consumerConnections = new Connection [p . consumerCount ];
47- for (int i = 0 ; i < p . consumerCount ; i ++) {
45+ Thread [] consumerThreads = new Thread [params . getConsumerCount () ];
46+ Connection [] consumerConnections = new Connection [consumerThreads . length ];
47+ for (int i = 0 ; i < consumerConnections . length ; i ++) {
4848 if (announceStartup ) {
4949 System .out .println ("starting consumer #" + i );
5050 }
5151 Connection conn = factory .newConnection ();
5252 consumerConnections [i ] = conn ;
5353 Channel channel = conn .createChannel ();
54- if (p .consumerTxSize > 0 ) channel .txSelect ();
55- channel .exchangeDeclare (p .exchangeName , p .exchangeType );
56- String qName =
57- channel .queueDeclare (p .queueName ,
58- p .flags .contains ("persistent" ),
59- p .exclusive , p .autoDelete ,
60- null ).getQueue ();
61- if (p .prefetchCount > 0 ) channel .basicQos (p .prefetchCount );
62- channel .queueBind (qName , p .exchangeName , id );
63- Thread t =
64- new Thread (new Consumer (channel , id , qName ,
65- p .consumerTxSize , p .autoAck , p .multiAckEvery ,
66- stats , p .consumerMsgCount , p .timeLimit ));
54+ Thread t = new Thread (params .createConsumer (channel , stats , id ));
6755 consumerThreads [i ] = t ;
6856 }
6957
70- if (p . consumerCount == 0 && ! p . queueName . equals ( "" )) {
58+ if (params . shouldConfigureQueue ( )) {
7159 Connection conn = factory .newConnection ();
7260 Channel channel = conn .createChannel ();
73- channel .exchangeDeclare (p .exchangeName , p .exchangeType );
74- channel .queueDeclare (p .queueName ,
75- p .flags .contains ("persistent" ),
76- p .exclusive , p .autoDelete ,
77- null ).getQueue ();
78- channel .queueBind (p .queueName , p .exchangeName , id );
61+ params .configureQueue (channel , id );
7962 conn .close ();
8063 }
8164
82- Thread [] producerThreads = new Thread [p . producerCount ];
83- Connection [] producerConnections = new Connection [p . producerCount ];
84- Channel [] producerChannels = new Channel [p . producerCount ];
85- for (int i = 0 ; i < p . producerCount ; i ++) {
65+ Thread [] producerThreads = new Thread [params . getProducerCount () ];
66+ Connection [] producerConnections = new Connection [producerThreads . length ];
67+ Channel [] producerChannels = new Channel [producerConnections . length ];
68+ for (int i = 0 ; i < producerChannels . length ; i ++) {
8669 if (announceStartup ) {
8770 System .out .println ("starting producer #" + i );
8871 }
8972 Connection conn = factory .newConnection ();
9073 producerConnections [i ] = conn ;
9174 Channel channel = conn .createChannel ();
9275 producerChannels [i ] = channel ;
93- if (p .producerTxSize > 0 ) channel .txSelect ();
94- if (p .confirm >= 0 ) channel .confirmSelect ();
95- channel .exchangeDeclare (p .exchangeName , p .exchangeType );
96- final Producer producer = new Producer (channel , p .exchangeName , id ,
97- p .flags , p .producerTxSize ,
98- p .rateLimit , p .producerMsgCount ,
99- p .minMsgSize , p .timeLimit ,
100- p .confirm , stats );
101- channel .addReturnListener (producer );
102- channel .addConfirmListener (producer );
103- Thread t = new Thread (producer );
76+ Thread t = new Thread (params .createProducer (channel , stats , id ));
10477 producerThreads [i ] = t ;
10578 }
10679
107- for (int i = 0 ; i < p . consumerCount ; i ++ ) {
108- consumerThreads [ i ] .start ();
80+ for (Thread consumerThread : consumerThreads ) {
81+ consumerThread .start ();
10982 }
11083
111- for (int i = 0 ; i < p . producerCount ; i ++ ) {
112- producerThreads [ i ] .start ();
84+ for (Thread producerThread : producerThreads ) {
85+ producerThread .start ();
11386 }
11487
115- for (int i = 0 ; i < p . producerCount ; i ++) {
88+ for (int i = 0 ; i < producerThreads . length ; i ++) {
11689 producerThreads [i ].join ();
11790 producerChannels [i ].clearReturnListeners ();
11891 producerChannels [i ].clearConfirmListeners ();
11992 producerConnections [i ].close ();
12093 }
12194
122- for (int i = 0 ; i < p . consumerCount ; i ++) {
95+ for (int i = 0 ; i < consumerThreads . length ; i ++) {
12396 consumerThreads [i ].join ();
12497 consumerConnections [i ].close ();
12598 }
0 commit comments