james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [20/24] james-project git commit: JAMES-2366 Avoid variable re-allocation in HBase mapAddress
Date Fri, 20 Apr 2018 02:13:05 GMT
JAMES-2366 Avoid variable re-allocation in HBase mapAddress


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a7d50635
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a7d50635
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a7d50635

Branch: refs/heads/master
Commit: a7d506355d33dc440464bedb3396bf6d5c89f848
Parents: 443ed73
Author: benwa <btellier@linagora.com>
Authored: Tue Apr 17 09:54:10 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Apr 20 09:12:02 2018 +0700

----------------------------------------------------------------------
 .../rrt/hbase/HBaseRecipientRewriteTable.java   | 22 ++++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d50635/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
b/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
index d2556c3..f859b08 100644
--- a/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
+++ b/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
@@ -41,9 +41,11 @@ import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.system.hbase.TablePool;
+import org.apache.james.util.OptionalUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Splitter;
 
 /**
@@ -152,17 +154,20 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
 
     @Override
     protected Mappings mapAddress(String user, Domain domain) throws RecipientRewriteTableException
{
+        return getApplicableMappingRow(user, domain)
+            .map(MappingsImpl::fromRawString)
+            .orElse(MappingsImpl.empty());
+    }
+
+    private Optional<String> getApplicableMappingRow(String user, Domain domain) throws
RecipientRewriteTableException {
         HTableInterface table = null;
-        String mappings;
         try {
             table = TablePool.getInstance().getRecipientRewriteTable();
-            mappings = getMapping(table, user, domain);
-            if (mappings == null) {
-                mappings = getMapping(table, WILDCARD, domain);
-            }
-            if (mappings == null) {
-                mappings = getMapping(table, user, Domains.WILDCARD);
-            }
+            HTableInterface tableCopy = table;
+            return OptionalUtils.orSuppliers(
+                Throwing.supplier(() -> Optional.ofNullable(getMapping(tableCopy, user,
domain))).sneakyThrow(),
+                Throwing.supplier(() -> Optional.ofNullable(getMapping(tableCopy, WILDCARD,
domain))).sneakyThrow(),
+                Throwing.supplier(() -> Optional.ofNullable(getMapping(tableCopy, user,
Domains.WILDCARD))).sneakyThrow());
         } catch (IOException e) {
             log.error("Error while mapping address in HBase", e);
             throw new RecipientRewriteTableException("Error while mapping address in HBase",
e);
@@ -175,7 +180,6 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
                 }
             }
         }
-        return MappingsImpl.fromRawString(Optional.ofNullable(mappings).orElse(""));
     }
 
     private String getMapping(HTableInterface table, String user, Domain domain) throws IOException
{


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message