Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Formatted code.

Change-Id: Ib5700f44129e5be33fee86f05b153527f66e9c01
Reviewed-on: http://review.couchbase.org/8644
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information...
commit fd7ce14565b3243ac630bd39b2c147eaa4e35289 1 parent b406daa
@mikewied mikewied authored mikewied committed
Showing with 19,181 additions and 14,572 deletions.
  1. +78 −55 src/main/java/net/spy/memcached/AddrUtil.java
  2. +119 −98 src/main/java/net/spy/memcached/ArrayModNodeLocator.java
  3. +123 −103 src/main/java/net/spy/memcached/BaseCacheMap.java
  4. +62 −43 src/main/java/net/spy/memcached/BinaryConnectionFactory.java
  5. +27 −5 src/main/java/net/spy/memcached/BroadcastOpFactory.java
  6. +29 −7 src/main/java/net/spy/memcached/CASMutation.java
  7. +110 −89 src/main/java/net/spy/memcached/CASMutator.java
  8. +38 −16 src/main/java/net/spy/memcached/CASResponse.java
  9. +51 −30 src/main/java/net/spy/memcached/CASValue.java
  10. +47 −28 src/main/java/net/spy/memcached/CacheMap.java
  11. +71 −48 src/main/java/net/spy/memcached/CachedData.java
  12. +142 −121 src/main/java/net/spy/memcached/ConnectionFactory.java
  13. +525 −508 src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java
  14. +36 −15 src/main/java/net/spy/memcached/ConnectionObserver.java
  15. +472 −411 src/main/java/net/spy/memcached/CouchbaseClient.java
  16. +44 −15 src/main/java/net/spy/memcached/CouchbaseClientIF.java
  17. +246 −220 src/main/java/net/spy/memcached/CouchbaseConnection.java
  18. +60 −37 src/main/java/net/spy/memcached/CouchbaseConnectionFactory.java
  19. +197 −179 src/main/java/net/spy/memcached/CouchbaseNode.java
  20. +312 −257 src/main/java/net/spy/memcached/DefaultConnectionFactory.java
  21. +46 −25 src/main/java/net/spy/memcached/FailureMode.java
  22. +147 −130 src/main/java/net/spy/memcached/HashAlgorithm.java
  23. +53 −28 src/main/java/net/spy/memcached/KetamaConnectionFactory.java
  24. +81 −56 src/main/java/net/spy/memcached/KetamaIterator.java
  25. +173 −144 src/main/java/net/spy/memcached/KetamaNodeLocator.java
  26. +53 −27 src/main/java/net/spy/memcached/KeyUtil.java
  27. +263 −231 src/main/java/net/spy/memcached/MembaseClient.java
  28. +29 −6 src/main/java/net/spy/memcached/MembaseClientIF.java
  29. +112 −86 src/main/java/net/spy/memcached/MembaseConnectionFactory.java
  30. +1,835 −1,784 src/main/java/net/spy/memcached/MemcachedClient.java
  31. +100 −93 src/main/java/net/spy/memcached/MemcachedClientIF.java
  32. +892 −886 src/main/java/net/spy/memcached/MemcachedConnection.java
  33. +207 −184 src/main/java/net/spy/memcached/MemcachedNode.java
  34. +131 −111 src/main/java/net/spy/memcached/MemcachedNodeROImpl.java
  35. +60 −37 src/main/java/net/spy/memcached/NodeLocator.java
  36. +263 −240 src/main/java/net/spy/memcached/OperationFactory.java
  37. +30 −9 src/main/java/net/spy/memcached/OperationTimeoutException.java
  38. +393 −359 src/main/java/net/spy/memcached/TapClient.java
  39. +339 −308 src/main/java/net/spy/memcached/TapConnectionProvider.java
  40. +52 −22 src/main/java/net/spy/memcached/TapMessagePrinter.java
  41. +80 −49 src/main/java/net/spy/memcached/auth/AuthDescriptor.java
  42. +99 −77 src/main/java/net/spy/memcached/auth/AuthThread.java
  43. +58 −37 src/main/java/net/spy/memcached/auth/AuthThreadMonitor.java
  44. +51 −29 src/main/java/net/spy/memcached/auth/PlainCallbackHandler.java
  45. +42 −19 src/main/java/net/spy/memcached/compat/CloseUtil.java
  46. +41 −23 src/main/java/net/spy/memcached/compat/SpyObject.java
  47. +51 −32 src/main/java/net/spy/memcached/compat/SpyThread.java
  48. +109 −88 src/main/java/net/spy/memcached/compat/SyncThread.java
  49. +239 −216 src/main/java/net/spy/memcached/compat/log/AbstractLogger.java
  50. +64 −45 src/main/java/net/spy/memcached/compat/log/DefaultLogger.java
  51. +48 −29 src/main/java/net/spy/memcached/compat/log/Level.java
  52. +84 −65 src/main/java/net/spy/memcached/compat/log/Log4JLogger.java
  53. +173 −143 src/main/java/net/spy/memcached/compat/log/Logger.java
  54. +154 −142 src/main/java/net/spy/memcached/compat/log/LoggerFactory.java
  55. +112 −93 src/main/java/net/spy/memcached/compat/log/SunLogger.java
  56. +256 −238 src/main/java/net/spy/memcached/couch/AsyncConnectionManager.java
  57. +70 −46 src/main/java/net/spy/memcached/couch/AsyncConnectionRequest.java
  58. +73 −48 src/main/java/net/spy/memcached/couch/RequestHandle.java
  59. +37 −15 src/main/java/net/spy/memcached/internal/BasicThreadFactory.java
  60. +53 −34 src/main/java/net/spy/memcached/internal/BulkFuture.java
  61. +168 −143 src/main/java/net/spy/memcached/internal/BulkGetFuture.java
  62. +67 −45 src/main/java/net/spy/memcached/internal/CheckedOperationTimeoutException.java
  63. +56 −32 src/main/java/net/spy/memcached/internal/GetFuture.java
  64. +116 −93 src/main/java/net/spy/memcached/internal/HttpFuture.java
  65. +59 −42 src/main/java/net/spy/memcached/internal/ImmediateFuture.java
  66. +129 −106 src/main/java/net/spy/memcached/internal/OperationFuture.java
  67. +45 −25 src/main/java/net/spy/memcached/internal/SingleElementInfiniteIterator.java
  68. +144 −117 src/main/java/net/spy/memcached/internal/ViewFuture.java
  69. +41 −18 src/main/java/net/spy/memcached/ops/ArrayOperationQueueFactory.java
  70. +82 −60 src/main/java/net/spy/memcached/ops/BaseOperationFactory.java
  71. +47 −26 src/main/java/net/spy/memcached/ops/CASOperation.java
  72. +33 −12 src/main/java/net/spy/memcached/ops/CASOperationStatus.java
  73. +25 −4 src/main/java/net/spy/memcached/ops/CancelledOperationStatus.java
  74. +39 −17 src/main/java/net/spy/memcached/ops/ConcatenationOperation.java
  75. +30 −8 src/main/java/net/spy/memcached/ops/ConcatenationType.java
  76. +24 −3 src/main/java/net/spy/memcached/ops/DeleteOperation.java
  77. +25 −3 src/main/java/net/spy/memcached/ops/FlushOperation.java
  78. +35 −15 src/main/java/net/spy/memcached/ops/GetAndTouchOperation.java
  79. +36 −16 src/main/java/net/spy/memcached/ops/GetOperation.java
  80. +35 −15 src/main/java/net/spy/memcached/ops/GetlOperation.java
  81. +37 −17 src/main/java/net/spy/memcached/ops/GetsOperation.java
  82. +27 −5 src/main/java/net/spy/memcached/ops/KeyedOperation.java
  83. +30 −7 src/main/java/net/spy/memcached/ops/LinkedOperationQueueFactory.java
  84. +30 −9 src/main/java/net/spy/memcached/ops/MultiGetOperationCallback.java
  85. +29 −9 src/main/java/net/spy/memcached/ops/MultiGetsOperationCallback.java
  86. +47 −26 src/main/java/net/spy/memcached/ops/MultiOperationCallback.java
  87. +31 −9 src/main/java/net/spy/memcached/ops/Mutator.java
  88. +39 −17 src/main/java/net/spy/memcached/ops/MutatorOperation.java
  89. +23 −1 src/main/java/net/spy/memcached/ops/NoopOperation.java
  90. +135 −113 src/main/java/net/spy/memcached/ops/Operation.java
  91. +31 −11 src/main/java/net/spy/memcached/ops/OperationCallback.java
  92. +35 −14 src/main/java/net/spy/memcached/ops/OperationErrorType.java
  93. +62 −41 src/main/java/net/spy/memcached/ops/OperationException.java
  94. +26 −6 src/main/java/net/spy/memcached/ops/OperationQueueFactory.java
  95. +44 −21 src/main/java/net/spy/memcached/ops/OperationState.java
  96. +45 −23 src/main/java/net/spy/memcached/ops/OperationStatus.java
  97. +23 −1 src/main/java/net/spy/memcached/ops/SASLAuthOperation.java
  98. +23 −1 src/main/java/net/spy/memcached/ops/SASLMechsOperation.java
  99. +23 −1 src/main/java/net/spy/memcached/ops/SASLStepOperation.java
  100. +35 −15 src/main/java/net/spy/memcached/ops/StatsOperation.java
  101. +45 −22 src/main/java/net/spy/memcached/ops/StoreOperation.java
  102. +37 −15 src/main/java/net/spy/memcached/ops/StoreType.java
  103. +36 −15 src/main/java/net/spy/memcached/ops/TapOperation.java
  104. +35 −9 src/main/java/net/spy/memcached/ops/VBucketAware.java
  105. +24 −2 src/main/java/net/spy/memcached/ops/VersionOperation.java
  106. +198 −170 src/main/java/net/spy/memcached/protocol/BaseOperationImpl.java
  107. +52 −35 src/main/java/net/spy/memcached/protocol/GetCallbackWrapper.java
  108. +61 −41 src/main/java/net/spy/memcached/protocol/ProxyCallback.java
  109. +572 −496 src/main/java/net/spy/memcached/protocol/TCPMemcachedNodeImpl.java
  110. +55 −33 src/main/java/net/spy/memcached/protocol/ascii/AsciiMemcachedNodeImpl.java
  111. +147 −123 src/main/java/net/spy/memcached/protocol/ascii/AsciiOperationFactory.java
  112. +189 −166 src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java
  113. +76 −55 src/main/java/net/spy/memcached/protocol/ascii/BaseStoreOperationImpl.java
  114. +100 −81 src/main/java/net/spy/memcached/protocol/ascii/CASOperationImpl.java
  115. +36 −15 src/main/java/net/spy/memcached/protocol/ascii/ConcatenationOperationImpl.java
  116. +56 −37 src/main/java/net/spy/memcached/protocol/ascii/DeleteOperationImpl.java
  117. +53 −35 src/main/java/net/spy/memcached/protocol/ascii/FlushOperationImpl.java
  118. +31 −7 src/main/java/net/spy/memcached/protocol/ascii/GetAndTouchOperationImpl.java
  119. +28 −9 src/main/java/net/spy/memcached/protocol/ascii/GetOperationImpl.java
  120. +26 −5 src/main/java/net/spy/memcached/protocol/ascii/GetlOperationImpl.java
  121. +26 −5 src/main/java/net/spy/memcached/protocol/ascii/GetsOperationImpl.java
  122. +89 −70 src/main/java/net/spy/memcached/protocol/ascii/MutatorOperationImpl.java
  123. +136 −112 src/main/java/net/spy/memcached/protocol/ascii/OperationImpl.java
  124. +31 −9 src/main/java/net/spy/memcached/protocol/ascii/OperationReadType.java
  125. +38 −16 src/main/java/net/spy/memcached/protocol/ascii/OptimizedGetImpl.java
  126. +60 −42 src/main/java/net/spy/memcached/protocol/ascii/StatsOperationImpl.java
  127. +32 −14 src/main/java/net/spy/memcached/protocol/ascii/StoreOperationImpl.java
  128. +42 −23 src/main/java/net/spy/memcached/protocol/ascii/VersionOperationImpl.java
  129. +83 −63 src/main/java/net/spy/memcached/protocol/binary/BinaryMemcachedNodeImpl.java
  130. +144 −120 src/main/java/net/spy/memcached/protocol/binary/BinaryOperationFactory.java
  131. +73 −45 src/main/java/net/spy/memcached/protocol/binary/ConcatenationOperationImpl.java
  132. +37 −15 src/main/java/net/spy/memcached/protocol/binary/DeleteOperationImpl.java
  133. +37 −15 src/main/java/net/spy/memcached/protocol/binary/FlushOperationImpl.java
  134. +53 −26 src/main/java/net/spy/memcached/protocol/binary/GetAndTouchOperationImpl.java
  135. +55 −31 src/main/java/net/spy/memcached/protocol/binary/GetOperationImpl.java
  136. +57 −31 src/main/java/net/spy/memcached/protocol/binary/GetlOperationImpl.java
  137. +54 −29 src/main/java/net/spy/memcached/protocol/binary/GetsOperationImpl.java
  138. +109 −89 src/main/java/net/spy/memcached/protocol/binary/MultiGetOperationImpl.java
  139. +58 −35 src/main/java/net/spy/memcached/protocol/binary/MultiKeyOperationImpl.java
  140. +71 −49 src/main/java/net/spy/memcached/protocol/binary/MutatorOperationImpl.java
  141. +31 −9 src/main/java/net/spy/memcached/protocol/binary/NoopOperationImpl.java
  142. +328 −302 src/main/java/net/spy/memcached/protocol/binary/OperationImpl.java
  143. +48 −26 src/main/java/net/spy/memcached/protocol/binary/OptimizedGetImpl.java
  144. +167 −136 src/main/java/net/spy/memcached/protocol/binary/OptimizedSetImpl.java
  145. +38 −14 src/main/java/net/spy/memcached/protocol/binary/SASLAuthOperationImpl.java
  146. +71 −48 src/main/java/net/spy/memcached/protocol/binary/SASLBaseOperationImpl.java
  147. +35 −15 src/main/java/net/spy/memcached/protocol/binary/SASLMechsOperationImpl.java
  148. +37 −12 src/main/java/net/spy/memcached/protocol/binary/SASLStepOperationImpl.java
  149. +55 −29 src/main/java/net/spy/memcached/protocol/binary/SingleKeyOperationImpl.java
  150. +54 −31 src/main/java/net/spy/memcached/protocol/binary/StatsOperationImpl.java
  151. +101 −71 src/main/java/net/spy/memcached/protocol/binary/StoreOperationImpl.java
  152. +54 −28 src/main/java/net/spy/memcached/protocol/binary/TapAckOperationImpl.java
  153. +59 −32 src/main/java/net/spy/memcached/protocol/binary/TapBackfillOperationImpl.java
  154. +49 −21 src/main/java/net/spy/memcached/protocol/binary/TapCustomOperationImpl.java
  155. +51 −25 src/main/java/net/spy/memcached/protocol/binary/TapDumpOperationImpl.java
  156. +81 −51 src/main/java/net/spy/memcached/protocol/binary/TapOperationImpl.java
  157. +33 −10 src/main/java/net/spy/memcached/protocol/binary/TouchOperationImpl.java
  158. +35 −13 src/main/java/net/spy/memcached/protocol/binary/VersionOperationImpl.java
  159. +33 −3 src/main/java/net/spy/memcached/protocol/couch/DocsOperation.java
  160. +80 −54 src/main/java/net/spy/memcached/protocol/couch/DocsOperationImpl.java
  161. +34 −9 src/main/java/net/spy/memcached/protocol/couch/HttpOperation.java
  162. +117 −94 src/main/java/net/spy/memcached/protocol/couch/HttpOperationImpl.java
  163. +32 −3 src/main/java/net/spy/memcached/protocol/couch/NoDocsOperation.java
  164. +80 −54 src/main/java/net/spy/memcached/protocol/couch/NoDocsOperationImpl.java
  165. +147 −118 src/main/java/net/spy/memcached/protocol/couch/Query.java
  166. +32 −4 src/main/java/net/spy/memcached/protocol/couch/ReducedOperation.java
  167. +79 −53 src/main/java/net/spy/memcached/protocol/couch/ReducedOperationImpl.java
  168. +38 −12 src/main/java/net/spy/memcached/protocol/couch/RowError.java
  169. +39 −13 src/main/java/net/spy/memcached/protocol/couch/RowNoDocs.java
  170. +48 −22 src/main/java/net/spy/memcached/protocol/couch/RowReduced.java
  171. +39 −13 src/main/java/net/spy/memcached/protocol/couch/RowWithDocs.java
  172. +36 −10 src/main/java/net/spy/memcached/protocol/couch/Stale.java
  173. +64 −38 src/main/java/net/spy/memcached/protocol/couch/View.java
  174. +32 −3 src/main/java/net/spy/memcached/protocol/couch/ViewOperation.java
  175. +84 −61 src/main/java/net/spy/memcached/protocol/couch/ViewOperationImpl.java
  176. +27 −2 src/main/java/net/spy/memcached/protocol/couch/ViewResponse.java
  177. +56 −31 src/main/java/net/spy/memcached/protocol/couch/ViewResponseNoDocs.java
  178. +56 −30 src/main/java/net/spy/memcached/protocol/couch/ViewResponseReduced.java
  179. +166 −141 src/main/java/net/spy/memcached/protocol/couch/ViewResponseWithDocs.java
  180. +32 −3 src/main/java/net/spy/memcached/protocol/couch/ViewsOperation.java
  181. +77 −53 src/main/java/net/spy/memcached/protocol/couch/ViewsOperationImpl.java
  182. +37 −11 src/main/java/net/spy/memcached/spring/MemcachedClientFactoryBean.java
  183. +319 −272 src/main/java/net/spy/memcached/tapmessage/BaseMessage.java
  184. +63 −38 src/main/java/net/spy/memcached/tapmessage/MessageBuilder.java
  185. +170 −139 src/main/java/net/spy/memcached/tapmessage/RequestMessage.java
  186. +174 −138 src/main/java/net/spy/memcached/tapmessage/ResponseMessage.java
  187. +79 −54 src/main/java/net/spy/memcached/tapmessage/TapFlag.java
  188. +48 −20 src/main/java/net/spy/memcached/tapmessage/TapMagic.java
  189. +100 −71 src/main/java/net/spy/memcached/tapmessage/TapOpcode.java
  190. +63 −37 src/main/java/net/spy/memcached/tapmessage/Util.java
  191. +195 −174 src/main/java/net/spy/memcached/transcoders/BaseSerializingTranscoder.java
  192. +41 −22 src/main/java/net/spy/memcached/transcoders/IntegerTranscoder.java
  193. +42 −23 src/main/java/net/spy/memcached/transcoders/LongTranscoder.java
Sorry, we could not display the entire diff because too many files (313) changed.
View
133 src/main/java/net/spy/memcached/AddrUtil.java
@@ -1,3 +1,26 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ * Copyright (C) 2009-2011 Couchbase, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
import java.net.InetSocketAddress;
@@ -7,66 +30,66 @@
/**
* Convenience utilities for simplifying common address parsing.
*/
-public class AddrUtil {
-
- /**
- * Split a string containing whitespace or comma separated host or
- * IP addresses and port numbers of the form "host:port host2:port"
- * or "host:port, host2:port" into a List of InetSocketAddress
- * instances suitable for instantiating a MemcachedClient.
- *
- * Note that colon-delimited IPv6 is also supported.
- * For example: ::1:11211
- */
- public static List<InetSocketAddress> getAddresses(String s) {
- if(s == null) {
- throw new NullPointerException("Null host list");
- }
- if(s.trim().equals("")) {
- throw new IllegalArgumentException("No hosts in list: ``"
- + s + "''");
- }
- ArrayList<InetSocketAddress> addrs=
- new ArrayList<InetSocketAddress>();
+public final class AddrUtil {
- for(String hoststuff : s.split("(?:\\s|,)+")) {
- if(hoststuff.equals("")) {
- continue;
- }
+ private AddrUtil() {
+ // Empty
+ }
- int finalColon=hoststuff.lastIndexOf(':');
- if(finalColon < 1) {
- throw new IllegalArgumentException("Invalid server ``"
- + hoststuff + "'' in list: " + s);
+ /**
+ * Split a string containing whitespace or comma separated host or IP
+ * addresses and port numbers of the form "host:port host2:port" or
+ * "host:port, host2:port" into a List of InetSocketAddress instances suitable
+ * for instantiating a MemcachedClient.
+ *
+ * Note that colon-delimited IPv6 is also supported. For example: ::1:11211
+ */
+ public static List<InetSocketAddress> getAddresses(String s) {
+ if (s == null) {
+ throw new NullPointerException("Null host list");
+ }
+ if (s.trim().equals("")) {
+ throw new IllegalArgumentException("No hosts in list: ``" + s + "''");
+ }
+ ArrayList<InetSocketAddress> addrs = new ArrayList<InetSocketAddress>();
- }
- String hostPart=hoststuff.substring(0, finalColon);
- String portNum=hoststuff.substring(finalColon+1);
+ for (String hoststuff : s.split("(?:\\s|,)+")) {
+ if (hoststuff.equals("")) {
+ continue;
+ }
- addrs.add(new InetSocketAddress(hostPart,
- Integer.parseInt(portNum)));
- }
- assert !addrs.isEmpty() : "No addrs found";
- return addrs;
- }
+ int finalColon = hoststuff.lastIndexOf(':');
+ if (finalColon < 1) {
+ throw new IllegalArgumentException("Invalid server ``" + hoststuff
+ + "'' in list: " + s);
+ }
+ String hostPart = hoststuff.substring(0, finalColon);
+ String portNum = hoststuff.substring(finalColon + 1);
- public static List<InetSocketAddress> getAddresses(List<String> servers) {
- ArrayList<InetSocketAddress> addrs = new ArrayList<InetSocketAddress>(servers.size());
- for (String server : servers) {
- int finalColon=server.lastIndexOf(':');
- if(finalColon < 1) {
- throw new IllegalArgumentException("Invalid server ``"
- + server + "'' in list: " + server);
- }
- String hostPart=server.substring(0, finalColon);
- String portNum=server.substring(finalColon+1);
+ addrs.add(new InetSocketAddress(hostPart, Integer.parseInt(portNum)));
+ }
+ assert !addrs.isEmpty() : "No addrs found";
+ return addrs;
+ }
- addrs.add(new InetSocketAddress(hostPart, Integer.parseInt(portNum)));
- }
- if (addrs.isEmpty()) {
- throw new IllegalArgumentException("servers cannot be empty"); //servers was passed in empty, and shouldn't have been
- }
- return addrs;
+ public static List<InetSocketAddress> getAddresses(List<String> servers) {
+ ArrayList<InetSocketAddress> addrs =
+ new ArrayList<InetSocketAddress>(servers.size());
+ for (String server : servers) {
+ int finalColon = server.lastIndexOf(':');
+ if (finalColon < 1) {
+ throw new IllegalArgumentException("Invalid server ``" + server
+ + "'' in list: " + server);
+ }
+ String hostPart = server.substring(0, finalColon);
+ String portNum = server.substring(finalColon + 1);
- }
+ addrs.add(new InetSocketAddress(hostPart, Integer.parseInt(portNum)));
+ }
+ if (addrs.isEmpty()) {
+ // servers was passed in empty, and shouldn't have been
+ throw new IllegalArgumentException("servers cannot be empty");
+ }
+ return addrs;
+ }
}
View
217 src/main/java/net/spy/memcached/ArrayModNodeLocator.java
@@ -1,112 +1,133 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ * Copyright (C) 2009-2011 Couchbase, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
-import net.spy.memcached.vbucket.config.Config;
-
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import net.spy.memcached.vbucket.config.Config;
+
/**
* NodeLocator implementation for dealing with simple array lookups using a
* modulus of the hash code and node list length.
*/
public final class ArrayModNodeLocator implements NodeLocator {
- private MemcachedNode[] nodes;
-
- private final HashAlgorithm hashAlg;
-
- /**
- * Construct an ArraymodNodeLocator over the given array of nodes and
- * using the given hash algorithm.
- *
- * @param n the array of nodes
- * @param alg the hash algorithm
- */
- public ArrayModNodeLocator(List<MemcachedNode> n, HashAlgorithm alg) {
- super();
- nodes=n.toArray(new MemcachedNode[n.size()]);
- hashAlg=alg;
- }
-
- private ArrayModNodeLocator(MemcachedNode[] n, HashAlgorithm alg) {
- super();
- nodes=n;
- hashAlg=alg;
- }
-
- public Collection<MemcachedNode> getAll() {
- return Arrays.asList(nodes);
- }
-
- public MemcachedNode getPrimary(String k) {
- return nodes[getServerForKey(k)];
- }
-
- public Iterator<MemcachedNode> getSequence(String k) {
- return new NodeIterator(getServerForKey(k));
- }
-
- public NodeLocator getReadonlyCopy() {
- MemcachedNode[] n=new MemcachedNode[nodes.length];
- for(int i=0; i<nodes.length; i++) {
- n[i] = new MemcachedNodeROImpl(nodes[i]);
- }
- return new ArrayModNodeLocator(n, hashAlg);
- }
-
- @Override
- public void updateLocator(List<MemcachedNode> nodes, Config conf) {
- this.nodes=nodes.toArray(new MemcachedNode[nodes.size()]);
- }
-
- private int getServerForKey(String key) {
- int rv=(int)(hashAlg.hash(key) % nodes.length);
- assert rv >= 0 : "Returned negative key for key " + key;
- assert rv < nodes.length
- : "Invalid server number " + rv + " for key " + key;
- return rv;
- }
-
- class NodeIterator implements Iterator<MemcachedNode> {
-
- private final int start;
- private int next=0;
-
- public NodeIterator(int keyStart) {
- start=keyStart;
- next=start;
- computeNext();
- assert next >= 0 || nodes.length == 1
- : "Starting sequence at " + start + " of "
- + nodes.length + " next is " + next;
- }
-
- public boolean hasNext() {
- return next >= 0;
- }
-
- private void computeNext() {
- if(++next >= nodes.length) {
- next=0;
- }
- if(next == start) {
- next=-1;
- }
- }
-
- public MemcachedNode next() {
- try {
- return nodes[next];
- } finally {
- computeNext();
- }
- }
-
- public void remove() {
- throw new UnsupportedOperationException("Can't remove a node");
- }
-
- }
+ private final HashAlgorithm hashAlg;
+
+ private MemcachedNode[] nodes;
+
+ /**
+ * Construct an ArraymodNodeLocator over the given array of nodes and using
+ * the given hash algorithm.
+ *
+ * @param n the array of nodes
+ * @param alg the hash algorithm
+ */
+ public ArrayModNodeLocator(List<MemcachedNode> n, HashAlgorithm alg) {
+ super();
+ nodes = n.toArray(new MemcachedNode[n.size()]);
+ hashAlg = alg;
+ }
+
+ private ArrayModNodeLocator(MemcachedNode[] n, HashAlgorithm alg) {
+ super();
+ nodes = n;
+ hashAlg = alg;
+ }
+
+ public Collection<MemcachedNode> getAll() {
+ return Arrays.asList(nodes);
+ }
+
+ public MemcachedNode getPrimary(String k) {
+ return nodes[getServerForKey(k)];
+ }
+
+ public Iterator<MemcachedNode> getSequence(String k) {
+ return new NodeIterator(getServerForKey(k));
+ }
+
+ public NodeLocator getReadonlyCopy() {
+ MemcachedNode[] n = new MemcachedNode[nodes.length];
+ for (int i = 0; i < nodes.length; i++) {
+ n[i] = new MemcachedNodeROImpl(nodes[i]);
+ }
+ return new ArrayModNodeLocator(n, hashAlg);
+ }
+
+ @Override
+ public void updateLocator(List<MemcachedNode> newNodes, Config conf) {
+ this.nodes = newNodes.toArray(new MemcachedNode[newNodes.size()]);
+ }
+
+ private int getServerForKey(String key) {
+ int rv = (int) (hashAlg.hash(key) % nodes.length);
+ assert rv >= 0 : "Returned negative key for key " + key;
+ assert rv < nodes.length : "Invalid server number " + rv + " for key "
+ + key;
+ return rv;
+ }
+
+ class NodeIterator implements Iterator<MemcachedNode> {
+
+ private final int start;
+ private int next = 0;
+
+ public NodeIterator(int keyStart) {
+ start = keyStart;
+ next = start;
+ computeNext();
+ assert next >= 0 || nodes.length == 1 : "Starting sequence at " + start
+ + " of " + nodes.length + " next is " + next;
+ }
+
+ public boolean hasNext() {
+ return next >= 0;
+ }
+
+ private void computeNext() {
+ if (++next >= nodes.length) {
+ next = 0;
+ }
+ if (next == start) {
+ next = -1;
+ }
+ }
+
+ public MemcachedNode next() {
+ try {
+ return nodes[next];
+ } finally {
+ computeNext();
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("Can't remove a node");
+ }
+ }
}
View
226 src/main/java/net/spy/memcached/BaseCacheMap.java
@@ -1,3 +1,25 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
import java.util.Collection;
@@ -11,116 +33,114 @@
* Base class for a Map interface to memcached.
*
* <p>
- * This Map interface makes memcached a bit easier to use for some purposes
- * by providing a limited Map implementation.
+ * This Map interface makes memcached a bit easier to use for some purposes by
+ * providing a limited Map implementation.
* </p>
*
* <p>
- * Do note that nothing that iterates over the map will work (such is
- * memcached). All iteration mechanisms will return empty iterators and
- * such.
+ * Do note that nothing that iterates over the map will work (such is
+ * memcached). All iteration mechanisms will return empty iterators and such.
* </p>
*
* @param <V> the type of value taken and returned by this Map's underlying
- * transcoder, and thus taken and returned by this Map.
+ * transcoder, and thus taken and returned by this Map.
*/
public class BaseCacheMap<V> implements Map<String, V> {
- private final String keyPrefix;
- private final Transcoder<V> transcoder;
- private final MemcachedClientIF client;
- private final int exp;
-
- /**
- * Build a BaseCacheMap.
- *
- * @param c the underlying client
- * @param expiration the expiration for objects set through this Map
- * @param prefix a prefix to ensure objects in this map are unique
- * @param t the transcoder to serialize and deserialize objects
- */
- public BaseCacheMap(MemcachedClientIF c, int expiration,
- String prefix, Transcoder<V> t) {
- super();
- keyPrefix = prefix;
- transcoder = t;
- client = c;
- exp = expiration;
- }
-
- public void clear() {
- // TODO: Support a rolling key generation.
- throw new UnsupportedOperationException();
- }
-
- private String getKey(String k) {
- return keyPrefix + k;
- }
-
- public boolean containsKey(Object key) {
- return get(key) != null;
- }
-
- /**
- * This method always returns false, as truth cannot be determined without
- * iteration.
- */
- public boolean containsValue(Object value) {
- return false;
- }
-
- public Set<Map.Entry<String, V>> entrySet() {
- return Collections.emptySet();
- }
-
- public V get(Object key) {
- V rv = null;
- try {
- rv = client.get(getKey((String)key), transcoder);
- } catch(ClassCastException e) {
- // Most likely, this is because the key wasn't a String.
- // Either way, it's a no.
- }
- return rv;
- }
-
- public boolean isEmpty() {
- return false;
- }
-
- public Set<String> keySet() {
- return Collections.emptySet();
- }
-
- public void putAll(Map<? extends String, ? extends V> t) {
- for(Map.Entry<? extends String, ? extends V> me : t.entrySet()) {
- client.set(getKey(me.getKey()), exp, me.getValue());
- }
- }
-
- public V remove(Object key) {
- V rv = null;
- try {
- rv = get(key);
- client.delete(getKey((String)key));
- } catch(ClassCastException e) {
- // Not a string key. Ignore.
- }
- return rv;
- }
-
- public int size() {
- return 0;
- }
-
- public Collection<V> values() {
- return Collections.emptySet();
- }
-
- public V put(String key, V value) {
- V rv = get(key);
- client.set(getKey(key), exp, value);
- return rv;
- }
-
+ private final String keyPrefix;
+ private final Transcoder<V> transcoder;
+ private final MemcachedClientIF client;
+ private final int exp;
+
+ /**
+ * Build a BaseCacheMap.
+ *
+ * @param c the underlying client
+ * @param expiration the expiration for objects set through this Map
+ * @param prefix a prefix to ensure objects in this map are unique
+ * @param t the transcoder to serialize and deserialize objects
+ */
+ public BaseCacheMap(MemcachedClientIF c, int expiration, String prefix,
+ Transcoder<V> t) {
+ super();
+ keyPrefix = prefix;
+ transcoder = t;
+ client = c;
+ exp = expiration;
+ }
+
+ public void clear() {
+ // TODO: Support a rolling key generation.
+ throw new UnsupportedOperationException();
+ }
+
+ private String getKey(String k) {
+ return keyPrefix + k;
+ }
+
+ public boolean containsKey(Object key) {
+ return get(key) != null;
+ }
+
+ /**
+ * This method always returns false, as truth cannot be determined without
+ * iteration.
+ */
+ public boolean containsValue(Object value) {
+ return false;
+ }
+
+ public Set<Map.Entry<String, V>> entrySet() {
+ return Collections.emptySet();
+ }
+
+ public V get(Object key) {
+ V rv = null;
+ try {
+ rv = client.get(getKey((String) key), transcoder);
+ } catch (ClassCastException e) {
+ // Most likely, this is because the key wasn't a String.
+ // Either way, it's a no.
+ }
+ return rv;
+ }
+
+ public boolean isEmpty() {
+ return false;
+ }
+
+ public Set<String> keySet() {
+ return Collections.emptySet();
+ }
+
+ public void putAll(Map<? extends String, ? extends V> t) {
+ for (Map.Entry<? extends String, ? extends V> me : t.entrySet()) {
+ client.set(getKey(me.getKey()), exp, me.getValue());
+ }
+ }
+
+ public V remove(Object key) {
+ V rv = null;
+ try {
+ rv = get(key);
+ client.delete(getKey((String) key));
+ } catch (ClassCastException e) {
+ // Not a string key. Ignore.
+ }
+ return rv;
+ }
+
+ public int size() {
+ return 0;
+ }
+
+ public Collection<V> values() {
+ return Collections.emptySet();
+ }
+
+ public V put(String key, V value) {
+ V rv = get(key);
+ client.set(getKey(key), exp, value);
+ return rv;
+ }
}
View
105 src/main/java/net/spy/memcached/BinaryConnectionFactory.java
@@ -1,3 +1,26 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ * Copyright (C) 2009-2011 Couchbase, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
import java.net.SocketAddress;
@@ -11,48 +34,44 @@
*/
public class BinaryConnectionFactory extends DefaultConnectionFactory {
- /**
- * Create a DefaultConnectionFactory with the default parameters.
- */
- public BinaryConnectionFactory() {
- super();
- }
-
- /**
- * Create a BinaryConnectionFactory with the given maximum operation
- * queue length, and the given read buffer size.
- */
- public BinaryConnectionFactory(int len, int bufSize) {
- super(len, bufSize);
- }
-
- /**
- * Construct a BinaryConnectionFactory with the given parameters.
- *
- * @param len the queue length.
- * @param bufSize the buffer size
- * @param hash the algorithm to use for hashing
- */
- public BinaryConnectionFactory(int len, int bufSize, HashAlgorithm hash) {
- super(len, bufSize, hash);
- }
-
- @Override
- public MemcachedNode createMemcachedNode(SocketAddress sa,
- SocketChannel c, int bufSize) {
- boolean doAuth = false;
- return new BinaryMemcachedNodeImpl(sa, c, bufSize,
- createReadOperationQueue(),
- createWriteOperationQueue(),
- createOperationQueue(),
- getOpQueueMaxBlockTime(),
- doAuth,
- getOperationTimeout());
- }
-
- @Override
- public OperationFactory getOperationFactory() {
- return new BinaryOperationFactory();
- }
+ /**
+ * Create a DefaultConnectionFactory with the default parameters.
+ */
+ public BinaryConnectionFactory() {
+ super();
+ }
+
+ /**
+ * Create a BinaryConnectionFactory with the given maximum operation queue
+ * length, and the given read buffer size.
+ */
+ public BinaryConnectionFactory(int len, int bufSize) {
+ super(len, bufSize);
+ }
+
+ /**
+ * Construct a BinaryConnectionFactory with the given parameters.
+ *
+ * @param len the queue length.
+ * @param bufSize the buffer size
+ * @param hash the algorithm to use for hashing
+ */
+ public BinaryConnectionFactory(int len, int bufSize, HashAlgorithm hash) {
+ super(len, bufSize, hash);
+ }
+
+ @Override
+ public MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c,
+ int bufSize) {
+ boolean doAuth = false;
+ return new BinaryMemcachedNodeImpl(sa, c, bufSize,
+ createReadOperationQueue(), createWriteOperationQueue(),
+ createOperationQueue(), getOpQueueMaxBlockTime(), doAuth,
+ getOperationTimeout());
+ }
+ @Override
+ public OperationFactory getOperationFactory() {
+ return new BinaryOperationFactory();
+ }
}
View
32 src/main/java/net/spy/memcached/BroadcastOpFactory.java
@@ -1,3 +1,25 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
import java.util.concurrent.CountDownLatch;
@@ -9,9 +31,9 @@
*/
public interface BroadcastOpFactory {
- /**
- * Construct a new operation for delivery to the given node.
- * Each operation should count the given latch down upon completion.
- */
- Operation newOp(MemcachedNode n, CountDownLatch latch);
+ /**
+ * Construct a new operation for delivery to the given node. Each operation
+ * should count the given latch down upon completion.
+ */
+ Operation newOp(MemcachedNode n, CountDownLatch latch);
}
View
36 src/main/java/net/spy/memcached/CASMutation.java
@@ -1,3 +1,25 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
/**
@@ -5,11 +27,11 @@
*/
public interface CASMutation<T> {
- /**
- * Get the new value to replace the current value.
- *
- * @param current the current value in the cache
- * @return the replacement value
- */
- T getNewValue(T current);
+ /**
+ * Get the new value to replace the current value.
+ *
+ * @param current the current value in the cache
+ * @return the replacement value
+ */
+ T getNewValue(T current);
}
View
199 src/main/java/net/spy/memcached/CASMutator.java
@@ -1,3 +1,25 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
import net.spy.memcached.compat.SpyObject;
@@ -6,7 +28,9 @@
/**
* Object that provides mutation via CAS over a given memcache client.
*
- * <p>Example usage (reinventing incr):</p>
+ * <p>
+ * Example usage (reinventing incr):
+ * </p>
*
* <pre>
* // Get or create a client.
@@ -31,99 +55,96 @@
*/
public class CASMutator<T> extends SpyObject {
- private static final int MAX_TRIES=8192;
+ private static final int MAX_TRIES = 8192;
- private final MemcachedClientIF client;
- private final Transcoder<T> transcoder;
- private final int max;
+ private final MemcachedClientIF client;
+ private final Transcoder<T> transcoder;
+ private final int max;
- /**
- * Construct a CASMutator that uses the given client.
- *
- * @param c the client
- * @param tc the Transcoder to use
- * @param max_tries the maximum number of attempts to get a CAS to succeed
- */
- public CASMutator(MemcachedClientIF c, Transcoder<T> tc, int max_tries) {
- super();
- client=c;
- transcoder=tc;
- max=max_tries;
- }
+ /**
+ * Construct a CASMutator that uses the given client.
+ *
+ * @param c the client
+ * @param tc the Transcoder to use
+ * @param max_tries the maximum number of attempts to get a CAS to succeed
+ */
+ public CASMutator(MemcachedClientIF c, Transcoder<T> tc, int maxTries) {
+ super();
+ client = c;
+ transcoder = tc;
+ max = maxTries;
+ }
- /**
- * Construct a CASMutator that uses the given client.
- *
- * @param c the client
- * @param tc the Transcoder to use
- */
- public CASMutator(MemcachedClientIF c, Transcoder<T> tc) {
- this(c, tc, MAX_TRIES);
- }
+ /**
+ * Construct a CASMutator that uses the given client.
+ *
+ * @param c the client
+ * @param tc the Transcoder to use
+ */
+ public CASMutator(MemcachedClientIF c, Transcoder<T> tc) {
+ this(c, tc, MAX_TRIES);
+ }
- /**
- * CAS a new value in for a key.
- *
- * <p>
- * Note that if initial is null, this method will only update existing
- * values.
- * </p>
- *
- * @param key the key to be CASed
- * @param initial the value to use when the object is not cached
- * @param initialExp the expiration time to use when initializing
- * @param m the mutation to perform on an object if a value exists for the
- * key
- * @return the new value that was set
- */
- public T cas(final String key, final T initial, int initialExp,
- final CASMutation<T> m) throws Exception {
- T rv=initial;
+ /**
+ * CAS a new value in for a key.
+ *
+ * <p>
+ * Note that if initial is null, this method will only update existing values.
+ * </p>
+ *
+ * @param key the key to be CASed
+ * @param initial the value to use when the object is not cached
+ * @param initialExp the expiration time to use when initializing
+ * @param m the mutation to perform on an object if a value exists for the key
+ * @return the new value that was set
+ */
+ public T cas(final String key, final T initial, int initialExp,
+ final CASMutation<T> m) throws Exception {
+ T rv = initial;
- boolean done=false;
- for(int i=0; !done && i<max; i++) {
- CASValue<T> casval=client.gets(key, transcoder);
- T current=null;
- // If there were a CAS value, check to see if it's compatible.
- if(casval != null) {
- T tmp = casval.getValue();
- current=tmp;
- }
- // If we have anything mutate and CAS, else add.
- if(current != null) {
- // Declaring this impossible since the only way current can
- // be non-null is if casval was set.
- assert casval != null : "casval was null with a current value";
+ boolean done = false;
+ for (int i = 0; !done && i < max; i++) {
+ CASValue<T> casval = client.gets(key, transcoder);
+ T current = null;
+ // If there were a CAS value, check to see if it's compatible.
+ if (casval != null) {
+ T tmp = casval.getValue();
+ current = tmp;
+ }
+ // If we have anything mutate and CAS, else add.
+ if (current != null) {
+ // Declaring this impossible since the only way current can
+ // be non-null is if casval was set.
+ assert casval != null : "casval was null with a current value";
- rv=m.getNewValue(current);
- // There are three possibilities here:
- // 1) It worked and we're done.
- // 2) It collided and we need to reload and try again.
- // 3) It disappeared between our fetch and our cas.
- // We're ignoring #3 because it's *extremely* unlikely and the
- // behavior will be fine in this code -- we'll do another gets
- // and follow it up with either an add or another cas depending
- // on whether it exists the next time.
- if(client.cas(key, casval.getCas(), rv, transcoder)
- == CASResponse.OK) {
- done=true;
- }
- } else {
- // No value found, try an add.
- if(initial == null) {
- done = true;
- rv = null;
- } else if(client.add(key, initialExp, initial, transcoder).get()) {
- done=true;
- rv=initial;
- }
- }
- }
- if(!done) {
- throw new RuntimeException("Couldn't get a CAS in " + max
- + " attempts");
- }
+ rv = m.getNewValue(current);
+ // There are three possibilities here:
+ // 1) It worked and we're done.
+ // 2) It collided and we need to reload and try again.
+ // 3) It disappeared between our fetch and our cas.
+ // We're ignoring #3 because it's *extremely* unlikely and the
+ // behavior will be fine in this code -- we'll do another gets
+ // and follow it up with either an add or another cas depending
+ // on whether it exists the next time.
+ if (client.cas(key, casval.getCas(), rv, transcoder)
+ == CASResponse.OK) {
+ done = true;
+ }
+ } else {
+ // No value found, try an add.
+ if (initial == null) {
+ done = true;
+ rv = null;
+ } else if (client.add(key, initialExp, initial, transcoder).get()) {
+ done = true;
+ rv = initial;
+ }
+ }
+ }
+ if (!done) {
+ throw new RuntimeException("Couldn't get a CAS in " + max + " attempts");
+ }
- return rv;
- }
+ return rv;
+ }
}
View
54 src/main/java/net/spy/memcached/CASResponse.java
@@ -1,23 +1,45 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
/**
* Response codes for a CAS operation.
*/
public enum CASResponse {
- /**
- * Status indicating that the CAS was successful and the new value is
- * stored in the cache.
- */
- OK,
- /**
- * Status indicating the value was not found in the cache (an add
- * operation may be issued to store the value).
- */
- NOT_FOUND,
- /**
- * Status indicating the value was found in the cache, but exists with a
- * different CAS value than expected. In this case, the value must be
- * refetched and the CAS operation tried again.
- */
- EXISTS
+ /**
+ * Status indicating that the CAS was successful and the new value is stored
+ * in the cache.
+ */
+ OK,
+ /**
+ * Status indicating the value was not found in the cache (an add operation
+ * may be issued to store the value).
+ */
+ NOT_FOUND,
+ /**
+ * Status indicating the value was found in the cache, but exists with a
+ * different CAS value than expected. In this case, the value must be
+ * refetched and the CAS operation tried again.
+ */
+ EXISTS
}
View
81 src/main/java/net/spy/memcached/CASValue.java
@@ -1,41 +1,62 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
/**
* A value with a CAS identifier.
*/
public class CASValue<T> {
- private final long cas;
- private final T value;
-
- /**
- * Construct a new CASValue with the given identifer and value.
- *
- * @param c the CAS identifier
- * @param v the value
- */
- public CASValue(long c, T v) {
- super();
- cas=c;
- value=v;
- }
+ private final long cas;
+ private final T value;
- /**
- * Get the CAS identifier.
- */
- public long getCas() {
- return cas;
- }
+ /**
+ * Construct a new CASValue with the given identifer and value.
+ *
+ * @param c the CAS identifier
+ * @param v the value
+ */
+ public CASValue(long c, T v) {
+ super();
+ cas = c;
+ value = v;
+ }
- /**
- * Get the object value.
- */
- public T getValue() {
- return value;
- }
+ /**
+ * Get the CAS identifier.
+ */
+ public long getCas() {
+ return cas;
+ }
- @Override
- public String toString() {
- return "{CasValue " + cas + "/" + value + "}";
- }
+ /**
+ * Get the object value.
+ */
+ public T getValue() {
+ return value;
+ }
+ @Override
+ public String toString() {
+ return "{CasValue " + cas + "/" + value + "}";
+ }
}
View
75 src/main/java/net/spy/memcached/CacheMap.java
@@ -1,40 +1,59 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
/**
* A Map interface to memcached.
*
* <p>
- * Do note that nothing that iterates over the map will work (such is
- * memcached). All iteration mechanisms will return empty iterators and
- * such.
+ * Do note that nothing that iterates over the map will work (such is
+ * memcached). All iteration mechanisms will return empty iterators and such.
* </p>
*/
public class CacheMap extends BaseCacheMap<Object> {
- /**
- * Construct a CacheMap over the given MemcachedClient.
- *
- * @param c the client
- * @param expiration the expiration to set for keys written to the cache
- * @param prefix a prefix used to make keys in this map unique
- */
- public CacheMap(MemcachedClientIF c, int expiration, String prefix) {
- super(c, expiration, prefix, c.getTranscoder());
- }
-
- /**
- * Construct a CacheMap over the given MemcachedClient with no expiration.
- *
- * <p>
- * Keys written into this Map will only expire when the LRU pushes them
- * out.
- * </p>
- *
- * @param c the client
- * @param prefix a prefix used to make keys in this map unique
- */
- public CacheMap(MemcachedClientIF c, String prefix) {
- this(c, 0, prefix);
- }
+ /**
+ * Construct a CacheMap over the given MemcachedClient.
+ *
+ * @param c the client
+ * @param expiration the expiration to set for keys written to the cache
+ * @param prefix a prefix used to make keys in this map unique
+ */
+ public CacheMap(MemcachedClientIF c, int expiration, String prefix) {
+ super(c, expiration, prefix, c.getTranscoder());
+ }
+ /**
+ * Construct a CacheMap over the given MemcachedClient with no expiration.
+ *
+ * <p>
+ * Keys written into this Map will only expire when the LRU pushes them out.
+ * </p>
+ *
+ * @param c the client
+ * @param prefix a prefix used to make keys in this map unique
+ */
+ public CacheMap(MemcachedClientIF c, String prefix) {
+ this(c, 0, prefix);
+ }
}
View
119 src/main/java/net/spy/memcached/CachedData.java
@@ -1,4 +1,25 @@
-// Copyright (c) 2006 Dustin Sallings <dustin@spy.net>
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ * Copyright (C) 2009-2011 Couchbase, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
package net.spy.memcached;
@@ -9,51 +30,53 @@
*/
public final class CachedData {
- /**
- * The maximum size that should be considered storing in a server.
- */
- /* though memcached no longer has a maximum size, rather than remove this entirely just bump it up for now */
- public static final int MAX_SIZE = 20*1024*1024;
-
- private final int flags;
- private final byte[] data;
-
- /**
- * Get a CachedData instance for the given flags and byte array.
- *
- * @param f the flags
- * @param d the data
- * @param max_size the maximum allowable size.
- */
- public CachedData(int f, byte[] d, int max_size) {
- super();
- if(d.length > max_size) {
- throw new IllegalArgumentException(
- "Cannot cache data larger than " + max_size
- + " bytes (you tried to cache a "
- + d.length + " byte object)");
- }
- flags=f;
- data=d;
- }
-
- /**
- * Get the stored data.
- */
- public byte[] getData() {
- return data;
- }
-
- /**
- * Get the flags stored along with this value.
- */
- public int getFlags() {
- return flags;
- }
-
- @Override
- public String toString() {
- return "{CachedData flags=" + flags + " data="
- + Arrays.toString(data) + "}";
- }
+ /**
+ * The maximum size that should be considered storing in a server.
+ */
+ /*
+ * though memcached no longer has a maximum size, rather than remove this
+ * entirely just bump it up for now
+ */
+ public static final int MAX_SIZE = 20 * 1024 * 1024;
+
+ private final int flags;
+ private final byte[] data;
+
+ /**
+ * Get a CachedData instance for the given flags and byte array.
+ *
+ * @param f the flags
+ * @param d the data
+ * @param maxSize the maximum allowable size.
+ */
+ public CachedData(int f, byte[] d, int maxSize) {
+ super();
+ if (d.length > maxSize) {
+ throw new IllegalArgumentException("Cannot cache data larger than "
+ + maxSize + " bytes (you tried to cache a " + d.length
+ + " byte object)");
+ }
+ flags = f;
+ data = d;
+ }
+
+ /**
+ * Get the stored data.
+ */
+ public byte[] getData() {
+ return data;
+ }
+
+ /**
+ * Get the flags stored along with this value.
+ */
+ public int getFlags() {
+ return flags;
+ }
+
+ @Override
+ public String toString() {
+ return "{CachedData flags=" + flags + " data=" + Arrays.toString(data)
+ + "}";
+ }
}
View
263 src/main/java/net/spy/memcached/ConnectionFactory.java
@@ -1,3 +1,25 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
import java.io.IOException;
@@ -13,128 +35,127 @@
import net.spy.memcached.transcoders.Transcoder;
/**
- * Factory for creating instances of MemcachedConnection.
- * This is used to provide more fine-grained configuration of connections.
+ * Factory for creating instances of MemcachedConnection. This is used to
+ * provide more fine-grained configuration of connections.
*/
public interface ConnectionFactory {
- /**
- * Create a MemcachedConnection for the given SocketAddresses.
- *
- * @param addrs the addresses of the memcached servers
- * @return a new MemcachedConnection connected to those addresses
- * @throws IOException for problems initializing the memcached connections
- */
- MemcachedConnection createConnection(List<InetSocketAddress> addrs)
- throws IOException;
-
- /**
- * Create a new memcached node.
- */
- MemcachedNode createMemcachedNode(SocketAddress sa,
- SocketChannel c, int bufSize);
-
- /**
- * Create a BlockingQueue for operations for a connection.
- */
- BlockingQueue<Operation> createOperationQueue();
-
- /**
- * Create a BlockingQueue for the operations currently expecting to read
- * responses from memcached.
- */
- BlockingQueue<Operation> createReadOperationQueue();
-
- /**
- * Create a BlockingQueue for the operations currently expecting to write
- * requests to memcached.
- */
- BlockingQueue<Operation> createWriteOperationQueue();
-
- /**
- * Get the maximum amount of time (in milliseconds) a client is willing
- * to wait to add a new item to a queue.
- */
- long getOpQueueMaxBlockTime();
-
- /**
- * Create a NodeLocator instance for the given list of nodes.
- */
- NodeLocator createLocator(List<MemcachedNode> nodes);
-
- /**
- * Get the operation factory for connections built by this connection
- * factory.
- */
- OperationFactory getOperationFactory();
-
- /**
- * Get the operation timeout used by this connection.
- */
- long getOperationTimeout();
-
- /**
- * If true, the IO thread should be a daemon thread.
- */
- boolean isDaemon();
-
- /**
- * If true, the nagle algorithm will be used on connected sockets.
- *
- * <p>
- * See {@link java.net.Socket#setTcpNoDelay(boolean)} for more information.
- * </p>
- */
- boolean useNagleAlgorithm();
-
- /**
- * Observers that should be established at the time of connection
- * instantiation.
- *
- * These observers will see the first connection established.
- */
- Collection<ConnectionObserver> getInitialObservers();
-
- /**
- * Get the default failure mode for the underlying connection.
- */
- FailureMode getFailureMode();
-
- /**
- * Get the default transcoder to be used in connections created by this
- * factory.
- */
- Transcoder<Object> getDefaultTranscoder();
-
- /**
- * If true, low-level optimization is in effect.
- */
- boolean shouldOptimize();
-
- /*
- * Get the read buffer size set at construct time.
- */
- int getReadBufSize();
-
- /**
- * Get the hash algorithm to be used.
- */
- public HashAlgorithm getHashAlg();
-
- /**
- * Maximum number of milliseconds to wait between reconnect attempts.
- */
- long getMaxReconnectDelay();
-
- /**
- * Authenticate connections using the given auth descriptor.
- *
- * @return null if no authentication should take place
- */
- AuthDescriptor getAuthDescriptor();
-
- /**
- * Maximum number of timeout exception for shutdown connection
- */
- int getTimeoutExceptionThreshold();
+ /**
+ * Create a MemcachedConnection for the given SocketAddresses.
+ *
+ * @param addrs the addresses of the memcached servers
+ * @return a new MemcachedConnection connected to those addresses
+ * @throws IOException for problems initializing the memcached connections
+ */
+ MemcachedConnection createConnection(List<InetSocketAddress> addrs)
+ throws IOException;
+
+ /**
+ * Create a new memcached node.
+ */
+ MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c,
+ int bufSize);
+
+ /**
+ * Create a BlockingQueue for operations for a connection.
+ */
+ BlockingQueue<Operation> createOperationQueue();
+
+ /**
+ * Create a BlockingQueue for the operations currently expecting to read
+ * responses from memcached.
+ */
+ BlockingQueue<Operation> createReadOperationQueue();
+
+ /**
+ * Create a BlockingQueue for the operations currently expecting to write
+ * requests to memcached.
+ */
+ BlockingQueue<Operation> createWriteOperationQueue();
+
+ /**
+ * Get the maximum amount of time (in milliseconds) a client is willing to
+ * wait to add a new item to a queue.
+ */
+ long getOpQueueMaxBlockTime();
+
+ /**
+ * Create a NodeLocator instance for the given list of nodes.
+ */
+ NodeLocator createLocator(List<MemcachedNode> nodes);
+
+ /**
+ * Get the operation factory for connections built by this connection factory.
+ */
+ OperationFactory getOperationFactory();
+
+ /**
+ * Get the operation timeout used by this connection.
+ */
+ long getOperationTimeout();
+
+ /**
+ * If true, the IO thread should be a daemon thread.
+ */
+ boolean isDaemon();
+
+ /**
+ * If true, the nagle algorithm will be used on connected sockets.
+ *
+ * <p>
+ * See {@link java.net.Socket#setTcpNoDelay(boolean)} for more information.
+ * </p>
+ */
+ boolean useNagleAlgorithm();
+
+ /**
+ * Observers that should be established at the time of connection
+ * instantiation.
+ *
+ * These observers will see the first connection established.
+ */
+ Collection<ConnectionObserver> getInitialObservers();
+
+ /**
+ * Get the default failure mode for the underlying connection.
+ */
+ FailureMode getFailureMode();
+
+ /**
+ * Get the default transcoder to be used in connections created by this
+ * factory.
+ */
+ Transcoder<Object> getDefaultTranscoder();
+
+ /**
+ * If true, low-level optimization is in effect.
+ */
+ boolean shouldOptimize();
+
+ /*
+ * Get the read buffer size set at construct time.
+ */
+ int getReadBufSize();
+
+ /**
+ * Get the hash algorithm to be used.
+ */
+ HashAlgorithm getHashAlg();
+
+ /**
+ * Maximum number of milliseconds to wait between reconnect attempts.
+ */
+ long getMaxReconnectDelay();
+
+ /**
+ * Authenticate connections using the given auth descriptor.
+ *
+ * @return null if no authentication should take place
+ */
+ AuthDescriptor getAuthDescriptor();
+
+ /**
+ * Maximum number of timeout exception for shutdown connection.
+ */
+ int getTimeoutExceptionThreshold();
}
View
1,033 src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java
@@ -1,3 +1,26 @@
+/**
+ * Copyright (C) 2006-2009 Dustin Sallings
+ * Copyright (C) 2009-2011 Couchbase, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
+ * IN THE SOFTWARE.
+ */
+
package net.spy.memcached;
import java.io.IOException;
@@ -21,513 +44,507 @@
*/
public class ConnectionFactoryBuilder {
- private OperationQueueFactory opQueueFactory;
- private OperationQueueFactory readQueueFactory;
- private OperationQueueFactory writeQueueFactory;
-
- private Transcoder<Object> transcoder;
-
- private FailureMode failureMode;
-
- private Collection<ConnectionObserver> initialObservers
- = Collections.emptyList();
-
- private OperationFactory opFact;
-
- private Locator locator = Locator.ARRAY_MOD;
- private long opTimeout = -1;
- private boolean isDaemon = false;
- private boolean shouldOptimize = true;
- private boolean useNagle = false;
- private long maxReconnectDelay =
- DefaultConnectionFactory.DEFAULT_MAX_RECONNECT_DELAY;
-
- private int readBufSize = -1;
- private HashAlgorithm hashAlg;
- private AuthDescriptor authDescriptor = null;
- private long opQueueMaxBlockTime = -1;
-
- private int timeoutExceptionThreshold = DefaultConnectionFactory.DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLD;
- private Config vBucketConfig;
- /**
- * Set the operation queue factory.
- */
-
- public ConnectionFactoryBuilder() {
- // empty
- }
-
- public ConnectionFactoryBuilder(ConnectionFactory cf) {
- setAuthDescriptor(cf.getAuthDescriptor());
- setDaemon(cf.isDaemon());
- setFailureMode(cf.getFailureMode());
- setHashAlg(cf.getHashAlg());
- setInitialObservers(cf.getInitialObservers());
- setMaxReconnectDelay(cf.getMaxReconnectDelay());
- setOpQueueMaxBlockTime(cf.getOpQueueMaxBlockTime());
- setOpTimeout(cf.getOperationTimeout());
- setReadBufferSize(cf.getReadBufSize());
- setShouldOptimize(cf.shouldOptimize());
- setTimeoutExceptionThreshold(cf.getTimeoutExceptionThreshold());
- setTranscoder(cf.getDefaultTranscoder());
- setUseNagleAlgorithm(cf.useNagleAlgorithm());
+ private OperationQueueFactory opQueueFactory;
+ private OperationQueueFactory readQueueFactory;
+ private OperationQueueFactory writeQueueFactory;
+
+ private Transcoder<Object> transcoder;
+
+ private FailureMode failureMode;
+
+ private Collection<ConnectionObserver> initialObservers =
+ Collections.emptyList();
+
+ private OperationFactory opFact;
+
+ private Locator locator = Locator.ARRAY_MOD;
+ private long opTimeout = -1;
+ private boolean isDaemon = false;
+ private boolean shouldOptimize = true;
+ private boolean useNagle = false;
+ private long maxReconnectDelay =
+ DefaultConnectionFactory.DEFAULT_MAX_RECONNECT_DELAY;
+
+ private int readBufSize = -1;
+ private HashAlgorithm hashAlg;
+ private AuthDescriptor authDescriptor = null;
+ private long opQueueMaxBlockTime = -1;
+
+ private int timeoutExceptionThreshold =
+ DefaultConnectionFactory.DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLD;
+ private Config vBucketConfig;
+
+ /**
+ * Set the operation queue factory.
+ */
+
+ public ConnectionFactoryBuilder() {
+ // empty
+ }
+
+ public ConnectionFactoryBuilder(ConnectionFactory cf) {
+ setAuthDescriptor(cf.getAuthDescriptor());
+ setDaemon(cf.isDaemon());
+ setFailureMode(cf.getFailureMode());
+ setHashAlg(cf.getHashAlg());
+ setInitialObservers(cf.getInitialObservers());
+ setMaxReconnectDelay(cf.getMaxReconnectDelay());
+ setOpQueueMaxBlockTime(cf.getOpQueueMaxBlockTime());
+ setOpTimeout(cf.getOperationTimeout());
+ setReadBufferSize(cf.getReadBufSize());
+ setShouldOptimize(cf.shouldOptimize());
+ setTimeoutExceptionThreshold(cf.getTimeoutExceptionThreshold());
+ setTranscoder(cf.getDefaultTranscoder());
+ setUseNagleAlgorithm(cf.useNagleAlgorithm());
+ }
+
+ public ConnectionFactoryBuilder setOpQueueFactory(OperationQueueFactory q) {
+ opQueueFactory = q;
+ return this;
+ }
+
+ /**
+ * Set the read queue factory.
+ */
+ public ConnectionFactoryBuilder
+ setReadOpQueueFactory(OperationQueueFactory q) {
+ readQueueFactory = q;
+ return this;
+ }
+
+ /**
+ * Set the write queue factory.
+ */
+ public ConnectionFactoryBuilder
+ setWriteOpQueueFactory(OperationQueueFactory q) {
+ writeQueueFactory = q;
+ return this;
+ }
+
+ /**
+ * Set the maximum amount of time (in milliseconds) a client is willing to
+ * wait for space to become available in an output queue.
+ */
+ public ConnectionFactoryBuilder setOpQueueMaxBlockTime(long t) {
+ opQueueMaxBlockTime = t;
+ return this;
+ }
+
+ /**
+ * Set the default transcoder.
+ */
+ public ConnectionFactoryBuilder setTranscoder(Transcoder<Object> t) {
+ transcoder = t;
+ return this;
+ }
+
+ /**
+ * Set the failure mode.
+ */
+ public ConnectionFactoryBuilder setFailureMode(FailureMode fm) {
+ failureMode = fm;
+ return this;
+ }
+
+ /**
+ * Set the initial connection observers (will observe initial connection).
+ */
+ public ConnectionFactoryBuilder setInitialObservers(
+ Collection<ConnectionObserver> obs) {
+ initialObservers = obs;
+ return this;
+ }
+
+ /**
+ * Set the operation factory.
+ *
+ * Note that the operation factory is used to also imply the type of nodes to
+ * create.
+ *
+ * @see MemcachedNode
+ */
+ public ConnectionFactoryBuilder setOpFact(OperationFactory f) {
+ opFact = f;
+ return this;
+ }
+
+ /**
+ * Set the default operation timeout in milliseconds.
+ */
+ public ConnectionFactoryBuilder setOpTimeout(long t) {
+ opTimeout = t;
+ return this;
+ }
+
+ /**
+ * Set the daemon state of the IO thread (defaults to true).
+ */
+ public ConnectionFactoryBuilder setDaemon(boolean d) {
+ isDaemon = d;
+ return this;
+ }
+
+ /**
+ * Set to false if the default operation optimization is not desirable.
+ */
+ public ConnectionFactoryBuilder setShouldOptimize(boolean o) {
+ shouldOptimize = o;
+ return this;
+ }
+
+ /**
+ * Set the read buffer size.
+ */
+ public ConnectionFactoryBuilder setReadBufferSize(int to) {
+ readBufSize = to;
+ return this;
+ }
+
+ /**
+ * Set the hash algorithm.
+ */
+ public ConnectionFactoryBuilder setHashAlg(HashAlgorithm to) {
+ hashAlg = to;
+ return this;
+ }
+
+ /**
+ * Set to true if you'd like to enable the Nagle algorithm.
+ */
+ public ConnectionFactoryBuilder setUseNagleAlgorithm(boolean to) {
+ useNagle = to;
+ return this;
+ }
+
+ /**
+ * Convenience method to specify the protocol to use.
+ */
+ public ConnectionFactoryBuilder setProtocol(Protocol prot) {
+ switch (prot) {
+ case TEXT:
+ opFact = new AsciiOperationFactory();
+ break;
+ case BINARY:
+ opFact = new BinaryOperationFactory();
+ break;
+ default:
+ assert false : "Unhandled protocol: " + prot;
}
-
- public ConnectionFactoryBuilder setOpQueueFactory(OperationQueueFactory q) {
- opQueueFactory = q;
- return this;
- }
-
- /**
- * Set the read queue factory.
- */
- public ConnectionFactoryBuilder setReadOpQueueFactory(OperationQueueFactory q) {
- readQueueFactory = q;
- return this;
- }
-
- /**
- * Set the write queue factory.
- */
- public ConnectionFactoryBuilder setWriteOpQueueFactory(OperationQueueFactory q) {
- writeQueueFactory = q;
- return this;
- }
-
- /**
- * Set the maximum amount of time (in milliseconds) a client is willing to
- * wait for space to become available in an output queue.
- */
- public ConnectionFactoryBuilder setOpQueueMaxBlockTime(long t) {
- opQueueMaxBlockTime = t;
- return this;
- }
-
- /**
- * Set the default transcoder.
- */
- public ConnectionFactoryBuilder setTranscoder(Transcoder<Object> t) {
- transcoder = t;
- return this;
- }
-
- /**
- * Set the failure mode.
- */
- public ConnectionFactoryBuilder setFailureMode(FailureMode fm) {
- failureMode = fm;
- return this;
- }
-
- /**
- * Set the initial connection observers (will observe initial connection).
- */
- public ConnectionFactoryBuilder setInitialObservers(
- Collection<ConnectionObserver> obs) {
- initialObservers = obs;
- return this;
- }
-
- /**
- * Set the operation factory.
- *
- * Note that the operation factory is used to also imply the type of
- * nodes to create.
- *
- * @see MemcachedNode
- */
- public ConnectionFactoryBuilder setOpFact(OperationFactory f) {
- opFact = f;
- return this;
- }
-
- /**
- * Set the default operation timeout in milliseconds.
- */
- public ConnectionFactoryBuilder setOpTimeout(long t) {
- opTimeout = t;
- return this;
- }
-
- /**
- * Set the daemon state of the IO thread (defaults to true).
- */
- public ConnectionFactoryBuilder setDaemon(boolean d) {
- isDaemon = d;
- return this;
- }
-
- /**
- * Set to false if the default operation optimization is not desirable.
- */
- public ConnectionFactoryBuilder setShouldOptimize(boolean o) {
- shouldOptimize = o;
- return this;
- }
-
- /**
- * Set the read buffer size.
- */
- public ConnectionFactoryBuilder setReadBufferSize(int to) {
- readBufSize = to;
- return this;
- }
-
- /**
- * Set the hash algorithm.
- */
- public ConnectionFactoryBuilder setHashAlg(HashAlgorithm to) {
- hashAlg = to;