View Javadoc

1   /**
2    *Copyright [2009-2010] [dennis zhuang]
3    *Licensed under the Apache License, Version 2.0 (the "License");
4    *you may not use this file except in compliance with the License.
5    *You may obtain a copy of the License at
6    *             http://www.apache.org/licenses/LICENSE-2.0
7    *Unless required by applicable law or agreed to in writing,
8    *software distributed under the License is distributed on an "AS IS" BASIS,
9    *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10   *either express or implied. See the License for the specific language governing permissions and limitations under the License
11   */
12  package com.google.code.yanf4j.config;
13  
14  import net.rubyeye.xmemcached.impl.ReconnectRequest;
15  
16  import java.util.concurrent.DelayQueue;
17  
18  /**
19   * Networking configuration
20   * 
21   * @author dennis
22   * 
23   */
24  public class Configuration {
25  
26      public static final String XMEMCACHED_SELECTOR_POOL_SIZE = "xmemcached.selector.pool.size";
27  
28  	/**
29  	 * Read buffer size per connection
30  	 */
31  	private int sessionReadBufferSize = 32 * 1024;
32  
33  	/**
34  	 * Socket SO_TIMEOUT option
35  	 */
36  	private int soTimeout = 0;
37  
38  	/**
39  	 * Thread count for processing WRITABLE event
40  	 */
41  	private int writeThreadCount = 0;
42  
43  	/**
44  	 * Whether to enable statistics
45  	 */
46  	private boolean statisticsServer = false;
47  
48  	/**
49  	 * Whether to handle read write concurrently,default is true
50  	 */
51  	private boolean handleReadWriteConcurrently = true;
52  
53  	/**
54  	 * Thread coount for processing message dispatching
55  	 */
56  	private int dispatchMessageThreadCount = 0;
57  
58  	/**
59  	 * THread count for processing READABLE event
60  	 */
61  	private int readThreadCount = 1;
62  
63      private int selectorPoolSize = System.getProperty(XMEMCACHED_SELECTOR_POOL_SIZE) == null ? 2 * Runtime.getRuntime().availableProcessors() : Integer.parseInt(System.getProperty(XMEMCACHED_SELECTOR_POOL_SIZE));
64  
65  	/**
66  	 * Increasing buffer size per time
67  	 */
68  	public static final int DEFAULT_INCREASE_BUFF_SIZE = 32 * 1024;
69  
70  	/**
71  	 * Max read buffer size for connection
72  	 */
73  	public final static int MAX_READ_BUFFER_SIZE = 128 * 1024;
74  
75  	/**
76  	 * check session idle interval
77  	 */
78  	private volatile long checkSessionTimeoutInterval = 1000L;
79  
80  	public final int getWriteThreadCount() {
81  		return this.writeThreadCount;
82  	}
83  
84  	public final int getDispatchMessageThreadCount() {
85  		return this.dispatchMessageThreadCount;
86  	}
87  
88  	public final void setDispatchMessageThreadCount(
89  			int dispatchMessageThreadCount) {
90  		this.dispatchMessageThreadCount = dispatchMessageThreadCount;
91  	}
92  
93  	public final void setWriteThreadCount(int writeThreadCount) {
94  		this.writeThreadCount = writeThreadCount;
95  	}
96  
97  	private volatile long sessionIdleTimeout = 5000L;
98  
99  	/**
100 	 * @see setSessionIdleTimeout
101 	 * @return
102 	 */
103 	public final long getSessionIdleTimeout() {
104 		return this.sessionIdleTimeout;
105 	}
106 
107 	public final void setSessionIdleTimeout(long sessionIdleTimeout) {
108 		this.sessionIdleTimeout = sessionIdleTimeout;
109 	}
110 
111 	/**
112 	 * @see setSessionReadBufferSize
113 	 * @return
114 	 */
115 	public final int getSessionReadBufferSize() {
116 		return this.sessionReadBufferSize;
117 	}
118 
119 	public final boolean isHandleReadWriteConcurrently() {
120 		return this.handleReadWriteConcurrently;
121 	}
122 
123 	public final int getSoTimeout() {
124 		return this.soTimeout;
125 	}
126 
127 	protected long statisticsInterval = 5 * 60 * 1000L;
128 
129 	public final long getStatisticsInterval() {
130 		return this.statisticsInterval;
131 	}
132 
133 	public final void setStatisticsInterval(long statisticsInterval) {
134 		this.statisticsInterval = statisticsInterval;
135 	}
136 
137 	public final void setSoTimeout(int soTimeout) {
138 		if (soTimeout < 0) {
139 			throw new IllegalArgumentException("soTimeout<0");
140 		}
141 		this.soTimeout = soTimeout;
142 	}
143 
144 	public final void setHandleReadWriteConcurrently(
145 			boolean handleReadWriteConcurrently) {
146 		this.handleReadWriteConcurrently = handleReadWriteConcurrently;
147 	}
148 
149 	public final void setSessionReadBufferSize(int tcpHandlerReadBufferSize) {
150 		if (tcpHandlerReadBufferSize <= 0) {
151 			throw new IllegalArgumentException("tcpHandlerReadBufferSize<=0");
152 		}
153 		this.sessionReadBufferSize = tcpHandlerReadBufferSize;
154 	}
155 
156 	public final boolean isStatisticsServer() {
157 		return this.statisticsServer;
158 	}
159 
160 	public final void setStatisticsServer(boolean statisticsServer) {
161 		this.statisticsServer = statisticsServer;
162 	}
163 
164 	/**
165 	 * @see setReadThreadCount
166 	 * @return
167 	 */
168 	public final int getReadThreadCount() {
169 		return this.readThreadCount;
170 	}
171 
172 	public final void setReadThreadCount(int readThreadCount) {
173 		if (readThreadCount < 0) {
174 			throw new IllegalArgumentException("readThreadCount<0");
175 		}
176 		this.readThreadCount = readThreadCount;
177 	}
178 
179 	public void setCheckSessionTimeoutInterval(long checkSessionTimeoutInterval) {
180 		this.checkSessionTimeoutInterval = checkSessionTimeoutInterval;
181 	}
182 
183 	public long getCheckSessionTimeoutInterval() {
184 		return this.checkSessionTimeoutInterval;
185 	}
186 
187     public void setSelectorPoolSize(int selectorPoolSize) {
188         this.selectorPoolSize = selectorPoolSize;
189     }
190 
191     public int getSelectorPoolSize() {
192         return selectorPoolSize;
193     }
194 }