forked from ihaoqihao/Zookeeper.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,287 additions
and
1,153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Test2 | ||
{ | ||
public class Class1 | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{84915CA4-6481-4980-9D77-609C564B4805}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Test2</RootNamespace> | ||
<AssemblyName>Test2</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject /> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="log4net"> | ||
<HintPath>..\packages\log4net.1.2.10\lib\2.0\log4net.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="ZooKeeperNet"> | ||
<HintPath>..\packages\ZooKeeperDotNet.3.3.4.8\lib\net40\ZooKeeperNet.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Class1.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="log4net" version="1.2.10" targetFramework="net40" /> | ||
<package id="ZooKeeper.Net" version="3.4.6.2" targetFramework="net40" /> | ||
<package id="ZooKeeperDotNet" version="3.3.4.8" targetFramework="net40" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zookeeper", "Zookeeper\Zookeeper.csproj", "{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{1161071A-C58B-44BD-BB1A-70A787C6F55A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|Mixed Platforms = Debug|Mixed Platforms | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|Mixed Platforms = Release|Mixed Platforms | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|Mixed Platforms.Build.0 = Release|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|x86.ActiveCfg = Release|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|Mixed Platforms.Build.0 = Debug|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|x86.ActiveCfg = Debug|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|x86.Build.0 = Debug|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|Mixed Platforms.ActiveCfg = Release|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|Mixed Platforms.Build.0 = Release|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|x86.ActiveCfg = Release|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Express 2013 for Web | ||
VisualStudioVersion = 12.0.21005.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zookeeper", "Zookeeper\Zookeeper.csproj", "{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{1161071A-C58B-44BD-BB1A-70A787C6F55A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|Mixed Platforms = Debug|Mixed Platforms | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|Mixed Platforms = Release|Mixed Platforms | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|Mixed Platforms.Build.0 = Release|Any CPU | ||
{517E7868-C7D0-4F50-BCE8-90D1D343EFAD}.Release|x86.ActiveCfg = Release|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|Mixed Platforms.Build.0 = Debug|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|x86.ActiveCfg = Debug|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Debug|x86.Build.0 = Debug|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|Mixed Platforms.ActiveCfg = Release|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|Mixed Platforms.Build.0 = Release|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|x86.ActiveCfg = Release|x86 | ||
{1161071A-C58B-44BD-BB1A-70A787C6F55A}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,84 @@ | ||
using System; | ||
using Sodao.FastSocket.SocketBase.Utils; | ||
|
||
namespace Sodao.Zookeeper | ||
{ | ||
/// <summary> | ||
/// zk node children watcher | ||
/// </summary> | ||
public sealed class ChildrenWatcher | ||
{ | ||
#region Private Members | ||
private readonly IZookClient _zk = null; | ||
private readonly string _path; | ||
private readonly Action<string[]> _callback; | ||
private readonly WatcherWrapper _wrapper = null; | ||
|
||
private volatile bool _isStop = false; | ||
#endregion | ||
|
||
#region Constructors | ||
/// <summary> | ||
/// new | ||
/// </summary> | ||
/// <param name="zk"></param> | ||
/// <param name="path"></param> | ||
/// <param name="callback"></param> | ||
/// <exception cref="ArgumentNullException">zk is null.</exception> | ||
/// <exception cref="ArgumentNullException">callback is null.</exception> | ||
public ChildrenWatcher(IZookClient zk, string path, Action<string[]> callback) | ||
{ | ||
if (zk == null) throw new ArgumentNullException("zk"); | ||
if (callback == null) throw new ArgumentNullException("callback"); | ||
|
||
this._zk = zk; | ||
this._path = path; | ||
this._callback = callback; | ||
|
||
this._wrapper = new WatcherWrapper(_ => { if (!this._isStop) this.ListChildren(); }); | ||
this._zk.KeeperStateChanged += this.KeeperStateChanged; | ||
|
||
this.ListChildren(); | ||
} | ||
#endregion | ||
|
||
#region Private Methods | ||
/// <summary> | ||
/// KeeperStateChanged | ||
/// </summary> | ||
/// <param name="currentState"></param> | ||
private void KeeperStateChanged(Data.KeeperState currentState) | ||
{ | ||
if (!this._isStop && currentState == Data.KeeperState.SyncConnected) this.ListChildren(); | ||
} | ||
/// <summary> | ||
/// list children | ||
/// </summary> | ||
private void ListChildren() | ||
{ | ||
this._zk.GetChildren(this._path, this._wrapper).ContinueWith(c => | ||
{ | ||
if (c.IsFaulted) { TaskEx.Delay(new Random().Next(500, 1500), this.ListChildren); return; } | ||
this._callback(c.Result); | ||
}); | ||
} | ||
#endregion | ||
|
||
#region Public Methods | ||
/// <summary> | ||
/// stop | ||
/// </summary> | ||
public void Stop() | ||
{ | ||
if (this._isStop) return; | ||
this._isStop = true; | ||
this._zk.KeeperStateChanged -= this.KeeperStateChanged; | ||
} | ||
#endregion | ||
} | ||
using System; | ||
using Sodao.FastSocket.SocketBase.Utils; | ||
|
||
namespace Sodao.Zookeeper | ||
{ | ||
/// <summary> | ||
/// zk node children watcher | ||
/// </summary> | ||
public sealed class ChildrenWatcher | ||
{ | ||
#region Private Members | ||
private readonly IZookClient _zk = null; | ||
private readonly string _path; | ||
private readonly Action<string[]> _callback; | ||
private readonly WatcherWrapper _wrapper = null; | ||
|
||
private volatile bool _isStop = false; | ||
#endregion | ||
|
||
#region Constructors | ||
/// <summary> | ||
/// new | ||
/// </summary> | ||
/// <param name="zk"></param> | ||
/// <param name="path"></param> | ||
/// <param name="callback"></param> | ||
/// <exception cref="ArgumentNullException">zk is null.</exception> | ||
/// <exception cref="ArgumentNullException">callback is null.</exception> | ||
public ChildrenWatcher(IZookClient zk, string path, Action<string[]> callback) | ||
{ | ||
if (zk == null) throw new ArgumentNullException("zk"); | ||
if (callback == null) throw new ArgumentNullException("callback"); | ||
|
||
this._zk = zk; | ||
this._path = path; | ||
this._callback = callback; | ||
|
||
this._wrapper = new WatcherWrapper(_ => { if (!this._isStop) this.ListChildren(); }); | ||
this._zk.KeeperStateChanged += this.KeeperStateChanged; | ||
|
||
this.ListChildren(); | ||
} | ||
#endregion | ||
|
||
#region Private Methods | ||
/// <summary> | ||
/// KeeperStateChanged | ||
/// </summary> | ||
/// <param name="currentState"></param> | ||
private void KeeperStateChanged(Data.KeeperState currentState) | ||
{ | ||
if (!this._isStop && currentState == Data.KeeperState.SyncConnected) this.ListChildren(); | ||
} | ||
/// <summary> | ||
/// list children | ||
/// </summary> | ||
private void ListChildren() | ||
{ | ||
this._zk.GetChildren(this._path, this._wrapper).ContinueWith(c => | ||
{ | ||
if (c.IsFaulted) | ||
{ | ||
TaskEx.Delay(new Random().Next(500, 1500)).ContinueWith(_ => | ||
this.ListChildren()); | ||
return; | ||
} | ||
this._callback(c.Result); | ||
}); | ||
} | ||
#endregion | ||
|
||
#region Public Methods | ||
/// <summary> | ||
/// stop | ||
/// </summary> | ||
public void Stop() | ||
{ | ||
if (this._isStop) return; | ||
this._isStop = true; | ||
this._zk.KeeperStateChanged -= this.KeeperStateChanged; | ||
} | ||
#endregion | ||
} | ||
} |
Oops, something went wrong.