Skip to content

Commit

Permalink
Update to Orleans 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhen committed Feb 21, 2017
1 parent cf2e062 commit df0859f
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 46 deletions.
10 changes: 7 additions & 3 deletions Source/Example.Serialization.Hyperion/HyperionSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public bool IsSupportedType(Type itemType)
return BaseInterfaceType.IsAssignableFrom(itemType);
}

public object DeepCopy(object source)
public object DeepCopy(object source, ICopyContext context)
{
if (source == null)
return null;
Expand All @@ -64,8 +64,10 @@ public object DeepCopy(object source)
}
}

public void Serialize(object item, BinaryTokenStreamWriter writer, Type expectedType)
public void Serialize(object item, ISerializationContext context, Type expectedType)
{
var writer = context.StreamWriter;

if (item == null)
{
writer.WriteNull();
Expand All @@ -81,8 +83,10 @@ public void Serialize(object item, BinaryTokenStreamWriter writer, Type expected
}
}

public object Deserialize(Type expectedType, BinaryTokenStreamReader reader)
public object Deserialize(Type expectedType, IDeserializationContext context)
{
var reader = context.StreamReader;

var length = reader.ReadInt();
var inBytes = reader.ReadBytes(length);

Expand Down
10 changes: 7 additions & 3 deletions Source/Example.Serialization.ProtoBuf/ProtobufSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public bool IsSupportedType(Type itemType)
return true;
}

public object DeepCopy(object source)
public object DeepCopy(object source, ICopyContext context)
{
if (source == null)
return null;
Expand All @@ -43,8 +43,10 @@ public object DeepCopy(object source)
return dynamicSource.Clone();
}

public void Serialize(object item, BinaryTokenStreamWriter writer, Type expectedType)
public void Serialize(object item, ISerializationContext context, Type expectedType)
{
var writer = context.StreamWriter;

if (item == null)
{
// Special handling for null value.
Expand All @@ -63,14 +65,16 @@ public void Serialize(object item, BinaryTokenStreamWriter writer, Type expected
writer.Write(outBytes);
}

public object Deserialize(Type expectedType, BinaryTokenStreamReader reader)
public object Deserialize(Type expectedType, IDeserializationContext context)
{
var typeHandle = expectedType.TypeHandle;

MessageParser parser;
if (!Parsers.TryGetValue(typeHandle, out parser))
throw new ArgumentException("No parser found for the expected type " + expectedType, nameof(expectedType));

var reader = context.StreamReader;

var length = reader.ReadInt();
var data = reader.ReadBytes(length);

Expand Down
10 changes: 8 additions & 2 deletions Source/Orleankka.Runtime/Cluster/ClusterConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void Configure()
RegisterTypes();
RegisterAutoruns();
RegisterStreamProviders();
RegisterStorageProviders();
RegisterStreamSubscriptions();
RegisterBootstrappers();
RegisterBehaviors();
Expand Down Expand Up @@ -187,6 +188,11 @@ void RegisterAutoruns()
Bootstrapper<AutorunBootstrapper>(autoruns);
}

void RegisterStorageProviders()
{
Configuration.Globals.RegisterStorageProvider<GrainFactoryProvider>("#ORLKKA_GFP");
}

void RegisterStreamProviders()
{
foreach (var each in streamProviders)
Expand Down Expand Up @@ -214,8 +220,8 @@ void RegisterStreamSubscriptions()

var properties = new Dictionary<string, string>();
properties["providers"] = string.Join(";", streamProviders
.Where(x => x.IsPersistentStreamProvider())
.Select(x => x.Name));
.Where(x => x.IsPersistentStreamProvider())
.Select(x => x.Name));

Configuration.Globals.RegisterStorageProvider<StreamSubscriptionBootstrapper>(id, properties);
}
Expand Down
35 changes: 35 additions & 0 deletions Source/Orleankka.Runtime/Cluster/GrainFactoryProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Threading.Tasks;

using Orleans;
using Orleans.Providers;
using Orleans.Runtime;
using Orleans.Storage;

namespace Orleankka.Cluster
{
using Core;

class GrainFactoryProvider : IStorageProvider
{
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
{
var factory = providerRuntime.GrainFactory;
ActorInterface.Bind(factory);
return TaskDone.Done;
}

#region Garbage

public Task Close() => TaskDone.Done;

public string Name { get; }
public Logger Log { get; }

public Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState) => TaskDone.Done;
public Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState) => TaskDone.Done;
public Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState) => TaskDone.Done;


#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfigu
var system = ClusterActorSystem.Current;
var providers = config.Properties["providers"].Split(';');

StreamPubSubWrapper.Hook(providers, stream =>
StreamPubSubWrapper.Hook(providerRuntime.ServiceProvider, providers, stream =>
StreamSubscriptionMatcher
.Match(system, stream)
.Select(x => new StreamPubSubMatch(x.Receive))
Expand Down
1 change: 1 addition & 0 deletions Source/Orleankka.Runtime/Orleankka.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Behaviors\RequestOrigin.cs" />
<Compile Include="Behaviors\Transition.cs" />
<Content Include="Core\ActorEndpoint.Common.T.cs" />
<Compile Include="Cluster\GrainFactoryProvider.cs" />
<Compile Include="Core\ActorEndpoint.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
4 changes: 4 additions & 0 deletions Source/Orleankka/Client/ClientActorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Orleankka.Client
{
using Core;

public sealed class ClientActorSystem : ActorSystem
{
static ClientActorSystem current;
Expand Down Expand Up @@ -63,6 +65,8 @@ public void Connect(int retries = 0, TimeSpan? retryTimeout = null)
}
}
}

ActorInterface.Bind(GrainClient.GrainFactory);
}
}
}
3 changes: 2 additions & 1 deletion Source/Orleankka/Client/ClientConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;

using Orleans;
using Orleans.Streams;
using Orleans.Runtime.Configuration;

Expand Down Expand Up @@ -113,7 +114,7 @@ void RegisterStreamProviders()

void RegisterActorInterfaces()
{
ActorInterface.Register(assemblies, interfaces);
ActorInterface.Register(assemblies, interfaces);
}
}

Expand Down
16 changes: 8 additions & 8 deletions Source/Orleankka/Core/ActorInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ static void Register(ActorInterface @interface)

readonly string name;
readonly Type grain;
readonly Func<string, object> factory;
Func<string, object> factory;

internal ActorInterface(ActorInterfaceMapping mapping, Type grain)
{
name = mapping.Name;
Array.ForEach(mapping.Types, ActorTypeName.Register);

this.grain = grain;
factory = Bind(grain);
}

public Assembly GrainAssembly() => grain.Assembly;

static Func<string, object> Bind(Type type)
internal static void Bind(IGrainFactory factory)
{
var method = typeof(GrainFactory).GetMethod("GetGrain", new[] { typeof(string), typeof(string) });
var invoker = method.MakeGenericMethod(type);
var instance = Activator.CreateInstance(typeof(GrainFactory), nonPublic: true);
return x => invoker.Invoke(instance, new object[] { x, null });
foreach (var @interface in interfaces.Values)
{
var method = factory.GetType().GetMethod("GetGrain", new[] { typeof(string), typeof(string) });
var invoker = method.MakeGenericMethod(@interface.grain);
@interface.factory = x => invoker.Invoke(factory, new object[] { x, null });
}
}

internal static IEnumerable<ActorInterface> Registered() => interfaces.Values.ToArray();
Expand Down
4 changes: 2 additions & 2 deletions Source/Orleans.Internals/StreamPubSubWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace Orleans.Internals
/// </summary>
public class StreamPubSubWrapper : IStreamPubSub
{
public static void Hook(string[] providers, Func<StreamIdentity, StreamPubSubMatch[]> matcher)
public static void Hook(IServiceProvider provider, string[] providers, Func<StreamIdentity, StreamPubSubMatch[]> matcher)
{
var runtimeType = typeof(SiloHost).Assembly.GetType("Orleans.Runtime.Providers.SiloProviderRuntime");
var runtime = runtimeType.GetProperty("Instance").GetValue(null);
var runtime = provider.GetService(runtimeType);

var grainBasedPubSubField = runtimeType
.GetField("grainBasedPubSub",
Expand Down
12 changes: 6 additions & 6 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ lowest_matching: false

source https://api.nuget.org/v3/index.json

nuget Hyperion
nuget Nake
nuget NuGet.CommandLine

Expand Down Expand Up @@ -50,11 +49,11 @@ nuget Microsoft.CodeAnalysis.CSharp 1.3.2
nuget System.Collections.Immutable 1.1.37
nuget System.Reflection.Metadata 1.2.0

nuget Microsoft.Orleans.Core 1.3.1
nuget Microsoft.Orleans.OrleansAzureUtils 1.3.1
nuget Microsoft.Orleans.OrleansCodeGenerator 1.3.1
nuget Microsoft.Orleans.OrleansProviders 1.3.1
nuget Microsoft.Orleans.OrleansRuntime 1.3.1
nuget Microsoft.Orleans.Core 1.4.0
nuget Microsoft.Orleans.OrleansAzureUtils 1.4.0
nuget Microsoft.Orleans.OrleansCodeGenerator 1.4.0
nuget Microsoft.Orleans.OrleansProviders 1.4.0
nuget Microsoft.Orleans.OrleansRuntime 1.4.0
nuget Microsoft.Extensions.DependencyInjection 1.0.0
nuget Microsoft.Extensions.DependencyInjection.Abstractions 1.0.0

Expand All @@ -66,4 +65,5 @@ nuget Microsoft.Data.OData 5.6.4
nuget Microsoft.Data.Services.Client 5.6.4
nuget System.Spatial 5.6.4

nuget Hyperion
nuget Google.Protobuf
40 changes: 20 additions & 20 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,24 @@ NUGET
Microsoft.jQuery.Unobtrusive.Validation (3.2)
jQuery (>= 1.8)
jQuery.Validation (>= 1.8)
Microsoft.Orleans.Core (1.3.1)
Microsoft.Orleans.Core (1.4)
Newtonsoft.Json (>= 7.0.1)
System.Collections.Immutable (>= 1.1.37)
Microsoft.Orleans.OrleansAzureUtils (1.3.1)
Microsoft.Orleans.Core (>= 1.3.1)
Microsoft.Orleans.OrleansProviders (>= 1.3.1)
Microsoft.Orleans.OrleansRuntime (>= 1.3.1)
System.Reflection.Metadata (>= 1.2)
Microsoft.Orleans.OrleansAzureUtils (1.4)
Microsoft.Orleans.Core (>= 1.4)
Microsoft.Orleans.OrleansProviders (>= 1.4)
Microsoft.Orleans.OrleansRuntime (>= 1.4)
WindowsAzure.Storage (>= 7.0)
Microsoft.Orleans.OrleansCodeGenerator (1.3.1)
Microsoft.Orleans.OrleansCodeGenerator (1.4)
Microsoft.CodeAnalysis.CSharp (>= 1.3.2)
Microsoft.Orleans.Core (>= 1.3.1)
Microsoft.Orleans.OrleansProviders (1.3.1)
Microsoft.Orleans.Core (>= 1.3.1)
Microsoft.Orleans.OrleansRuntime (1.3.1)
Microsoft.Orleans.Core (>= 1.4)
Microsoft.Orleans.OrleansProviders (1.4)
Microsoft.Orleans.Core (>= 1.4)
Microsoft.Orleans.OrleansRuntime (1.4)
Microsoft.Extensions.DependencyInjection (>= 1.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.0)
Microsoft.Orleans.Core (>= 1.3.1)
Microsoft.Orleans.Core (>= 1.4)
Microsoft.Owin (2.0.1)
Owin (>= 1.0)
Microsoft.Owin.Host.SystemWeb (2.0)
Expand All @@ -92,20 +93,28 @@ NUGET
Microsoft.Web.Infrastructure (1.0)
Microsoft.WindowsAzure.ConfigurationManager (2.0.3)
Modernizr (2.6.2)
Nake (2.4)
Newtonsoft.Json (7.0.1)
NuGet.CommandLine (3.5)
NUnit (2.6.4)
NUnit.Runners (2.6.4)
Owin (1.0)
PowerAssert (1.0.41)
Respond (1.2)
Streamstone (0.9.5)
WindowsAzure.Storage (>= 6.1)
Suave (0.31)
FSharp.Core (>= 4.0.0.1)
FsPickler (>= 1.2.5)
System.Collections (4.3)
System.Collections.Concurrent (4.3)
System.Collections.Immutable (1.1.37)
System.Reflection.Metadata (1.2)
System.Collections.Immutable (>= 1.1.37)
System.Runtime.Extensions (4.3)
System.Spatial (5.6.4)
System.Threading (4.3)
System.Threading.Tasks (4.3)
WebGrease (1.5.2)
Antlr (>= 3.4.1.9004)
Newtonsoft.Json (>= 5.0.4)
Expand All @@ -114,12 +123,3 @@ NUGET
Microsoft.Data.OData (>= 5.6.4)
Microsoft.Data.Services.Client (>= 5.6.4)
Newtonsoft.Json (>= 6.0.8)
remote: http://api.nuget.org/v3/index.json
Nake (2.4)
NuGet.CommandLine (3.4.3)
PowerAssert (1.0.41)
System.Collections (4.3)
System.Collections.Concurrent (4.3)
System.Runtime.Extensions (4.3)
System.Threading (4.3)
System.Threading.Tasks (4.3)

0 comments on commit df0859f

Please sign in to comment.