Created
March 11, 2022 16:02
-
-
Save ptupitsyn/e3e23845b0bc4de45403c7bcc7c704ae to your computer and use it in GitHub Desktop.
Ignite.NET Thin Client AtomicLong usage via Services
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Apache.Ignite" Version="2.12.0" /> | |
</ItemGroup> | |
</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
using Apache.Ignite.Core; | |
using Apache.Ignite.Core.Client; | |
using Apache.Ignite.Core.Resource; | |
using Apache.Ignite.Core.Services; | |
// Start server and deploy service. | |
var ignite = Ignition.Start(); | |
ignite.GetServices().DeployNodeSingleton("atomic-long", new IgniteAtomicLongService()); | |
// Start thin client and use AtomicLong | |
var thinClient = Ignition.StartClient(new IgniteClientConfiguration("127.0.0.1")); | |
var atomicLongService = thinClient.GetServices().GetServiceProxy<IAtomicLongService>("atomic-long"); | |
Console.WriteLine(atomicLongService.Increment("atomicLong1")); | |
Console.WriteLine(atomicLongService.Increment("atomicLong1")); | |
Console.WriteLine(atomicLongService.Increment("atomicLong1")); | |
Console.WriteLine(atomicLongService.Increment("atomicLong2")); | |
Console.WriteLine(atomicLongService.Increment("atomicLong2")); | |
public interface IAtomicLongService | |
{ | |
long Increment(string name); | |
} | |
public class IgniteAtomicLongService : IService, IAtomicLongService | |
{ | |
[InstanceResource] public IIgnite Ignite { get; set; } = null!; | |
public void Init(IServiceContext context) | |
{ | |
} | |
public void Execute(IServiceContext context) | |
{ | |
} | |
public void Cancel(IServiceContext context) | |
{ | |
} | |
public long Increment(string name) => Ignite.GetAtomicLong(name, 0, true).Increment(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment