Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
Service クラス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Google Protocol RPC サービスは、コンストラクタまたはパラメータを受け取らないファクトリを使用して作成されます。しかし、一部のアプリケーションでは、複数のリクエストにまたがって状態または構成をサービスに渡す必要があります。これを行うには、サービスのコンストラクタへのパラメータを定義し、new_factory() クラス メソッドを使用して、コンストラクタにパラメータを渡すファクトリを作成します。次に例を示します:
from protorpc import remote
class MyService(remote.Service):
def __init__(self, configuration, state):
self.configuration = configuration
self.state = state
configuration = MyServiceConfiguration()
global_state = MyServiceState()
my_service_factory = MyService.new_factory(configuration,
state=global_state)
サービス ハンドラとの取り決めでは、ユーザー リクエストを処理するたびに新しいサービス オブジェクトを作成すること、パラメータを受け取らないことが必要です。ファクトリはこの条件を満たします。
new_instance = my_service_factory()
assert new_instance.state is global_state
Service
は protorpc.remote
モジュールによって提供されます。
クラスのプロパティ
Service でインスタンス化されるプロパティは次の 1 つです:
- request_state
- この Service インスタンスに関連するリクエストの状態です。
クラス メソッド
Service クラスには次のクラス メソッドがあります:
- all_remote_methods()
-
Service クラスのすべてのリモート メソッドを取得します。
注: 組み込みのメソッドは、リモート メソッドのディクショナリに表示されません。
メソッド名をリモート メソッドにマップするディクショナリを返します。
- new_factory(args, **kwargs)
-
サービスのファクトリを作成します。 設定オブジェクトまたは状態オブジェクトをサービスに渡すのに役立ちます。任意のパラメータとキーワードを受け取りますが、基になるサービスでは、コンストラクタで他のパラメータを受け取ってはいけません。
引数
- args
- サービスのコンストラクタに渡す引数です。
- **kwargs
新しいインスタンスを作成するファクトリ関数を返し、引数とキーワードをコンストラクタに渡します。
インスタンス メソッド
Service インスタンスには次のメソッドがあります:
- initialize_request_state(request_state)
- 引数:
- request_state
- RequestState インスタンス。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-19 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-19 UTC。"],[[["\u003cp\u003eGoogle Protocol RPC services typically use parameterless constructors or factories, but the \u003ccode\u003enew_factory()\u003c/code\u003e method allows for passing state or configuration to the service constructor.\u003c/p\u003e\n"],["\u003cp\u003eA new service object is created for each user request, adhering to the contract that service construction does not take parameters, a condition fulfilled by the factory.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eService\u003c/code\u003e class from \u003ccode\u003eprotorpc.remote\u003c/code\u003e offers class methods like \u003ccode\u003eall_remote_methods()\u003c/code\u003e to get all remote methods, excluding built-in methods, and \u003ccode\u003enew_factory()\u003c/code\u003e to pass configuration or state objects during service creation.\u003c/p\u003e\n"],["\u003cp\u003eService instances have one property, \u003ccode\u003erequest_state\u003c/code\u003e, and one instance method, \u003ccode\u003einitialize_request_state(request_state)\u003c/code\u003e which initializes a RequestState instance.\u003c/p\u003e\n"]]],[],null,[]]