Skip to content

Commit

Permalink
JAMES-2050 Move all default configurations of processor to ImapConfig…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
quynhn committed Jun 12, 2017
1 parent 1bb8211 commit 4adf702
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
Expand Up @@ -21,7 +21,6 @@

import java.util.concurrent.TimeUnit;

import org.apache.james.imap.processor.IdleProcessor;
import org.apache.commons.lang.StringUtils;

import com.google.common.base.Function;
Expand All @@ -34,6 +33,9 @@
import com.google.common.collect.ImmutableSet;

public class ImapConfiguration {
public final static boolean DEFAULT_ENABLE_IDLE = true;
public final static long DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS = 2 * 60;
public final static TimeUnit DEFAULT_HEARTBEAT_INTERVAL_UNIT = TimeUnit.SECONDS;

public static Builder builder() {
return new Builder();
Expand Down Expand Up @@ -105,9 +107,9 @@ public ImapConfiguration build() {
.transform(NORMALIZE_STRING)
.toSet();
return new ImapConfiguration(
enableIdle.or(IdleProcessor.DEFAULT_ENABLE_IDLE),
idleTimeInterval.or(IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS),
idleTimeIntervalUnit.or(IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_UNIT),
enableIdle.or(DEFAULT_ENABLE_IDLE),
idleTimeInterval.or(DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS),
idleTimeIntervalUnit.or(DEFAULT_HEARTBEAT_INTERVAL_UNIT),
normalizeDisableCaps);
}
}
Expand Down
Expand Up @@ -51,10 +51,6 @@
public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> implements CapabilityImplementingProcessor {

private final static List<String> CAPS = Collections.unmodifiableList(Arrays.asList(SUPPORTS_IDLE));
// 2 minutes
public final static long DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS = 2 * 60;
public final static TimeUnit DEFAULT_HEARTBEAT_INTERVAL_UNIT = TimeUnit.SECONDS;
public final static boolean DEFAULT_ENABLE_IDLE = true;
public final static int DEFAULT_SCHEDULED_POOL_CORE_SIZE = 5;
private final static String DONE = "DONE";
private TimeUnit heartbeatIntervalUnit;
Expand All @@ -64,17 +60,7 @@ public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> impleme

public IdleProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
MetricFactory metricFactory) {
this(next, mailboxManager, factory, DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS, DEFAULT_HEARTBEAT_INTERVAL_UNIT, Executors.newScheduledThreadPool(DEFAULT_SCHEDULED_POOL_CORE_SIZE), metricFactory);

}

public IdleProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory, long heartbeatInterval, TimeUnit heartbeatIntervalUnit, ScheduledExecutorService heartbeatExecutor,
MetricFactory metricFactory) {
super(IdleRequest.class, next, mailboxManager, factory, metricFactory);
this.heartbeatInterval = heartbeatInterval;
this.heartbeatIntervalUnit = heartbeatIntervalUnit;
this.heartbeatExecutor = heartbeatExecutor;

}

@Override
Expand Down
Expand Up @@ -22,8 +22,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.TimeUnit;

import org.apache.james.imap.processor.IdleProcessor;

import com.google.common.collect.ImmutableSet;

import nl.jqno.equalsverifier.EqualsVerifier;
Expand All @@ -44,7 +42,7 @@ public void shouldRespectBeanContract() {
public void idleKeepAliveShouldBeDefaultValueWhenNoSetting() throws Exception {
ImapConfiguration imapConfiguration = ImapConfiguration.builder().build();

assertThat(imapConfiguration.getIdleTimeInterval()).isEqualTo(IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS);
assertThat(imapConfiguration.getIdleTimeInterval()).isEqualTo(ImapConfiguration.DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS);
}

@Test
Expand Down Expand Up @@ -79,7 +77,7 @@ public void idleKeepAliveShouldThrowWhenNegative() throws Exception {
public void millisecondsShouldBeDefaultValueWhenNoSetting() throws Exception {
ImapConfiguration imapConfiguration = ImapConfiguration.builder().build();

assertThat(imapConfiguration.getIdleTimeIntervalUnit()).isEqualTo(IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_UNIT);
assertThat(imapConfiguration.getIdleTimeIntervalUnit()).isEqualTo(ImapConfiguration.DEFAULT_HEARTBEAT_INTERVAL_UNIT);
}

@Test
Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.decode.ImapDecoder;
import org.apache.james.imap.encode.ImapEncoder;
import org.apache.james.imap.processor.IdleProcessor;
import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
import org.apache.james.protocols.netty.ChannelGroupHandler;
Expand Down Expand Up @@ -117,8 +116,8 @@ public void doConfigure(HierarchicalConfiguration configuration) throws Configur
ImmutableSet<String> disabledCaps = ImmutableSet.copyOf(Splitter.on(CAPABILITY_SEPARATOR).split(configuration.getString("disabledCaps", "")));

return ImapConfiguration.builder()
.enableIdle(configuration.getBoolean("enableIdle", IdleProcessor.DEFAULT_ENABLE_IDLE))
.idleTimeInterval(configuration.getLong("idleTimeInterval", IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS))
.enableIdle(configuration.getBoolean("enableIdle", ImapConfiguration.DEFAULT_ENABLE_IDLE))
.idleTimeInterval(configuration.getLong("idleTimeInterval", ImapConfiguration.DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS))
.idleTimeIntervalUnit(getTimeIntervalUnit(configuration.getString("idleTimeIntervalUnit", DEFAULT_TIME_UNIT)))
.disabledCaps(disabledCaps)
.build();
Expand All @@ -128,8 +127,8 @@ private static TimeUnit getTimeIntervalUnit(String timeIntervalUnit) {
try {
return TimeUnit.valueOf(timeIntervalUnit);
} catch (IllegalArgumentException e) {
LOG.info("Time interval unit is not valid {}, the default {} value should be used", timeIntervalUnit, IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_UNIT);
return IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_UNIT;
LOG.info("Time interval unit is not valid {}, the default {} value should be used", timeIntervalUnit, ImapConfiguration.DEFAULT_HEARTBEAT_INTERVAL_UNIT);
return ImapConfiguration.DEFAULT_HEARTBEAT_INTERVAL_UNIT;
}
}

Expand Down
Expand Up @@ -23,7 +23,6 @@
import java.util.concurrent.TimeUnit;

import org.apache.james.imap.api.ImapConfiguration;
import org.apache.james.imap.processor.IdleProcessor;
import org.apache.commons.configuration.DefaultConfigurationBuilder;

import com.google.common.collect.ImmutableSet;
Expand All @@ -41,9 +40,9 @@ public void getImapConfigurationShouldReturnDefaultValuesWhenEmpty() throws Exce
ImapConfiguration imapConfiguration = IMAPServer.getImapConfiguration(new DefaultConfigurationBuilder());

ImapConfiguration expectImapConfiguration = ImapConfiguration.builder()
.enableIdle(IdleProcessor.DEFAULT_ENABLE_IDLE)
.idleTimeInterval(IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS)
.idleTimeIntervalUnit(IdleProcessor.DEFAULT_HEARTBEAT_INTERVAL_UNIT)
.enableIdle(ImapConfiguration.DEFAULT_ENABLE_IDLE)
.idleTimeInterval(ImapConfiguration.DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS)
.idleTimeIntervalUnit(ImapConfiguration.DEFAULT_HEARTBEAT_INTERVAL_UNIT)
.disabledCaps(ImmutableSet.<String>of())
.build();

Expand Down

0 comments on commit 4adf702

Please sign in to comment.