cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [cassandra] ifesdjeen commented on a change in pull request #428: CASSANDRA-15505
Date Thu, 23 Jan 2020 10:23:12 GMT
ifesdjeen commented on a change in pull request #428: CASSANDRA-15505 
URL: https://github.com/apache/cassandra/pull/428#discussion_r370036470
 
 

 ##########
 File path: test/distributed/org/apache/cassandra/distributed/impl/MessageFilters.java
 ##########
 @@ -86,65 +69,77 @@ public boolean equals(Object that)
 
         public boolean equals(Filter that)
         {
-            return Arrays.equals(from, that.from)
-                    && Arrays.equals(to, that.to)
-                    && Arrays.equals(verbs, that.verbs);
+            return that.matchers.equals(matchers);
         }
 
-        public boolean matches(int from, int to, int verb)
-        {
-            return (this.from == null || Arrays.binarySearch(this.from, from) >= 0)
-                    && (this.to == null || Arrays.binarySearch(this.to, to) >=
0)
-                    && (this.verbs == null || Arrays.binarySearch(this.verbs, verb)
>= 0);
-        }
-
-        public Filter restore()
+        public Filter off()
         {
             filters.remove(this);
             return this;
         }
 
-        public Filter drop()
+        public Filter on()
         {
             filters.add(this);
             return this;
         }
+
+        public boolean matches(int from, int to, IMessage message)
+        {
+            // Compose matchers using logical AND
+            for (IMatcher matcher : matchers)
+            {
+                if (!matcher.matches(from, to, message))
+                    return false;
+            }
+            return true;
+        }
     }
 
     public class Builder implements IMessageFilters.Builder
     {
-        int[] from;
-        int[] to;
-        int[] verbs;
+        final List<IMatcher> matchers;
+
+        private Builder(int... verbs)
+        {
+            this((from, to, msg) -> Arrays.binarySearch(verbs, msg.verb()) >= 0);
+        }
 
-        private Builder(int[] verbs)
+        private Builder(IMatcher matcher)
         {
-            this.verbs = verbs;
+            this.matchers = new ArrayList<>(2);
+            this.matchers.add(matcher);
         }
 
         public Builder from(int ... nums)
         {
-            from = nums;
+            this.matchers.add((from, to, msg) -> Arrays.binarySearch(nums, from) >=
0);
             return this;
         }
 
         public Builder to(int ... nums)
         {
-            to = nums;
+            this.matchers.add((from, to, msg) -> Arrays.binarySearch(nums, to) >= 0);
             return this;
         }
 
-        public Filter ready()
+        /**
+         * Every message for which matcher returns `true` will be _dropped_ (assuming all
+         * other matchers in the chain will return `true` as well).
+         */
+        public Builder messagesMatching(IMatcher matcher)
         {
-            return new Filter(from, to, verbs);
+            this.matchers.add(matcher);
+            return this;
         }
 
         public Filter drop()
         {
-            return ready().drop();
+            return new Filter(matchers).on();
 
 Review comment:
   Just looking at the patch may make it seem confusing, since it's actually two separate
classes. `Builder` has a `List<Matcher>`, which describes its child matchers. When it
combines these matchers into a "sum" matcher, it adds this "sum" matcher (all child matchers
of a specific filter appended to each other with `&&`) to `filters` field of `MessageFilters`.
I still see no descripancy here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message