KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > jms > common > routing > impl > SelectorSourceSpec


1 package com.ubermq.jms.common.routing.impl;
2
3 import com.ubermq.jms.common.datagram.*;
4 import com.ubermq.jms.common.routing.*;
5 import com.ubermq.kernel.*;
6 import java.io.*;
7
8 /**
9  * A selector destination node uses a JMS selector implementation to provide a filter on messages
10  * to a particular destination node. <P>
11  *
12  */

13 public class SelectorSourceSpec
14     implements SourceSpec
15 {
16     private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(SelectorSourceSpec.class);
17     
18     private SourceSpec delegate;
19     private Selector selector;
20
21     public SelectorSourceSpec(SourceSpec delegate, Selector selector)
22     {
23         this.delegate = delegate;
24         this.selector = selector;
25         log.debug("selector is " + this.selector.toString());
26     }
27     
28     /**
29      * The only interesting thing that this implementation does is gate the matches
30      * function to check the selector in addition to the primary selector. We assume
31      * that the primary selector is faster and more picky than the selector, so that is
32      * always checked first.
33      *
34      * @param other the descriptor match against. The selector is only checked if the
35      * descriptor is of type <code>MessageDatagramSourceDescriptor</code>. If not, we delegate.
36      *
37      * @return true if the delegate matches and if the descriptor
38      * contains a message datagram, if our selector matches. false o/w.
39      *
40      */

41     public boolean matches(SourceDescriptor other)
42     {
43         if (this.delegate.matches(other))
44         {
45             if (other instanceof MessageDatagramSourceDescriptor)
46             {
47                 MessageDatagramSourceDescriptor mdsd = (MessageDatagramSourceDescriptor)other;
48                 
49                 log.debug("delegate would forward " + mdsd + " checking selector...");
50                 boolean accept = selector.accept(mdsd.getMessageDatagram());
51                 log.debug("selector says " + accept);
52                 return accept;
53             }
54             else
55             {
56                 log.debug("Unknown source descriptor: " + other);
57                 return false;
58             }
59         }
60         else
61             return false;
62     }
63     
64     /**
65      * This implementation is not idempotent. The selector based implementation of this
66      * interface returns <code>false</code> for this method. This is because
67      * <code>MessageDatagramSourceDescriptor</code>
68      */

69     public boolean isIdempotentForEqualDescriptors()
70     {
71         return false;
72     }
73     
74     public String JavaDoc getDisplayName()
75     {
76         return this.delegate.getDisplayName() + " (with " + selector.toString() + ")";
77     }
78     
79     public boolean equals(Object JavaDoc obj)
80     {
81         return this.delegate.equals(obj);
82     }
83     public int hashCode()
84     {
85         return this.delegate.hashCode();
86     }
87     public boolean isMoreSpecificThan(SourceSpec other)
88     {
89         return this.delegate.isMoreSpecificThan(other);
90     }
91     public String JavaDoc toString()
92     {
93         return this.delegate.toString();
94     }
95 }
96
Popular Tags