Permalink
Browse files

Membase client now lives at https://github.com/couchbase/couchbase-ne…

  • Loading branch information...
1 parent 0c6fe75 commit b993e333f24a26a9cf9a668aafe42fcbd12f35ea @enyim enyim committed May 13, 2012
Showing with 10 additions and 4,501 deletions.
  1. +0 −4 DemoApp/DemoApp.csproj
  2. +2 −7 DemoApp/Program.cs
  3. +0 −11 Enyim.Caching.sln
  4. +0 −45 Membase/BasicMembaseOperationFactory.cs
  5. +0 −276 Membase/BucketConfigListener.cs
  6. +0 −32 Membase/Changes.mdown
  7. +0 −28 Membase/Config.transform
  8. +0 −92 Membase/ConfigHelper.cs
  9. +0 −40 Membase/Configuration/BucketPortType.cs
  10. +0 −44 Membase/Configuration/DefaultPerformanceMonitorFactory.cs
  11. +0 −75 Membase/Configuration/IMembaseClientConfiguration.cs
  12. +0 −33 Membase/Configuration/IMembasePerformanceMonitorFactory.cs
  13. +0 −293 Membase/Configuration/MembaseClientConfiguration.cs
  14. +0 −169 Membase/Configuration/MembaseClientSection.cs
  15. +0 −119 Membase/Configuration/ServersElement.cs
  16. +0 −42 Membase/Configuration/UriElement.cs
  17. +0 −68 Membase/Configuration/UriElementCollection.cs
  18. +0 −85 Membase/Configuration/UriValidator.cs
  19. +0 −28 Membase/Demo.config
  20. +0 −218 Membase/Deserialization.cs
  21. +0 −15 Membase/IMembaseOperationFactory.cs
  22. +0 −13 Membase/IMembaseServerPool.cs
  23. +0 −91 Membase/Membase.csproj
  24. +0 −19 Membase/Membase.nuspec
  25. +0 −464 Membase/MembaseClient.cs
  26. +0 −577 Membase/MembasePool.cs
  27. +0 −564 Membase/MessageStreamListener.cs
  28. +0 −11 Membase/OperationInterfaces.cs
  29. +0 −88 Membase/Operations/GetAndTouchOperation.cs
  30. +0 −240 Membase/Operations/SyncOperation.cs
  31. +0 −65 Membase/Operations/TouchOperation.cs
  32. +0 −35 Membase/Properties/AssemblyInfo.cs
  33. +0 −359 Membase/VBucketAwareOperationFactory.cs
  34. +0 −116 Membase/WebClientWithTimeout.cs
  35. +2 −27 MemcachedTest/ConfigTest.cs
  36. +0 −47 MemcachedTest/MembaseClientTest.cs
  37. +0 −41 MemcachedTest/MembaseMemcachedBucketTest.cs
  38. +0 −6 MemcachedTest/MemcachedTest.csproj
  39. +4 −8 TestApp/Program.cs
  40. +0 −4 TestApp/TestApp.csproj
  41. +2 −2 build/properties.ps1
View
@@ -39,10 +39,6 @@
<Project>{D438C0B3-A168-40B8-BDDD-61F0939DFF35}</Project>
<Name>Enyim.Caching</Name>
</ProjectReference>
- <ProjectReference Include="..\Membase\Membase.csproj">
- <Project>{708A2350-A26C-444D-B975-8164263951A7}</Project>
- <Name>Membase</Name>
- </ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
View
@@ -1,13 +1,8 @@
using System;
-using System.Collections.Generic;
-using System.Text;
-using Enyim.Caching;
-using Enyim.Caching.Memcached;
using System.Net;
+using Enyim.Caching;
using Enyim.Caching.Configuration;
-using Membase;
-using Membase.Configuration;
-using System.Threading;
+using Enyim.Caching.Memcached;
namespace DemoApp
{
View
@@ -13,10 +13,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MemcachedTest", "MemcachedT
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoApp", "DemoApp\DemoApp.csproj", "{7225B6E0-A1FB-4F64-A5C5-1F640E21C90B}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Membase", "Membase\Membase.csproj", "{708A2350-A26C-444D-B975-8164263951A7}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{607B1927-A964-48B2-AEA3-6810D10A6831}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enyim.Caching.Log4NetAdapter", "Enyim.Caching.Log4NetAdapter\Enyim.Caching.Log4NetAdapter.csproj", "{9D3F12E6-6BDD-4DED-8B25-D877780640B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enyim.Caching.NLogAdapter", "Enyim.Caching.NLogAdapter\Enyim.Caching.NLogAdapter.csproj", "{C96760B1-7CAD-4983-9FAD-EB00CD7A9FC6}"
@@ -37,13 +33,6 @@ Global
{7225B6E0-A1FB-4F64-A5C5-1F640E21C90B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7225B6E0-A1FB-4F64-A5C5-1F640E21C90B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7225B6E0-A1FB-4F64-A5C5-1F640E21C90B}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {708A2350-A26C-444D-B975-8164263951A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {708A2350-A26C-444D-B975-8164263951A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {708A2350-A26C-444D-B975-8164263951A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {708A2350-A26C-444D-B975-8164263951A7}.Release|Any CPU.Build.0 = Release|Any CPU
- {607B1927-A964-48B2-AEA3-6810D10A6831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {607B1927-A964-48B2-AEA3-6810D10A6831}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {607B1927-A964-48B2-AEA3-6810D10A6831}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D3F12E6-6BDD-4DED-8B25-D877780640B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D3F12E6-6BDD-4DED-8B25-D877780640B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D3F12E6-6BDD-4DED-8B25-D877780640B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -1,45 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Membase
-{
- internal class BasicMembaseOperationFactory : Enyim.Caching.Memcached.Protocol.Binary.BinaryOperationFactory, IMembaseOperationFactory
- {
- internal static readonly BasicMembaseOperationFactory Instance = new BasicMembaseOperationFactory();
-
- ITouchOperation IMembaseOperationFactory.Touch(string key, uint newExpiration)
- {
- return new TouchOperation(null, key, newExpiration);
- }
-
- IGetAndTouchOperation IMembaseOperationFactory.GetAndTouch(string key, uint newExpiration)
- {
- return new GetAndTouchOperation(null, key, newExpiration);
- }
-
- ISyncOperation IMembaseOperationFactory.Sync(SyncMode mode, IList<KeyValuePair<string, ulong>> keys, int replicationCount)
- {
- throw new NotSupportedException("Sync is not supported on memcached buckets.");
- }
- }
-}
-
-#region [ License information ]
-/* ************************************************************
- *
- * Copyright (c) 2010 Attila Kiskó, enyim.com
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ************************************************************/
-#endregion
@@ -1,276 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web.Script.Serialization;
-using System.Threading;
-using System.Net;
-using Enyim;
-using Membase.Configuration;
-
-namespace Membase
-{
- internal class BucketConfigListener
- {
- private static readonly Enyim.Caching.ILog log = Enyim.Caching.LogManager.GetLogger(typeof(BucketConfigListener));
-
- private Uri[] poolUrls;
- private string bucketName;
- private NetworkCredential credential;
- private int? lastHash;
- private ManualResetEvent mre;
- private MessageStreamListener listener;
-
- public BucketConfigListener(Uri[] poolUrls, string bucketName, string bucketPassword)
- {
- this.poolUrls = poolUrls;
- this.bucketName = String.IsNullOrEmpty(bucketName)
- ? "default"
- : bucketName;
-
- this.credential = bucketName == "default" || String.IsNullOrEmpty(bucketPassword)
- ? null
- : new NetworkCredential(bucketName, bucketPassword);
-
- this.Timeout = 10000;
- this.DeadTimeout = 10000;
-
- this.RetryCount = 0;
- this.RetryTimeout = new TimeSpan(0, 0, 0, 0, 500);
- }
-
- /// <summary>
- /// Connection timeout in milliseconds for connecting the pool.
- /// </summary>
- public int Timeout { get; set; }
-
- public int RetryCount { get; set; }
- public TimeSpan RetryTimeout { get; set; }
-
- /// <summary>
- /// Time to wait in milliseconds to reconnect to the pool when all nodes are down.
- /// </summary>
- public int DeadTimeout { get; set; }
-
- /// <summary>
- /// Raised when the pool's configuration changes.
- /// </summary>
- public event Action<ClusterConfig> ClusterConfigChanged;
-
- /// <summary>
- /// Starts listening for configuration data. This method blocks until the initial configuration is received. (Or until all pool urls fail.)
- /// </summary>
- public void Start()
- {
- var reset = this.mre = new ManualResetEvent(false);
-
- // subscribe to the config url
- this.listener = this.GetPooledListener();
-
- // this will be signaled by the config changed event handler
- reset.WaitOne();
-
- // set to null, then dispose, so RaiseConfigChanged will not
- // fail at Set when the config changes while we're cleaning up here
- this.mre = null;
- ((IDisposable)reset).Dispose();
- }
-
- public void Stop()
- {
- this.ReleaseListener(this.listener);
- this.listener = null;
- }
-
- private static readonly JavaScriptConverter[] KnownConverters = { ClusterNode.ConverterInstance };
-
- private void HandleMessage(string message)
- {
- // everything failed
- if (String.IsNullOrEmpty(message))
- {
- this.lastHash = null;
- this.RaiseConfigChanged(null);
- return;
- }
-
- // deserialize the buckets
- var jss = new JavaScriptSerializer();
- jss.RegisterConverters(KnownConverters);
-
- var config = jss.Deserialize<ClusterConfig>(message);
-
- // check if the config is the same as the previous
- // we cannot compare the messages because they have more information than we deserialize from them
- var configHash = config.GetHashCode();
-
- if (lastHash != configHash)
- {
- lastHash = configHash;
- this.RaiseConfigChanged(config);
- }
- else if (log.IsDebugEnabled)
- log.Debug("Last message was the same as current, ignoring.");
- }
-
- private void RaiseConfigChanged(ClusterConfig config)
- {
- var ccc = this.ClusterConfigChanged;
-
- // we got a new config, notify the pool to reload itself
- if (ccc != null)
- ccc(config);
-
- // trigger the event so Start stops blocking
- if (this.mre != null)
- this.mre.Set();
- }
-
- #region [ message listener pooling ]
- private static readonly object ListenerSync = new Object();
-
- // we pool and refcount the listeners here so we can safely dispose them when all clients are destroyed
- private static Dictionary<int, MessageStreamListener> listeners = new Dictionary<int, MessageStreamListener>();
- private static Dictionary<MessageStreamListener, ListenerInfo> listenerRefs = new Dictionary<MessageStreamListener, ListenerInfo>();
-
- private class ListenerInfo
- {
- public int RefCount;
- public int HashKey;
- }
-
- /// <summary>
- /// Unsubscibes from a pooled listener, and destrpys it if no additionals subscribers are present.
- /// </summary>
- /// <param name="listener"></param>
- private void ReleaseListener(MessageStreamListener listener)
- {
- lock (ListenerSync)
- {
- listener.Unsubscribe(this.HandleMessage);
-
- var info = listenerRefs[listener];
- if (info.RefCount == 1)
- {
- listenerRefs.Remove(listener);
- listeners.Remove(info.HashKey);
-
- try { using (listener) listener.Stop(); }
- catch { }
- }
- else
- {
- info.RefCount--;
- }
- }
- }
-
- /// <summary>
- /// Returns a MessageStreamListener instance based on this instance's configuratino (timeout, bucket name etc.)
- ///
- /// When multiple listeners are requested with the exact same parameters (usually when multiple clients are instantiated from the same configuration),
- /// the same listener will be returned each time.
- /// </summary>
- /// <returns></returns>
- private MessageStreamListener GetPooledListener()
- {
- // create a unique key based on the parameters
- // to find out if we already have a listener attached to this pool
- var hcc = new HashCodeCombiner();
-
- hcc.Add(this.Timeout);
- hcc.Add(this.DeadTimeout);
- hcc.Add(this.RetryCount);
- hcc.Add(this.RetryTimeout.GetHashCode());
- hcc.Add(this.bucketName.GetHashCode());
-
- if (credential != null)
- {
- hcc.Add((this.credential.UserName ?? String.Empty).GetHashCode());
- hcc.Add((this.credential.Password ?? String.Empty).GetHashCode());
- hcc.Add((this.credential.Domain ?? String.Empty).GetHashCode());
- }
-
- for (var i = 0; i < this.poolUrls.Length; i++)
- hcc.Add(this.poolUrls[i].GetHashCode());
-
- var hash = hcc.CurrentHash;
-
- MessageStreamListener retval;
-
- lock (ListenerSync)
- if (listeners.TryGetValue(hash, out retval))
- {
- listenerRefs[retval].RefCount++;
- retval.Subscribe(this.HandleMessage);
- }
- else
- {
- var name = this.bucketName;
-
- // create a new listener for the pool urls
- retval = new MessageStreamListener(poolUrls, (client, root) => ResolveBucketUri(client, root, name));
-
- retval.ConnectionTimeout = this.Timeout;
- retval.DeadTimeout = this.DeadTimeout;
- retval.Credentials = this.credential;
- retval.RetryCount = this.RetryCount;
- retval.RetryTimeout = this.RetryTimeout;
-
- retval.Subscribe(this.HandleMessage);
-
- listeners[hash] = retval;
- listenerRefs[retval] = new ListenerInfo { RefCount = 1, HashKey = hash };
-
- retval.Start();
- }
-
- return retval;
- }
-
- private static Uri ResolveBucketUri(WebClientWithTimeout client, Uri root, string bucketName)
- {
- try
- {
- var bucket = ConfigHelper.ResolveBucket(client, root, bucketName);
- if (bucket == null)
- return null;
-
- if (String.IsNullOrEmpty(bucket.streamingUri))
- {
- log.ErrorFormat("Url {0} for bucket {1} returned a config with no streamingUri", root, bucketName);
- return null;
- }
-
- return new Uri(root, bucket.streamingUri);
- }
- catch (Exception e)
- {
- log.Error("Error resolving streaming uri: " + root, e);
-
- return null;
- }
- }
-
- #endregion
- }
-}
-
-#region [ License information ]
-/* ************************************************************
- *
- * Copyright (c) 2010 Attila Kiskó, enyim.com
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ************************************************************/
-#endregion
Oops, something went wrong.

0 comments on commit b993e33

Please sign in to comment.