You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which are all built-in to every sublass of `SocketOwner.SingletonById`. You can add more methods too for your usecase.
117
+
Which are all public methods of `SocketOwner.SingletonById`. You can add more methods too for your usecase.
118
118
119
119
### (Id vs Descriptor) and (Singleton vs Ephemeral)
120
120
@@ -124,21 +124,32 @@ The `Socket` is responsible for:
124
124
- maintaining the runtime registry of available plugins
125
125
- instantiating the actual objects from their metadata
126
126
127
-
When it comes to the registry of available plugins, there are two obvious design points
127
+
When it comes to the registry of available plugins, there are two obvious design points:
128
128
129
129
- declare some String which functions as a unique id => `Id`
130
-
- parse the `Map<String, String>` into a descriptor class, and run filters against the set of parsed descriptors to get all the plugins which apply to the given situation => `Descriptor`.
130
+
- parse the `Map<String, String>` into a descriptor class, and run filters against the set of parsed descriptors to get all the plugins which apply to a given situation => `Descriptor`.
131
131
132
132
When it comes to instantiating the actual objects from their metadata, there are again two obvious designs:
133
133
134
134
- Once a plugin is instantiated, cache it forever and return the same instance each time => `Singleton`
135
-
- Call the plugin constructor each time it is instantiated, so that you may end up with multiple instances of a single plugin => `Ephemeral`
135
+
- Call the plugin constructor each time it is instantiated, so that you may end up with multiple instances of a single plugin, and unused instances can be garbage collected => `Ephemeral`
136
136
137
137
In most cases, if a plugin has a unique id, then it also makes sense to treat that plugin as a global singleton => `SocketOwner.SingletonById`. Likewise, if plugins do not have unique ids, then their concept of identity probably doesn't matter so there's no need to cache them as singletons => `SocketOwner.EphemeralByDescriptor`.
138
138
139
-
Those two classes, `SingletonById` and `EphemeralByDescriptor`, are the only two options we provide out of the box - we did not fill the full 2x2 matrix. For every case we have encountered, we can easily extend one or the other and get exactly what we need.
139
+
Those two classes, `SingletonById` and `EphemeralByDescriptor`, are the only two options we provide out of the box - we did not fill the full 2x2 matrix (no `SingletonByDescriptor` or `EphemeralById`) because we have not found a need anywhere in our codebase for the other cases. You are free to implement `SocketOwner` yourself from scratch if you want a different design point.
140
140
141
-
But you are free to implement `SocketOwner` yourself from scratch if you want a different design point.
141
+
The public methods of `SingletonById` are just above this section. `EphemeralByDescriptor` doesn't have any public methods, only protected methods which you can use to build an API appropriate to your case.
0 commit comments