|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +#ifndef PULSAR_SERVICE_INFO_PROVIDER_H_ |
| 20 | +#define PULSAR_SERVICE_INFO_PROVIDER_H_ |
| 21 | + |
| 22 | +#include <pulsar/ServiceInfo.h> |
| 23 | + |
| 24 | +#include <functional> |
| 25 | + |
| 26 | +namespace pulsar { |
| 27 | + |
| 28 | +class PULSAR_PUBLIC ServiceInfoProvider { |
| 29 | + public: |
| 30 | + /** |
| 31 | + * The destructor will be called when `Client::close()` is invoked, and the provider should stop any |
| 32 | + * ongoing work and release the resources in the destructor. |
| 33 | + */ |
| 34 | + virtual ~ServiceInfoProvider() = default; |
| 35 | + |
| 36 | + /** |
| 37 | + * Get the initial `ServiceInfo` connection for the client. |
| 38 | + * This method is called **only once** internally in `Client::create()` to get the initial `ServiceInfo` |
| 39 | + * for the client to connect to the Pulsar service, typically before {@link initialize} is invoked. |
| 40 | + * Since it's only called once, it's legal to return a moved `ServiceInfo` object to avoid unnecessary |
| 41 | + * copying. |
| 42 | + */ |
| 43 | + virtual ServiceInfo initialServiceInfo() = 0; |
| 44 | + |
| 45 | + /** |
| 46 | + * Initialize the ServiceInfoProvider. |
| 47 | + * |
| 48 | + * After the client has obtained the initial `ServiceInfo` via {@link initialServiceInfo}, this method is |
| 49 | + * called to allow the provider to start any background work (for example, service discovery or watching |
| 50 | + * configuration changes) and to report subsequent updates to the service information. |
| 51 | + * |
| 52 | + * @param onServiceInfoUpdate the callback to deliver updated `ServiceInfo` values to the client after |
| 53 | + * the initial connection has been established |
| 54 | + * |
| 55 | + * Implementations may choose not to invoke `onServiceInfoUpdate` if the `ServiceInfo` never changes. |
| 56 | + */ |
| 57 | + virtual void initialize(std::function<void(ServiceInfo)> onServiceInfoUpdate) = 0; |
| 58 | +}; |
| 59 | + |
| 60 | +}; // namespace pulsar |
| 61 | + |
| 62 | +#endif |
0 commit comments