You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by er...@apache.org on 2011/08/20 06:53:39 UTC
svn commit: r1159842 -
/james/server/trunk/hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
Author: eric
Date: Sat Aug 20 04:53:39 2011
New Revision: 1159842
URL: http://svn.apache.org/viewvc?rev=1159842&view=rev
Log:
Better implement HBase RT, Fix alias mapping (JAMES-1273)
Modified:
james/server/trunk/hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
Modified: james/server/trunk/hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java?rev=1159842&r1=1159841&r2=1159842&view=diff
==============================================================================
--- james/server/trunk/hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java (original)
+++ james/server/trunk/hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java Sat Aug 20 04:53:39 2011
@@ -40,6 +40,7 @@ import org.apache.hadoop.hbase.util.Byte
import org.apache.james.rrt.api.RecipientRewriteTableException;
import org.apache.james.rrt.hbase.def.HRecipientRewriteTable;
import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.RecipientRewriteTableUtil;
import org.apache.james.system.hbase.TablePool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,7 +48,7 @@ import org.slf4j.LoggerFactory;
/**
* Implementation of the RecipientRewriteTable for a HBase persistence.
*
- * TODO Fix wildcards, recursive and alias.
+ * TODO Fix wildcard and recursive mapping.
*/
public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable {
@@ -61,50 +62,14 @@ public class HBaseRecipientRewriteTable
*/
@Override
protected void addMappingInternal(String user, String domain, String mapping) throws RecipientRewriteTableException {
- HTable table = null;
- try {
- table = TablePool.getInstance().getRecipientRewriteTable();
- Put put = new Put(Bytes.toBytes(mapping));
- put.add(HRecipientRewriteTable.COLUMN_FAMILY_NAME, Bytes.toBytes(user), Bytes.toBytes(domain));
- table.put(put);
- table.flushCommits();
- } catch (IOException e) {
- log.error("Error while adding mapping in HBase", e);
- throw new RecipientRewriteTableException("Error while adding mapping in HBase", e);
- } finally {
- if (table != null) {
- try {
- TablePool.getInstance().putTable(table);
- } catch (IOException e) {
- // Do nothing, we can't get access to the HBaseSchema.
- }
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#removeMappingInternal(String, String, String)
- */
- @Override
- protected void removeMappingInternal(String user, String domain, String mapping) throws RecipientRewriteTableException {
- HTable table = null;
- try {
- table = TablePool.getInstance().getRecipientRewriteTable();
- Delete delete = new Delete(Bytes.toBytes(mapping));
- delete.deleteColumn(HRecipientRewriteTable.COLUMN_FAMILY_NAME, Bytes.toBytes(user));
- table.delete(delete);
- table.flushCommits();
- } catch (IOException e) {
- log.error("Error while removing mapping from HBase", e);
- throw new RecipientRewriteTableException("Error while removing mapping from HBase", e);
- } finally {
- if (table != null) {
- try {
- TablePool.getInstance().putTable(table);
- } catch (IOException e) {
- // Do nothing, we can't get access to the HBaseSchema.
- }
- }
+ String newUser = getUserString(user);
+ String newDomain = getDomainString(domain);
+ Collection<String> map = getUserDomainMappings(newUser, newDomain);
+ if (map != null && map.size() != 0) {
+ map.add(mapping);
+ doUpdateMapping(newUser, newDomain, RecipientRewriteTableUtil.CollectionToMapping(map));
+ } else {
+ doAddMapping(newUser, newDomain, mapping);
}
}
@@ -240,4 +205,92 @@ public class HBaseRecipientRewriteTable
return mapping.substring(0, mapping.length() - 1);
}
+ /* (non-Javadoc)
+ * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#removeMappingInternal(String, String, String)
+ */
+ @Override
+ protected void removeMappingInternal(String user, String domain, String mapping) throws RecipientRewriteTableException {
+ String newUser = getUserString(user);
+ String newDomain = getDomainString(domain);
+ Collection<String> map = getUserDomainMappings(newUser, newDomain);
+ if (map != null && map.size() > 1) {
+ map.remove(mapping);
+ doUpdateMapping(newUser, newDomain, RecipientRewriteTableUtil.CollectionToMapping(map));
+ } else {
+ doRemoveMapping(newUser, newDomain, mapping);
+ }
+ }
+
+ /**
+ * Update the mapping for the given user and domain
+ *
+ * @param user the user
+ * @param domain the domain
+ * @param mapping the mapping
+ * @throws RecipientRewriteTableException
+ */
+ private void doUpdateMapping(String user, String domain, String mapping) throws RecipientRewriteTableException {
+ doAddMapping(user, domain, mapping);
+ }
+
+ /**
+ * Remove a mapping for the given user and domain
+ *
+ * @param user the user
+ * @param domain the domain
+ * @param mapping the mapping
+ * @throws RecipientRewriteTableException
+ */
+ private void doRemoveMapping(String user, String domain, String mapping) throws RecipientRewriteTableException {
+ HTable table = null;
+ try {
+ table = TablePool.getInstance().getRecipientRewriteTable();
+ Delete delete = new Delete(Bytes.toBytes(mapping));
+ delete.deleteColumn(HRecipientRewriteTable.COLUMN_FAMILY_NAME, Bytes.toBytes(user));
+ table.delete(delete);
+ table.flushCommits();
+ } catch (IOException e) {
+ log.error("Error while removing mapping from HBase", e);
+ throw new RecipientRewriteTableException("Error while removing mapping from HBase", e);
+ } finally {
+ if (table != null) {
+ try {
+ TablePool.getInstance().putTable(table);
+ } catch (IOException e) {
+ // Do nothing, we can't get access to the HBaseSchema.
+ }
+ }
+ }
+ }
+
+ /**
+ * Add mapping for given user and domain
+ *
+ * @param user the user
+ * @param domain the domain
+ * @param mapping the mapping
+ * @throws RecipientRewriteTableException
+ */
+ private void doAddMapping(String user, String domain, String mapping) throws RecipientRewriteTableException {
+ HTable table = null;
+ try {
+ table = TablePool.getInstance().getRecipientRewriteTable();
+ Put put = new Put(Bytes.toBytes(mapping));
+ put.add(HRecipientRewriteTable.COLUMN_FAMILY_NAME, Bytes.toBytes(user), Bytes.toBytes(domain));
+ table.put(put);
+ table.flushCommits();
+ } catch (IOException e) {
+ log.error("Error while adding mapping in HBase", e);
+ throw new RecipientRewriteTableException("Error while adding mapping in HBase", e);
+ } finally {
+ if (table != null) {
+ try {
+ TablePool.getInstance().putTable(table);
+ } catch (IOException e) {
+ // Do nothing, we can't get access to the HBaseSchema.
+ }
+ }
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org