7474import net .spy .memcached .ops .StoreOperation ;
7575import net .spy .memcached .ops .StoreType ;
7676import net .spy .memcached .ops .TimedOutOperationStatus ;
77+ import net .spy .memcached .protocol .ascii .AsciiOperationFactory ;
7778import net .spy .memcached .protocol .binary .BinaryOperationFactory ;
7879import net .spy .memcached .transcoders .TranscodeService ;
7980import net .spy .memcached .transcoders .Transcoder ;
@@ -1978,6 +1979,12 @@ private long mutateWithDefault(Mutator t, String key, long by, long def,
19781979
19791980 private OperationFuture <Long > asyncMutate (Mutator m , String key , long by ,
19801981 long def , int exp ) {
1982+ if (!(opFact instanceof BinaryOperationFactory ) && (def != 0 || exp != -1 )) {
1983+ throw new UnsupportedOperationException ("Default value or expiration "
1984+ + "time are not supported on the async mutate methods. Use either the "
1985+ + "binary protocol or the sync variant." );
1986+ }
1987+
19811988 final CountDownLatch latch = new CountDownLatch (1 );
19821989 final OperationFuture <Long > rv =
19831990 new OperationFuture <Long >(key , latch , operationTimeout , executorService );
@@ -2030,9 +2037,9 @@ public OperationFuture<Long> asyncIncr(String key, int by) {
20302037 /**
20312038 * Asynchronous decrement.
20322039 *
2033- * @param key key to increment
2034- * @param by the amount to increment the value by
2035- * @return a future with the decremented value, or -1 if the increment failed.
2040+ * @param key key to decrement
2041+ * @param by the amount to decrement the value by
2042+ * @return a future with the decremented value, or -1 if the decrement failed.
20362043 * @throws IllegalStateException in the rare circumstance where queue is too
20372044 * full to accept any more requests
20382045 */
@@ -2044,9 +2051,9 @@ public OperationFuture<Long> asyncDecr(String key, long by) {
20442051 /**
20452052 * Asynchronous decrement.
20462053 *
2047- * @param key key to increment
2048- * @param by the amount to increment the value by
2049- * @return a future with the decremented value, or -1 if the increment failed.
2054+ * @param key key to decrement
2055+ * @param by the amount to decrement the value by
2056+ * @return a future with the decremented value, or -1 if the decrement failed.
20502057 * @throws IllegalStateException in the rare circumstance where queue is too
20512058 * full to accept any more requests
20522059 */
@@ -2055,6 +2062,134 @@ public OperationFuture<Long> asyncDecr(String key, int by) {
20552062 return asyncMutate (Mutator .decr , key , by , 0 , -1 );
20562063 }
20572064
2065+ /**
2066+ * Asychronous increment.
2067+ *
2068+ * @param key key to increment
2069+ * @param by the amount to increment the value by
2070+ * @param def the default value (if the counter does not exist)
2071+ * @param exp the expiration of this object
2072+ * @return a future with the incremented value, or -1 if the increment failed.
2073+ * @throws IllegalStateException in the rare circumstance where queue is too
2074+ * full to accept any more requests
2075+ */
2076+ @ Override
2077+ public OperationFuture <Long > asyncIncr (String key , long by , long def ,
2078+ int exp ) {
2079+ return asyncMutate (Mutator .incr , key , by , def , exp );
2080+ }
2081+
2082+ /**
2083+ * Asychronous increment.
2084+ *
2085+ * @param key key to increment
2086+ * @param by the amount to increment the value by
2087+ * @param def the default value (if the counter does not exist)
2088+ * @param exp the expiration of this object
2089+ * @return a future with the incremented value, or -1 if the increment failed.
2090+ * @throws IllegalStateException in the rare circumstance where queue is too
2091+ * full to accept any more requests
2092+ */
2093+ @ Override
2094+ public OperationFuture <Long > asyncIncr (String key , int by , long def ,
2095+ int exp ) {
2096+ return asyncMutate (Mutator .incr , key , by , def , exp );
2097+ }
2098+
2099+ /**
2100+ * Asynchronous decrement.
2101+ *
2102+ * @param key key to decrement
2103+ * @param by the amount to decrement the value by
2104+ * @param def the default value (if the counter does not exist)
2105+ * @param exp the expiration of this object
2106+ * @return a future with the decremented value, or -1 if the decrement failed.
2107+ * @throws IllegalStateException in the rare circumstance where queue is too
2108+ * full to accept any more requests
2109+ */
2110+ @ Override
2111+ public OperationFuture <Long > asyncDecr (String key , long by , long def ,
2112+ int exp ) {
2113+ return asyncMutate (Mutator .decr , key , by , def , exp );
2114+ }
2115+
2116+ /**
2117+ * Asynchronous decrement.
2118+ *
2119+ * @param key key to decrement
2120+ * @param by the amount to decrement the value by
2121+ * @param def the default value (if the counter does not exist)
2122+ * @param exp the expiration of this object
2123+ * @return a future with the decremented value, or -1 if the decrement failed.
2124+ * @throws IllegalStateException in the rare circumstance where queue is too
2125+ * full to accept any more requests
2126+ */
2127+ @ Override
2128+ public OperationFuture <Long > asyncDecr (String key , int by , long def ,
2129+ int exp ) {
2130+ return asyncMutate (Mutator .decr , key , by , def , exp );
2131+ }
2132+
2133+ /**
2134+ * Asychronous increment.
2135+ *
2136+ * @param key key to increment
2137+ * @param by the amount to increment the value by
2138+ * @param def the default value (if the counter does not exist)
2139+ * @return a future with the incremented value, or -1 if the increment failed.
2140+ * @throws IllegalStateException in the rare circumstance where queue is too
2141+ * full to accept any more requests
2142+ */
2143+ @ Override
2144+ public OperationFuture <Long > asyncIncr (String key , long by , long def ) {
2145+ return asyncMutate (Mutator .incr , key , by , def , 0 );
2146+ }
2147+
2148+ /**
2149+ * Asychronous increment.
2150+ *
2151+ * @param key key to increment
2152+ * @param by the amount to increment the value by
2153+ * @param def the default value (if the counter does not exist)
2154+ * @return a future with the incremented value, or -1 if the increment failed.
2155+ * @throws IllegalStateException in the rare circumstance where queue is too
2156+ * full to accept any more requests
2157+ */
2158+ @ Override
2159+ public OperationFuture <Long > asyncIncr (String key , int by , long def ) {
2160+ return asyncMutate (Mutator .incr , key , by , def , 0 );
2161+ }
2162+
2163+ /**
2164+ * Asynchronous decrement.
2165+ *
2166+ * @param key key to decrement
2167+ * @param by the amount to decrement the value by
2168+ * @param def the default value (if the counter does not exist)
2169+ * @return a future with the decremented value, or -1 if the decrement failed.
2170+ * @throws IllegalStateException in the rare circumstance where queue is too
2171+ * full to accept any more requests
2172+ */
2173+ @ Override
2174+ public OperationFuture <Long > asyncDecr (String key , long by , long def ) {
2175+ return asyncMutate (Mutator .decr , key , by , def , 0 );
2176+ }
2177+
2178+ /**
2179+ * Asynchronous decrement.
2180+ *
2181+ * @param key key to decrement
2182+ * @param by the amount to decrement the value by
2183+ * @param def the default value (if the counter does not exist)
2184+ * @return a future with the decremented value, or -1 if the decrement failed.
2185+ * @throws IllegalStateException in the rare circumstance where queue is too
2186+ * full to accept any more requests
2187+ */
2188+ @ Override
2189+ public OperationFuture <Long > asyncDecr (String key , int by , long def ) {
2190+ return asyncMutate (Mutator .decr , key , by , def , 0 );
2191+ }
2192+
20582193 /**
20592194 * Increment the given counter, returning the new value.
20602195 *
0 commit comments