Skip to content

Commit

Permalink
MAILBOX-262 try to make Abstract*Message useless by delegating when n…
Browse files Browse the repository at this point in the history
…eeded

git-svn-id: https://svn.apache.org/repos/asf/james/project/trunk@1724227 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mbaechler committed Jan 12, 2016
1 parent a028066 commit b09bb0b
Show file tree
Hide file tree
Showing 15 changed files with 712 additions and 746 deletions.
Expand Up @@ -25,6 +25,7 @@


import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.SequenceInputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
Expand All @@ -36,18 +37,22 @@
import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.hbase.HBaseId; import org.apache.james.mailbox.hbase.HBaseId;
import org.apache.james.mailbox.hbase.io.ChunkInputStream; import org.apache.james.mailbox.hbase.io.ChunkInputStream;
import org.apache.james.mailbox.store.mail.model.AbstractMailboxMessage; import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
import org.apache.james.mailbox.store.mail.model.MailboxMessage; import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.apache.james.mailbox.store.mail.model.MessageId;
import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.mail.model.Property;
import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder; import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;


/** /**
* Concrete HBaseMailboxMessage implementation. This implementation does not store any * Concrete HBaseMailboxMessage implementation. This implementation does not store any
* message content. The message content is retrieved using a ChunkedInputStream * message content. The message content is retrieved using a ChunkedInputStream
* directly from HBase. * directly from HBase.
*/ */
public class HBaseMailboxMessage extends AbstractMailboxMessage<HBaseId> { public class HBaseMailboxMessage implements MailboxMessage<HBaseId> {


private static final MessageUidComparator MESSAGE_UID_COMPARATOR = new MessageUidComparator();
private static final String TOSTRING_SEPARATOR = " "; private static final String TOSTRING_SEPARATOR = " ";
/** Configuration for the HBase cluster */ /** Configuration for the HBase cluster */
private final Configuration conf; private final Configuration conf;
Expand Down Expand Up @@ -84,18 +89,12 @@ public class HBaseMailboxMessage extends AbstractMailboxMessage<HBaseId> {
/** Meta data for this message */ /** Meta data for this message */
private List<Property> properties; private List<Property> properties;
private List<String> userFlags; private List<String> userFlags;

/** /**
* Create a copy of the given message. * Create a copy of the given message.
* All properties are cloned except mailbox and UID. * All properties are cloned except mailbox and UID.
* @param mailboxId
* @param uid
* @param modSeq
* @param original
* @throws MailboxException
*/ */
public HBaseMailboxMessage(Configuration conf, HBaseId mailboxId, long uid, long modSeq, MailboxMessage<?> original) throws MailboxException { public HBaseMailboxMessage(Configuration conf, HBaseId mailboxId, long uid, long modSeq, MailboxMessage<?> original) throws MailboxException {
super();
this.conf = conf; this.conf = conf;
this.mailboxId = mailboxId; this.mailboxId = mailboxId;
this.uid = uid; this.uid = uid;
Expand All @@ -117,15 +116,6 @@ public HBaseMailboxMessage(Configuration conf, HBaseId mailboxId, long uid, long
this.properties = original.getProperties(); this.properties = original.getProperties();
} }


/**
* Create a copy of the given message.
* @param mailboxId
* @param internalDate
* @param flags
* @param contentOctets
* @param bodyStartOctet
* @param propertyBuilder
*/
public HBaseMailboxMessage(Configuration conf, HBaseId mailboxId, Date internalDate, Flags flags, long contentOctets, int bodyStartOctet, PropertyBuilder propertyBuilder) { public HBaseMailboxMessage(Configuration conf, HBaseId mailboxId, Date internalDate, Flags flags, long contentOctets, int bodyStartOctet, PropertyBuilder propertyBuilder) {
super(); super();
this.conf = conf; this.conf = conf;
Expand All @@ -142,24 +132,21 @@ public HBaseMailboxMessage(Configuration conf, HBaseId mailboxId, Date internalD
this.properties = propertyBuilder.toProperties(); this.properties = propertyBuilder.toProperties();
} }


/*
* (non-Javadoc)
* @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getBodyContent()
*/
@Override @Override
public InputStream getBodyContent() throws IOException { public InputStream getBodyContent() throws IOException {
return new ChunkInputStream(conf, MESSAGES_TABLE, MESSAGE_DATA_BODY_CF, messageRowKey(this)); return new ChunkInputStream(conf, MESSAGES_TABLE, MESSAGE_DATA_BODY_CF, messageRowKey(this));
} }


/*
* (non-Javadoc)
* @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getHeaderContent()
*/
@Override @Override
public InputStream getHeaderContent() throws IOException { public InputStream getHeaderContent() throws IOException {
return new ChunkInputStream(conf, MESSAGES_TABLE, MESSAGE_DATA_HEADERS_CF, messageRowKey(this)); return new ChunkInputStream(conf, MESSAGES_TABLE, MESSAGE_DATA_HEADERS_CF, messageRowKey(this));
} }


@Override
public InputStream getFullContent() throws IOException {
return new SequenceInputStream(getHeaderContent(), getBodyContent());
}

@Override @Override
public int hashCode() { public int hashCode() {
final int PRIME = 31; final int PRIME = 31;
Expand Down Expand Up @@ -196,19 +183,11 @@ public boolean equals(Object obj) {
return true; return true;
} }


/*
* (non-Javadoc)
* @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getModSeq()
*/
@Override @Override
public long getModSeq() { public long getModSeq() {
return modSeq; return modSeq;
} }


/*
* (non-Javadoc)
* @see org.apache.james.mailbox.store.mail.model.MailboxMessage#setModSeq(long)
*/
@Override @Override
public void setModSeq(long modSeq) { public void setModSeq(long modSeq) {
this.modSeq = modSeq; this.modSeq = modSeq;
Expand All @@ -234,6 +213,11 @@ public String getSubType() {
return subType; return subType;
} }


@Override
public long getBodyOctets() {
return getFullContentOctets() - bodyStartOctet;
}

/** /**
* Gets a read-only list of meta-data properties. * Gets a read-only list of meta-data properties.
* For properties with multiple values, this list will contain * For properties with multiple values, this list will contain
Expand All @@ -259,87 +243,56 @@ public void setTextualLineCount(Long textualLineCount) {
this.textualLineCount = textualLineCount; this.textualLineCount = textualLineCount;
} }


/*
* (non-Javadoc)
* @see org.apache.james.mailbox.store.mail.model.Document#getFullContentOctets()
*/
@Override @Override
public long getFullContentOctets() { public long getFullContentOctets() {
return contentOctets; return contentOctets;
} }


@Override @Override
protected int getBodyStartOctet() { public MessageId getMessageId() {
return bodyStartOctet; return new DefaultMessageId(getMailboxId(), getUid());
} }


/**
* @see MailboxMessage#getInternalDate()
*/
@Override @Override
public Date getInternalDate() { public Date getInternalDate() {
return internalDate; return internalDate;
} }


/**
* @see MailboxMessage#getMailboxId()
*/
@Override @Override
public HBaseId getMailboxId() { public HBaseId getMailboxId() {
return mailboxId; return mailboxId;
} }


/**
* @see MailboxMessage#getUid()
*/
@Override @Override
public long getUid() { public long getUid() {
return uid; return uid;
} }


/**
* @see MailboxMessage#isAnswered()
*/
@Override @Override
public boolean isAnswered() { public boolean isAnswered() {
return answered; return answered;
} }


/**
* @see MailboxMessage#isDeleted()
*/
@Override @Override
public boolean isDeleted() { public boolean isDeleted() {
return deleted; return deleted;
} }


/**
* @see MailboxMessage#isDraft()
*/
@Override @Override
public boolean isDraft() { public boolean isDraft() {
return draft; return draft;
} }


/**
* @see MailboxMessage#isFlagged()
*/
@Override @Override
public boolean isFlagged() { public boolean isFlagged() {
return flagged; return flagged;
} }


/**
* @see MailboxMessage#isRecent()
*/
@Override @Override
public boolean isRecent() { public boolean isRecent() {
return recent; return recent;
} }


/**
* @see MailboxMessage#isSeen()
*/
@Override @Override
public boolean isSeen() { public boolean isSeen() {
return seen; return seen;
Expand All @@ -350,9 +303,6 @@ public void setUid(long uid) {
this.uid = uid; this.uid = uid;
} }


/**
* @see MailboxMessage#setFlags(javax.mail.Flags)
*/
@Override @Override
public final void setFlags(Flags flags) { public final void setFlags(Flags flags) {
answered = flags.contains(Flags.Flag.ANSWERED); answered = flags.contains(Flags.Flag.ANSWERED);
Expand All @@ -366,12 +316,14 @@ public final void setFlags(Flags flags) {
userFlags.addAll(Arrays.asList(userflags)); userFlags.addAll(Arrays.asList(userflags));
} }


@Override
public Flags createFlags() {
return FlagsBuilder.createFlags(this, createUserFlags());
}

/** /**
* This implementation supports user flags * This implementation supports user flags
*
*
*/ */
@Override
public String[] createUserFlags() { public String[] createUserFlags() {
String[] flags = new String[userFlags.size()]; String[] flags = new String[userFlags.size()];
for (int i = 0; i < userFlags.size(); i++) { for (int i = 0; i < userFlags.size(); i++) {
Expand All @@ -396,4 +348,9 @@ public String toString() {
+ " )"; + " )";
return retValue; return retValue;
} }

@Override
public int compareTo(MailboxMessage<HBaseId> other) {
return MESSAGE_UID_COMPARATOR.compare(this, other);
}
} }

0 comments on commit b09bb0b

Please sign in to comment.