1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.jph.channels.router;
15
16 import org.jph.channels.OutputChannel;
17 import org.jph.collections.predicate.Predicate;
18 import org.jph.collections.predicate.TruePredicate;
19
20 /***
21 * The OutRouterEntry is a entry for in the RoutingOutputChannel. Every OutRouterEntry
22 * has 2 fields:
23 * <ul>
24 * <li>channel: this is the channel where the message can be send to.</li>
25 * <li>predicate: that checks if a message can be send to the channel.</li>
26 * </ul>
27 *
28 * @author Peter Veentjer.
29 */
30 public final class OutRouterEntry<M> {
31
32 private final OutputChannel<M> _channel;
33 private final Predicate<M> _predicate;
34
35 /***
36 * Constructs a OutRouterEntry with a TrueMessagePredicate.
37 *
38 * @param channel
39 * @throws NullPointerException if channel is null.
40 */
41 public OutRouterEntry(OutputChannel<M> channel) {
42 this(channel, null);
43 }
44
45 /***
46 * Constructs a OutRouterEntry with the given OutputChannel and MessagePredicate.
47 * If the MessagePredicate is null, a TrueMessagePredicate will be used instead.
48 *
49 * @param channel
50 * @param predicate
51 * @throws NullPointerException if channel is null.
52 */
53 public OutRouterEntry(OutputChannel<M> channel, Predicate<M> predicate) {
54 if (channel == null) throw new NullPointerException();
55
56 _channel = channel;
57 _predicate = predicate == null ? new TruePredicate<M>() : predicate;
58 }
59
60 /***
61 * Returns the OutputChannel where the message can be send to.
62 */
63 public OutputChannel<M> getChannel() {
64 return _channel;
65 }
66
67 /***
68 * Returns the MessagePredicate that checks if a message can be send
69 * to the OutputChannel.
70 */
71 public Predicate<M> getPredicate() {
72 return _predicate;
73 }
74
75 public String toString() {
76 return "OutRouterEntry(" + _channel + "," + _predicate + ")";
77 }
78 }