hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1394672 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/examples/org/apache/http/examples/nio/ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ httpcore/src/mai...
Date Fri, 05 Oct 2012 17:25:25 GMT
Author: olegk
Date: Fri Oct  5 17:25:25 2012
New Revision: 1394672

URL: http://svn.apache.org/viewvc?rev=1394672&view=rev
Log:
Configuration API changes: made IOReactorConfig (potentially) immutable

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java?rev=1394672&r1=1394671&r2=1394672&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
Fri Oct  5 17:25:25 2012
@@ -123,14 +123,14 @@ public class NHttpReverseProxy {
         System.out.println("Reverse proxy to " + targetHost);
 
         HttpParams params = new HttpCoreConfigBuilder()
-            .setSocketTimeout(3000)
-            .setConnectTimeout(3000)
-            .setSocketBufferSize(8 * 1024)
             .setUserAgent("Test/1.1")
             .setOriginServer("Test/1.1").build();
 
-        IOReactorConfig config = new IOReactorConfig();
-        config.setIoThreadCount(1);
+        IOReactorConfig config = IOReactorConfig.custom()
+            .setIoThreadCount(1)
+            .setSoTimeout(3000)
+            .setConnectTimeout(3000)
+            .build();
         final ConnectingIOReactor connectingIOReactor = new DefaultConnectingIOReactor(config);
         final ListeningIOReactor listeningIOReactor = new DefaultListeningIOReactor(config);
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java?rev=1394672&r1=1394671&r2=1394672&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java
Fri Oct  5 17:25:25 2012
@@ -52,6 +52,7 @@ import org.apache.http.impl.nio.DefaultN
 import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
 import org.apache.http.impl.nio.SSLNHttpServerConnectionFactory;
 import org.apache.http.impl.nio.reactor.DefaultListeningIOReactor;
+import org.apache.http.impl.nio.reactor.IOReactorConfig;
 import org.apache.http.nio.NHttpConnection;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.NHttpServerConnection;
@@ -96,10 +97,9 @@ public class NHttpServer {
         }
         // HTTP parameters for the server
         HttpParams params = new HttpCoreConfigBuilder()
-            .setSocketTimeout(3000)
-            .setConnectTimeout(3000)
-            .setSocketBufferSize(8 * 1024)
+            .setUserAgent("Test/1.1")
             .setOriginServer("Test/1.1").build();
+
         // Create HTTP protocol processing chain
         HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[]
{
                 // Use standard server-side protocol interceptors
@@ -147,14 +147,20 @@ public class NHttpServer {
             KeyManager[] keymanagers = kmfactory.getKeyManagers();
             SSLContext sslcontext = SSLContext.getInstance("TLS");
             sslcontext.init(keymanagers, null, null);
-            connFactory = new SSLNHttpServerConnectionFactory(sslcontext, null, params);
+            connFactory = new SSLNHttpServerConnectionFactory(sslcontext, null);
         } else {
-            connFactory = new DefaultNHttpServerConnectionFactory(params);
+            connFactory = new DefaultNHttpServerConnectionFactory();
         }
         // Create server-side I/O event dispatch
         IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler,
connFactory);
+        // Set I/O reactor defaults
+        IOReactorConfig config = IOReactorConfig.custom()
+            .setIoThreadCount(1)
+            .setSoTimeout(3000)
+            .setConnectTimeout(3000)
+            .build();
         // Create server-side I/O reactor
-        ListeningIOReactor ioReactor = new DefaultListeningIOReactor();
+        ListeningIOReactor ioReactor = new DefaultListeningIOReactor(config);
         try {
             // Listen of the given port
             ioReactor.listen(new InetSocketAddress(port));

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=1394672&r1=1394671&r2=1394672&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Fri Oct  5 17:25:25 2012
@@ -92,17 +92,6 @@ import org.apache.http.util.Args;
  * can obtain the audit log using {@link #getAuditLog()}, examine exceptions
  * thrown by the I/O reactor prior and in the course of the reactor shutdown
  * and decide whether it is safe to restart the I/O reactor.
- * <p>
- * The following parameters can be used to customize the behavior of this
- * class:
- * <ul>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_LINGER}</li>
- *  <li>{@link org.apache.http.nio.params.NIOReactorPNames#SELECT_INTERVAL}</li>
- *  <li>{@link org.apache.http.nio.params.NIOReactorPNames#GRACE_PERIOD}</li>
- *  <li>{@link org.apache.http.nio.params.NIOReactorPNames#INTEREST_OPS_QUEUEING}</li>
- * </ul>
  *
  * @since 4.0
  */
@@ -148,15 +137,7 @@ public abstract class AbstractMultiworke
             final IOReactorConfig config,
             final ThreadFactory threadFactory) throws IOReactorException {
         super();
-        if (config != null) {
-            try {
-                this.config = config.clone();
-            } catch (CloneNotSupportedException ex) {
-                throw new IOReactorException("Unable to clone configuration");
-            }
-        } else {
-            this.config = new IOReactorConfig();
-        }
+        this.config = config != null ? config : IOReactorConfig.DEFAULT;
         this.params = new BasicHttpParams();
         try {
             this.selector = Selector.open();
@@ -191,17 +172,18 @@ public abstract class AbstractMultiworke
 
     static IOReactorConfig convert(int workerCount, final HttpParams params) {
         Args.notNull(params, "HTTP parameters");
-        IOReactorConfig config = new IOReactorConfig();
-        config.setSelectInterval(NIOReactorParams.getSelectInterval(params));
-        config.setShutdownGracePeriod(NIOReactorParams.getGracePeriod(params));
-        config.setInterestOpQueued(NIOReactorParams.getInterestOpsQueueing(params));
-        config.setIoThreadCount(workerCount);
-        config.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
-        config.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
-        config.setSoLinger(HttpConnectionParams.getLinger(params));
-        config.setSoKeepalive(HttpConnectionParams.getSoKeepalive(params));
-        config.setConnectTimeout(HttpConnectionParams.getConnectionTimeout(params));
-        config.setSoReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
+        IOReactorConfig config = IOReactorConfig.custom()
+            .setSelectInterval(NIOReactorParams.getSelectInterval(params))
+            .setShutdownGracePeriod(NIOReactorParams.getGracePeriod(params))
+            .setInterestOpQueued(NIOReactorParams.getInterestOpsQueueing(params))
+            .setIoThreadCount(workerCount)
+            .setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params))
+            .setSoTimeout(HttpConnectionParams.getSoTimeout(params))
+            .setSoLinger(HttpConnectionParams.getLinger(params))
+            .setSoKeepAlive(HttpConnectionParams.getSoKeepalive(params))
+            .setConnectTimeout(HttpConnectionParams.getConnectionTimeout(params))
+            .setSoReuseAddress(HttpConnectionParams.getSoReuseaddr(params))
+            .build();
 
         return config;
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java?rev=1394672&r1=1394671&r2=1394672&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
Fri Oct  5 17:25:25 2012
@@ -42,7 +42,10 @@ import org.apache.http.util.Args;
 public final class IOReactorConfig implements Cloneable {
 
     private static final int AVAIL_PROCS = Runtime.getRuntime().availableProcessors();
-    
+
+    public static final IOReactorConfig DEFAULT = new Builder().build();
+
+    // TODO: make final
     private long selectInterval;
     private long shutdownGracePeriod;
     private boolean interestOpQueued;
@@ -54,6 +57,7 @@ public final class IOReactorConfig imple
     private boolean tcpNoDelay;
     private int connectTimeout;
 
+    @Deprecated
     public IOReactorConfig() {
         super();
         this.selectInterval = 1000;
@@ -68,6 +72,30 @@ public final class IOReactorConfig imple
         this.connectTimeout = 0;
     }
 
+    IOReactorConfig(
+            long selectInterval,
+            long shutdownGracePeriod,
+            boolean interestOpQueued,
+            int ioThreadCount,
+            int soTimeout,
+            boolean soReuseAddress,
+            int soLinger,
+            boolean soKeepAlive,
+            boolean tcpNoDelay,
+            int connectTimeout) {
+        super();
+        this.selectInterval = selectInterval;
+        this.shutdownGracePeriod = shutdownGracePeriod;
+        this.interestOpQueued = interestOpQueued;
+        this.ioThreadCount = ioThreadCount;
+        this.soTimeout = soTimeout;
+        this.soReuseAddress = soReuseAddress;
+        this.soLinger = soLinger;
+        this.soKeepAlive = soKeepAlive;
+        this.tcpNoDelay = tcpNoDelay;
+        this.connectTimeout = connectTimeout;
+    }
+
     /**
      * Determines time interval in milliseconds at which the I/O reactor wakes up to check
for
      * timed out sessions and session requests.
@@ -78,10 +106,7 @@ public final class IOReactorConfig imple
         return this.selectInterval;
     }
 
-    /**
-     * Defines time interval in milliseconds at which the I/O reactor wakes up to check for
-     * timed out sessions and session requests. May not be negative or zero.
-     */
+    @Deprecated
     public void setSelectInterval(long selectInterval) {
         Args.positive(selectInterval, "Select internal");
         this.selectInterval = selectInterval;
@@ -97,10 +122,7 @@ public final class IOReactorConfig imple
         return this.shutdownGracePeriod;
     }
 
-    /**
-     * Defines grace period in milliseconds the I/O reactors are expected to block waiting
-     * for individual worker threads to terminate cleanly. May not be negative or zero.
-     */
+    @Deprecated
     public void setShutdownGracePeriod(long gracePeriod) {
         Args.positive(gracePeriod, "Shutdown grace period");
         this.shutdownGracePeriod = gracePeriod;
@@ -121,15 +143,7 @@ public final class IOReactorConfig imple
         return this.interestOpQueued;
     }
 
-    /**
-     * Defines whether or not I/O interest operations are to be queued and executed
-     * asynchronously by the I/O reactor thread or to be applied to the underlying
-     * {@link SelectionKey} immediately.
-     *
-     * @see SelectionKey
-     * @see SelectionKey#interestOps()
-     * @see SelectionKey#interestOps(int)
-     */
+    @Deprecated
     public void setInterestOpQueued(boolean interestOpQueued) {
         this.interestOpQueued = interestOpQueued;
     }
@@ -143,10 +157,7 @@ public final class IOReactorConfig imple
         return this.ioThreadCount;
     }
 
-    /**
-     * Defines the number of I/O dispatch threads to be used by the I/O reactor.
-     * May not be negative or zero.
-     */
+    @Deprecated
     public void setIoThreadCount(int ioThreadCount) {
         Args.positive(ioThreadCount, "I/O thread count");
         this.ioThreadCount = ioThreadCount;
@@ -163,13 +174,7 @@ public final class IOReactorConfig imple
         return soTimeout;
     }
 
-    /**
-     * Defines the default socket timeout value for non-blocking I/O operations.
-     * <p/>
-     * Default: <code>0</code> (no timeout)
-     *
-     * @see SocketOptions#SO_TIMEOUT
-     */
+    @Deprecated
     public void setSoTimeout(int soTimeout) {
         this.soTimeout = soTimeout;
     }
@@ -186,12 +191,7 @@ public final class IOReactorConfig imple
         return soReuseAddress;
     }
 
-    /**
-     * Defines the default value of the {@link SocketOptions#SO_REUSEADDR} parameter
-     * for newly created sockets.
-     *
-     * @see SocketOptions#SO_REUSEADDR
-     */
+    @Deprecated
     public void setSoReuseAddress(boolean soReuseAddress) {
         this.soReuseAddress = soReuseAddress;
     }
@@ -208,12 +208,7 @@ public final class IOReactorConfig imple
         return soLinger;
     }
 
-    /**
-     * Defines the default value of the {@link SocketOptions#SO_LINGER} parameter
-     * for newly created sockets.
-     *
-     * @see SocketOptions#SO_LINGER
-     */
+    @Deprecated
     public void setSoLinger(int soLinger) {
         this.soLinger = soLinger;
     }
@@ -230,14 +225,7 @@ public final class IOReactorConfig imple
         return this.soKeepAlive;
     }
 
-    /**
-     * Defines the default value of the {@link SocketOptions#SO_KEEPALIVE} parameter
-     * for newly created sockets.
-     * <p/>
-     * Default: <code>-1</code>
-     *
-     * @see SocketOptions#SO_KEEPALIVE
-     */
+    @Deprecated
     public void setSoKeepalive(boolean soKeepAlive) {
         this.soKeepAlive = soKeepAlive;
     }
@@ -254,12 +242,7 @@ public final class IOReactorConfig imple
         return tcpNoDelay;
     }
 
-    /**
-     * Defines the default value of the {@link SocketOptions#TCP_NODELAY} parameter
-     * for newly created sockets.
-     *
-     * @see SocketOptions#TCP_NODELAY
-     */
+    @Deprecated
     public void setTcpNoDelay(boolean tcpNoDelay) {
         this.tcpNoDelay = tcpNoDelay;
     }
@@ -273,9 +256,7 @@ public final class IOReactorConfig imple
         return connectTimeout;
     }
 
-    /**
-     * Defines the default connect timeout value for non-blocking connection requests.
-     */
+    @Deprecated
     public void setConnectTimeout(int connectTimeout) {
         this.connectTimeout = connectTimeout;
     }
@@ -285,6 +266,94 @@ public final class IOReactorConfig imple
         return (IOReactorConfig) super.clone();
     }
 
+    public static Builder custom() {
+        return new Builder();
+    }
+
+    public static class Builder {
+
+        private long selectInterval;
+        private long shutdownGracePeriod;
+        private boolean interestOpQueued;
+        private int ioThreadCount;
+        private int soTimeout;
+        private boolean soReuseAddress;
+        private int soLinger;
+        private boolean soKeepAlive;
+        private boolean tcpNoDelay;
+        private int connectTimeout;
+
+        Builder() {
+            this.selectInterval = 1000;
+            this.shutdownGracePeriod = 500;
+            this.interestOpQueued = false;
+            this.ioThreadCount = AVAIL_PROCS;
+            this.soTimeout = 0;
+            this.soReuseAddress = false;
+            this.soLinger = -1;
+            this.soKeepAlive = false;
+            this.tcpNoDelay = true;
+            this.connectTimeout = 0;
+        }
+
+        public Builder setSelectInterval(long selectInterval) {
+            this.selectInterval = selectInterval;
+            return this;
+        }
+
+        public Builder setShutdownGracePeriod(long shutdownGracePeriod) {
+            this.shutdownGracePeriod = shutdownGracePeriod;
+            return this;
+        }
+
+        public Builder setInterestOpQueued(boolean interestOpQueued) {
+            this.interestOpQueued = interestOpQueued;
+            return this;
+        }
+
+        public Builder setIoThreadCount(int ioThreadCount) {
+            this.ioThreadCount = ioThreadCount;
+            return this;
+        }
+
+        public Builder setSoTimeout(int soTimeout) {
+            this.soTimeout = soTimeout;
+            return this;
+        }
+
+        public Builder setSoReuseAddress(boolean soReuseAddress) {
+            this.soReuseAddress = soReuseAddress;
+            return this;
+        }
+
+        public Builder setSoLinger(int soLinger) {
+            this.soLinger = soLinger;
+            return this;
+        }
+
+        public Builder setSoKeepAlive(boolean soKeepAlive) {
+            this.soKeepAlive = soKeepAlive;
+            return this;
+        }
+
+        public Builder setTcpNoDelay(boolean tcpNoDelay) {
+            this.tcpNoDelay = tcpNoDelay;
+            return this;
+        }
+
+        public Builder setConnectTimeout(int connectTimeout) {
+            this.connectTimeout = connectTimeout;
+            return this;
+        }
+
+        public IOReactorConfig build() {
+            return new IOReactorConfig(
+                    selectInterval, shutdownGracePeriod, interestOpQueued, ioThreadCount,
+                    soTimeout, soReuseAddress, soLinger, soKeepAlive, tcpNoDelay, connectTimeout);
+        }
+
+    }
+
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java?rev=1394672&r1=1394671&r2=1394672&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java
Fri Oct  5 17:25:25 2012
@@ -79,8 +79,7 @@ public class TestDefaultListeningIOReact
     @Test
     public void testEndpointUpAndDown() throws Exception {
         final IOEventDispatch eventDispatch = createIOEventDispatch();
-        IOReactorConfig config = new IOReactorConfig();
-        config.setIoThreadCount(1);
+        IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(1).build();
         final ListeningIOReactor ioreactor = new DefaultListeningIOReactor(config);
 
         Thread t = new Thread(new Runnable() {
@@ -130,8 +129,7 @@ public class TestDefaultListeningIOReact
     @Test
     public void testEndpointAlreadyBoundFatal() throws Exception {
         final IOEventDispatch eventDispatch = createIOEventDispatch();
-        IOReactorConfig config = new IOReactorConfig();
-        config.setIoThreadCount(1);
+        IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(1).build();
         final ListeningIOReactor ioreactor = new DefaultListeningIOReactor(config);
 
         final CountDownLatch latch = new CountDownLatch(1);
@@ -176,8 +174,7 @@ public class TestDefaultListeningIOReact
     @Test
     public void testEndpointAlreadyBoundNonFatal() throws Exception {
         final IOEventDispatch eventDispatch = createIOEventDispatch();
-        IOReactorConfig config = new IOReactorConfig();
-        config.setIoThreadCount(1);
+        IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(1).build();
         final DefaultListeningIOReactor ioreactor = new DefaultListeningIOReactor(config);
 
         ioreactor.setExceptionHandler(new IOReactorExceptionHandler() {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java?rev=1394672&r1=1394671&r2=1394672&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java
Fri Oct  5 17:25:25 2012
@@ -34,9 +34,9 @@ import org.apache.http.util.Args;
  *
  * @since 4.3
  */
-public class MessageConstraints {
+public class MessageConstraints implements Cloneable {
 
-    public static final MessageConstraints UNLIMITED = new MessageConstraints(-1, -1);
+    public static final MessageConstraints UNLIMITED = new Builder().build();
     public static final MessageConstraints DEFAULT = UNLIMITED;
 
     private final int maxLineLength;
@@ -48,14 +48,6 @@ public class MessageConstraints {
         this.maxHeaderCount = maxHeaderCount;
     }
 
-    public static MessageConstraints lineLen(int max) {
-        return new MessageConstraints(Args.notNegative(max, "Max line length"), -1);
-    }
-
-    public static MessageConstraints.Builder custom() {
-        return new MessageConstraints.Builder();
-    }
-
     public int getMaxLineLength() {
         return maxLineLength;
     }
@@ -65,6 +57,11 @@ public class MessageConstraints {
     }
 
     @Override
+    protected MessageConstraints clone() throws CloneNotSupportedException {
+        return (MessageConstraints) super.clone();
+    }
+
+    @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("[maxLineLength=").append(maxLineLength)
@@ -73,13 +70,22 @@ public class MessageConstraints {
         return builder.toString();
     }
 
+    public static MessageConstraints lineLen(int max) {
+        return new MessageConstraints(Args.notNegative(max, "Max line length"), -1);
+    }
+
+    public static MessageConstraints.Builder custom() {
+        return new Builder();
+    }
+
     public static class Builder {
 
         private int maxLineLength;
         private int maxHeaderCount;
 
-        public int getMaxLineLength() {
-            return maxLineLength;
+        Builder() {
+            this.maxLineLength = -1;
+            this.maxHeaderCount = -1;
         }
 
         public Builder setMaxLineLength(int maxLineLength) {
@@ -87,10 +93,6 @@ public class MessageConstraints {
             return this;
         }
 
-        public int getMaxHeaderCount() {
-            return maxHeaderCount;
-        }
-
         public Builder setMaxHeaderCount(int maxHeaderCount) {
             this.maxHeaderCount = maxHeaderCount;
             return this;



Mime
View raw message