Class GsonSerializerFactory

java.lang.Object
net.sodacan.core.serialize.gson.GsonSerializerFactory
All Implemented Interfaces:
SerializerFactory, PoolItemFactory<com.google.gson.Gson>

public class GsonSerializerFactory extends Object implements SerializerFactory, PoolItemFactory<com.google.gson.Gson>
Factory that creates individual Serializers. Each actor will ask for a serializer. The factory is free to hand out individual Serializers or a single shared serializer. In any case, the factory will be getting requests from multiple threads and so should be sure to avoid concurrency issues.

Our constructor is created during Config. At this time, before we are accessed by Actors, we create a thread-safe pool of Gson instances.

  • Field Details

    • messageClass

      protected Class<? extends Message> messageClass
    • builder

      protected com.google.gson.GsonBuilder builder
    • pool

      protected Pool<com.google.gson.Gson> pool
  • Constructor Details

    • GsonSerializerFactory

      public GsonSerializerFactory(Config config)
  • Method Details

    • getBuilderFor

      public com.google.gson.GsonBuilder getBuilderFor(ActorId actorId)
    • createItem

      public com.google.gson.Gson createItem()
      Specified by:
      createItem in interface PoolItemFactory<com.google.gson.Gson>
    • create

      public Serializer create(ActorId actorId)
      Create a serializer for the specified actorId. This method is called from an individual Actor's thread. We don't modify any shared variables here but if we did, then syncing is needed.
      Specified by:
      create in interface SerializerFactory
    • getConfig

      public Config getConfig()
    • getMessageClass

      public Class<? extends Message> getMessageClass()