DecisionIsolateMessage class
Message payload for communication between main isolate and worker isolate.
This class encapsulates all information needed to execute a decision-making task in a separate isolate and return results to the main isolate.
Isolate Communication Pattern:
In Dart, isolates don't share memory - they communicate by passing messages. This class serves as the standardized message format for all decision-making operations, ensuring type-safe and structured communication.
Message Flow:
Main Isolate Worker Isolate
| |
|---> DecisionIsolateMessage --->|
| (algorithm, command, data) |
| |
| [Process]
| |
|<--- Result via replyPort <-----|
| |
Why Isolates?
Heavy computational tasks (matrix operations, eigenvector calculations) can block the UI thread. By running these in isolates:
- UI remains responsive
- Utilizes multiple CPU cores
- Prevents app freezing during calculations
Architecture:
- Main isolate creates message with task details and reply port
- Worker isolate receives message, processes task
- Result is sent back through the reply port
- Main isolate receives result and continues execution
Fields:
- algorithm: Specifies which decision-making algorithm to use (AHP or SAW)
- command: The specific operation within that algorithm to execute
- payload: Input data required for the operation (matrices, vectors, etc.)
- replyPort: SendPort for the worker to send results back to the main isolate
Example Usage:
// In main isolate
final receivePort = ReceivePort();
final message = DecisionIsolateMessage(
algorithm: DecisionAlgorithm.ahp,
command: AhpProcessingCommand.calculateEigenVectorCriteria,
payload: {
'matrix': [
[1.0, 3.0, 5.0],
[0.33, 1.0, 2.0],
[0.2, 0.5, 1.0]
]
},
replyPort: receivePort.sendPort,
);
// Send to worker isolate
workerSendPort.send(message);
// Wait for result
final result = await receivePort.first;
print('Eigenvector: $result');
Supported Algorithms:
DecisionAlgorithm.ahp: Analytic Hierarchy ProcessDecisionAlgorithm.saw: Simple Additive Weighting
AHP Commands:
generateInputPairwiseAlternative: Create comparison templatesgenerateResultPairwiseMatrixCriteria: Build criteria matrixgenerateResultPairwiseMatrixAlternative: Build alternative matrixcalculateEigenVectorCriteria: Compute criteria weightscalculateEigenVectorAlternative: Compute alternative prioritiescheckConsistencyRatio: Validate comparison consistencycalculateFinalScore: Compute final decision scores
SAW Commands:
generateSawMatrix: Create decision matrixnormalizeMatrix: Normalize values for calculation
Payload Requirements:
The payload map must contain all data required by the specific command. Structure varies by command - refer to individual command documentation for required keys and value types.
Error Handling:
If the worker encounters an error, it sends back a map with 'error' key:
{
'error': 'Error message here',
'stack': 'Stack trace here'
}
The main isolate should check for this error format and handle appropriately.
Performance Considerations:
- Message passing has overhead - use isolates for computationally heavy tasks
- Small calculations may be faster on main isolate
- Threshold typically: matrix size > 80 or criteria count > 25
- Serialization cost increases with payload size
Thread Safety:
This message is immutable by design (all fields are final). Once created, it cannot be modified, ensuring thread-safe communication.
Constructors
-
DecisionIsolateMessage({required DecisionAlgorithm algorithm, required dynamic command, required Map<
String, dynamic> payload, required SendPort replyPort}) - Creates a new decision isolate message.
Properties
- algorithm → DecisionAlgorithm
-
The decision-making algorithm to execute.
final
- command → dynamic
-
The specific command/operation to perform within the algorithm.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
payload
→ Map<
String, dynamic> -
Input data required for the operation.
final
- replyPort → SendPort
-
Port for sending results back to the main isolate.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited