|
| 1 | +# Copyright 2015-2020 SWIM.AI inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 16 | +# you may not use this file except in compliance with the License. |
| 17 | +# You may obtain a copy of the License at |
| 18 | +# |
| 19 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 20 | +# |
| 21 | +# Unless required by applicable law or agreed to in writing, software |
| 22 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 23 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 24 | +# See the License for the specific language governing permissions and |
| 25 | +# limitations under the License. |
| 26 | +# |
| 27 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 28 | +# you may not use this file except in compliance with the License. |
| 29 | +# You may obtain a copy of the License at |
| 30 | +# |
| 31 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 32 | +# |
| 33 | +# Unless required by applicable law or agreed to in writing, software |
| 34 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 35 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 36 | +# See the License for the specific language governing permissions and |
| 37 | +# limitations under the License. |
| 38 | +# |
| 39 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 40 | +# you may not use this file except in compliance with the License. |
| 41 | +# You may obtain a copy of the License at |
| 42 | +# |
| 43 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 44 | +# |
| 45 | +# Unless required by applicable law or agreed to in writing, software |
| 46 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 47 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 48 | +# See the License for the specific language governing permissions and |
| 49 | +# limitations under the License. |
| 50 | +import time |
| 51 | +from swimai import SwimClient |
| 52 | + |
| 53 | +THRESHOLD = 1000 |
| 54 | + |
| 55 | + |
| 56 | +async def custom_did_update(key, new_value, old_value): |
| 57 | + if new_value > THRESHOLD: |
| 58 | + print(f'{key} has {new_value} residents') |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == '__main__': |
| 62 | + with SwimClient() as swim_client: |
| 63 | + host_uri = 'warp://localhost:53556' |
| 64 | + node_uri = '/join/state/all' |
| 65 | + lane_uri = 'join' |
| 66 | + |
| 67 | + map_downlink = swim_client.downlink_map() |
| 68 | + map_downlink.set_host_uri(host_uri) |
| 69 | + map_downlink.set_node_uri(node_uri) |
| 70 | + map_downlink.set_lane_uri(lane_uri) |
| 71 | + map_downlink.did_update(custom_did_update) |
| 72 | + map_downlink.open() |
| 73 | + |
| 74 | + time.sleep(2) |
| 75 | + |
| 76 | + print('Stopping the client in 2 seconds') |
| 77 | + time.sleep(2) |
0 commit comments