1
2
3
4
5
6
7
8
9
10 package org.apache.commons.messagelet;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import javax.jms.Destination;
16 import javax.jms.JMSException;
17 import javax.servlet.ServletException;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class DistributeBridgeMDO extends BridgeMDO {
36
37
38 private static final Log log = LogFactory.getLog(DistributeBridgeMDO.class);
39
40
41 private List outputDestinations = new ArrayList();
42
43 public DistributeBridgeMDO() {
44 }
45
46
47
48
49
50
51
52 public List getOutputDestinations() {
53 return outputDestinations;
54 }
55
56
57
58
59 public void addOutputSubject(String subject) throws JMSException {
60 Destination destination = getOutputMessenger().getDestination( subject );
61 outputDestinations.add( destination );
62 }
63
64
65
66
67
68
69 public Destination getOutputDestination() throws JMSException {
70 int size = outputDestinations.size();
71 if ( size < 1 ) {
72 throw new JMSException( "No output destinations are available" );
73 }
74
75 int index = (int) Math.round( Math.random() * size );
76 if ( index == size ) {
77 index = size -1;
78 }
79 return (Destination) outputDestinations.get(index);
80 }
81
82
83
84
85
86 protected void validateOutputDestination() throws JMSException, ServletException {
87 int size = outputDestinations.size();
88 if ( size < 1 ) {
89 throw new JMSException( "No output destinations are available" );
90 }
91 }
92 }
93
94