|
5 | 5 |
|
6 | 6 | Sessions
|
7 | 7 | ========
|
| 8 | + |
| 9 | +Coherence uses the concept of a `Session` to manage a set of related Coherence resources, |
| 10 | +such as maps and/or caches. When using the Coherence Python Client, a `Session` connects to a specific |
| 11 | +gRPC endpoint and uses a specific serialization format to marshal requests and responses. |
| 12 | +This means that different sessions using different serializers may connect to the same server endpoint. Typically, |
| 13 | +for efficiency the client and server would be configured to use matching serialization formats to avoid |
| 14 | +deserialization of data on the server, but this does not have to be the case. If the server is using a different |
| 15 | +serializer for the server-side caches, it must be able to deserialize the client's requests, so there must be |
| 16 | +a serializer configured on the server to match that used by the client. |
| 17 | + |
| 18 | +.. note:: |
| 19 | + Currently, the Coherence Python client only supports JSON serialization |
| 20 | + |
| 21 | +A `Session` is constructed using an `Options` instance, or a generic object with the same keys and values. |
| 22 | + |
| 23 | +The currently supported arguments foe `Options` are: |
| 24 | + - `address` - the address of the Coherence gRPC proxy. This defaults to `localhost:1408`. |
| 25 | + - `request_timeout_seconds` - the gRPC request timeout in seconds. This defaults to `30.0`. |
| 26 | + - `channel_options` - per-request gRPC channel options. |
| 27 | + - `tls_options` - options related to the configuration of TLS. |
| 28 | + |
| 29 | + - `enabled` - determines if TLS is enabled or not. This defaults to `false` (NOTE: assumes `true` if all three `COHERENCE_TLS_*` (see subsequent bullets) environment variables are defined) |
| 30 | + - `ca_cert_path` - the path to the CA certificate. This may be configured using the environment variable `COHERENCE_TLS_CERTS_PATH` |
| 31 | + - `client_cert_path` - the path to the client certificate. This may be configured with the environment variable `COHERENCE_TLS_CLIENT_CERT` |
| 32 | + - `client_key_path` - the path to the client certificate key. This may be configured with the environment variable `COHERENCE_TLS_CLIENT_KEY` |
| 33 | + |
| 34 | +.. code-block:: python |
| 35 | +
|
| 36 | + from coherence import NamedCache, Session |
| 37 | + import asyncio |
| 38 | +
|
| 39 | + # create a new Session to the Coherence server |
| 40 | + session: Session = Session(None) |
| 41 | +
|
| 42 | +This is the simplest invocation which assumes the following defaults: |
| 43 | + - `address` is `localhost:1408` |
| 44 | + - `request_timeout_seconds` is `30.0` |
| 45 | + - `tls_options` is `disabled` |
| 46 | + |
| 47 | +To use values other than the default, create a new `Options` instance, configure as desired, |
| 48 | +and pass it to the constructor of the `Session`: |
| 49 | + |
| 50 | +.. code-block:: python |
| 51 | +
|
| 52 | + from coherence import NamedCache, Session |
| 53 | + import asyncio |
| 54 | +
|
| 55 | + # create a new Session to the Coherence server |
| 56 | + addr: str = 'example.com:4444' |
| 57 | + opt: Options = Options(addr, default_scope, default_request_timeout, default_format) |
| 58 | + session: Session = Session(opt) |
| 59 | +
|
| 60 | +It's also possible to control the default address the session will bind to by providing |
| 61 | +an address via the `COHERENCE_SERVER_ADDRESS` environment variable. The format of the value would |
| 62 | +be the same as if you configured it programmatically as the above example shows. The default timeout |
| 63 | +can also be configured using `COHERENCE_CLIENT_REQUEST_TIMEOUT` environment variable. |
| 64 | + |
| 65 | +Once the session has been constructed, it will now be possible to create maps and caches. |
0 commit comments