View Javadoc

1   //  Copyright 2005 The Apache Software Foundation
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
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  }