| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// An isolate-compatible object registry and lookup service. | 5 /// An isolate-compatible object registry and lookup service. |
| 6 library isolate.registry; | 6 library isolate.registry; |
| 7 | 7 |
| 8 import 'dart:async' show Future, Completer, TimeoutException; | 8 import 'dart:async' show Future, Completer, TimeoutException; |
| 9 import 'dart:collection' show HashMap, HashSet; | 9 import 'dart:collection' show HashMap, HashSet; |
| 10 import 'dart:isolate' show RawReceivePort, SendPort, Capability; | 10 import 'dart:isolate' show RawReceivePort, SendPort, Capability; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 /// | 27 /// |
| 28 /// A `Registry` object caches objects found using the [lookup] | 28 /// A `Registry` object caches objects found using the [lookup] |
| 29 /// method, or added using [add], and returns the same object every time | 29 /// method, or added using [add], and returns the same object every time |
| 30 /// they are requested. | 30 /// they are requested. |
| 31 /// A different `Registry` object that works on the same registry will not | 31 /// A different `Registry` object that works on the same registry will not |
| 32 /// preserve the identity of elements | 32 /// preserve the identity of elements |
| 33 /// | 33 /// |
| 34 /// It is recommended to only have one `Registry` object working on the | 34 /// It is recommended to only have one `Registry` object working on the |
| 35 /// same registry in each isolate. | 35 /// same registry in each isolate. |
| 36 /// | 36 /// |
| 37 /// When the registry is shared accross isolates, both elements and tags must | 37 /// When the registry is shared across isolates, both elements and tags must |
| 38 /// be sendable between the isolates. | 38 /// be sendable between the isolates. |
| 39 /// Between isolates spawned using [Isolate.spawn] from the same initial | 39 /// Between isolates spawned using [Isolate.spawn] from the same initial |
| 40 /// isolate, most objectes can be sent. | 40 /// isolate, most objects can be sent. |
| 41 /// Only simple objects can be sent between isolates originating from different | 41 /// Only simple objects can be sent between isolates originating from different |
| 42 /// [Isolate.spawnUri] calls. | 42 /// [Isolate.spawnUri] calls. |
| 43 class Registry<T> { | 43 class Registry<T> { |
| 44 // Most operations fail if they haven't received a response for this duration. | 44 // Most operations fail if they haven't received a response for this duration. |
| 45 final Duration _timeout; | 45 final Duration _timeout; |
| 46 | 46 |
| 47 // Each `Registry` object has a cache of objects being controlled by it. | 47 // Each `Registry` object has a cache of objects being controlled by it. |
| 48 // The cache is stored in an [Expando], not on the object. | 48 // The cache is stored in an [Expando], not on the object. |
| 49 // This allows sending the `Registry` object through a `SendPort` without | 49 // This allows sending the `Registry` object through a `SendPort` without |
| 50 // also copying the cache. | 50 // also copying the cache. |
| 51 static Expando _caches = new Expando(); | 51 static Expando _caches = new Expando(); |
| 52 | 52 |
| 53 /// Port for sending command to the central registry mananger. | 53 /// Port for sending command to the central registry manager. |
| 54 SendPort _commandPort; | 54 SendPort _commandPort; |
| 55 | 55 |
| 56 /// Create a registry linked to a [RegistryManager] through [commandPort]. | 56 /// Create a registry linked to a [RegistryManager] through [commandPort]. |
| 57 /// | 57 /// |
| 58 /// In most cases, a registry is created by using the | 58 /// In most cases, a registry is created by using the |
| 59 /// [RegistryManager.registry] getter. | 59 /// [RegistryManager.registry] getter. |
| 60 /// | 60 /// |
| 61 /// If a registry is used between isolates created using [Isolate.spawnUri], | 61 /// If a registry is used between isolates created using [Isolate.spawnUri], |
| 62 /// the `Registry` object can't be sent between the isolates directly. | 62 /// the `Registry` object can't be sent between the isolates directly. |
| 63 /// Instead the [RegistryManager.commandPort] port can be sent and a | 63 /// Instead the [RegistryManager.commandPort] port can be sent and a |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 455 } |
| 456 | 456 |
| 457 /// Entry in [RegistryManager]. | 457 /// Entry in [RegistryManager]. |
| 458 class _RegistryEntry { | 458 class _RegistryEntry { |
| 459 final int id; | 459 final int id; |
| 460 final Object element; | 460 final Object element; |
| 461 final Set tags = new HashSet(); | 461 final Set tags = new HashSet(); |
| 462 final Capability removeCapability = new Capability(); | 462 final Capability removeCapability = new Capability(); |
| 463 _RegistryEntry(this.id, this.element); | 463 _RegistryEntry(this.id, this.element); |
| 464 } | 464 } |
| OLD | NEW |