Skip to content

Commit

Permalink
Add interfaed actor-ref for DistributedActorTable.
Browse files Browse the repository at this point in the history
  • Loading branch information
veblush committed Jul 4, 2016
1 parent bc47a05 commit 3642723
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/Akka.Cluster.Utility/Akka.Cluster.Utility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="DistributedActorTable.cs" />
<Compile Include="DistributedActorTableMessage.cs" />
<Compile Include="DistributedActorTableContainer.cs" />
<Compile Include="DistributedActorTableRef.cs" />
<Compile Include="IActorFactory.cs" />
<Compile Include="IIdGenerator.cs" />
<Compile Include="IncrementalIntegerIdGenerator.cs" />
Expand Down
90 changes: 90 additions & 0 deletions core/Akka.Cluster.Utility/DistributedActorTableRef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;

namespace Akka.Cluster.Utility
{
// Intefaced actor-ref for DistributedActorTable<TKey>
public sealed class DistributedActorTableRef<TKey>
{
public IActorRef Target { get; private set; }
public TimeSpan? Timeout { get; private set; }

public DistributedActorTableRef(IActorRef target, TimeSpan? timeout = null)
{
Target = target;
Timeout = timeout;
}

public DistributedActorTableRef<TKey> WithTimeout(TimeSpan? timeout)
{
return new DistributedActorTableRef<TKey>(Target, timeout);
}

public Task<DistributedActorTableMessage<TKey>.CreateReply> Create(object[] args)
{
return Target.Ask<DistributedActorTableMessage<TKey>.CreateReply>(
new DistributedActorTableMessage<TKey>.Create(args), Timeout);
}

public Task<DistributedActorTableMessage<TKey>.CreateReply> Create(TKey id, object[] args)
{
return Target.Ask<DistributedActorTableMessage<TKey>.CreateReply>(
new DistributedActorTableMessage<TKey>.Create(id, args), Timeout);
}

public Task<DistributedActorTableMessage<TKey>.GetOrCreateReply> GetOrCreate(TKey id, object[] args)
{
return Target.Ask<DistributedActorTableMessage<TKey>.GetOrCreateReply>(
new DistributedActorTableMessage<TKey>.GetOrCreate(id, args), Timeout);
}

public Task<DistributedActorTableMessage<TKey>.GetReply> Get(TKey id)
{
return Target.Ask<DistributedActorTableMessage<TKey>.GetReply>(
new DistributedActorTableMessage<TKey>.Get(id), Timeout);
}

public Task<DistributedActorTableMessage<TKey>.GetIdsReply> GetIds()
{
return Target.Ask<DistributedActorTableMessage<TKey>.GetIdsReply>(
new DistributedActorTableMessage<TKey>.GetIds(), Timeout);
}

public void GracefulStop(object stopMessage)
{
Target.Tell(new DistributedActorTableMessage<TKey>.GracefulStop(stopMessage));
}
}

// Intefaced actor-ref for DistributedActorTableContainer<TKey>
public class DistributedActorTableContainerRef<TKey>
{
public IActorRef Target { get; private set; }
public TimeSpan? Timeout { get; private set; }

public DistributedActorTableContainerRef(IActorRef target, TimeSpan? timeout = null)
{
Target = target;
Timeout = timeout;
}

public DistributedActorTableContainerRef<TKey> WithTimeout(TimeSpan? timeout)
{
return new DistributedActorTableContainerRef<TKey>(Target, timeout);
}

public Task<DistributedActorTableMessage<TKey>.AddReply> Add(TKey id, IActorRef actor)
{
return Target.Ask<DistributedActorTableMessage<TKey>.AddReply>(
new DistributedActorTableMessage<TKey>.Add(id, actor), Timeout);
}

public void Remove(TKey id)
{
Target.Tell(new DistributedActorTableMessage<TKey>.Remove(id));
}
}
}

0 comments on commit 3642723

Please sign in to comment.