JCBC-346: Supporting CRAM-MD5 as a SASL mechanism.

This changeset implements support for CRAM-MD5 as SASL mechanism,
by sending a "list sasl mechs" first. Depending on the response,
either CRAM-MD5 or PLAIN will be used.

Regular memcached servers wil make use of PLAIN as before, but
systems that support it (like couchbase) will use the more secure
variant.

The list sasl mechs process will only proceed if the AuthDescriptor
either gets null or an empty list of mechanisms in order to be
backwards compatible, so no changes to code need to be done when
upgrading to a new version.

Change-Id: I7c7e935e4307c181f98e5ff5615b18cba3f403b4
Reviewed-on: http://review.couchbase.org/28292
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-131: Expose cas with expiration.

This changeset simply exposes the expiration time on cas() without
a custom transcoder and adds tests to verify the correct behavior.

Change-Id: I2fb28d96121c5bd337ec1c33c8e907a13e3a8bfa
Reviewed-on: http://review.couchbase.org/28018
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Ignore IntelliJ Idea .idea directory.

Change-Id: Ief5af0aa2267665e763972f39bd27e7ca6894e7b
Reviewed-on: http://review.couchbase.org/28738
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Ignore intellij directory on ant clean.

Change-Id: If564fdb8eee84ff2f1fe39718588bbe5fb98f4a6
Reviewed-on: http://review.couchbase.org/28765
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
SPY-133: Add additional metrics support.

This changeset adds basic metrics for performance measurement and
debug support. It is optional and can be enabled through the factory
or via a system property.

The collected values can be exported through:
 - The Console
 - JMX
 - CSV
 - SLF4J

These output reporters can also be configured through properties, by
default the console reporter will be used.

Change-Id: If206f0be0c0bd6c6ff11d63f1be25debab2e524e
Reviewed-on: http://review.couchbase.org/28575
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Remove unreliable tests.

These tests fail/not fail on a constant basis and are therefore
not reliable and lead to false positivies. They are removed for
now and can be considered to be readded later with different
implementations.

Change-Id: Ic94d7a3a2ce4cd8c17f2aeb94b57eb670e2a41a5
Reviewed-on: http://review.couchbase.org/28792
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
SPY-132: Adding Callbacks to Futures.

This changeset adds a onComplete callback to futures and executes
the callback in a configurable ExecutorService. By default, this
is a fixed size thread pool (threads = num of processors), but
configurable through the Factory.

Change-Id: I516af74918e57521542a0bad2ff7142b75ab7b13
Reviewed-on: http://review.couchbase.org/28025
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
SPY-135: Expose asyncCAS with Expiration and default transcoder.

Change-Id: I99ecf0b293a9d52871b81e9166f07a35f90c712a
Reviewed-on: http://review.couchbase.org/29346
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-138: Allow the ExecutorService to be overridden.

Change-Id: I6f9c577f734c33f2d6004031253dd561b6302b4c
Reviewed-on: http://review.couchbase.org/29373
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
SPY-137: Properly shutdown executorService on shutdown().

Change-Id: I23bf0a30cc96c5721d6ed0d5c16bdfc2113c0fe4
Reviewed-on: http://review.couchbase.org/29372
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-140: Use LinkedBlockingQueue for listener task queuing.

Change-Id: I3e3db7861a6e6e6c24c61c40ea02b19c8bc57fab
Reviewed-on: http://review.couchbase.org/29548
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-141: Do not assume positive CAS.

This changeset makes sure that when loading the CAS value, there
is no assumption of the actual value done on the client side.
Especially, -1 is a valid CAS and can cause issues when running
with -ea in production (since the callback is executed on the
IO thread, it can die for no reason).

Change-Id: Ic944bca9c7e005fb793edc0ddb3a51674f2d2be0
Reviewed-on: http://review.couchbase.org/29584
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-106: Allow GetAndTouchOperation to be cloned.

This fixes an issue where GAT called during rebalance, causing it
to be cloned potentially, fails the IO threads since its not
supported in there properly.

Change-Id: I3ff86456c5f2f28e206612890c08834fc96935f1
Reviewed-on: http://review.couchbase.org/29585
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-136: Do not timeout when waiting on the sasl mechs.

Since we also dont timeout on the return of the auth op, keeping
the process consistent. This avoids the situation where the server
is potentially rebooting and the timeout occurs. In combination with
code depending on the sasl list, exceptions can occur and the auth
thread dies.

Change-Id: I270e91e0794ea7de10cd26a9dafc85e35f87095d
Reviewed-on: http://review.couchbase.org/29657
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-144: Avoid growing callstack on get* clones.

This changeset makes sure that if an operation gets cloned over
and over again (which is not the norm, but can happen in certain
failure scenarios), it will not lead to a stack overflow.

Special thanks to Kirill Safonov for pointing out the right fix.

Change-Id: I6846fe9b23d43d9f2e257a5206a511f941aed8ff
Reviewed-on: http://review.couchbase.org/30415
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Allow OperationImpl to be used elswhere.

Change-Id: I89818f2a94e8e746c562b5a115602f8d3ccfb8d2
Reviewed-on: http://review.couchbase.org/30447
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
This changeset refactors the MemcachedConnection class.

It also breaks out certain large blocks into their own methods
to make it better readable and easier for the JIT to inline
the code.

Change-Id: I3369606afeef00b50740e54c01a78e89682cade1
Reviewed-on: http://review.couchbase.org/30416
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-145: Make OperationImpl inline properly.

Change-Id: Ia03701670d9b3bb82d7e8c4798dd5cb99c9e25c7
Reviewed-on: http://review.couchbase.org/30418
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-146: Use correct length of key in observe.

This changeset makes sure that the correct length of the key is used in the
protocol. Since UTF-8 chars like the pound sign (currency) are represented
in two bytes but are one character in a string, the length of the key needs
to be determined after it is converted into a byte array.

Change-Id: I48b68127f384e3bcb963a5df1cddd5b5c2d5ca7a
Reviewed-on: http://review.couchbase.org/30701
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
SPY-145: Make MemcachedConnection inline properly.

Change-Id: I1be0a3ea410e9bed0a155ac821d41bf64125beac
Reviewed-on: http://review.couchbase.org/30417
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>