77from etpproto .messages import Message
88
99from etptypes .helpers import AvroModel
10- from etptypes .energistics .etp .v12 .protocol .store_notification import UnsolicitedStoreNotifications
11- from etptypes .energistics .etp .v12 .datatypes .object .subscription_info import SubscriptionInfo
12- from etptypes .energistics .etp .v12 .datatypes .object .context_info import ContextInfo
13- from etptypes .energistics .etp .v12 .datatypes .object .relationship_kind import RelationshipKind
14- from etptypes .energistics .etp .v12 .datatypes .object .context_scope_kind import ContextScopeKind
10+ from etptypes .energistics .etp .v12 .protocol .store_notification import (
11+ UnsolicitedStoreNotifications ,
12+ )
13+ from etptypes .energistics .etp .v12 .datatypes .object .subscription_info import (
14+ SubscriptionInfo ,
15+ )
16+ from etptypes .energistics .etp .v12 .datatypes .object .context_info import (
17+ ContextInfo ,
18+ )
19+ from etptypes .energistics .etp .v12 .datatypes .object .relationship_kind import (
20+ RelationshipKind ,
21+ )
22+ from etptypes .energistics .etp .v12 .datatypes .object .context_scope_kind import (
23+ ContextScopeKind ,
24+ )
1525
1626from gabbro .etp .connection_register import ConnectionRegister
1727
2030class ETPNotifyer :
2131
2232 # For each ETPConnection, store a list of notifications subscription
23- map_client_to_subscribtion : ClassVar [Mapping [ClientInfo , list [AvroModel ]]] = {}
33+ map_client_to_subscribtion : ClassVar [
34+ Mapping [ClientInfo , list [AvroModel ]]
35+ ] = {}
2436
2537 unsolicited_notification : ClassVar [list [AvroModel ]] = []
2638
2739 @classmethod
28- async def subscribe (cls , client_info : ClientInfo , subscription : Any ) -> None :
40+ async def subscribe (
41+ cls , client_info : ClientInfo , subscription : Any
42+ ) -> None :
2943 print (client_info .ip , ": #ETPNotiyer.subscribe" )
3044
3145 if client_info not in cls .map_client_to_subscribtion :
@@ -34,7 +48,9 @@ async def subscribe(cls, client_info: ClientInfo, subscription: Any) -> None:
3448 cls .map_client_to_subscribtion [client_info ].append (subscription )
3549
3650 @classmethod
37- async def unsubscribe (cls , client_info : ClientInfo , subscription : Any ) -> None :
51+ async def unsubscribe (
52+ cls , client_info : ClientInfo , subscription : Any
53+ ) -> None :
3854 print (client_info .ip , ": #ETPNotiyer.unsubscribe" )
3955 cls .map_client_to_subscribtion .pop (client_info , None )
4056
@@ -48,22 +64,36 @@ async def trigger(cls, notif_content: Any):
4864 async def _notify (cls , client_info : ClientInfo , msg : bytes ):
4965 print (client_info .ip , ": #ETPNotiyer._notify" )
5066 websocket , connection = ConnectionRegister .get_ws_n_con (client_info )
51-
67+
5268 if websocket :
5369 await websocket .send_bytes (msg )
5470 else :
55- print (client_info .ip , ": #ETPNotiyer._notify => websocket not found" )
71+ print (
72+ client_info .ip , ": #ETPNotiyer._notify => websocket not found"
73+ )
5674
5775 @classmethod
5876 async def send_unsolicited_notification (cls , client_info : ClientInfo ):
59- print (client_info .ip , ": #ETPNotiyer.send_unsolicited_notification : <" , len (cls .unsolicited_notification ), ">" )
77+ print (
78+ client_info .ip ,
79+ ": #ETPNotiyer.send_unsolicited_notification : <" ,
80+ len (cls .unsolicited_notification ),
81+ ">" ,
82+ )
6083 websocket , connection = ConnectionRegister .get_ws_n_con (client_info )
6184
6285 for msg in cls .unsolicited_notification :
6386 m = Message .get_object_message (etp_object = msg )
64- print (client_info .ip , ": sending unsolicited_notification " , m , "\n \n " )
87+ print (
88+ client_info .ip ,
89+ ": sending unsolicited_notification " ,
90+ m ,
91+ "\n \n " ,
92+ )
6593
66- async for msg_part in connection .send_msg_and_error_generator (m , None ):
94+ async for msg_part in connection .send_msg_and_error_generator (
95+ m , None
96+ ):
6797 await websocket .send_bytes (msg_part )
6898
6999 @classmethod
@@ -72,13 +102,16 @@ def add_unsolicited_notification(cls, msg: AvroModel):
72102
73103
74104u_store_notif = UnsolicitedStoreNotifications (
75- subscriptions = [
76- SubscriptionInfo ( context = ContextInfo (uri = "eml:///" , depth = 3 , navigable_edges = RelationshipKind .BOTH ),
77- scope = ContextScopeKind .SOURCES ,
78- request_uuid = pyUUID .uuid4 ().bytes ,
79- start_time = 0 ,
80- include_object_data = False ,
81- )
82- ]
83- )
105+ subscriptions = [
106+ SubscriptionInfo (
107+ context = ContextInfo (
108+ uri = "eml:///" , depth = 3 , navigable_edges = RelationshipKind .BOTH
109+ ),
110+ scope = ContextScopeKind .SOURCES ,
111+ request_uuid = pyUUID .uuid4 ().bytes ,
112+ start_time = 0 ,
113+ include_object_data = False ,
114+ )
115+ ]
116+ )
84117ETPNotifyer .add_unsolicited_notification (msg = u_store_notif )
0 commit comments