Skip to content

Commit 94d40af

Browse files
authored
COH-26192 - Add end user documentation for Sessions (#3)
1 parent 9df0a7b commit 94d40af

File tree

2 files changed

+114
-10
lines changed

2 files changed

+114
-10
lines changed

coherence/client.py

Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,22 @@ def is_locked(self) -> bool:
833833

834834

835835
class Options:
836+
"""
837+
Supported :func:`coherence.client.Session` options.
838+
"""
839+
836840
ENV_SERVER_ADDRESS = "COHERENCE_SERVER_ADDRESS"
841+
"""
842+
Environment variable to specify the Coherence gRPC server address for the client to connect to. The
843+
environment variable is used if address is not passed as an argument in the constructor. If the environment
844+
variable is not set and address is not passed as an argument then `DEFAULT_ADDRESS` is used
845+
"""
837846
ENV_REQUEST_TIMEOUT = "COHERENCE_CLIENT_REQUEST_TIMEOUT"
847+
"""
848+
Environment variable to specify the request timeout for each remote call. The environment variable is used if
849+
request timeout is not passed as an argument in the constructor. If the environment variable is not set and
850+
request timeout is not passed as an argument then `DEFAULT_REQUEST_TIMEOUT` of 30 seconds is used
851+
"""
838852

839853
DEFAULT_ADDRESS: Final[str] = "localhost:1408"
840854
"""The default target address to connect to Coherence gRPC server."""
@@ -854,6 +868,23 @@ def __init__(
854868
channel_options: Optional[Sequence[Tuple[str, Any]]] = None,
855869
tls_options: Optional[TlsOptions] = None,
856870
) -> None:
871+
"""
872+
Construct a new :func:`coherence.client.Options`
873+
874+
:param address: Address of the target Coherence cluster. If not explicitly set, this defaults
875+
to :func:`coherence.client.Options.DEFAULT_ADDRESS`. See
876+
also :func:`coherence.client.Options.ENV_SERVER_ADDRESS`
877+
:param scope: scope name used to link this :func:`coherence.client.Options` to the
878+
corresponding `ConfigurableCacheFactory` on the server.
879+
:param request_timeout_seconds: Defines the request timeout, in `seconds`, that will be applied to each
880+
remote call. If not explicitly set, this defaults to :func:`coherence.client.Options.DEFAULT_REQUEST_TIMEOUT`.
881+
See also See also :func:`coherence.client.Options.ENV_REQUEST_TIMEOUT`
882+
:param ser_format: The serialization format. Currently, this is always `json`
883+
:param channel_options: The `gRPC` `ChannelOptions`. See
884+
https://grpc.github.io/grpc/python/glossary.html#term-channel_arguments and
885+
https://github.com/grpc/grpc/blob/master/include/grpc/impl/grpc_types.h
886+
:param tls_options: Optional TLS configuration.
887+
"""
857888
addr = os.getenv(Options.ENV_SERVER_ADDRESS)
858889
if addr is not None:
859890
self._address = addr
@@ -882,34 +913,77 @@ def __init__(
882913

883914
@property
884915
def tls_options(self) -> Optional[TlsOptions]:
916+
"""
917+
Returns the TLS-specific configuration options.
918+
919+
:return: the TLS-specific configuration options.
920+
"""
885921
return getattr(self, "_tls_options", None)
886922

887923
@tls_options.setter
888924
def tls_options(self, tls_options: TlsOptions) -> None:
925+
"""
926+
Sets the TLS-specific configuration options.
927+
928+
:param tls_options: the TLS-specific configuration options.
929+
"""
889930
self._tls_options = tls_options
890931

891932
@property
892933
def address(self) -> str:
934+
"""
935+
Return the IPv4 host address and port in the format of ``[host]:[port]``.
936+
937+
:return: the IPv4 host address and port in the format of ``[host]:[port]``.
938+
"""
893939
return self._address
894940

895941
@property
896942
def scope(self) -> str:
943+
"""
944+
Return the scope name used to link this `Session` with to the corresponding `ConfigurableCacheFactory` on the
945+
server.
946+
947+
:return: the scope name used to link this `Session` with to the corresponding `ConfigurableCacheFactory` on the
948+
server.
949+
"""
897950
return self._scope
898951

899952
@property
900953
def format(self) -> str:
954+
"""
955+
The serialization format used by this session. This library currently supports JSON serialization only,
956+
thus this always returns 'json'.
957+
958+
:return: the serialization format used by this session.
959+
"""
901960
return self._ser_format
902961

903962
@property
904963
def request_timeout_seconds(self) -> float:
964+
"""
965+
Returns the request timeout in `seconds`
966+
967+
:return: the request timeout in `seconds`
968+
"""
905969
return self._request_timeout_seconds
906970

907971
@property
908972
def channel_options(self) -> Optional[Sequence[Tuple[str, Any]]]:
973+
"""
974+
Return the `gRPC` `ChannelOptions`.
975+
976+
:return: the `gRPC` `ChannelOptions`.
977+
"""
909978
return getattr(self, "_channel_options", None)
910979

911980
@channel_options.setter
912981
def channel_options(self, channel_options: Sequence[Tuple[str, Any]]) -> None:
982+
"""
983+
Set the `gRPC` `ChannelOptions`.
984+
985+
:param channel_options: the `gRPC` `ChannelOptions`.
986+
"""
913987
self._channel_options = channel_options
914988

915989

@@ -957,8 +1031,9 @@ class Session:
9571031

9581032
def __init__(self, session_options: Optional[Options] = None):
9591033
"""
1034+
Construct a new `Session` based on the provided :func:`coherence.client.Options`
9601035
961-
:param session_options:
1036+
:param session_options: the provided :func:`coherence.client.Options`
9621037
"""
9631038
self._closed: bool = False
9641039
self._caches: dict[str, NamedCache[Any, Any]] = dict()
@@ -1028,51 +1103,60 @@ def on(
10281103
@property
10291104
def channel(self) -> grpc.aio.Channel:
10301105
"""
1106+
Return the underlying `gRPC` Channel used by this session.
10311107
1032-
:return:
1108+
:return: the underlying `gRPC` Channel used by this session.
10331109
"""
10341110
return self._channel
10351111

10361112
@property
10371113
def scope(self) -> str:
10381114
"""
1115+
Return the scope name used to link this `Session` with to the corresponding `ConfigurableCacheFactory` on the
1116+
server.
10391117
1040-
:return:
1118+
:return: the scope name used to link this `Session` with to the corresponding `ConfigurableCacheFactory` on the
1119+
server.
10411120
"""
10421121
return self._session_options.scope
10431122

10441123
@property
10451124
def format(self) -> str:
10461125
"""
1126+
Returns the default serialization format used by the `Session`
10471127
1048-
:return:
1128+
:return: the default serialization format used by the `Session`
10491129
"""
10501130
return self._session_options.format
10511131

10521132
@property
10531133
def options(self) -> Options:
10541134
"""
1135+
Return the :func:`coherence.client.Options` (read-only) used to configure this session.
10551136
1056-
:return:
1137+
:return: the :func:`coherence.client.Options` (read-only) used to configure this session.
10571138
"""
10581139
return self._session_options
10591140

10601141
@property
10611142
def closed(self) -> bool:
10621143
"""
1144+
Returns `True` if Session is closed else `False`
10631145
1064-
:return:
1146+
:return: `True` if Session is closed else `False`
10651147
"""
10661148
return self._closed
10671149

10681150
# noinspection PyProtectedMember
10691151
@_pre_call_session
10701152
async def get_cache(self, name: str, ser_format: str = DEFAULT_FORMAT) -> "NamedCache[K, V]":
10711153
"""
1154+
Returns a :func:`coherence.client.NamedCache` for the specified cache name.
1155+
1156+
:param name: the cache name
1157+
:param ser_format: the serialization format for keys and values stored within the cache
10721158
1073-
:param name:
1074-
:param ser_format:
1075-
:return:
1159+
:return: Returns a :func:`coherence.client.NamedCache` for the specified cache name.
10761160
"""
10771161
serializer = SerializerRegistry.serializer(ser_format)
10781162
c = self._caches.get(name)
@@ -1086,7 +1170,9 @@ async def get_cache(self, name: str, ser_format: str = DEFAULT_FORMAT) -> "Named
10861170

10871171
# noinspection PyUnresolvedReferences
10881172
async def close(self) -> None:
1089-
""" """
1173+
"""
1174+
Close the `Session`
1175+
"""
10901176
if not self._closed:
10911177
self._closed = True
10921178
self._emitter.emit(SessionLifecycleEvent.CLOSED.value)

docs/api_reference/client.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ Session
1515
:show-inheritance:
1616
:members:
1717

18+
.. automethod:: __init__
19+
20+
Options
21+
-------
22+
.. autoclass:: coherence.client.Options
23+
:show-inheritance:
24+
:members:
25+
26+
.. automethod:: __init__
27+
28+
TlsOptions
29+
----------
30+
.. autoclass:: coherence.client.TlsOptions
31+
:show-inheritance:
32+
:members:
33+
34+
.. automethod:: __init__
35+
1836
NamedCache
1937
----------
2038
.. autoclass:: coherence.client.NamedCache

0 commit comments

Comments
 (0)