Skip to content

Conversation

Danthar
Copy link
Member

@Danthar Danthar commented Sep 29, 2017

Serializer id is now only determined once, upon initialisation. And its
the serializer implementation which dictates where that id comes from.
We no longer assume it always comes from the hocon config.

{
_serializers.Add(serializer.Identifier, serializer);
_serializerIdByName.Add(name, serializer.Identifier);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so technically, the Identifier is retrieved twice. But since Hocon caching is a thing. I found this to be more expressive then first storing the id in a temp var and using that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd take a look at my previous comment and consider just maintaining two <TKey, Serializer> dictionaries - the ID-based one and the name based one, rather than go name --> id --> serializer you can just go name --> serializer. Does that make sense?

@Aaronontheweb Aaronontheweb self-requested a review October 3, 2017 12:58
@Aaronontheweb
Copy link
Member

Going to do a review of this today

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is good but needs a bit of API love.

@@ -91,7 +92,8 @@ public Serialization(ExtendedActorSystem system)
var serializer = serializerConfig != null
? (Serializer)Activator.CreateInstance(serializerType, system, serializerConfig)
: (Serializer)Activator.CreateInstance(serializerType, system);
AddSerializer(serializer);

AddSerializer(kvp.Key, serializer);
namedSerializers.Add(kvp.Key, serializer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Danthar so aren't we doing the same thing with _serializerIdByName and the namedSerializers local here? Why not just use that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we already have a dictionary mapping id => serializer instance. I could have promoted the namedSerializers collection to a private member var. But that would mean we would store a reference to the same instance twice.

Not sure what my rationale was when i was writing this, but i wanted to avoid that. Hence the separate map _serializerIdByName

@@ -129,10 +131,9 @@ private Serializer GetSerializerByName(string name)
{
if (kvp.Key.Equals(name))
{
var serializerTypeName = kvp.Value.GetString();
var serializerType = Type.GetType(serializerTypeName);
if (!_serializerIdByName.TryGetValue(name, out int serializerId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove the serializersConfig line here - no need to read in HOCON if we're just using a cached map.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah your right. The extra check on line 132 serves no purpose.

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddSerializer(Serializer serializer)
public void AddSerializer(string name, Serializer serializer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking API change since we're modifying a public method. IMHO, add a new overload and mark the old one as deprecated. That way we won't have binary compatibility issues on upgrade.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. However seeing as its being aggressively inlined. Im wondering why it was public in the first place. But ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Danthar

Im wondering why it was public in the first place.

I'm right there with you.

{
_serializers.Add(serializer.Identifier, serializer);
_serializerIdByName.Add(name, serializer.Identifier);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd take a look at my previous comment and consider just maintaining two <TKey, Serializer> dictionaries - the ID-based one and the name based one, rather than go name --> id --> serializer you can just go name --> serializer. Does that make sense?

var serializerTypeName = kvp.Value.GetString();
var serializerType = Type.GetType(serializerTypeName);
if (!_serializersByName.TryGetValue(name, out Serializer serializer))
throw new ArgumentException($"Couldn't find serializer for [{name}] make sure you correctly defined.");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this check. Because it still possible to misconfigure for example serializer setting in persistence. Which is not checked during initialization.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

/// <param name="serializer">TBD</param>
/// <returns>TBD</returns>
/// <param name="serializer">Serializer instance</param>
[Obsolete("No longer supported. Use the AddSerializer(name, serializer) overload instead.", true)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left out a "deadline" version here. Or would you rather have i put in something like. will be removed in 1.4 or something ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine as-is.

@Aaronontheweb
Copy link
Member

@Danthar looks like a NRE in your new spec

@Danthar
Copy link
Member Author

Danthar commented Oct 4, 2017

:D its interesting that the linux-netcore/unit-tests does complete.

However another spec failed as well. Ill be fixing both.

@alexvaluyskiy
Copy link
Contributor

@Danthar because it does not work #3123

Danthar and others added 7 commits October 4, 2017 20:09
Serializer id is now only determined once, upon initialisation. And its
the serializer implementation which dictates where that id comes from.
We no longer assume it always comes from the hocon config.
@Aaronontheweb Aaronontheweb merged commit 89a1d6b into akkadotnet:dev Oct 10, 2017
Aaronontheweb added a commit to Aaronontheweb/akka.net that referenced this pull request Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants