|
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 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 __future__ import annotations |
| 16 | + |
| 17 | +from typing import TYPE_CHECKING |
| 18 | + |
| 19 | +if TYPE_CHECKING: |
| 20 | + from aws_wrapper.host_list_provider import HostListProviderService |
| 21 | + from aws_wrapper.hostinfo import HostInfo |
| 22 | + from aws_wrapper.plugin_service import PluginService |
| 23 | + from aws_wrapper.utils.properties import Properties |
| 24 | + |
| 25 | +from typing import Any, Callable, Set |
| 26 | + |
| 27 | +from aws_wrapper.pep249 import Connection |
| 28 | +from aws_wrapper.plugin import Plugin, PluginFactory |
| 29 | +from aws_wrapper.utils.notifications import (ConnectionEvent, |
| 30 | + OldConnectionSuggestedAction) |
| 31 | + |
| 32 | + |
| 33 | +class ReadWriteSplittingPlugin(Plugin): |
| 34 | + _SUBSCRIBED_METHODS: Set[str] = {"init_host_provider", |
| 35 | + "connect", |
| 36 | + "notify_connection_changed", |
| 37 | + "Connection.set_read_only", |
| 38 | + "Connection.clear_warnings"} |
| 39 | + |
| 40 | + def __init__(self, plugin_service: PluginService, props: Properties): |
| 41 | + self._plugin_service = plugin_service |
| 42 | + self._properties = props |
| 43 | + |
| 44 | + @property |
| 45 | + def subscribed_methods(self) -> Set[str]: |
| 46 | + return self._SUBSCRIBED_METHODS |
| 47 | + |
| 48 | + def init_host_provider( |
| 49 | + self, |
| 50 | + props: Properties, |
| 51 | + host_list_provider_service: HostListProviderService, |
| 52 | + init_host_provider_func: Callable): |
| 53 | + ... |
| 54 | + |
| 55 | + def connect( |
| 56 | + self, |
| 57 | + host_info: HostInfo, |
| 58 | + props: Properties, |
| 59 | + initial: bool, |
| 60 | + connect_func: Callable) -> Connection: |
| 61 | + return Connection() |
| 62 | + |
| 63 | + def force_connect( |
| 64 | + self, |
| 65 | + host_info: HostInfo, |
| 66 | + props: Properties, |
| 67 | + initial: bool, |
| 68 | + force_connect_func: Callable) -> Connection: |
| 69 | + return Connection() |
| 70 | + |
| 71 | + def notify_connection_changed(self, changes: Set[ConnectionEvent]) -> OldConnectionSuggestedAction: |
| 72 | + return OldConnectionSuggestedAction.NO_OPINION |
| 73 | + |
| 74 | + def execute(self, target: type, method_name: str, execute_func: Callable, *args: Any) -> Any: |
| 75 | + ... |
| 76 | + |
| 77 | + |
| 78 | +class ReadWriteSplittingPluginFactory(PluginFactory): |
| 79 | + def get_instance(self, plugin_service: PluginService, props: Properties) -> Plugin: |
| 80 | + return ReadWriteSplittingPlugin(plugin_service, props) |
0 commit comments