協調

□未翻訳

□翻訳中

□翻訳完了(細田謙二)

■レビュー(中垣健志)

協調

複数のアプリケーションを協調させる方法は多数あります:

There are many ways applications can cooperate:

  • 複数のアプリケーションは同じデータベースに接続することができ、テーブルを共有することができます。データベースのすべてのテーブルをすべてのアプリケーションで定義する必要はありません。しかし、それらを使用するアプリケーションではそれらを定義しなければなりません。同じテーブルを使用するすべてのアプリケーションは、1つを除いて、migrate=Falseに設定してテーブルを定義しなければなりません。

  • Applications can connect to the same database and thus share tables. It is not necessary that all tables in the database are defined by all applications, but they must be defined by those applications that use them. All applications that use the same table, but one, must define the table with migrate=False.

  • 複数のアプリケーションは、(第13章で説明する)LOADヘルパーを用いて、他のアクションからのコンポーネントを埋め込むことができます。

  • Applications can embed components from other actions using the LOAD helper (described in Chapter 13).

  • 複数のアプリケーションは、セッションを共有することができます。

  • Applications can share sessions.

  • 複数のアプリケーションは、XML-RPCを介してリモートで互いのアクションを呼び出すことができます。

  • Applications can call each other's actions remotely via XML-RPC.

  • 複数のアプリケーションは、ファイルシステム(それらが同一のファイルシステムを共有すると仮定)を介して互いのファイルにアクセスすることができます。

  • Applications can access each other's files via the filesystem (assuming they share the same filesystem).

  • 複数のアプリケーションは、互いのアクションを、前述のようにexec_environmentを用いて、ローカルに呼ぶ出すことができます。

  • Applications can call each other's actions locally using exec_environment as discussed above.

  • 複数のアプリケーションは、説明した構文を用いて、互いのモジュールをインポートすることができます:

  • Applications can import each other's modules using the syntax:

  • 複数のアプリケーションは、PYTHONPATHの検索パス、つまり、sys.path内にある任意のモジュールをインポートすることができます。

    • Applications can import any module in the PYTHONPATH search path, sys.path.

アプリは他のアプリのセッションを次のようなコマンドで読み込むことができます:

One app can load the session of another app using the command:

1.

session.connect(request, response, masterapp='appname', db=db)

ここで、"appname"は、クッキーに最初のsession_idを設定するマスターアプリケーションの名前です。dbはセッションテーブル(web2py_session)を含むデータベースへのデータベース接続です。セッションを共有するすべてのアプリは、セッションストレージとして同じデータベースを使用する必要があります。

Here "appname" is the name of the master application, the one that sets the initial session_id in the cookie. db is a database connection to the database that contains the session table (web2py_session). All apps that share sessions must use the same database for session storage.

アプリケーションは、次のようにして、他のアプリのモジュールをロードすることができます。

One application can load a module from another app using

1.

othermodule = local_import('othermodule',app='otherapp')

もしモジュール関数がコアオブジェクト(request、response、session、cache、T)にアクセスする必要がある場合、そのオブジェクトは明示的に関数に渡される必要があります。モジュールがコアオブジェクトの別のインスタンスを作成するようにはしないでください。そうしないと、関数は期待どおりに動作しないでしょう。

If a module function needs access to one of the core objects (request, response, session, cache, and T), the objects must be passed explicitly to the function. Do not let the module create another instance of the core objects. Otherwise, the function will not behave as expected.