|
| 1 | +# Copyright 1999-2022 Alibaba Group Holding Ltd. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from enum import Enum |
| 16 | +from types import TracebackType |
| 17 | +from typing import Any, Type |
| 18 | + |
| 19 | +from ..core import ActorRef |
| 20 | + |
| 21 | +DEFAULT_PROTOCOL: int = 0 |
| 22 | + |
| 23 | +class MessageType(Enum): |
| 24 | + control = 0 |
| 25 | + result = 1 |
| 26 | + error = 2 |
| 27 | + create_actor = 3 |
| 28 | + destroy_actor = 4 |
| 29 | + has_actor = 5 |
| 30 | + actor_ref = 6 |
| 31 | + send = 7 |
| 32 | + tell = 8 |
| 33 | + cancel = 9 |
| 34 | + |
| 35 | +class ControlMessageType(Enum): |
| 36 | + stop = 0 |
| 37 | + restart = 1 |
| 38 | + sync_config = 2 |
| 39 | + get_config = 3 |
| 40 | + wait_pool_recovered = 4 |
| 41 | + add_sub_pool_actor = 5 |
| 42 | + |
| 43 | +class _MessageBase: |
| 44 | + message_type: MessageType |
| 45 | + protocol: int |
| 46 | + message_id: bytes |
| 47 | + message_trace: list |
| 48 | + profiling_context: Any |
| 49 | + |
| 50 | + def __init__( |
| 51 | + self, |
| 52 | + message_id: bytes = None, |
| 53 | + protocol: int = DEFAULT_PROTOCOL, |
| 54 | + message_trace: list = None, |
| 55 | + profiling_context: Any = None, |
| 56 | + ): ... |
| 57 | + def __repr__(self): ... |
| 58 | + |
| 59 | +class ControlMessage(_MessageBase): |
| 60 | + message_type = MessageType.control |
| 61 | + |
| 62 | + address: str |
| 63 | + control_message_type: ControlMessageType |
| 64 | + content: Any |
| 65 | + |
| 66 | + def __init__( |
| 67 | + self, |
| 68 | + message_id: bytes = None, |
| 69 | + address: str = None, |
| 70 | + control_message_type: ControlMessageType = None, |
| 71 | + content: Any = None, |
| 72 | + protocol: int = DEFAULT_PROTOCOL, |
| 73 | + ): ... |
| 74 | + |
| 75 | +class ResultMessage(_MessageBase): |
| 76 | + message_type = MessageType.result |
| 77 | + |
| 78 | + result: Any |
| 79 | + |
| 80 | + def __init__( |
| 81 | + self, |
| 82 | + message_id: bytes = None, |
| 83 | + result: Any = None, |
| 84 | + protocol: int = DEFAULT_PROTOCOL, |
| 85 | + message_trace: list = None, |
| 86 | + profiling_context: Any = None, |
| 87 | + ): ... |
| 88 | + |
| 89 | +class ErrorMessage(_MessageBase): |
| 90 | + message_type = MessageType.error |
| 91 | + |
| 92 | + address: str |
| 93 | + pid: int |
| 94 | + error_type: Type |
| 95 | + error: BaseException |
| 96 | + traceback: TracebackType |
| 97 | + |
| 98 | + def __init__( |
| 99 | + self, |
| 100 | + message_id: bytes = None, |
| 101 | + address: str = None, |
| 102 | + pid: int = -1, |
| 103 | + error_type: Type[BaseException] = None, |
| 104 | + error: BaseException = None, |
| 105 | + traceback: TracebackType = None, |
| 106 | + protocol: int = DEFAULT_PROTOCOL, |
| 107 | + message_trace: list = None, |
| 108 | + ): ... |
| 109 | + def as_instanceof_cause(self) -> BaseException: ... |
| 110 | + |
| 111 | +class CreateActorMessage(_MessageBase): |
| 112 | + message_type = MessageType.create_actor |
| 113 | + |
| 114 | + actor_cls: Type |
| 115 | + actor_id: bytes |
| 116 | + args: tuple |
| 117 | + kwargs: dict |
| 118 | + allocate_strategy: Any |
| 119 | + from_main: bool |
| 120 | + |
| 121 | + def __init__( |
| 122 | + self, |
| 123 | + message_id: bytes = None, |
| 124 | + actor_cls: Type = None, |
| 125 | + actor_id: bytes = None, |
| 126 | + args: tuple = None, |
| 127 | + kwargs: dict = None, |
| 128 | + allocate_strategy: Any = None, |
| 129 | + from_main: bool = False, |
| 130 | + protocol: int = DEFAULT_PROTOCOL, |
| 131 | + message_trace: list = None, |
| 132 | + ): ... |
| 133 | + |
| 134 | +class DestroyActorMessage(_MessageBase): |
| 135 | + message_type = MessageType.destroy_actor |
| 136 | + |
| 137 | + actor_ref: ActorRef |
| 138 | + from_main: bool |
| 139 | + |
| 140 | + def __init__( |
| 141 | + self, |
| 142 | + message_id: bytes = None, |
| 143 | + actor_ref: ActorRef = None, |
| 144 | + from_main: bool = False, |
| 145 | + protocol: int = DEFAULT_PROTOCOL, |
| 146 | + message_trace: list = None, |
| 147 | + ): ... |
| 148 | + |
| 149 | +class HasActorMessage(_MessageBase): |
| 150 | + message_type = MessageType.has_actor |
| 151 | + |
| 152 | + actor_ref: ActorRef |
| 153 | + |
| 154 | + def __init__( |
| 155 | + self, |
| 156 | + message_id: bytes = None, |
| 157 | + actor_ref: ActorRef = None, |
| 158 | + protocol: int = DEFAULT_PROTOCOL, |
| 159 | + message_trace: list = None, |
| 160 | + ): ... |
| 161 | + |
| 162 | +class ActorRefMessage(_MessageBase): |
| 163 | + message_type = MessageType.actor_ref |
| 164 | + |
| 165 | + actor_ref: ActorRef |
| 166 | + |
| 167 | + def __init__( |
| 168 | + self, |
| 169 | + message_id: bytes = None, |
| 170 | + actor_ref: ActorRef = None, |
| 171 | + protocol: int = DEFAULT_PROTOCOL, |
| 172 | + message_trace: list = None, |
| 173 | + ): ... |
| 174 | + |
| 175 | +class SendMessage(_MessageBase): |
| 176 | + message_type = MessageType.send |
| 177 | + |
| 178 | + actor_ref: ActorRef |
| 179 | + content: Any |
| 180 | + |
| 181 | + def __init__( |
| 182 | + self, |
| 183 | + message_id: bytes = None, |
| 184 | + actor_ref: ActorRef = None, |
| 185 | + content: object = None, |
| 186 | + protocol: int = DEFAULT_PROTOCOL, |
| 187 | + message_trace: list = None, |
| 188 | + profiling_context: Any = None, |
| 189 | + ): ... |
| 190 | + |
| 191 | +class TellMessage(SendMessage): |
| 192 | + message_type = MessageType.tell |
| 193 | + |
| 194 | +class CancelMessage(_MessageBase): |
| 195 | + message_type = MessageType.cancel |
| 196 | + |
| 197 | + address: str |
| 198 | + cancel_message_id: bytes |
| 199 | + |
| 200 | + def __init__( |
| 201 | + self, |
| 202 | + message_id: bytes = None, |
| 203 | + address: str = None, |
| 204 | + cancel_message_id: bytes = None, |
| 205 | + protocol: int = DEFAULT_PROTOCOL, |
| 206 | + message_trace: list = None, |
| 207 | + ): ... |
| 208 | + |
| 209 | +class DeserializeMessageFailed(RuntimeError): |
| 210 | + def __init__(self, message_id: bytes): ... |
| 211 | + def __str__(self): ... |
| 212 | + |
| 213 | +def reset_random_seed(): ... |
| 214 | +def new_message_id() -> bytes: ... |
0 commit comments