Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 1e657da

Browse files
authored
Remove the MultiThreadedSpatialOSConnectionHandler (#1367)
* Remove the MultiThreadedSpatialOSConnectionHandler Remove CommandMetaDataManager and CommandMetaDataAggregate * Changelog and upgrade guide * put back parameter name * Re-factor CommandMetaData to remove request context directly Stop naming things `s` * Squash nested Dictionaries into single instance
1 parent 54bbedb commit 1e657da

26 files changed

+67
-791
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- `WorkerConnector.HandleWorkerConnectionFailure` has been removed and `WorkerConnector.Connect` now throws exceptions for connection errors instead. [#1365](https://github.com/spatialos/gdk-for-unity/pull/1365)
88
- `WorkerConnector` no longer destroys itself in `Dispose`. [#1365](https://github.com/spatialos/gdk-for-unity/pull/1365)
9+
- `MultiThreadedSpatialOSConnectionHandler` and `SpatialOSConnectionHandlerBuilder.SetThreadingMode` have been removed. [#1367](https://github.com/spatialos/gdk-for-unity/pull/1367)
910

1011
### Added
1112

UPGRADE_GUIDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## From `0.3.5` to `0.3.6`
44

5+
### Multithreaded connection removed
6+
7+
The `MultiThreadedSpatialOSConnectionHandler` has been removed and the method `SpatialOSConnectionHandlerBuilder.SetThreadingMode` has been removed to reflect this change.
8+
59
### WorkerConnector changes
610

711
There are two related changes that you will need to adjust for.

test-project/Assets/Generated/Source/improbable/dependentschema/DependentDataComponentCommandDiffDeserializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void AddRequestToDiff(CommandRequestOp op, ViewDiff diff)
2525
diff.AddCommandRequest(request, ComponentId, 1);
2626
}
2727

28-
public void AddResponseToDiff(CommandResponseOp op, ViewDiff diff, CommandMetaDataAggregate commandMetaData)
28+
public void AddResponseToDiff(CommandResponseOp op, ViewDiff diff, CommandMetaData commandMetaData)
2929
{
3030
global::Improbable.TestSchema.SomeType? rawResponse = null;
3131
if (op.StatusCode == StatusCode.Success)
@@ -34,7 +34,7 @@ public void AddResponseToDiff(CommandResponseOp op, ViewDiff diff, CommandMetaDa
3434
}
3535

3636
var commandContext = commandMetaData.GetContext<global::Improbable.TestSchema.SomeType>(ComponentId, 1, op.RequestId);
37-
commandMetaData.MarkIdForRemoval(ComponentId, 1, op.RequestId);
37+
commandMetaData.RemoveRequest(ComponentId, 1, op.RequestId);
3838

3939
var response = new BarCommand.ReceivedResponse(
4040
commandContext.SendingEntity,

workers/unity/Packages/io.improbable.gdk.core/.codegen/Source/Generators/Core/CommandDiffDeserializerGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void AddRequestToDiff(CommandRequestOp op, ViewDiff diff)
5252
diff.AddCommandRequest(request, ComponentId, {command.CommandIndex});
5353
}}
5454
55-
public void AddResponseToDiff(CommandResponseOp op, ViewDiff diff, CommandMetaDataAggregate commandMetaData)
55+
public void AddResponseToDiff(CommandResponseOp op, ViewDiff diff, CommandMetaData commandMetaData)
5656
{{
5757
{command.FqnResponseType}? rawResponse = null;
5858
if (op.StatusCode == StatusCode.Success)
@@ -61,7 +61,7 @@ public void AddResponseToDiff(CommandResponseOp op, ViewDiff diff, CommandMetaDa
6161
}}
6262
6363
var commandContext = commandMetaData.GetContext<{command.FqnRequestType}>(ComponentId, {command.CommandIndex}, op.RequestId);
64-
commandMetaData.MarkIdForRemoval(ComponentId, {command.CommandIndex}, op.RequestId);
64+
commandMetaData.RemoveRequest(ComponentId, {command.CommandIndex}, op.RequestId);
6565
6666
var response = new {command.PascalCaseName}.ReceivedResponse(
6767
commandContext.SendingEntity,

workers/unity/Packages/io.improbable.gdk.core/Worker/CommandMetaData.cs

Lines changed: 16 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ public class CommandMetaData
2828

2929
private readonly HashSet<long> internalRequestIds = new HashSet<long>();
3030

31-
private readonly Dictionary<uint, Dictionary<uint, ICommandMetaDataStorage>> componentIdToCommandIdToStorage =
32-
new Dictionary<uint, Dictionary<uint, ICommandMetaDataStorage>>();
33-
34-
private List<CommandIds> requestsToRemove = new List<CommandIds>();
31+
private readonly Dictionary<(uint componentId, uint commandId), ICommandMetaDataStorage> componentCommandToStorage =
32+
new Dictionary<(uint componentId, uint commandId), ICommandMetaDataStorage>();
3533

3634
public CommandMetaData()
3735
{
@@ -46,96 +44,46 @@ public CommandMetaData()
4644
foreach (var (componentId, type) in storageTypes)
4745
{
4846
var instance = (ICommandMetaDataStorage) Activator.CreateInstance(type);
49-
50-
if (!componentIdToCommandIdToStorage.TryGetValue(componentId,
51-
out var commandIdToStorage))
52-
{
53-
commandIdToStorage = new Dictionary<uint, ICommandMetaDataStorage>();
54-
componentIdToCommandIdToStorage.Add(componentId, commandIdToStorage);
55-
}
56-
57-
commandIdToStorage.Add(instance.CommandId, instance);
47+
componentCommandToStorage.Add((componentId, instance.CommandId), instance);
5848
}
5949

60-
componentIdToCommandIdToStorage.Add(0, new Dictionary<uint, ICommandMetaDataStorage>
61-
{
62-
{ 0, new WorldCommandMetaDataStorage() }
63-
});
50+
componentCommandToStorage.Add((0, 0), new WorldCommandMetaDataStorage());
6451
}
6552

66-
public void MarkIdForRemoval(uint componentId, uint commandId, long internalRequestId)
53+
public void RemoveRequest(uint componentId, uint commandId, long internalRequestId)
6754
{
68-
requestsToRemove.Add(new CommandIds(componentId, commandId, internalRequestId));
69-
}
70-
71-
public void FlushRemovedIds()
72-
{
73-
foreach (var commandIds in requestsToRemove)
74-
{
75-
var s = GetCommandDiffStorage(commandIds.ComponentId, commandIds.CommandId);
76-
s.RemoveMetaData(commandIds.InternalRequestId);
77-
internalRequestIds.Remove(commandIds.InternalRequestId);
78-
}
79-
80-
requestsToRemove.Clear();
55+
var commandMetaDataStorage = GetCommandDiffStorage(componentId, commandId);
56+
commandMetaDataStorage.RemoveMetaData(internalRequestId);
57+
internalRequestIds.Remove(internalRequestId);
8158
}
8259

8360
public void AddRequest<T>(uint componentId, uint commandId, in CommandContext<T> context)
8461
{
85-
var s = (ICommandPayloadStorage<T>) GetCommandDiffStorage(componentId, commandId);
86-
s.AddRequest(in context);
62+
var commandPayloadStorage = (ICommandPayloadStorage<T>) GetCommandDiffStorage(componentId, commandId);
63+
commandPayloadStorage.AddRequest(in context);
8764
}
8865

8966
public void AddInternalRequestId(uint componentId, uint commandId, long requestId, long internalRequestId)
9067
{
9168
internalRequestIds.Add(internalRequestId);
92-
var s = GetCommandDiffStorage(componentId, commandId);
93-
s.SetInternalRequestId(internalRequestId, requestId);
69+
var commandMetaDataStorage = GetCommandDiffStorage(componentId, commandId);
70+
commandMetaDataStorage.SetInternalRequestId(internalRequestId, requestId);
9471
}
9572

9673
public CommandContext<T> GetContext<T>(uint componentId, uint commandId, long internalRequestId)
9774
{
98-
var s = (ICommandPayloadStorage<T>) GetCommandDiffStorage(componentId, commandId);
99-
return s.GetPayload(internalRequestId);
100-
}
101-
102-
internal bool ContainsCommandMetaData(long internalRequestId)
103-
{
104-
return internalRequestIds.Contains(internalRequestId);
105-
}
106-
107-
internal bool IsEmpty()
108-
{
109-
return internalRequestIds.Count == 0;
75+
var commandPayloadStorage = (ICommandPayloadStorage<T>) GetCommandDiffStorage(componentId, commandId);
76+
return commandPayloadStorage.GetPayload(internalRequestId);
11077
}
11178

11279
private ICommandMetaDataStorage GetCommandDiffStorage(uint componentId, uint commandId)
11380
{
114-
if (!componentIdToCommandIdToStorage.TryGetValue(componentId, out var commandIdToStorage))
115-
{
116-
throw new ArgumentException($"Can not find command meta data. Unknown component ID {componentId}");
117-
}
118-
119-
if (!commandIdToStorage.TryGetValue(commandId, out var storage))
81+
if (!componentCommandToStorage.TryGetValue((componentId, commandId), out var storage))
12082
{
121-
throw new ArgumentException($"Can not find command meta data storage. Unknown command ID {commandId}");
83+
throw new ArgumentException($"Can not find command metadata. Unknown command ID {commandId} on component {componentId}.");
12284
}
12385

12486
return storage;
12587
}
126-
127-
private readonly struct CommandIds
128-
{
129-
public readonly uint ComponentId;
130-
public readonly uint CommandId;
131-
public readonly long InternalRequestId;
132-
133-
public CommandIds(uint componentId, uint commandId, long internalRequestId)
134-
{
135-
ComponentId = componentId;
136-
CommandId = commandId;
137-
InternalRequestId = internalRequestId;
138-
}
139-
}
14088
}
14189
}

workers/unity/Packages/io.improbable.gdk.core/Worker/CommandMetaDataAggregate.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

workers/unity/Packages/io.improbable.gdk.core/Worker/CommandMetaDataAggregate.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

workers/unity/Packages/io.improbable.gdk.core/Worker/CommandMetaDataManager.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

workers/unity/Packages/io.improbable.gdk.core/Worker/CommandMetaDataManager.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

workers/unity/Packages/io.improbable.gdk.core/Worker/ComponentOpDeserializer.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void DeserializeAndApplyCommandRequestReceived(CommandRequestOp op
6868
}
6969

7070
public static void DeserializeAndApplyCommandResponseReceived(CommandResponseOp op, ViewDiff viewDiff,
71-
CommandMetaDataAggregate commandMetaData)
71+
CommandMetaData commandMetaData)
7272
{
7373
if (!CommandIdsToCommandDeserializer.TryGetValue((op.Response.ComponentId, op.Response.CommandIndex),
7474
out var deserializer))
@@ -81,53 +81,53 @@ public static void DeserializeAndApplyCommandResponseReceived(CommandResponseOp
8181
}
8282

8383
public static void ApplyCreateEntityResponse(CreateEntityResponseOp op, ViewDiff viewDiff,
84-
CommandMetaDataAggregate commandMetaData)
84+
CommandMetaData commandMetaData)
8585
{
8686
var context = commandMetaData.GetContext<WorldCommands.CreateEntity.Request>(0, 0, op.RequestId);
8787
var response =
8888
new WorldCommands.CreateEntity.ReceivedResponse(op, context.SendingEntity, context.Request,
8989
context.RequestId);
9090

91-
commandMetaData.MarkIdForRemoval(0, 0, op.RequestId);
91+
commandMetaData.RemoveRequest(0, 0, op.RequestId);
9292

9393
viewDiff.AddCreateEntityResponse(response);
9494
}
9595

9696
public static void ApplyDeleteEntityResponse(DeleteEntityResponseOp op, ViewDiff viewDiff,
97-
CommandMetaDataAggregate commandMetaData)
97+
CommandMetaData commandMetaData)
9898
{
9999
var context = commandMetaData.GetContext<WorldCommands.DeleteEntity.Request>(0, 0, op.RequestId);
100100
var response =
101101
new WorldCommands.DeleteEntity.ReceivedResponse(op, context.SendingEntity, context.Request,
102102
context.RequestId);
103103

104-
commandMetaData.MarkIdForRemoval(0, 0, op.RequestId);
104+
commandMetaData.RemoveRequest(0, 0, op.RequestId);
105105

106106
viewDiff.AddDeleteEntityResponse(response);
107107
}
108108

109109
public static void ApplyReserveEntityIdsResponse(ReserveEntityIdsResponseOp op, ViewDiff viewDiff,
110-
CommandMetaDataAggregate commandMetaData)
110+
CommandMetaData commandMetaData)
111111
{
112112
var context = commandMetaData.GetContext<WorldCommands.ReserveEntityIds.Request>(0, 0, op.RequestId);
113113
var response =
114114
new WorldCommands.ReserveEntityIds.ReceivedResponse(op, context.SendingEntity, context.Request,
115115
context.RequestId);
116116

117-
commandMetaData.MarkIdForRemoval(0, 0, op.RequestId);
117+
commandMetaData.RemoveRequest(0, 0, op.RequestId);
118118

119119
viewDiff.AddReserveEntityIdsResponse(response);
120120
}
121121

122122
public static void ApplyEntityQueryResponse(EntityQueryResponseOp op, ViewDiff viewDiff,
123-
CommandMetaDataAggregate commandMetaData)
123+
CommandMetaData commandMetaData)
124124
{
125125
var context = commandMetaData.GetContext<WorldCommands.EntityQuery.Request>(0, 0, op.RequestId);
126126
var response =
127127
new WorldCommands.EntityQuery.ReceivedResponse(op, context.SendingEntity, context.Request,
128128
context.RequestId);
129129

130-
commandMetaData.MarkIdForRemoval(0, 0, op.RequestId);
130+
commandMetaData.RemoveRequest(0, 0, op.RequestId);
131131

132132
viewDiff.AddEntityQueryResponse(response);
133133
}

0 commit comments

Comments
 (0)