From 7374d7c9bdeed1cc501bcfde9c4b1994fef06237 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Wed, 5 Jul 2023 14:55:30 +0000 Subject: [PATCH] Update generated libraries --- .../v1/access_approval_connection.h | 135 ++++++++++++++- .../v1/access_context_manager_connection.h | 139 ++++++++++++++- .../v1/advisory_notifications_connection.h | 158 +++++++++++++++-- .../cloud/aiplatform/v1/dataset_connection.h | 135 ++++++++++++++- .../cloud/aiplatform/v1/endpoint_connection.h | 136 ++++++++++++++- .../aiplatform/v1/featurestore_connection.h | 138 ++++++++++++++- .../featurestore_online_serving_connection.h | 152 ++++++++++++++++- google/cloud/aiplatform/v1/index_connection.h | 135 ++++++++++++++- .../aiplatform/v1/index_endpoint_connection.h | 139 ++++++++++++++- google/cloud/aiplatform/v1/job_connection.h | 133 ++++++++++++++- google/cloud/aiplatform/v1/match_connection.h | 135 ++++++++++++++- .../cloud/aiplatform/v1/metadata_connection.h | 136 ++++++++++++++- .../aiplatform/v1/migration_connection.h | 136 ++++++++++++++- google/cloud/aiplatform/v1/model_connection.h | 135 ++++++++++++++- .../aiplatform/v1/model_garden_connection.h | 138 ++++++++++++++- .../cloud/aiplatform/v1/pipeline_connection.h | 136 ++++++++++++++- .../aiplatform/v1/prediction_connection.h | 136 ++++++++++++++- .../v1/specialist_pool_connection.h | 140 ++++++++++++++- .../aiplatform/v1/tensorboard_connection.h | 138 ++++++++++++++- .../cloud/aiplatform/v1/vizier_connection.h | 135 ++++++++++++++- .../alloydb/v1/alloy_db_admin_connection.h | 135 ++++++++++++++- .../apigateway/v1/api_gateway_connection.h | 138 ++++++++++++++- .../apigeeconnect/v1/connection_connection.h | 138 ++++++++++++++- google/cloud/apikeys/v2/api_keys_connection.h | 131 ++++++++++++++- .../appengine/v1/applications_connection.h | 135 ++++++++++++++- .../v1/authorized_certificates_connection.h | 140 ++++++++++++++- .../v1/authorized_domains_connection.h | 136 ++++++++++++++- .../appengine/v1/domain_mappings_connection.h | 135 ++++++++++++++- .../cloud/appengine/v1/firewall_connection.h | 131 ++++++++++++++- .../cloud/appengine/v1/instances_connection.h | 133 ++++++++++++++- .../cloud/appengine/v1/services_connection.h | 131 ++++++++++++++- .../cloud/appengine/v1/versions_connection.h | 131 ++++++++++++++- .../v1/artifact_registry_connection.h | 136 ++++++++++++++- google/cloud/asset/v1/asset_connection.h | 135 ++++++++++++++- .../v1/assured_workloads_connection.h | 141 +++++++++++++++- google/cloud/automl/v1/auto_ml_connection.h | 130 +++++++++++++- .../cloud/automl/v1/prediction_connection.h | 136 ++++++++++++++- .../v2/bare_metal_solution_connection.h | 136 ++++++++++++++- google/cloud/batch/v1/batch_connection.h | 135 ++++++++++++++- .../v1/app_connections_connection.h | 147 ++++++++++++++-- .../v1/app_connectors_connection.h | 139 ++++++++++++++- .../appgateways/v1/app_gateways_connection.h | 138 ++++++++++++++- .../v1/client_connector_services_connection.h | 159 ++++++++++++++++-- .../v1/client_gateways_connection.h | 147 ++++++++++++++-- .../v1/analytics_hub_connection.h | 138 ++++++++++++++- .../biglake/v1/metastore_connection.h | 136 ++++++++++++++- .../connection/v1/connection_connection.h | 136 ++++++++++++++- .../datapolicies/v1/data_policy_connection.h | 136 ++++++++++++++- .../v1/data_transfer_connection.h | 138 ++++++++++++++- .../migration/v2/migration_connection.h | 136 ++++++++++++++- .../reservation/v1/reservation_connection.h | 138 ++++++++++++++- .../storage/v1/bigquery_read_connection.h | 135 ++++++++++++++- .../storage/v1/bigquery_write_connection.h | 135 ++++++++++++++- .../bigtable_instance_admin_connection.h | 142 +++++++++++++++- .../admin/bigtable_table_admin_connection.h | 140 ++++++++++++++- .../billing/budgets/v1/budget_connection.h | 135 ++++++++++++++- .../billing/v1/cloud_billing_connection.h | 135 ++++++++++++++- .../billing/v1/cloud_catalog_connection.h | 135 ++++++++++++++- ...inauthz_management_service_v1_connection.h | 156 +++++++++++++++-- .../v1/system_policy_v1_connection.h | 135 ++++++++++++++- .../v1/validation_helper_v1_connection.h | 138 ++++++++++++++- .../v1/certificate_manager_connection.h | 138 ++++++++++++++- .../channel/v1/cloud_channel_connection.h | 138 ++++++++++++++- .../cloudbuild/v1/cloud_build_connection.h | 133 ++++++++++++++- .../v2/repository_manager_connection.h | 136 ++++++++++++++- .../composer/v1/environments_connection.h | 135 ++++++++++++++- .../composer/v1/image_versions_connection.h | 135 ++++++++++++++- .../v1/accelerator_types_connection.h | 136 ++++++++++++++- .../addresses/v1/addresses_connection.h | 133 ++++++++++++++- .../autoscalers/v1/autoscalers_connection.h | 133 ++++++++++++++- .../v1/backend_buckets_connection.h | 135 ++++++++++++++- .../v1/backend_services_connection.h | 136 ++++++++++++++- .../disk_types/v1/disk_types_connection.h | 133 ++++++++++++++- .../cloud/compute/disks/v1/disks_connection.h | 130 +++++++++++++- .../v1/external_vpn_gateways_connection.h | 145 ++++++++++++++-- .../v1/firewall_policies_connection.h | 136 ++++++++++++++- .../firewalls/v1/firewalls_connection.h | 133 ++++++++++++++- .../v1/forwarding_rules_connection.h | 136 ++++++++++++++- .../v1/global_addresses_connection.h | 136 ++++++++++++++- .../v1/global_forwarding_rules_connection.h | 149 ++++++++++++++-- ...lobal_network_endpoint_groups_connection.h | 158 +++++++++++++++-- .../v1/global_operations_connection.h | 136 ++++++++++++++- ...lobal_organization_operations_connection.h | 158 +++++++++++++++-- ...bal_public_delegated_prefixes_connection.h | 159 ++++++++++++++++-- .../v1/health_checks_connection.h | 135 ++++++++++++++- .../v1/http_health_checks_connection.h | 136 ++++++++++++++- .../v1/https_health_checks_connection.h | 136 ++++++++++++++- .../v1/image_family_views_connection.h | 136 ++++++++++++++- .../compute/images/v1/images_connection.h | 130 +++++++++++++- .../v1/instance_group_managers_connection.h | 149 ++++++++++++++-- .../v1/instance_groups_connection.h | 135 ++++++++++++++- .../v1/instance_templates_connection.h | 136 ++++++++++++++- .../instances/v1/instances_connection.h | 133 ++++++++++++++- .../v1/interconnect_attachments_connection.h | 150 +++++++++++++++-- .../v1/interconnect_locations_connection.h | 149 ++++++++++++++-- .../v1/interconnects_connection.h | 135 ++++++++++++++- .../v1/license_codes_connection.h | 135 ++++++++++++++- .../compute/licenses/v1/licenses_connection.h | 131 ++++++++++++++- .../v1/machine_images_connection.h | 135 ++++++++++++++- .../v1/machine_types_connection.h | 135 ++++++++++++++- .../v1/network_attachments_connection.h | 138 ++++++++++++++- ...etwork_edge_security_services_connection.h | 158 +++++++++++++++-- .../v1/network_endpoint_groups_connection.h | 149 ++++++++++++++-- .../v1/network_firewall_policies_connection.h | 150 +++++++++++++++-- .../compute/networks/v1/networks_connection.h | 131 ++++++++++++++- .../node_groups/v1/node_groups_connection.h | 133 ++++++++++++++- .../v1/node_templates_connection.h | 135 ++++++++++++++- .../node_types/v1/node_types_connection.h | 133 ++++++++++++++- .../v1/packet_mirrorings_connection.h | 136 ++++++++++++++- .../compute/projects/v1/projects_connection.h | 131 ++++++++++++++- .../public_advertised_prefixes_connection.h | 155 +++++++++++++++-- .../v1/public_delegated_prefixes_connection.h | 150 +++++++++++++++-- .../v1/region_autoscalers_connection.h | 136 ++++++++++++++- .../v1/region_backend_services_connection.h | 149 ++++++++++++++-- .../v1/region_commitments_connection.h | 136 ++++++++++++++- .../v1/region_disk_types_connection.h | 136 ++++++++++++++- .../region_disks/v1/region_disks_connection.h | 133 ++++++++++++++- .../region_health_check_services_connection.h | 155 +++++++++++++++-- .../v1/region_health_checks_connection.h | 145 ++++++++++++++-- ...egion_instance_group_managers_connection.h | 158 +++++++++++++++-- .../v1/region_instance_groups_connection.h | 148 ++++++++++++++-- .../v1/region_instance_templates_connection.h | 150 +++++++++++++++-- .../v1/region_instances_connection.h | 136 ++++++++++++++- ...egion_network_endpoint_groups_connection.h | 158 +++++++++++++++-- ...ion_network_firewall_policies_connection.h | 159 ++++++++++++++++-- ...region_notification_endpoints_connection.h | 158 +++++++++++++++-- .../v1/region_operations_connection.h | 136 ++++++++++++++- .../v1/region_security_policies_connection.h | 149 ++++++++++++++-- .../v1/region_ssl_certificates_connection.h | 149 ++++++++++++++-- .../v1/region_ssl_policies_connection.h | 136 ++++++++++++++- .../region_target_http_proxies_connection.h | 150 +++++++++++++++-- .../region_target_https_proxies_connection.h | 155 +++++++++++++++-- .../v1/region_target_tcp_proxies_connection.h | 149 ++++++++++++++-- .../v1/region_url_maps_connection.h | 135 ++++++++++++++- .../compute/regions/v1/regions_connection.h | 131 ++++++++++++++- .../reservations/v1/reservations_connection.h | 135 ++++++++++++++- .../v1/resource_policies_connection.h | 136 ++++++++++++++- .../compute/routers/v1/routers_connection.h | 131 ++++++++++++++- .../compute/routes/v1/routes_connection.h | 130 +++++++++++++- .../v1/security_policies_connection.h | 136 ++++++++++++++- .../v1/service_attachments_connection.h | 138 ++++++++++++++- .../snapshots/v1/snapshots_connection.h | 133 ++++++++++++++- .../v1/ssl_certificates_connection.h | 136 ++++++++++++++- .../ssl_policies/v1/ssl_policies_connection.h | 133 ++++++++++++++- .../subnetworks/v1/subnetworks_connection.h | 133 ++++++++++++++- .../v1/target_grpc_proxies_connection.h | 136 ++++++++++++++- .../v1/target_http_proxies_connection.h | 136 ++++++++++++++- .../v1/target_https_proxies_connection.h | 145 ++++++++++++++-- .../v1/target_instances_connection.h | 136 ++++++++++++++- .../target_pools/v1/target_pools_connection.h | 133 ++++++++++++++- .../v1/target_ssl_proxies_connection.h | 136 ++++++++++++++- .../v1/target_tcp_proxies_connection.h | 136 ++++++++++++++- .../v1/target_vpn_gateways_connection.h | 136 ++++++++++++++- .../compute/url_maps/v1/url_maps_connection.h | 131 ++++++++++++++- .../vpn_gateways/v1/vpn_gateways_connection.h | 133 ++++++++++++++- .../vpn_tunnels/v1/vpn_tunnels_connection.h | 133 ++++++++++++++- .../v1/zone_operations_connection.h | 135 ++++++++++++++- .../cloud/compute/zones/v1/zones_connection.h | 130 +++++++++++++- .../v1/confidential_computing_connection.h | 140 ++++++++++++++- .../connectors/v1/connectors_connection.h | 133 ++++++++++++++- .../v1/contact_center_insights_connection.h | 140 ++++++++++++++- .../container/v1/cluster_manager_connection.h | 135 ++++++++++++++- .../v1/container_analysis_connection.h | 136 ++++++++++++++- .../containeranalysis/v1/grafeas_connection.h | 131 ++++++++++++++- .../contentwarehouse/v1/document_connection.h | 136 ++++++++++++++- .../v1/document_link_connection.h | 138 ++++++++++++++- .../v1/document_schema_connection.h | 140 ++++++++++++++- .../contentwarehouse/v1/rule_set_connection.h | 135 ++++++++++++++- .../v1/synonym_set_connection.h | 136 ++++++++++++++- .../lineage/v1/lineage_connection.h | 131 ++++++++++++++- .../datacatalog/v1/data_catalog_connection.h | 133 ++++++++++++++- .../v1/policy_tag_manager_connection.h | 136 ++++++++++++++- ...icy_tag_manager_serialization_connection.h | 150 ++++++++++++++++- .../datafusion/v1/data_fusion_connection.h | 133 ++++++++++++++- .../v1/data_migration_connection.h | 139 ++++++++++++++- google/cloud/dataplex/v1/content_connection.h | 135 ++++++++++++++- .../cloud/dataplex/v1/dataplex_connection.h | 136 ++++++++++++++- .../cloud/dataplex/v1/metadata_connection.h | 136 ++++++++++++++- .../v1/autoscaling_policy_connection.h | 146 +++++++++++++++- .../dataproc/v1/batch_controller_connection.h | 136 ++++++++++++++- .../v1/cluster_controller_connection.h | 136 ++++++++++++++- .../dataproc/v1/job_controller_connection.h | 135 ++++++++++++++- .../v1/workflow_template_connection.h | 141 +++++++++++++++- .../datastream/v1/datastream_connection.h | 133 ++++++++++++++- .../cloud/deploy/v1/cloud_deploy_connection.h | 133 ++++++++++++++- .../cloud/dialogflow_cx/agents_connection.h | 130 +++++++++++++- .../dialogflow_cx/changelogs_connection.h | 133 ++++++++++++++- .../dialogflow_cx/deployments_connection.h | 133 ++++++++++++++- .../dialogflow_cx/entity_types_connection.h | 133 ++++++++++++++- .../dialogflow_cx/environments_connection.h | 135 ++++++++++++++- .../dialogflow_cx/experiments_connection.h | 133 ++++++++++++++- google/cloud/dialogflow_cx/flows_connection.h | 130 +++++++++++++- .../cloud/dialogflow_cx/intents_connection.h | 131 ++++++++++++++- google/cloud/dialogflow_cx/pages_connection.h | 130 +++++++++++++- .../security_settings_connection.h | 141 +++++++++++++++- .../session_entity_types_connection.h | 138 ++++++++++++++- .../cloud/dialogflow_cx/sessions_connection.h | 131 ++++++++++++++- .../dialogflow_cx/test_cases_connection.h | 133 ++++++++++++++- .../transition_route_groups_connection.h | 140 ++++++++++++++- .../cloud/dialogflow_cx/versions_connection.h | 131 ++++++++++++++- .../cloud/dialogflow_cx/webhooks_connection.h | 131 ++++++++++++++- .../cloud/dialogflow_es/agents_connection.h | 130 +++++++++++++- .../dialogflow_es/answer_records_connection.h | 135 ++++++++++++++- .../cloud/dialogflow_es/contexts_connection.h | 131 ++++++++++++++- .../conversation_datasets_connection.h | 139 ++++++++++++++- .../conversation_models_connection.h | 138 ++++++++++++++- .../conversation_profiles_connection.h | 139 ++++++++++++++- .../dialogflow_es/conversations_connection.h | 135 ++++++++++++++- .../dialogflow_es/documents_connection.h | 133 ++++++++++++++- .../dialogflow_es/entity_types_connection.h | 133 ++++++++++++++- .../dialogflow_es/environments_connection.h | 135 ++++++++++++++- .../dialogflow_es/fulfillments_connection.h | 135 ++++++++++++++- .../cloud/dialogflow_es/intents_connection.h | 131 ++++++++++++++- .../knowledge_bases_connection.h | 135 ++++++++++++++- .../dialogflow_es/participants_connection.h | 135 ++++++++++++++- .../session_entity_types_connection.h | 138 ++++++++++++++- .../cloud/dialogflow_es/sessions_connection.h | 131 ++++++++++++++- .../cloud/dialogflow_es/versions_connection.h | 131 ++++++++++++++- google/cloud/dlp/v2/dlp_connection.h | 133 ++++++++++++++- .../v1/document_processor_connection.h | 146 +++++++++++++++- google/cloud/domains/v1/domains_connection.h | 131 ++++++++++++++- .../v1/edge_container_connection.h | 135 ++++++++++++++- .../v1/essential_contacts_connection.h | 146 +++++++++++++++- .../publishing/v1/publisher_connection.h | 133 ++++++++++++++- .../cloud/eventarc/v1/eventarc_connection.h | 133 ++++++++++++++- .../v1/cloud_filestore_manager_connection.h | 140 ++++++++++++++- .../functions/v1/cloud_functions_connection.h | 140 ++++++++++++++- .../gkebackup/v1/backup_for_gke_connection.h | 135 ++++++++++++++- google/cloud/gkehub/v1/gke_hub_connection.h | 130 +++++++++++++- .../v1/attached_clusters_connection.h | 136 ++++++++++++++- .../v1/aws_clusters_connection.h | 133 ++++++++++++++- .../v1/azure_clusters_connection.h | 135 ++++++++++++++- google/cloud/iam/admin/v1/iam_connection.h | 130 +++++++++++++- .../v1/iam_credentials_connection.h | 135 ++++++++++++++- google/cloud/iam/v1/iam_policy_connection.h | 133 ++++++++++++++- google/cloud/iam/v2/policies_connection.h | 131 ++++++++++++++- .../identity_aware_proxy_admin_connection.h | 150 ++++++++++++++++- .../identity_aware_proxy_o_auth_connection.h | 150 ++++++++++++++++- google/cloud/ids/v1/ids_connection.h | 130 +++++++++++++- .../cloud/iot/v1/device_manager_connection.h | 135 ++++++++++++++- .../inventory/v1/key_dashboard_connection.h | 138 ++++++++++++++- .../inventory/v1/key_tracking_connection.h | 138 ++++++++++++++- google/cloud/kms/v1/ekm_connection.h | 133 ++++++++++++++- .../cloud/kms/v1/key_management_connection.h | 139 ++++++++++++++- .../cloud/language/v1/language_connection.h | 136 ++++++++++++++- .../v2/logging_service_v2_connection.h | 138 ++++++++++++++- .../v1/managed_identities_connection.h | 146 +++++++++++++++- .../memcache/v1/cloud_memcache_connection.h | 135 ++++++++++++++- .../v1/dataproc_metastore_connection.h | 136 ++++++++++++++- ...dataproc_metastore_federation_connection.h | 149 +++++++++++++++- .../v1/migration_center_connection.h | 136 ++++++++++++++- .../dashboard/v1/dashboards_connection.h | 136 ++++++++++++++- .../v1/metrics_scopes_connection.h | 135 ++++++++++++++- .../monitoring/v3/alert_policy_connection.h | 138 ++++++++++++++- google/cloud/monitoring/v3/group_connection.h | 135 ++++++++++++++- .../cloud/monitoring/v3/metric_connection.h | 135 ++++++++++++++- .../v3/notification_channel_connection.h | 149 +++++++++++++++- google/cloud/monitoring/v3/query_connection.h | 135 ++++++++++++++- .../v3/service_monitoring_connection.h | 146 +++++++++++++++- .../monitoring/v3/uptime_check_connection.h | 138 ++++++++++++++- .../networkconnectivity/v1/hub_connection.h | 133 ++++++++++++++- .../v1/reachability_connection.h | 138 ++++++++++++++- .../v1/network_security_connection.h | 136 ++++++++++++++- .../v1/network_services_connection.h | 136 ++++++++++++++- .../v1/managed_notebook_connection.h | 140 ++++++++++++++- .../cloud/notebooks/v1/notebook_connection.h | 136 ++++++++++++++- .../v1/fleet_routing_connection.h | 135 ++++++++++++++- .../orgpolicy/v2/org_policy_connection.h | 133 ++++++++++++++- .../v1/agent_endpoint_connection.h | 139 ++++++++++++++- .../cloud/osconfig/v1/os_config_connection.h | 136 ++++++++++++++- google/cloud/oslogin/v1/os_login_connection.h | 135 ++++++++++++++- .../v1/iam_checker_connection.h | 133 ++++++++++++++- .../v1/certificate_authority_connection.h | 151 ++++++++++++++++- .../cloud/profiler/v2/profiler_connection.h | 136 ++++++++++++++- google/cloud/pubsub/schema_connection.h | 135 ++++++++++++++- google/cloud/pubsublite/admin_connection.h | 137 ++++++++++++++- .../cloud/pubsublite/topic_stats_connection.h | 138 ++++++++++++++- .../rapid_migration_assessment_connection.h | 153 +++++++++++++++-- .../v1/recaptcha_enterprise_connection.h | 149 +++++++++++++++- .../recommender/v1/recommender_connection.h | 133 ++++++++++++++- .../cloud/redis/v1/cloud_redis_connection.h | 133 ++++++++++++++- .../resourcemanager/v3/folders_connection.h | 131 ++++++++++++++- .../v3/organizations_connection.h | 135 ++++++++++++++- .../resourcemanager/v3/projects_connection.h | 131 ++++++++++++++- .../v1/resource_settings_connection.h | 141 +++++++++++++++- google/cloud/retail/v2/catalog_connection.h | 135 ++++++++++++++- .../cloud/retail/v2/completion_connection.h | 136 ++++++++++++++- .../cloud/retail/v2/prediction_connection.h | 136 ++++++++++++++- google/cloud/retail/v2/product_connection.h | 135 ++++++++++++++- google/cloud/retail/v2/search_connection.h | 135 ++++++++++++++- .../cloud/retail/v2/user_event_connection.h | 136 ++++++++++++++- google/cloud/run/v2/revisions_connection.h | 133 ++++++++++++++- google/cloud/run/v2/services_connection.h | 131 ++++++++++++++- .../scheduler/v1/cloud_scheduler_connection.h | 135 ++++++++++++++- .../v1/secret_manager_connection.h | 139 ++++++++++++++- .../v1/security_center_connection.h | 135 ++++++++++++++- .../v1/quota_controller_connection.h | 136 ++++++++++++++- .../v1/service_controller_connection.h | 136 ++++++++++++++- .../v2/service_controller_connection.h | 136 ++++++++++++++- .../servicedirectory/v1/lookup_connection.h | 137 ++++++++++++++- .../v1/registration_connection.h | 140 ++++++++++++++- .../v1/service_manager_connection.h | 135 ++++++++++++++- .../v1/service_usage_connection.h | 135 ++++++++++++++- .../cloud/shell/v1/cloud_shell_connection.h | 138 ++++++++++++++- .../spanner/admin/database_admin_connection.h | 135 ++++++++++++++- .../spanner/admin/instance_admin_connection.h | 135 ++++++++++++++- google/cloud/speech/v1/speech_connection.h | 130 +++++++++++++- google/cloud/speech/v2/speech_connection.h | 130 +++++++++++++- .../cloud/sql/v1/sql_backup_runs_connection.h | 139 ++++++++++++++- google/cloud/sql/v1/sql_connect_connection.h | 136 ++++++++++++++- .../cloud/sql/v1/sql_databases_connection.h | 138 ++++++++++++++- google/cloud/sql/v1/sql_flags_connection.h | 136 ++++++++++++++- .../cloud/sql/v1/sql_instances_connection.h | 138 ++++++++++++++- .../cloud/sql/v1/sql_operations_connection.h | 139 ++++++++++++++- .../cloud/sql/v1/sql_ssl_certs_connection.h | 138 ++++++++++++++- google/cloud/sql/v1/sql_tiers_connection.h | 136 ++++++++++++++- google/cloud/sql/v1/sql_users_connection.h | 136 ++++++++++++++- .../v1/storage_insights_connection.h | 136 ++++++++++++++- .../v1/storage_transfer_connection.h | 140 ++++++++++++++- .../support/v2/case_attachment_connection.h | 140 ++++++++++++++- google/cloud/support/v2/case_connection.h | 133 ++++++++++++++- google/cloud/support/v2/comment_connection.h | 135 ++++++++++++++- google/cloud/talent/v4/company_connection.h | 135 ++++++++++++++- .../cloud/talent/v4/completion_connection.h | 133 ++++++++++++++- google/cloud/talent/v4/event_connection.h | 135 ++++++++++++++- google/cloud/talent/v4/job_connection.h | 133 ++++++++++++++- google/cloud/talent/v4/tenant_connection.h | 135 ++++++++++++++- .../cloud/tasks/v2/cloud_tasks_connection.h | 135 ++++++++++++++- .../v1/text_to_speech_connection.h | 135 ++++++++++++++- ...imeseries_insights_controller_connection.h | 156 +++++++++++++++-- google/cloud/tpu/v1/tpu_connection.h | 130 +++++++++++++- google/cloud/tpu/v2/tpu_connection.h | 130 +++++++++++++- google/cloud/trace/v1/trace_connection.h | 135 ++++++++++++++- google/cloud/trace/v2/trace_connection.h | 135 ++++++++++++++- .../translate/v3/translation_connection.h | 138 ++++++++++++++- .../livestream/v1/livestream_connection.h | 136 ++++++++++++++- .../stitcher/v1/video_stitcher_connection.h | 139 ++++++++++++++- .../transcoder/v1/transcoder_connection.h | 136 ++++++++++++++- .../v1/video_intelligence_connection.h | 146 +++++++++++++++- .../vision/v1/image_annotator_connection.h | 135 ++++++++++++++- .../vision/v1/product_search_connection.h | 135 ++++++++++++++- .../vmmigration/v1/vm_migration_connection.h | 133 ++++++++++++++- .../v1/vmware_engine_connection.h | 135 ++++++++++++++- .../vpcaccess/v1/vpc_access_connection.h | 138 ++++++++++++++- google/cloud/webrisk/v1/web_risk_connection.h | 135 ++++++++++++++- .../v1/web_security_scanner_connection.h | 138 ++++++++++++++- .../executions/v1/executions_connection.h | 133 ++++++++++++++- .../cloud/workflows/v1/workflows_connection.h | 133 ++++++++++++++- .../workstations/v1/workstations_connection.h | 135 ++++++++++++++- 349 files changed, 44722 insertions(+), 3227 deletions(-) diff --git a/google/cloud/accessapproval/v1/access_approval_connection.h b/google/cloud/accessapproval/v1/access_approval_connection.h index 794dc75bc47d8..613727bf693d7 100644 --- a/google/cloud/accessapproval/v1/access_approval_connection.h +++ b/google/cloud/accessapproval/v1/access_approval_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace accessapproval_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AccessApprovalRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - accessapproval_v1_internal::AccessApprovalRetryTraits>; +/// The retry policy for `AccessApprovalConnection`. +class AccessApprovalRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AccessApprovalConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AccessApprovalLimitedErrorCountRetryPolicy + : public AccessApprovalRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AccessApprovalLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AccessApprovalLimitedErrorCountRetryPolicy( + AccessApprovalLimitedErrorCountRetryPolicy&& rhs) noexcept + : AccessApprovalLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AccessApprovalLimitedErrorCountRetryPolicy( + AccessApprovalLimitedErrorCountRetryPolicy const& rhs) noexcept + : AccessApprovalLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AccessApprovalRetryPolicy; -using AccessApprovalLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - accessapproval_v1_internal::AccessApprovalRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + accessapproval_v1_internal::AccessApprovalRetryTraits> + impl_; +}; + +/** + * A retry policy for `AccessApprovalConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AccessApprovalLimitedTimeRetryPolicy : public AccessApprovalRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AccessApprovalLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AccessApprovalLimitedTimeRetryPolicy( + AccessApprovalLimitedTimeRetryPolicy&& rhs) noexcept + : AccessApprovalLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AccessApprovalLimitedTimeRetryPolicy( + AccessApprovalLimitedTimeRetryPolicy const& rhs) noexcept + : AccessApprovalLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AccessApprovalLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - accessapproval_v1_internal::AccessApprovalRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AccessApprovalRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + accessapproval_v1_internal::AccessApprovalRetryTraits> + impl_; +}; /** * The `AccessApprovalConnection` object for `AccessApprovalClient`. diff --git a/google/cloud/accesscontextmanager/v1/access_context_manager_connection.h b/google/cloud/accesscontextmanager/v1/access_context_manager_connection.h index 8c3687ab4ca34..972f61f090595 100644 --- a/google/cloud/accesscontextmanager/v1/access_context_manager_connection.h +++ b/google/cloud/accesscontextmanager/v1/access_context_manager_connection.h @@ -38,17 +38,138 @@ namespace cloud { namespace accesscontextmanager_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AccessContextManagerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - accesscontextmanager_v1_internal::AccessContextManagerRetryTraits>; +/// The retry policy for `AccessContextManagerConnection`. +class AccessContextManagerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AccessContextManagerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - accesscontextmanager_v1_internal::AccessContextManagerRetryTraits>; +/** + * A retry policy for `AccessContextManagerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AccessContextManagerLimitedErrorCountRetryPolicy + : public AccessContextManagerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AccessContextManagerLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + AccessContextManagerLimitedErrorCountRetryPolicy( + AccessContextManagerLimitedErrorCountRetryPolicy&& rhs) noexcept + : AccessContextManagerLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AccessContextManagerLimitedErrorCountRetryPolicy( + AccessContextManagerLimitedErrorCountRetryPolicy const& rhs) noexcept + : AccessContextManagerLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AccessContextManagerRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + accesscontextmanager_v1_internal::AccessContextManagerRetryTraits> + impl_; +}; -using AccessContextManagerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - accesscontextmanager_v1_internal::AccessContextManagerRetryTraits>; +/** + * A retry policy for `AccessContextManagerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AccessContextManagerLimitedTimeRetryPolicy + : public AccessContextManagerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AccessContextManagerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AccessContextManagerLimitedTimeRetryPolicy( + AccessContextManagerLimitedTimeRetryPolicy&& rhs) noexcept + : AccessContextManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AccessContextManagerLimitedTimeRetryPolicy( + AccessContextManagerLimitedTimeRetryPolicy const& rhs) noexcept + : AccessContextManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AccessContextManagerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + accesscontextmanager_v1_internal::AccessContextManagerRetryTraits> + impl_; +}; /** * The `AccessContextManagerConnection` object for `AccessContextManagerClient`. diff --git a/google/cloud/advisorynotifications/v1/advisory_notifications_connection.h b/google/cloud/advisorynotifications/v1/advisory_notifications_connection.h index 8a770cbb1b765..1f0719d716d2f 100644 --- a/google/cloud/advisorynotifications/v1/advisory_notifications_connection.h +++ b/google/cloud/advisorynotifications/v1/advisory_notifications_connection.h @@ -35,20 +35,150 @@ namespace cloud { namespace advisorynotifications_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AdvisoryNotificationsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - advisorynotifications_v1_internal:: - AdvisoryNotificationsServiceRetryTraits>; - -using AdvisoryNotificationsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - advisorynotifications_v1_internal:: - AdvisoryNotificationsServiceRetryTraits>; - -using AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - advisorynotifications_v1_internal:: - AdvisoryNotificationsServiceRetryTraits>; +/// The retry policy for `AdvisoryNotificationsServiceConnection`. +class AdvisoryNotificationsServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `AdvisoryNotificationsServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy + : public AdvisoryNotificationsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy( + AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy( + AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + AdvisoryNotificationsServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AdvisoryNotificationsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + advisorynotifications_v1_internal:: + AdvisoryNotificationsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `AdvisoryNotificationsServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AdvisoryNotificationsServiceLimitedTimeRetryPolicy + : public AdvisoryNotificationsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AdvisoryNotificationsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AdvisoryNotificationsServiceLimitedTimeRetryPolicy( + AdvisoryNotificationsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AdvisoryNotificationsServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + AdvisoryNotificationsServiceLimitedTimeRetryPolicy( + AdvisoryNotificationsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AdvisoryNotificationsServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AdvisoryNotificationsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + advisorynotifications_v1_internal:: + AdvisoryNotificationsServiceRetryTraits> + impl_; +}; /** * The `AdvisoryNotificationsServiceConnection` object for diff --git a/google/cloud/aiplatform/v1/dataset_connection.h b/google/cloud/aiplatform/v1/dataset_connection.h index a7503c53ba9fc..196ba60a8c45c 100644 --- a/google/cloud/aiplatform/v1/dataset_connection.h +++ b/google/cloud/aiplatform/v1/dataset_connection.h @@ -39,17 +39,134 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DatasetServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::DatasetServiceRetryTraits>; +/// The retry policy for `DatasetServiceConnection`. +class DatasetServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DatasetServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DatasetServiceLimitedErrorCountRetryPolicy + : public DatasetServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DatasetServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DatasetServiceLimitedErrorCountRetryPolicy( + DatasetServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DatasetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DatasetServiceLimitedErrorCountRetryPolicy( + DatasetServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DatasetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DatasetServiceRetryPolicy; -using DatasetServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::DatasetServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::DatasetServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `DatasetServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DatasetServiceLimitedTimeRetryPolicy : public DatasetServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DatasetServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DatasetServiceLimitedTimeRetryPolicy( + DatasetServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DatasetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DatasetServiceLimitedTimeRetryPolicy( + DatasetServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DatasetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DatasetServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::DatasetServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DatasetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::DatasetServiceRetryTraits> + impl_; +}; /** * The `DatasetServiceConnection` object for `DatasetServiceClient`. diff --git a/google/cloud/aiplatform/v1/endpoint_connection.h b/google/cloud/aiplatform/v1/endpoint_connection.h index 469606ddc143b..1c6b11115e1fe 100644 --- a/google/cloud/aiplatform/v1/endpoint_connection.h +++ b/google/cloud/aiplatform/v1/endpoint_connection.h @@ -39,17 +39,135 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EndpointServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::EndpointServiceRetryTraits>; +/// The retry policy for `EndpointServiceConnection`. +class EndpointServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using EndpointServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::EndpointServiceRetryTraits>; +/** + * A retry policy for `EndpointServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EndpointServiceLimitedErrorCountRetryPolicy + : public EndpointServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EndpointServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EndpointServiceLimitedErrorCountRetryPolicy( + EndpointServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : EndpointServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EndpointServiceLimitedErrorCountRetryPolicy( + EndpointServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : EndpointServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EndpointServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::EndpointServiceRetryTraits> + impl_; +}; -using EndpointServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::EndpointServiceRetryTraits>; +/** + * A retry policy for `EndpointServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EndpointServiceLimitedTimeRetryPolicy + : public EndpointServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EndpointServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EndpointServiceLimitedTimeRetryPolicy( + EndpointServiceLimitedTimeRetryPolicy&& rhs) noexcept + : EndpointServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EndpointServiceLimitedTimeRetryPolicy( + EndpointServiceLimitedTimeRetryPolicy const& rhs) noexcept + : EndpointServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EndpointServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::EndpointServiceRetryTraits> + impl_; +}; /** * The `EndpointServiceConnection` object for `EndpointServiceClient`. diff --git a/google/cloud/aiplatform/v1/featurestore_connection.h b/google/cloud/aiplatform/v1/featurestore_connection.h index 17baa30e422b9..aba807f30157a 100644 --- a/google/cloud/aiplatform/v1/featurestore_connection.h +++ b/google/cloud/aiplatform/v1/featurestore_connection.h @@ -39,17 +39,137 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FeaturestoreServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::FeaturestoreServiceRetryTraits>; +/// The retry policy for `FeaturestoreServiceConnection`. +class FeaturestoreServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using FeaturestoreServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::FeaturestoreServiceRetryTraits>; +/** + * A retry policy for `FeaturestoreServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FeaturestoreServiceLimitedErrorCountRetryPolicy + : public FeaturestoreServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FeaturestoreServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + FeaturestoreServiceLimitedErrorCountRetryPolicy( + FeaturestoreServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : FeaturestoreServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + FeaturestoreServiceLimitedErrorCountRetryPolicy( + FeaturestoreServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : FeaturestoreServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FeaturestoreServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::FeaturestoreServiceRetryTraits> + impl_; +}; -using FeaturestoreServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::FeaturestoreServiceRetryTraits>; +/** + * A retry policy for `FeaturestoreServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FeaturestoreServiceLimitedTimeRetryPolicy + : public FeaturestoreServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FeaturestoreServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FeaturestoreServiceLimitedTimeRetryPolicy( + FeaturestoreServiceLimitedTimeRetryPolicy&& rhs) noexcept + : FeaturestoreServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + FeaturestoreServiceLimitedTimeRetryPolicy( + FeaturestoreServiceLimitedTimeRetryPolicy const& rhs) noexcept + : FeaturestoreServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FeaturestoreServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::FeaturestoreServiceRetryTraits> + impl_; +}; /** * The `FeaturestoreServiceConnection` object for `FeaturestoreServiceClient`. diff --git a/google/cloud/aiplatform/v1/featurestore_online_serving_connection.h b/google/cloud/aiplatform/v1/featurestore_online_serving_connection.h index 22126421d1285..4df76e75a827b 100644 --- a/google/cloud/aiplatform/v1/featurestore_online_serving_connection.h +++ b/google/cloud/aiplatform/v1/featurestore_online_serving_connection.h @@ -36,17 +36,151 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FeaturestoreOnlineServingServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::FeaturestoreOnlineServingServiceRetryTraits>; +/// The retry policy for `FeaturestoreOnlineServingServiceConnection`. +class FeaturestoreOnlineServingServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `FeaturestoreOnlineServingServiceConnection` based on + * counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy + : public FeaturestoreOnlineServingServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy( + FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy&& + rhs) noexcept + : FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy( + FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FeaturestoreOnlineServingServiceRetryPolicy; -using FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::FeaturestoreOnlineServingServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::FeaturestoreOnlineServingServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `FeaturestoreOnlineServingServiceConnection` based on + * elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy + : public FeaturestoreOnlineServingServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy( + FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy&& rhs) noexcept + : FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy( + FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy const& + rhs) noexcept + : FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using FeaturestoreOnlineServingServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::FeaturestoreOnlineServingServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + FeaturestoreOnlineServingServiceLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FeaturestoreOnlineServingServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::FeaturestoreOnlineServingServiceRetryTraits> + impl_; +}; /** * The `FeaturestoreOnlineServingServiceConnection` object for diff --git a/google/cloud/aiplatform/v1/index_connection.h b/google/cloud/aiplatform/v1/index_connection.h index a91ac9f12518f..f58844a189316 100644 --- a/google/cloud/aiplatform/v1/index_connection.h +++ b/google/cloud/aiplatform/v1/index_connection.h @@ -39,17 +39,134 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IndexServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::IndexServiceRetryTraits>; +/// The retry policy for `IndexServiceConnection`. +class IndexServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using IndexServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::IndexServiceRetryTraits>; +/** + * A retry policy for `IndexServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IndexServiceLimitedErrorCountRetryPolicy + : public IndexServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IndexServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + IndexServiceLimitedErrorCountRetryPolicy( + IndexServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : IndexServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + IndexServiceLimitedErrorCountRetryPolicy( + IndexServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : IndexServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IndexServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::IndexServiceRetryTraits> + impl_; +}; -using IndexServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::IndexServiceRetryTraits>; +/** + * A retry policy for `IndexServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IndexServiceLimitedTimeRetryPolicy : public IndexServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IndexServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IndexServiceLimitedTimeRetryPolicy( + IndexServiceLimitedTimeRetryPolicy&& rhs) noexcept + : IndexServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IndexServiceLimitedTimeRetryPolicy( + IndexServiceLimitedTimeRetryPolicy const& rhs) noexcept + : IndexServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IndexServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::IndexServiceRetryTraits> + impl_; +}; /** * The `IndexServiceConnection` object for `IndexServiceClient`. diff --git a/google/cloud/aiplatform/v1/index_endpoint_connection.h b/google/cloud/aiplatform/v1/index_endpoint_connection.h index 33b52a0d72d6f..1e5592a6c1425 100644 --- a/google/cloud/aiplatform/v1/index_endpoint_connection.h +++ b/google/cloud/aiplatform/v1/index_endpoint_connection.h @@ -39,17 +39,138 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IndexEndpointServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::IndexEndpointServiceRetryTraits>; +/// The retry policy for `IndexEndpointServiceConnection`. +class IndexEndpointServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `IndexEndpointServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IndexEndpointServiceLimitedErrorCountRetryPolicy + : public IndexEndpointServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IndexEndpointServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + IndexEndpointServiceLimitedErrorCountRetryPolicy( + IndexEndpointServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : IndexEndpointServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + IndexEndpointServiceLimitedErrorCountRetryPolicy( + IndexEndpointServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : IndexEndpointServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IndexEndpointServiceRetryPolicy; -using IndexEndpointServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::IndexEndpointServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::IndexEndpointServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `IndexEndpointServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IndexEndpointServiceLimitedTimeRetryPolicy + : public IndexEndpointServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IndexEndpointServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IndexEndpointServiceLimitedTimeRetryPolicy( + IndexEndpointServiceLimitedTimeRetryPolicy&& rhs) noexcept + : IndexEndpointServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IndexEndpointServiceLimitedTimeRetryPolicy( + IndexEndpointServiceLimitedTimeRetryPolicy const& rhs) noexcept + : IndexEndpointServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using IndexEndpointServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::IndexEndpointServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IndexEndpointServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::IndexEndpointServiceRetryTraits> + impl_; +}; /** * The `IndexEndpointServiceConnection` object for `IndexEndpointServiceClient`. diff --git a/google/cloud/aiplatform/v1/job_connection.h b/google/cloud/aiplatform/v1/job_connection.h index 27a6f26704bfa..823d6e04c683d 100644 --- a/google/cloud/aiplatform/v1/job_connection.h +++ b/google/cloud/aiplatform/v1/job_connection.h @@ -39,16 +39,133 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using JobServiceRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::JobServiceRetryTraits>; +/// The retry policy for `JobServiceConnection`. +class JobServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using JobServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::JobServiceRetryTraits>; +/** + * A retry policy for `JobServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class JobServiceLimitedErrorCountRetryPolicy : public JobServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit JobServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + JobServiceLimitedErrorCountRetryPolicy( + JobServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : JobServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + JobServiceLimitedErrorCountRetryPolicy( + JobServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : JobServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = JobServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::JobServiceRetryTraits> + impl_; +}; -using JobServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::JobServiceRetryTraits>; +/** + * A retry policy for `JobServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class JobServiceLimitedTimeRetryPolicy : public JobServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit JobServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + JobServiceLimitedTimeRetryPolicy( + JobServiceLimitedTimeRetryPolicy&& rhs) noexcept + : JobServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + JobServiceLimitedTimeRetryPolicy( + JobServiceLimitedTimeRetryPolicy const& rhs) noexcept + : JobServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = JobServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::JobServiceRetryTraits> + impl_; +}; /** * The `JobServiceConnection` object for `JobServiceClient`. diff --git a/google/cloud/aiplatform/v1/match_connection.h b/google/cloud/aiplatform/v1/match_connection.h index e2ff424075d66..fea18a7b0e3a0 100644 --- a/google/cloud/aiplatform/v1/match_connection.h +++ b/google/cloud/aiplatform/v1/match_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MatchServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::MatchServiceRetryTraits>; +/// The retry policy for `MatchServiceConnection`. +class MatchServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `MatchServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MatchServiceLimitedErrorCountRetryPolicy + : public MatchServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MatchServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MatchServiceLimitedErrorCountRetryPolicy( + MatchServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : MatchServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MatchServiceLimitedErrorCountRetryPolicy( + MatchServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : MatchServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MatchServiceRetryPolicy; -using MatchServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::MatchServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::MatchServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `MatchServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MatchServiceLimitedTimeRetryPolicy : public MatchServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MatchServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MatchServiceLimitedTimeRetryPolicy( + MatchServiceLimitedTimeRetryPolicy&& rhs) noexcept + : MatchServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MatchServiceLimitedTimeRetryPolicy( + MatchServiceLimitedTimeRetryPolicy const& rhs) noexcept + : MatchServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using MatchServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::MatchServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MatchServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::MatchServiceRetryTraits> + impl_; +}; /** * The `MatchServiceConnection` object for `MatchServiceClient`. diff --git a/google/cloud/aiplatform/v1/metadata_connection.h b/google/cloud/aiplatform/v1/metadata_connection.h index 1b2e747bd6bb1..b361f4c8c31cb 100644 --- a/google/cloud/aiplatform/v1/metadata_connection.h +++ b/google/cloud/aiplatform/v1/metadata_connection.h @@ -39,17 +39,135 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MetadataServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::MetadataServiceRetryTraits>; +/// The retry policy for `MetadataServiceConnection`. +class MetadataServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using MetadataServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::MetadataServiceRetryTraits>; +/** + * A retry policy for `MetadataServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetadataServiceLimitedErrorCountRetryPolicy + : public MetadataServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MetadataServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MetadataServiceLimitedErrorCountRetryPolicy( + MetadataServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : MetadataServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MetadataServiceLimitedErrorCountRetryPolicy( + MetadataServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : MetadataServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetadataServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::MetadataServiceRetryTraits> + impl_; +}; -using MetadataServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::MetadataServiceRetryTraits>; +/** + * A retry policy for `MetadataServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetadataServiceLimitedTimeRetryPolicy + : public MetadataServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MetadataServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MetadataServiceLimitedTimeRetryPolicy( + MetadataServiceLimitedTimeRetryPolicy&& rhs) noexcept + : MetadataServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MetadataServiceLimitedTimeRetryPolicy( + MetadataServiceLimitedTimeRetryPolicy const& rhs) noexcept + : MetadataServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetadataServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::MetadataServiceRetryTraits> + impl_; +}; /** * The `MetadataServiceConnection` object for `MetadataServiceClient`. diff --git a/google/cloud/aiplatform/v1/migration_connection.h b/google/cloud/aiplatform/v1/migration_connection.h index c760ba4068938..5188000f0ebac 100644 --- a/google/cloud/aiplatform/v1/migration_connection.h +++ b/google/cloud/aiplatform/v1/migration_connection.h @@ -39,17 +39,135 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MigrationServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::MigrationServiceRetryTraits>; +/// The retry policy for `MigrationServiceConnection`. +class MigrationServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `MigrationServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MigrationServiceLimitedErrorCountRetryPolicy + : public MigrationServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MigrationServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MigrationServiceLimitedErrorCountRetryPolicy( + MigrationServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : MigrationServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MigrationServiceLimitedErrorCountRetryPolicy( + MigrationServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : MigrationServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MigrationServiceRetryPolicy; -using MigrationServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::MigrationServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::MigrationServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `MigrationServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MigrationServiceLimitedTimeRetryPolicy + : public MigrationServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MigrationServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MigrationServiceLimitedTimeRetryPolicy( + MigrationServiceLimitedTimeRetryPolicy&& rhs) noexcept + : MigrationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MigrationServiceLimitedTimeRetryPolicy( + MigrationServiceLimitedTimeRetryPolicy const& rhs) noexcept + : MigrationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using MigrationServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::MigrationServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MigrationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::MigrationServiceRetryTraits> + impl_; +}; /** * The `MigrationServiceConnection` object for `MigrationServiceClient`. diff --git a/google/cloud/aiplatform/v1/model_connection.h b/google/cloud/aiplatform/v1/model_connection.h index 6c9f89cb9b7f7..509cad1eed6f4 100644 --- a/google/cloud/aiplatform/v1/model_connection.h +++ b/google/cloud/aiplatform/v1/model_connection.h @@ -39,17 +39,134 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ModelServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::ModelServiceRetryTraits>; +/// The retry policy for `ModelServiceConnection`. +class ModelServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ModelServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ModelServiceLimitedErrorCountRetryPolicy + : public ModelServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ModelServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ModelServiceLimitedErrorCountRetryPolicy( + ModelServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ModelServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ModelServiceLimitedErrorCountRetryPolicy( + ModelServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ModelServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ModelServiceRetryPolicy; -using ModelServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::ModelServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::ModelServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ModelServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ModelServiceLimitedTimeRetryPolicy : public ModelServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ModelServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ModelServiceLimitedTimeRetryPolicy( + ModelServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ModelServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ModelServiceLimitedTimeRetryPolicy( + ModelServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ModelServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ModelServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::ModelServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ModelServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::ModelServiceRetryTraits> + impl_; +}; /** * The `ModelServiceConnection` object for `ModelServiceClient`. diff --git a/google/cloud/aiplatform/v1/model_garden_connection.h b/google/cloud/aiplatform/v1/model_garden_connection.h index 356364a5f7628..9129604b2ec9c 100644 --- a/google/cloud/aiplatform/v1/model_garden_connection.h +++ b/google/cloud/aiplatform/v1/model_garden_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ModelGardenServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::ModelGardenServiceRetryTraits>; +/// The retry policy for `ModelGardenServiceConnection`. +class ModelGardenServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ModelGardenServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ModelGardenServiceLimitedErrorCountRetryPolicy + : public ModelGardenServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ModelGardenServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ModelGardenServiceLimitedErrorCountRetryPolicy( + ModelGardenServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ModelGardenServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + ModelGardenServiceLimitedErrorCountRetryPolicy( + ModelGardenServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ModelGardenServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ModelGardenServiceRetryPolicy; -using ModelGardenServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::ModelGardenServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::ModelGardenServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ModelGardenServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ModelGardenServiceLimitedTimeRetryPolicy + : public ModelGardenServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ModelGardenServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ModelGardenServiceLimitedTimeRetryPolicy( + ModelGardenServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ModelGardenServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ModelGardenServiceLimitedTimeRetryPolicy( + ModelGardenServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ModelGardenServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ModelGardenServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::ModelGardenServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ModelGardenServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::ModelGardenServiceRetryTraits> + impl_; +}; /** * The `ModelGardenServiceConnection` object for `ModelGardenServiceClient`. diff --git a/google/cloud/aiplatform/v1/pipeline_connection.h b/google/cloud/aiplatform/v1/pipeline_connection.h index 2278949298fd3..c425257a38718 100644 --- a/google/cloud/aiplatform/v1/pipeline_connection.h +++ b/google/cloud/aiplatform/v1/pipeline_connection.h @@ -39,17 +39,135 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PipelineServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::PipelineServiceRetryTraits>; +/// The retry policy for `PipelineServiceConnection`. +class PipelineServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PipelineServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PipelineServiceLimitedErrorCountRetryPolicy + : public PipelineServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PipelineServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PipelineServiceLimitedErrorCountRetryPolicy( + PipelineServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : PipelineServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PipelineServiceLimitedErrorCountRetryPolicy( + PipelineServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : PipelineServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PipelineServiceRetryPolicy; -using PipelineServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::PipelineServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::PipelineServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `PipelineServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PipelineServiceLimitedTimeRetryPolicy + : public PipelineServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PipelineServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PipelineServiceLimitedTimeRetryPolicy( + PipelineServiceLimitedTimeRetryPolicy&& rhs) noexcept + : PipelineServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PipelineServiceLimitedTimeRetryPolicy( + PipelineServiceLimitedTimeRetryPolicy const& rhs) noexcept + : PipelineServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using PipelineServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::PipelineServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PipelineServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::PipelineServiceRetryTraits> + impl_; +}; /** * The `PipelineServiceConnection` object for `PipelineServiceClient`. diff --git a/google/cloud/aiplatform/v1/prediction_connection.h b/google/cloud/aiplatform/v1/prediction_connection.h index b3b8b499b2a45..a5cb0f88bc3fa 100644 --- a/google/cloud/aiplatform/v1/prediction_connection.h +++ b/google/cloud/aiplatform/v1/prediction_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PredictionServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::PredictionServiceRetryTraits>; +/// The retry policy for `PredictionServiceConnection`. +class PredictionServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PredictionServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PredictionServiceLimitedErrorCountRetryPolicy + : public PredictionServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PredictionServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PredictionServiceLimitedErrorCountRetryPolicy( + PredictionServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : PredictionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PredictionServiceLimitedErrorCountRetryPolicy( + PredictionServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : PredictionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PredictionServiceRetryPolicy; -using PredictionServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::PredictionServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::PredictionServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `PredictionServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PredictionServiceLimitedTimeRetryPolicy + : public PredictionServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PredictionServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PredictionServiceLimitedTimeRetryPolicy( + PredictionServiceLimitedTimeRetryPolicy&& rhs) noexcept + : PredictionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PredictionServiceLimitedTimeRetryPolicy( + PredictionServiceLimitedTimeRetryPolicy const& rhs) noexcept + : PredictionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using PredictionServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::PredictionServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PredictionServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::PredictionServiceRetryTraits> + impl_; +}; /** * The `PredictionServiceConnection` object for `PredictionServiceClient`. diff --git a/google/cloud/aiplatform/v1/specialist_pool_connection.h b/google/cloud/aiplatform/v1/specialist_pool_connection.h index 5a1fa577d9ac0..348d1d6fc5274 100644 --- a/google/cloud/aiplatform/v1/specialist_pool_connection.h +++ b/google/cloud/aiplatform/v1/specialist_pool_connection.h @@ -39,17 +39,139 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SpecialistPoolServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::SpecialistPoolServiceRetryTraits>; +/// The retry policy for `SpecialistPoolServiceConnection`. +class SpecialistPoolServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SpecialistPoolServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::SpecialistPoolServiceRetryTraits>; +/** + * A retry policy for `SpecialistPoolServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SpecialistPoolServiceLimitedErrorCountRetryPolicy + : public SpecialistPoolServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SpecialistPoolServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + SpecialistPoolServiceLimitedErrorCountRetryPolicy( + SpecialistPoolServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SpecialistPoolServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + SpecialistPoolServiceLimitedErrorCountRetryPolicy( + SpecialistPoolServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SpecialistPoolServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SpecialistPoolServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::SpecialistPoolServiceRetryTraits> + impl_; +}; -using SpecialistPoolServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::SpecialistPoolServiceRetryTraits>; +/** + * A retry policy for `SpecialistPoolServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SpecialistPoolServiceLimitedTimeRetryPolicy + : public SpecialistPoolServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SpecialistPoolServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SpecialistPoolServiceLimitedTimeRetryPolicy( + SpecialistPoolServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SpecialistPoolServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SpecialistPoolServiceLimitedTimeRetryPolicy( + SpecialistPoolServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SpecialistPoolServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SpecialistPoolServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::SpecialistPoolServiceRetryTraits> + impl_; +}; /** * The `SpecialistPoolServiceConnection` object for diff --git a/google/cloud/aiplatform/v1/tensorboard_connection.h b/google/cloud/aiplatform/v1/tensorboard_connection.h index d147c458391c8..249da42d1eace 100644 --- a/google/cloud/aiplatform/v1/tensorboard_connection.h +++ b/google/cloud/aiplatform/v1/tensorboard_connection.h @@ -39,17 +39,137 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TensorboardServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::TensorboardServiceRetryTraits>; +/// The retry policy for `TensorboardServiceConnection`. +class TensorboardServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TensorboardServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::TensorboardServiceRetryTraits>; +/** + * A retry policy for `TensorboardServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TensorboardServiceLimitedErrorCountRetryPolicy + : public TensorboardServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TensorboardServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TensorboardServiceLimitedErrorCountRetryPolicy( + TensorboardServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : TensorboardServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + TensorboardServiceLimitedErrorCountRetryPolicy( + TensorboardServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : TensorboardServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TensorboardServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::TensorboardServiceRetryTraits> + impl_; +}; -using TensorboardServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::TensorboardServiceRetryTraits>; +/** + * A retry policy for `TensorboardServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TensorboardServiceLimitedTimeRetryPolicy + : public TensorboardServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TensorboardServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TensorboardServiceLimitedTimeRetryPolicy( + TensorboardServiceLimitedTimeRetryPolicy&& rhs) noexcept + : TensorboardServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TensorboardServiceLimitedTimeRetryPolicy( + TensorboardServiceLimitedTimeRetryPolicy const& rhs) noexcept + : TensorboardServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TensorboardServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::TensorboardServiceRetryTraits> + impl_; +}; /** * The `TensorboardServiceConnection` object for `TensorboardServiceClient`. diff --git a/google/cloud/aiplatform/v1/vizier_connection.h b/google/cloud/aiplatform/v1/vizier_connection.h index bf2463a423e55..7d82ed6ea9c42 100644 --- a/google/cloud/aiplatform/v1/vizier_connection.h +++ b/google/cloud/aiplatform/v1/vizier_connection.h @@ -39,17 +39,134 @@ namespace cloud { namespace aiplatform_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VizierServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - aiplatform_v1_internal::VizierServiceRetryTraits>; +/// The retry policy for `VizierServiceConnection`. +class VizierServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `VizierServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VizierServiceLimitedErrorCountRetryPolicy + : public VizierServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VizierServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VizierServiceLimitedErrorCountRetryPolicy( + VizierServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : VizierServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VizierServiceLimitedErrorCountRetryPolicy( + VizierServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : VizierServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VizierServiceRetryPolicy; -using VizierServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - aiplatform_v1_internal::VizierServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + aiplatform_v1_internal::VizierServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `VizierServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VizierServiceLimitedTimeRetryPolicy : public VizierServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VizierServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VizierServiceLimitedTimeRetryPolicy( + VizierServiceLimitedTimeRetryPolicy&& rhs) noexcept + : VizierServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VizierServiceLimitedTimeRetryPolicy( + VizierServiceLimitedTimeRetryPolicy const& rhs) noexcept + : VizierServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using VizierServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - aiplatform_v1_internal::VizierServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VizierServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + aiplatform_v1_internal::VizierServiceRetryTraits> + impl_; +}; /** * The `VizierServiceConnection` object for `VizierServiceClient`. diff --git a/google/cloud/alloydb/v1/alloy_db_admin_connection.h b/google/cloud/alloydb/v1/alloy_db_admin_connection.h index 9f055685cfdfc..97f5aa7e57319 100644 --- a/google/cloud/alloydb/v1/alloy_db_admin_connection.h +++ b/google/cloud/alloydb/v1/alloy_db_admin_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace alloydb_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AlloyDBAdminRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - alloydb_v1_internal::AlloyDBAdminRetryTraits>; +/// The retry policy for `AlloyDBAdminConnection`. +class AlloyDBAdminRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AlloyDBAdminLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - alloydb_v1_internal::AlloyDBAdminRetryTraits>; +/** + * A retry policy for `AlloyDBAdminConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AlloyDBAdminLimitedErrorCountRetryPolicy + : public AlloyDBAdminRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AlloyDBAdminLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AlloyDBAdminLimitedErrorCountRetryPolicy( + AlloyDBAdminLimitedErrorCountRetryPolicy&& rhs) noexcept + : AlloyDBAdminLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AlloyDBAdminLimitedErrorCountRetryPolicy( + AlloyDBAdminLimitedErrorCountRetryPolicy const& rhs) noexcept + : AlloyDBAdminLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AlloyDBAdminRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + alloydb_v1_internal::AlloyDBAdminRetryTraits> + impl_; +}; -using AlloyDBAdminLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - alloydb_v1_internal::AlloyDBAdminRetryTraits>; +/** + * A retry policy for `AlloyDBAdminConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AlloyDBAdminLimitedTimeRetryPolicy : public AlloyDBAdminRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AlloyDBAdminLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AlloyDBAdminLimitedTimeRetryPolicy( + AlloyDBAdminLimitedTimeRetryPolicy&& rhs) noexcept + : AlloyDBAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AlloyDBAdminLimitedTimeRetryPolicy( + AlloyDBAdminLimitedTimeRetryPolicy const& rhs) noexcept + : AlloyDBAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AlloyDBAdminRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + alloydb_v1_internal::AlloyDBAdminRetryTraits> + impl_; +}; /** * The `AlloyDBAdminConnection` object for `AlloyDBAdminClient`. diff --git a/google/cloud/apigateway/v1/api_gateway_connection.h b/google/cloud/apigateway/v1/api_gateway_connection.h index 37a7958bc3cb1..87eca05fd1f5a 100644 --- a/google/cloud/apigateway/v1/api_gateway_connection.h +++ b/google/cloud/apigateway/v1/api_gateway_connection.h @@ -38,17 +38,137 @@ namespace cloud { namespace apigateway_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ApiGatewayServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - apigateway_v1_internal::ApiGatewayServiceRetryTraits>; +/// The retry policy for `ApiGatewayServiceConnection`. +class ApiGatewayServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ApiGatewayServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class ApiGatewayServiceLimitedErrorCountRetryPolicy + : public ApiGatewayServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ApiGatewayServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ApiGatewayServiceLimitedErrorCountRetryPolicy( + ApiGatewayServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ApiGatewayServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ApiGatewayServiceLimitedErrorCountRetryPolicy( + ApiGatewayServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ApiGatewayServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ApiGatewayServiceRetryPolicy; -using ApiGatewayServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - apigateway_v1_internal::ApiGatewayServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apigateway_v1_internal::ApiGatewayServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ApiGatewayServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class ApiGatewayServiceLimitedTimeRetryPolicy + : public ApiGatewayServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ApiGatewayServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ApiGatewayServiceLimitedTimeRetryPolicy( + ApiGatewayServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ApiGatewayServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ApiGatewayServiceLimitedTimeRetryPolicy( + ApiGatewayServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ApiGatewayServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ApiGatewayServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - apigateway_v1_internal::ApiGatewayServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ApiGatewayServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apigateway_v1_internal::ApiGatewayServiceRetryTraits> + impl_; +}; /** * The `ApiGatewayServiceConnection` object for `ApiGatewayServiceClient`. diff --git a/google/cloud/apigeeconnect/v1/connection_connection.h b/google/cloud/apigeeconnect/v1/connection_connection.h index fa459f3fe0675..506e345332ec4 100644 --- a/google/cloud/apigeeconnect/v1/connection_connection.h +++ b/google/cloud/apigeeconnect/v1/connection_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace apigeeconnect_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ConnectionServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - apigeeconnect_v1_internal::ConnectionServiceRetryTraits>; +/// The retry policy for `ConnectionServiceConnection`. +class ConnectionServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ConnectionServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class ConnectionServiceLimitedErrorCountRetryPolicy + : public ConnectionServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ConnectionServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ConnectionServiceLimitedErrorCountRetryPolicy( + ConnectionServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ConnectionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ConnectionServiceLimitedErrorCountRetryPolicy( + ConnectionServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ConnectionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConnectionServiceRetryPolicy; -using ConnectionServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - apigeeconnect_v1_internal::ConnectionServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apigeeconnect_v1_internal::ConnectionServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ConnectionServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class ConnectionServiceLimitedTimeRetryPolicy + : public ConnectionServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ConnectionServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ConnectionServiceLimitedTimeRetryPolicy( + ConnectionServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ConnectionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ConnectionServiceLimitedTimeRetryPolicy( + ConnectionServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ConnectionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ConnectionServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - apigeeconnect_v1_internal::ConnectionServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConnectionServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apigeeconnect_v1_internal::ConnectionServiceRetryTraits> + impl_; +}; /** * The `ConnectionServiceConnection` object for `ConnectionServiceClient`. diff --git a/google/cloud/apikeys/v2/api_keys_connection.h b/google/cloud/apikeys/v2/api_keys_connection.h index b6b59efde7fd4..54ef31369b267 100644 --- a/google/cloud/apikeys/v2/api_keys_connection.h +++ b/google/cloud/apikeys/v2/api_keys_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace apikeys_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ApiKeysRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - apikeys_v2_internal::ApiKeysRetryTraits>; +/// The retry policy for `ApiKeysConnection`. +class ApiKeysRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ApiKeysLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - apikeys_v2_internal::ApiKeysRetryTraits>; +/** + * A retry policy for `ApiKeysConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ApiKeysLimitedErrorCountRetryPolicy : public ApiKeysRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ApiKeysLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ApiKeysLimitedErrorCountRetryPolicy( + ApiKeysLimitedErrorCountRetryPolicy&& rhs) noexcept + : ApiKeysLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ApiKeysLimitedErrorCountRetryPolicy( + ApiKeysLimitedErrorCountRetryPolicy const& rhs) noexcept + : ApiKeysLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ApiKeysRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apikeys_v2_internal::ApiKeysRetryTraits> + impl_; +}; -using ApiKeysLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - apikeys_v2_internal::ApiKeysRetryTraits>; +/** + * A retry policy for `ApiKeysConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ApiKeysLimitedTimeRetryPolicy : public ApiKeysRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ApiKeysLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ApiKeysLimitedTimeRetryPolicy(ApiKeysLimitedTimeRetryPolicy&& rhs) noexcept + : ApiKeysLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ApiKeysLimitedTimeRetryPolicy( + ApiKeysLimitedTimeRetryPolicy const& rhs) noexcept + : ApiKeysLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ApiKeysRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apikeys_v2_internal::ApiKeysRetryTraits> + impl_; +}; /** * The `ApiKeysConnection` object for `ApiKeysClient`. diff --git a/google/cloud/appengine/v1/applications_connection.h b/google/cloud/appengine/v1/applications_connection.h index ecf3b0aac0e2e..433e55878fec5 100644 --- a/google/cloud/appengine/v1/applications_connection.h +++ b/google/cloud/appengine/v1/applications_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace appengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ApplicationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - appengine_v1_internal::ApplicationsRetryTraits>; +/// The retry policy for `ApplicationsConnection`. +class ApplicationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ApplicationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - appengine_v1_internal::ApplicationsRetryTraits>; +/** + * A retry policy for `ApplicationsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ApplicationsLimitedErrorCountRetryPolicy + : public ApplicationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ApplicationsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ApplicationsLimitedErrorCountRetryPolicy( + ApplicationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ApplicationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ApplicationsLimitedErrorCountRetryPolicy( + ApplicationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ApplicationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ApplicationsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + appengine_v1_internal::ApplicationsRetryTraits> + impl_; +}; -using ApplicationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - appengine_v1_internal::ApplicationsRetryTraits>; +/** + * A retry policy for `ApplicationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ApplicationsLimitedTimeRetryPolicy : public ApplicationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ApplicationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ApplicationsLimitedTimeRetryPolicy( + ApplicationsLimitedTimeRetryPolicy&& rhs) noexcept + : ApplicationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ApplicationsLimitedTimeRetryPolicy( + ApplicationsLimitedTimeRetryPolicy const& rhs) noexcept + : ApplicationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ApplicationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + appengine_v1_internal::ApplicationsRetryTraits> + impl_; +}; /** * The `ApplicationsConnection` object for `ApplicationsClient`. diff --git a/google/cloud/appengine/v1/authorized_certificates_connection.h b/google/cloud/appengine/v1/authorized_certificates_connection.h index 671b04001d9c6..bd2cbfdd1f457 100644 --- a/google/cloud/appengine/v1/authorized_certificates_connection.h +++ b/google/cloud/appengine/v1/authorized_certificates_connection.h @@ -36,17 +36,139 @@ namespace cloud { namespace appengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AuthorizedCertificatesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - appengine_v1_internal::AuthorizedCertificatesRetryTraits>; +/// The retry policy for `AuthorizedCertificatesConnection`. +class AuthorizedCertificatesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AuthorizedCertificatesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - appengine_v1_internal::AuthorizedCertificatesRetryTraits>; +/** + * A retry policy for `AuthorizedCertificatesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AuthorizedCertificatesLimitedErrorCountRetryPolicy + : public AuthorizedCertificatesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AuthorizedCertificatesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + AuthorizedCertificatesLimitedErrorCountRetryPolicy( + AuthorizedCertificatesLimitedErrorCountRetryPolicy&& rhs) noexcept + : AuthorizedCertificatesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AuthorizedCertificatesLimitedErrorCountRetryPolicy( + AuthorizedCertificatesLimitedErrorCountRetryPolicy const& rhs) noexcept + : AuthorizedCertificatesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AuthorizedCertificatesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + appengine_v1_internal::AuthorizedCertificatesRetryTraits> + impl_; +}; -using AuthorizedCertificatesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - appengine_v1_internal::AuthorizedCertificatesRetryTraits>; +/** + * A retry policy for `AuthorizedCertificatesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AuthorizedCertificatesLimitedTimeRetryPolicy + : public AuthorizedCertificatesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AuthorizedCertificatesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AuthorizedCertificatesLimitedTimeRetryPolicy( + AuthorizedCertificatesLimitedTimeRetryPolicy&& rhs) noexcept + : AuthorizedCertificatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AuthorizedCertificatesLimitedTimeRetryPolicy( + AuthorizedCertificatesLimitedTimeRetryPolicy const& rhs) noexcept + : AuthorizedCertificatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AuthorizedCertificatesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + appengine_v1_internal::AuthorizedCertificatesRetryTraits> + impl_; +}; /** * The `AuthorizedCertificatesConnection` object for diff --git a/google/cloud/appengine/v1/authorized_domains_connection.h b/google/cloud/appengine/v1/authorized_domains_connection.h index d044465db2790..396a0235da93f 100644 --- a/google/cloud/appengine/v1/authorized_domains_connection.h +++ b/google/cloud/appengine/v1/authorized_domains_connection.h @@ -36,17 +36,135 @@ namespace cloud { namespace appengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AuthorizedDomainsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - appengine_v1_internal::AuthorizedDomainsRetryTraits>; +/// The retry policy for `AuthorizedDomainsConnection`. +class AuthorizedDomainsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AuthorizedDomainsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AuthorizedDomainsLimitedErrorCountRetryPolicy + : public AuthorizedDomainsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AuthorizedDomainsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AuthorizedDomainsLimitedErrorCountRetryPolicy( + AuthorizedDomainsLimitedErrorCountRetryPolicy&& rhs) noexcept + : AuthorizedDomainsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AuthorizedDomainsLimitedErrorCountRetryPolicy( + AuthorizedDomainsLimitedErrorCountRetryPolicy const& rhs) noexcept + : AuthorizedDomainsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AuthorizedDomainsRetryPolicy; -using AuthorizedDomainsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - appengine_v1_internal::AuthorizedDomainsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + appengine_v1_internal::AuthorizedDomainsRetryTraits> + impl_; +}; + +/** + * A retry policy for `AuthorizedDomainsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AuthorizedDomainsLimitedTimeRetryPolicy + : public AuthorizedDomainsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AuthorizedDomainsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AuthorizedDomainsLimitedTimeRetryPolicy( + AuthorizedDomainsLimitedTimeRetryPolicy&& rhs) noexcept + : AuthorizedDomainsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AuthorizedDomainsLimitedTimeRetryPolicy( + AuthorizedDomainsLimitedTimeRetryPolicy const& rhs) noexcept + : AuthorizedDomainsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AuthorizedDomainsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - appengine_v1_internal::AuthorizedDomainsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AuthorizedDomainsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + appengine_v1_internal::AuthorizedDomainsRetryTraits> + impl_; +}; /** * The `AuthorizedDomainsConnection` object for `AuthorizedDomainsClient`. diff --git a/google/cloud/appengine/v1/domain_mappings_connection.h b/google/cloud/appengine/v1/domain_mappings_connection.h index 268cfc99f561b..968c321f29e43 100644 --- a/google/cloud/appengine/v1/domain_mappings_connection.h +++ b/google/cloud/appengine/v1/domain_mappings_connection.h @@ -39,17 +39,134 @@ namespace cloud { namespace appengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DomainMappingsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - appengine_v1_internal::DomainMappingsRetryTraits>; +/// The retry policy for `DomainMappingsConnection`. +class DomainMappingsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DomainMappingsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - appengine_v1_internal::DomainMappingsRetryTraits>; +/** + * A retry policy for `DomainMappingsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DomainMappingsLimitedErrorCountRetryPolicy + : public DomainMappingsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DomainMappingsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DomainMappingsLimitedErrorCountRetryPolicy( + DomainMappingsLimitedErrorCountRetryPolicy&& rhs) noexcept + : DomainMappingsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DomainMappingsLimitedErrorCountRetryPolicy( + DomainMappingsLimitedErrorCountRetryPolicy const& rhs) noexcept + : DomainMappingsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DomainMappingsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + appengine_v1_internal::DomainMappingsRetryTraits> + impl_; +}; -using DomainMappingsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - appengine_v1_internal::DomainMappingsRetryTraits>; +/** + * A retry policy for `DomainMappingsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DomainMappingsLimitedTimeRetryPolicy : public DomainMappingsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DomainMappingsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DomainMappingsLimitedTimeRetryPolicy( + DomainMappingsLimitedTimeRetryPolicy&& rhs) noexcept + : DomainMappingsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DomainMappingsLimitedTimeRetryPolicy( + DomainMappingsLimitedTimeRetryPolicy const& rhs) noexcept + : DomainMappingsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DomainMappingsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + appengine_v1_internal::DomainMappingsRetryTraits> + impl_; +}; /** * The `DomainMappingsConnection` object for `DomainMappingsClient`. diff --git a/google/cloud/appengine/v1/firewall_connection.h b/google/cloud/appengine/v1/firewall_connection.h index 87b475e8a0869..63d558a56d152 100644 --- a/google/cloud/appengine/v1/firewall_connection.h +++ b/google/cloud/appengine/v1/firewall_connection.h @@ -36,16 +36,131 @@ namespace cloud { namespace appengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FirewallRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - appengine_v1_internal::FirewallRetryTraits>; +/// The retry policy for `FirewallConnection`. +class FirewallRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using FirewallLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - appengine_v1_internal::FirewallRetryTraits>; +/** + * A retry policy for `FirewallConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FirewallLimitedErrorCountRetryPolicy : public FirewallRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FirewallLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + FirewallLimitedErrorCountRetryPolicy( + FirewallLimitedErrorCountRetryPolicy&& rhs) noexcept + : FirewallLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + FirewallLimitedErrorCountRetryPolicy( + FirewallLimitedErrorCountRetryPolicy const& rhs) noexcept + : FirewallLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FirewallRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + appengine_v1_internal::FirewallRetryTraits> + impl_; +}; -using FirewallLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - appengine_v1_internal::FirewallRetryTraits>; +/** + * A retry policy for `FirewallConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FirewallLimitedTimeRetryPolicy : public FirewallRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FirewallLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FirewallLimitedTimeRetryPolicy(FirewallLimitedTimeRetryPolicy&& rhs) noexcept + : FirewallLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + FirewallLimitedTimeRetryPolicy( + FirewallLimitedTimeRetryPolicy const& rhs) noexcept + : FirewallLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FirewallRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + appengine_v1_internal::FirewallRetryTraits> + impl_; +}; /** * The `FirewallConnection` object for `FirewallClient`. diff --git a/google/cloud/appengine/v1/instances_connection.h b/google/cloud/appengine/v1/instances_connection.h index 66e3f73ab9c2e..7988bf897710f 100644 --- a/google/cloud/appengine/v1/instances_connection.h +++ b/google/cloud/appengine/v1/instances_connection.h @@ -39,16 +39,133 @@ namespace cloud { namespace appengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InstancesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - appengine_v1_internal::InstancesRetryTraits>; +/// The retry policy for `InstancesConnection`. +class InstancesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using InstancesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - appengine_v1_internal::InstancesRetryTraits>; +/** + * A retry policy for `InstancesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstancesLimitedErrorCountRetryPolicy : public InstancesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InstancesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + InstancesLimitedErrorCountRetryPolicy( + InstancesLimitedErrorCountRetryPolicy&& rhs) noexcept + : InstancesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + InstancesLimitedErrorCountRetryPolicy( + InstancesLimitedErrorCountRetryPolicy const& rhs) noexcept + : InstancesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstancesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + appengine_v1_internal::InstancesRetryTraits> + impl_; +}; -using InstancesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - appengine_v1_internal::InstancesRetryTraits>; +/** + * A retry policy for `InstancesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstancesLimitedTimeRetryPolicy : public InstancesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InstancesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InstancesLimitedTimeRetryPolicy( + InstancesLimitedTimeRetryPolicy&& rhs) noexcept + : InstancesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InstancesLimitedTimeRetryPolicy( + InstancesLimitedTimeRetryPolicy const& rhs) noexcept + : InstancesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstancesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + appengine_v1_internal::InstancesRetryTraits> + impl_; +}; /** * The `InstancesConnection` object for `InstancesClient`. diff --git a/google/cloud/appengine/v1/services_connection.h b/google/cloud/appengine/v1/services_connection.h index 5f94fc4ae99c1..956cf4e741533 100644 --- a/google/cloud/appengine/v1/services_connection.h +++ b/google/cloud/appengine/v1/services_connection.h @@ -39,16 +39,131 @@ namespace cloud { namespace appengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ServicesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - appengine_v1_internal::ServicesRetryTraits>; +/// The retry policy for `ServicesConnection`. +class ServicesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ServicesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - appengine_v1_internal::ServicesRetryTraits>; +/** + * A retry policy for `ServicesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServicesLimitedErrorCountRetryPolicy : public ServicesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ServicesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ServicesLimitedErrorCountRetryPolicy( + ServicesLimitedErrorCountRetryPolicy&& rhs) noexcept + : ServicesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ServicesLimitedErrorCountRetryPolicy( + ServicesLimitedErrorCountRetryPolicy const& rhs) noexcept + : ServicesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServicesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + appengine_v1_internal::ServicesRetryTraits> + impl_; +}; -using ServicesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - appengine_v1_internal::ServicesRetryTraits>; +/** + * A retry policy for `ServicesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServicesLimitedTimeRetryPolicy : public ServicesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ServicesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ServicesLimitedTimeRetryPolicy(ServicesLimitedTimeRetryPolicy&& rhs) noexcept + : ServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ServicesLimitedTimeRetryPolicy( + ServicesLimitedTimeRetryPolicy const& rhs) noexcept + : ServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServicesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + appengine_v1_internal::ServicesRetryTraits> + impl_; +}; /** * The `ServicesConnection` object for `ServicesClient`. diff --git a/google/cloud/appengine/v1/versions_connection.h b/google/cloud/appengine/v1/versions_connection.h index 876a5c83fedf8..b5c55d1716280 100644 --- a/google/cloud/appengine/v1/versions_connection.h +++ b/google/cloud/appengine/v1/versions_connection.h @@ -39,16 +39,131 @@ namespace cloud { namespace appengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VersionsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - appengine_v1_internal::VersionsRetryTraits>; +/// The retry policy for `VersionsConnection`. +class VersionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VersionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - appengine_v1_internal::VersionsRetryTraits>; +/** + * A retry policy for `VersionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VersionsLimitedErrorCountRetryPolicy : public VersionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VersionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VersionsLimitedErrorCountRetryPolicy( + VersionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : VersionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VersionsLimitedErrorCountRetryPolicy( + VersionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : VersionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VersionsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + appengine_v1_internal::VersionsRetryTraits> + impl_; +}; -using VersionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - appengine_v1_internal::VersionsRetryTraits>; +/** + * A retry policy for `VersionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VersionsLimitedTimeRetryPolicy : public VersionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VersionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VersionsLimitedTimeRetryPolicy(VersionsLimitedTimeRetryPolicy&& rhs) noexcept + : VersionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VersionsLimitedTimeRetryPolicy( + VersionsLimitedTimeRetryPolicy const& rhs) noexcept + : VersionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VersionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + appengine_v1_internal::VersionsRetryTraits> + impl_; +}; /** * The `VersionsConnection` object for `VersionsClient`. diff --git a/google/cloud/artifactregistry/v1/artifact_registry_connection.h b/google/cloud/artifactregistry/v1/artifact_registry_connection.h index 40aa2185c5ed6..03b0a890aed1e 100644 --- a/google/cloud/artifactregistry/v1/artifact_registry_connection.h +++ b/google/cloud/artifactregistry/v1/artifact_registry_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace artifactregistry_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ArtifactRegistryRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - artifactregistry_v1_internal::ArtifactRegistryRetryTraits>; +/// The retry policy for `ArtifactRegistryConnection`. +class ArtifactRegistryRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ArtifactRegistryLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - artifactregistry_v1_internal::ArtifactRegistryRetryTraits>; +/** + * A retry policy for `ArtifactRegistryConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ArtifactRegistryLimitedErrorCountRetryPolicy + : public ArtifactRegistryRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ArtifactRegistryLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ArtifactRegistryLimitedErrorCountRetryPolicy( + ArtifactRegistryLimitedErrorCountRetryPolicy&& rhs) noexcept + : ArtifactRegistryLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ArtifactRegistryLimitedErrorCountRetryPolicy( + ArtifactRegistryLimitedErrorCountRetryPolicy const& rhs) noexcept + : ArtifactRegistryLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ArtifactRegistryRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + artifactregistry_v1_internal::ArtifactRegistryRetryTraits> + impl_; +}; -using ArtifactRegistryLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - artifactregistry_v1_internal::ArtifactRegistryRetryTraits>; +/** + * A retry policy for `ArtifactRegistryConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ArtifactRegistryLimitedTimeRetryPolicy + : public ArtifactRegistryRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ArtifactRegistryLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ArtifactRegistryLimitedTimeRetryPolicy( + ArtifactRegistryLimitedTimeRetryPolicy&& rhs) noexcept + : ArtifactRegistryLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ArtifactRegistryLimitedTimeRetryPolicy( + ArtifactRegistryLimitedTimeRetryPolicy const& rhs) noexcept + : ArtifactRegistryLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ArtifactRegistryRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + artifactregistry_v1_internal::ArtifactRegistryRetryTraits> + impl_; +}; /** * The `ArtifactRegistryConnection` object for `ArtifactRegistryClient`. diff --git a/google/cloud/asset/v1/asset_connection.h b/google/cloud/asset/v1/asset_connection.h index e92f18a4e264c..db744bb8366f9 100644 --- a/google/cloud/asset/v1/asset_connection.h +++ b/google/cloud/asset/v1/asset_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace asset_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AssetServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - asset_v1_internal::AssetServiceRetryTraits>; +/// The retry policy for `AssetServiceConnection`. +class AssetServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AssetServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - asset_v1_internal::AssetServiceRetryTraits>; +/** + * A retry policy for `AssetServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AssetServiceLimitedErrorCountRetryPolicy + : public AssetServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AssetServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AssetServiceLimitedErrorCountRetryPolicy( + AssetServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AssetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AssetServiceLimitedErrorCountRetryPolicy( + AssetServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AssetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AssetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + asset_v1_internal::AssetServiceRetryTraits> + impl_; +}; -using AssetServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - asset_v1_internal::AssetServiceRetryTraits>; +/** + * A retry policy for `AssetServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AssetServiceLimitedTimeRetryPolicy : public AssetServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AssetServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AssetServiceLimitedTimeRetryPolicy( + AssetServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AssetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AssetServiceLimitedTimeRetryPolicy( + AssetServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AssetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AssetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + asset_v1_internal::AssetServiceRetryTraits> + impl_; +}; /** * The `AssetServiceConnection` object for `AssetServiceClient`. diff --git a/google/cloud/assuredworkloads/v1/assured_workloads_connection.h b/google/cloud/assuredworkloads/v1/assured_workloads_connection.h index e265714880516..ad1d24d43d24d 100644 --- a/google/cloud/assuredworkloads/v1/assured_workloads_connection.h +++ b/google/cloud/assuredworkloads/v1/assured_workloads_connection.h @@ -38,17 +38,140 @@ namespace cloud { namespace assuredworkloads_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AssuredWorkloadsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - assuredworkloads_v1_internal::AssuredWorkloadsServiceRetryTraits>; +/// The retry policy for `AssuredWorkloadsServiceConnection`. +class AssuredWorkloadsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AssuredWorkloadsServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AssuredWorkloadsServiceLimitedErrorCountRetryPolicy + : public AssuredWorkloadsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AssuredWorkloadsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + AssuredWorkloadsServiceLimitedErrorCountRetryPolicy( + AssuredWorkloadsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AssuredWorkloadsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AssuredWorkloadsServiceLimitedErrorCountRetryPolicy( + AssuredWorkloadsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AssuredWorkloadsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + AssuredWorkloadsServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AssuredWorkloadsServiceRetryPolicy; -using AssuredWorkloadsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - assuredworkloads_v1_internal::AssuredWorkloadsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + assuredworkloads_v1_internal::AssuredWorkloadsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `AssuredWorkloadsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AssuredWorkloadsServiceLimitedTimeRetryPolicy + : public AssuredWorkloadsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AssuredWorkloadsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AssuredWorkloadsServiceLimitedTimeRetryPolicy( + AssuredWorkloadsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AssuredWorkloadsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AssuredWorkloadsServiceLimitedTimeRetryPolicy( + AssuredWorkloadsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AssuredWorkloadsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AssuredWorkloadsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - assuredworkloads_v1_internal::AssuredWorkloadsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AssuredWorkloadsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + assuredworkloads_v1_internal::AssuredWorkloadsServiceRetryTraits> + impl_; +}; /** * The `AssuredWorkloadsServiceConnection` object for diff --git a/google/cloud/automl/v1/auto_ml_connection.h b/google/cloud/automl/v1/auto_ml_connection.h index 7ba59a534a288..3926e82eb20cc 100644 --- a/google/cloud/automl/v1/auto_ml_connection.h +++ b/google/cloud/automl/v1/auto_ml_connection.h @@ -39,16 +39,130 @@ namespace cloud { namespace automl_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AutoMlRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - automl_v1_internal::AutoMlRetryTraits>; +/// The retry policy for `AutoMlConnection`. +class AutoMlRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AutoMlConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AutoMlLimitedErrorCountRetryPolicy : public AutoMlRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AutoMlLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AutoMlLimitedErrorCountRetryPolicy( + AutoMlLimitedErrorCountRetryPolicy&& rhs) noexcept + : AutoMlLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AutoMlLimitedErrorCountRetryPolicy( + AutoMlLimitedErrorCountRetryPolicy const& rhs) noexcept + : AutoMlLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AutoMlRetryPolicy; -using AutoMlLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - automl_v1_internal::AutoMlRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + automl_v1_internal::AutoMlRetryTraits> + impl_; +}; + +/** + * A retry policy for `AutoMlConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AutoMlLimitedTimeRetryPolicy : public AutoMlRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AutoMlLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AutoMlLimitedTimeRetryPolicy(AutoMlLimitedTimeRetryPolicy&& rhs) noexcept + : AutoMlLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AutoMlLimitedTimeRetryPolicy(AutoMlLimitedTimeRetryPolicy const& rhs) noexcept + : AutoMlLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AutoMlLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - automl_v1_internal::AutoMlRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AutoMlRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + automl_v1_internal::AutoMlRetryTraits> + impl_; +}; /** * The `AutoMlConnection` object for `AutoMlClient`. diff --git a/google/cloud/automl/v1/prediction_connection.h b/google/cloud/automl/v1/prediction_connection.h index bcc53d29bb035..08f3a6dc19121 100644 --- a/google/cloud/automl/v1/prediction_connection.h +++ b/google/cloud/automl/v1/prediction_connection.h @@ -37,17 +37,135 @@ namespace cloud { namespace automl_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PredictionServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - automl_v1_internal::PredictionServiceRetryTraits>; +/// The retry policy for `PredictionServiceConnection`. +class PredictionServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PredictionServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PredictionServiceLimitedErrorCountRetryPolicy + : public PredictionServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PredictionServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PredictionServiceLimitedErrorCountRetryPolicy( + PredictionServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : PredictionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PredictionServiceLimitedErrorCountRetryPolicy( + PredictionServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : PredictionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PredictionServiceRetryPolicy; -using PredictionServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - automl_v1_internal::PredictionServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + automl_v1_internal::PredictionServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `PredictionServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PredictionServiceLimitedTimeRetryPolicy + : public PredictionServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PredictionServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PredictionServiceLimitedTimeRetryPolicy( + PredictionServiceLimitedTimeRetryPolicy&& rhs) noexcept + : PredictionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PredictionServiceLimitedTimeRetryPolicy( + PredictionServiceLimitedTimeRetryPolicy const& rhs) noexcept + : PredictionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using PredictionServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - automl_v1_internal::PredictionServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PredictionServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + automl_v1_internal::PredictionServiceRetryTraits> + impl_; +}; /** * The `PredictionServiceConnection` object for `PredictionServiceClient`. diff --git a/google/cloud/baremetalsolution/v2/bare_metal_solution_connection.h b/google/cloud/baremetalsolution/v2/bare_metal_solution_connection.h index 5d8bde071b7f5..600ebe768f612 100644 --- a/google/cloud/baremetalsolution/v2/bare_metal_solution_connection.h +++ b/google/cloud/baremetalsolution/v2/bare_metal_solution_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace baremetalsolution_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BareMetalSolutionRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - baremetalsolution_v2_internal::BareMetalSolutionRetryTraits>; +/// The retry policy for `BareMetalSolutionConnection`. +class BareMetalSolutionRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BareMetalSolutionLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - baremetalsolution_v2_internal::BareMetalSolutionRetryTraits>; +/** + * A retry policy for `BareMetalSolutionConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BareMetalSolutionLimitedErrorCountRetryPolicy + : public BareMetalSolutionRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BareMetalSolutionLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BareMetalSolutionLimitedErrorCountRetryPolicy( + BareMetalSolutionLimitedErrorCountRetryPolicy&& rhs) noexcept + : BareMetalSolutionLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BareMetalSolutionLimitedErrorCountRetryPolicy( + BareMetalSolutionLimitedErrorCountRetryPolicy const& rhs) noexcept + : BareMetalSolutionLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BareMetalSolutionRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + baremetalsolution_v2_internal::BareMetalSolutionRetryTraits> + impl_; +}; -using BareMetalSolutionLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - baremetalsolution_v2_internal::BareMetalSolutionRetryTraits>; +/** + * A retry policy for `BareMetalSolutionConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BareMetalSolutionLimitedTimeRetryPolicy + : public BareMetalSolutionRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BareMetalSolutionLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BareMetalSolutionLimitedTimeRetryPolicy( + BareMetalSolutionLimitedTimeRetryPolicy&& rhs) noexcept + : BareMetalSolutionLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BareMetalSolutionLimitedTimeRetryPolicy( + BareMetalSolutionLimitedTimeRetryPolicy const& rhs) noexcept + : BareMetalSolutionLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BareMetalSolutionRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + baremetalsolution_v2_internal::BareMetalSolutionRetryTraits> + impl_; +}; /** * The `BareMetalSolutionConnection` object for `BareMetalSolutionClient`. diff --git a/google/cloud/batch/v1/batch_connection.h b/google/cloud/batch/v1/batch_connection.h index 79e86839cb4a1..e68337dba3fd8 100644 --- a/google/cloud/batch/v1/batch_connection.h +++ b/google/cloud/batch/v1/batch_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace batch_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BatchServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - batch_v1_internal::BatchServiceRetryTraits>; +/// The retry policy for `BatchServiceConnection`. +class BatchServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BatchServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - batch_v1_internal::BatchServiceRetryTraits>; +/** + * A retry policy for `BatchServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BatchServiceLimitedErrorCountRetryPolicy + : public BatchServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BatchServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BatchServiceLimitedErrorCountRetryPolicy( + BatchServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : BatchServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BatchServiceLimitedErrorCountRetryPolicy( + BatchServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : BatchServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BatchServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + batch_v1_internal::BatchServiceRetryTraits> + impl_; +}; -using BatchServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - batch_v1_internal::BatchServiceRetryTraits>; +/** + * A retry policy for `BatchServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BatchServiceLimitedTimeRetryPolicy : public BatchServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BatchServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BatchServiceLimitedTimeRetryPolicy( + BatchServiceLimitedTimeRetryPolicy&& rhs) noexcept + : BatchServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BatchServiceLimitedTimeRetryPolicy( + BatchServiceLimitedTimeRetryPolicy const& rhs) noexcept + : BatchServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BatchServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + batch_v1_internal::BatchServiceRetryTraits> + impl_; +}; /** * The `BatchServiceConnection` object for `BatchServiceClient`. diff --git a/google/cloud/beyondcorp/appconnections/v1/app_connections_connection.h b/google/cloud/beyondcorp/appconnections/v1/app_connections_connection.h index d709e26d216f4..9cecebeefd262 100644 --- a/google/cloud/beyondcorp/appconnections/v1/app_connections_connection.h +++ b/google/cloud/beyondcorp/appconnections/v1/app_connections_connection.h @@ -39,20 +39,139 @@ namespace cloud { namespace beyondcorp_appconnections_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AppConnectionsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - beyondcorp_appconnections_v1_internal:: - AppConnectionsServiceRetryTraits>; - -using AppConnectionsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - beyondcorp_appconnections_v1_internal:: - AppConnectionsServiceRetryTraits>; - -using AppConnectionsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - beyondcorp_appconnections_v1_internal:: - AppConnectionsServiceRetryTraits>; +/// The retry policy for `AppConnectionsServiceConnection`. +class AppConnectionsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AppConnectionsServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AppConnectionsServiceLimitedErrorCountRetryPolicy + : public AppConnectionsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AppConnectionsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + AppConnectionsServiceLimitedErrorCountRetryPolicy( + AppConnectionsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AppConnectionsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AppConnectionsServiceLimitedErrorCountRetryPolicy( + AppConnectionsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AppConnectionsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AppConnectionsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + beyondcorp_appconnections_v1_internal::AppConnectionsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `AppConnectionsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AppConnectionsServiceLimitedTimeRetryPolicy + : public AppConnectionsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AppConnectionsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AppConnectionsServiceLimitedTimeRetryPolicy( + AppConnectionsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AppConnectionsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AppConnectionsServiceLimitedTimeRetryPolicy( + AppConnectionsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AppConnectionsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AppConnectionsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + beyondcorp_appconnections_v1_internal::AppConnectionsServiceRetryTraits> + impl_; +}; /** * The `AppConnectionsServiceConnection` object for diff --git a/google/cloud/beyondcorp/appconnectors/v1/app_connectors_connection.h b/google/cloud/beyondcorp/appconnectors/v1/app_connectors_connection.h index 73422c7258955..32bfd8a4c457d 100644 --- a/google/cloud/beyondcorp/appconnectors/v1/app_connectors_connection.h +++ b/google/cloud/beyondcorp/appconnectors/v1/app_connectors_connection.h @@ -38,17 +38,138 @@ namespace cloud { namespace beyondcorp_appconnectors_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AppConnectorsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - beyondcorp_appconnectors_v1_internal::AppConnectorsServiceRetryTraits>; +/// The retry policy for `AppConnectorsServiceConnection`. +class AppConnectorsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AppConnectorsServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AppConnectorsServiceLimitedErrorCountRetryPolicy + : public AppConnectorsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AppConnectorsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + AppConnectorsServiceLimitedErrorCountRetryPolicy( + AppConnectorsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AppConnectorsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AppConnectorsServiceLimitedErrorCountRetryPolicy( + AppConnectorsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AppConnectorsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AppConnectorsServiceRetryPolicy; -using AppConnectorsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - beyondcorp_appconnectors_v1_internal::AppConnectorsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + beyondcorp_appconnectors_v1_internal::AppConnectorsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `AppConnectorsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AppConnectorsServiceLimitedTimeRetryPolicy + : public AppConnectorsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AppConnectorsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AppConnectorsServiceLimitedTimeRetryPolicy( + AppConnectorsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AppConnectorsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AppConnectorsServiceLimitedTimeRetryPolicy( + AppConnectorsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AppConnectorsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AppConnectorsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - beyondcorp_appconnectors_v1_internal::AppConnectorsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AppConnectorsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + beyondcorp_appconnectors_v1_internal::AppConnectorsServiceRetryTraits> + impl_; +}; /** * The `AppConnectorsServiceConnection` object for `AppConnectorsServiceClient`. diff --git a/google/cloud/beyondcorp/appgateways/v1/app_gateways_connection.h b/google/cloud/beyondcorp/appgateways/v1/app_gateways_connection.h index 83f89c22d8d79..def5f22760762 100644 --- a/google/cloud/beyondcorp/appgateways/v1/app_gateways_connection.h +++ b/google/cloud/beyondcorp/appgateways/v1/app_gateways_connection.h @@ -38,17 +38,137 @@ namespace cloud { namespace beyondcorp_appgateways_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AppGatewaysServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - beyondcorp_appgateways_v1_internal::AppGatewaysServiceRetryTraits>; +/// The retry policy for `AppGatewaysServiceConnection`. +class AppGatewaysServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AppGatewaysServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - beyondcorp_appgateways_v1_internal::AppGatewaysServiceRetryTraits>; +/** + * A retry policy for `AppGatewaysServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AppGatewaysServiceLimitedErrorCountRetryPolicy + : public AppGatewaysServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AppGatewaysServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AppGatewaysServiceLimitedErrorCountRetryPolicy( + AppGatewaysServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AppGatewaysServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + AppGatewaysServiceLimitedErrorCountRetryPolicy( + AppGatewaysServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AppGatewaysServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AppGatewaysServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + beyondcorp_appgateways_v1_internal::AppGatewaysServiceRetryTraits> + impl_; +}; -using AppGatewaysServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - beyondcorp_appgateways_v1_internal::AppGatewaysServiceRetryTraits>; +/** + * A retry policy for `AppGatewaysServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AppGatewaysServiceLimitedTimeRetryPolicy + : public AppGatewaysServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AppGatewaysServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AppGatewaysServiceLimitedTimeRetryPolicy( + AppGatewaysServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AppGatewaysServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AppGatewaysServiceLimitedTimeRetryPolicy( + AppGatewaysServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AppGatewaysServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AppGatewaysServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + beyondcorp_appgateways_v1_internal::AppGatewaysServiceRetryTraits> + impl_; +}; /** * The `AppGatewaysServiceConnection` object for `AppGatewaysServiceClient`. diff --git a/google/cloud/beyondcorp/clientconnectorservices/v1/client_connector_services_connection.h b/google/cloud/beyondcorp/clientconnectorservices/v1/client_connector_services_connection.h index f7ce95b18fe9a..1fa47252c124d 100644 --- a/google/cloud/beyondcorp/clientconnectorservices/v1/client_connector_services_connection.h +++ b/google/cloud/beyondcorp/clientconnectorservices/v1/client_connector_services_connection.h @@ -39,20 +39,151 @@ namespace cloud { namespace beyondcorp_clientconnectorservices_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ClientConnectorServicesServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - beyondcorp_clientconnectorservices_v1_internal:: - ClientConnectorServicesServiceRetryTraits>; - -using ClientConnectorServicesServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - beyondcorp_clientconnectorservices_v1_internal:: - ClientConnectorServicesServiceRetryTraits>; - -using ClientConnectorServicesServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - beyondcorp_clientconnectorservices_v1_internal:: - ClientConnectorServicesServiceRetryTraits>; +/// The retry policy for `ClientConnectorServicesServiceConnection`. +class ClientConnectorServicesServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `ClientConnectorServicesServiceConnection` based on + * counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ClientConnectorServicesServiceLimitedErrorCountRetryPolicy + : public ClientConnectorServicesServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ClientConnectorServicesServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ClientConnectorServicesServiceLimitedErrorCountRetryPolicy( + ClientConnectorServicesServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ClientConnectorServicesServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ClientConnectorServicesServiceLimitedErrorCountRetryPolicy( + ClientConnectorServicesServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : ClientConnectorServicesServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + ClientConnectorServicesServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ClientConnectorServicesServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + beyondcorp_clientconnectorservices_v1_internal:: + ClientConnectorServicesServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ClientConnectorServicesServiceConnection` based on + * elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ClientConnectorServicesServiceLimitedTimeRetryPolicy + : public ClientConnectorServicesServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ClientConnectorServicesServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ClientConnectorServicesServiceLimitedTimeRetryPolicy( + ClientConnectorServicesServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ClientConnectorServicesServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + ClientConnectorServicesServiceLimitedTimeRetryPolicy( + ClientConnectorServicesServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ClientConnectorServicesServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + ClientConnectorServicesServiceLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ClientConnectorServicesServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + beyondcorp_clientconnectorservices_v1_internal:: + ClientConnectorServicesServiceRetryTraits> + impl_; +}; /** * The `ClientConnectorServicesServiceConnection` object for diff --git a/google/cloud/beyondcorp/clientgateways/v1/client_gateways_connection.h b/google/cloud/beyondcorp/clientgateways/v1/client_gateways_connection.h index 94bf46c4b461d..00f4298407b47 100644 --- a/google/cloud/beyondcorp/clientgateways/v1/client_gateways_connection.h +++ b/google/cloud/beyondcorp/clientgateways/v1/client_gateways_connection.h @@ -39,20 +39,139 @@ namespace cloud { namespace beyondcorp_clientgateways_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ClientGatewaysServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - beyondcorp_clientgateways_v1_internal:: - ClientGatewaysServiceRetryTraits>; - -using ClientGatewaysServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - beyondcorp_clientgateways_v1_internal:: - ClientGatewaysServiceRetryTraits>; - -using ClientGatewaysServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - beyondcorp_clientgateways_v1_internal:: - ClientGatewaysServiceRetryTraits>; +/// The retry policy for `ClientGatewaysServiceConnection`. +class ClientGatewaysServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ClientGatewaysServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ClientGatewaysServiceLimitedErrorCountRetryPolicy + : public ClientGatewaysServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ClientGatewaysServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ClientGatewaysServiceLimitedErrorCountRetryPolicy( + ClientGatewaysServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ClientGatewaysServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ClientGatewaysServiceLimitedErrorCountRetryPolicy( + ClientGatewaysServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ClientGatewaysServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ClientGatewaysServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + beyondcorp_clientgateways_v1_internal::ClientGatewaysServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ClientGatewaysServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ClientGatewaysServiceLimitedTimeRetryPolicy + : public ClientGatewaysServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ClientGatewaysServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ClientGatewaysServiceLimitedTimeRetryPolicy( + ClientGatewaysServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ClientGatewaysServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ClientGatewaysServiceLimitedTimeRetryPolicy( + ClientGatewaysServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ClientGatewaysServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ClientGatewaysServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + beyondcorp_clientgateways_v1_internal::ClientGatewaysServiceRetryTraits> + impl_; +}; /** * The `ClientGatewaysServiceConnection` object for diff --git a/google/cloud/bigquery/analyticshub/v1/analytics_hub_connection.h b/google/cloud/bigquery/analyticshub/v1/analytics_hub_connection.h index 0723e7cce589d..172a90e239894 100644 --- a/google/cloud/bigquery/analyticshub/v1/analytics_hub_connection.h +++ b/google/cloud/bigquery/analyticshub/v1/analytics_hub_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace bigquery_analyticshub_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AnalyticsHubServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_analyticshub_v1_internal::AnalyticsHubServiceRetryTraits>; +/// The retry policy for `AnalyticsHubServiceConnection`. +class AnalyticsHubServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AnalyticsHubServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AnalyticsHubServiceLimitedErrorCountRetryPolicy + : public AnalyticsHubServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AnalyticsHubServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AnalyticsHubServiceLimitedErrorCountRetryPolicy( + AnalyticsHubServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AnalyticsHubServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AnalyticsHubServiceLimitedErrorCountRetryPolicy( + AnalyticsHubServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AnalyticsHubServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AnalyticsHubServiceRetryPolicy; -using AnalyticsHubServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_analyticshub_v1_internal::AnalyticsHubServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_analyticshub_v1_internal::AnalyticsHubServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `AnalyticsHubServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AnalyticsHubServiceLimitedTimeRetryPolicy + : public AnalyticsHubServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AnalyticsHubServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AnalyticsHubServiceLimitedTimeRetryPolicy( + AnalyticsHubServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AnalyticsHubServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AnalyticsHubServiceLimitedTimeRetryPolicy( + AnalyticsHubServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AnalyticsHubServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AnalyticsHubServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_analyticshub_v1_internal::AnalyticsHubServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AnalyticsHubServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_analyticshub_v1_internal::AnalyticsHubServiceRetryTraits> + impl_; +}; /** * The `AnalyticsHubServiceConnection` object for `AnalyticsHubServiceClient`. diff --git a/google/cloud/bigquery/biglake/v1/metastore_connection.h b/google/cloud/bigquery/biglake/v1/metastore_connection.h index b40b22d6dcbb3..acf97201beea7 100644 --- a/google/cloud/bigquery/biglake/v1/metastore_connection.h +++ b/google/cloud/bigquery/biglake/v1/metastore_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace bigquery_biglake_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MetastoreServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_biglake_v1_internal::MetastoreServiceRetryTraits>; +/// The retry policy for `MetastoreServiceConnection`. +class MetastoreServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `MetastoreServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetastoreServiceLimitedErrorCountRetryPolicy + : public MetastoreServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MetastoreServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MetastoreServiceLimitedErrorCountRetryPolicy( + MetastoreServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : MetastoreServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MetastoreServiceLimitedErrorCountRetryPolicy( + MetastoreServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : MetastoreServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetastoreServiceRetryPolicy; -using MetastoreServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_biglake_v1_internal::MetastoreServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_biglake_v1_internal::MetastoreServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `MetastoreServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetastoreServiceLimitedTimeRetryPolicy + : public MetastoreServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MetastoreServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MetastoreServiceLimitedTimeRetryPolicy( + MetastoreServiceLimitedTimeRetryPolicy&& rhs) noexcept + : MetastoreServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MetastoreServiceLimitedTimeRetryPolicy( + MetastoreServiceLimitedTimeRetryPolicy const& rhs) noexcept + : MetastoreServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using MetastoreServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_biglake_v1_internal::MetastoreServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetastoreServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_biglake_v1_internal::MetastoreServiceRetryTraits> + impl_; +}; /** * The `MetastoreServiceConnection` object for `MetastoreServiceClient`. diff --git a/google/cloud/bigquery/connection/v1/connection_connection.h b/google/cloud/bigquery/connection/v1/connection_connection.h index 82202cd03b5d0..cacdee9d8391c 100644 --- a/google/cloud/bigquery/connection/v1/connection_connection.h +++ b/google/cloud/bigquery/connection/v1/connection_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace bigquery_connection_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ConnectionServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_connection_v1_internal::ConnectionServiceRetryTraits>; +/// The retry policy for `ConnectionServiceConnection`. +class ConnectionServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ConnectionServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_connection_v1_internal::ConnectionServiceRetryTraits>; +/** + * A retry policy for `ConnectionServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConnectionServiceLimitedErrorCountRetryPolicy + : public ConnectionServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ConnectionServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ConnectionServiceLimitedErrorCountRetryPolicy( + ConnectionServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ConnectionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ConnectionServiceLimitedErrorCountRetryPolicy( + ConnectionServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ConnectionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConnectionServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_connection_v1_internal::ConnectionServiceRetryTraits> + impl_; +}; -using ConnectionServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_connection_v1_internal::ConnectionServiceRetryTraits>; +/** + * A retry policy for `ConnectionServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConnectionServiceLimitedTimeRetryPolicy + : public ConnectionServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ConnectionServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ConnectionServiceLimitedTimeRetryPolicy( + ConnectionServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ConnectionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ConnectionServiceLimitedTimeRetryPolicy( + ConnectionServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ConnectionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConnectionServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_connection_v1_internal::ConnectionServiceRetryTraits> + impl_; +}; /** * The `ConnectionServiceConnection` object for `ConnectionServiceClient`. diff --git a/google/cloud/bigquery/datapolicies/v1/data_policy_connection.h b/google/cloud/bigquery/datapolicies/v1/data_policy_connection.h index 32f116d931ac2..8adcf71c164fc 100644 --- a/google/cloud/bigquery/datapolicies/v1/data_policy_connection.h +++ b/google/cloud/bigquery/datapolicies/v1/data_policy_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace bigquery_datapolicies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DataPolicyServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_datapolicies_v1_internal::DataPolicyServiceRetryTraits>; +/// The retry policy for `DataPolicyServiceConnection`. +class DataPolicyServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DataPolicyServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataPolicyServiceLimitedErrorCountRetryPolicy + : public DataPolicyServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DataPolicyServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DataPolicyServiceLimitedErrorCountRetryPolicy( + DataPolicyServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DataPolicyServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DataPolicyServiceLimitedErrorCountRetryPolicy( + DataPolicyServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DataPolicyServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataPolicyServiceRetryPolicy; -using DataPolicyServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_datapolicies_v1_internal::DataPolicyServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_datapolicies_v1_internal::DataPolicyServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `DataPolicyServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataPolicyServiceLimitedTimeRetryPolicy + : public DataPolicyServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DataPolicyServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DataPolicyServiceLimitedTimeRetryPolicy( + DataPolicyServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DataPolicyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DataPolicyServiceLimitedTimeRetryPolicy( + DataPolicyServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DataPolicyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DataPolicyServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_datapolicies_v1_internal::DataPolicyServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataPolicyServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_datapolicies_v1_internal::DataPolicyServiceRetryTraits> + impl_; +}; /** * The `DataPolicyServiceConnection` object for `DataPolicyServiceClient`. diff --git a/google/cloud/bigquery/datatransfer/v1/data_transfer_connection.h b/google/cloud/bigquery/datatransfer/v1/data_transfer_connection.h index 03cd32e42e5d2..aa3895c3ec2a4 100644 --- a/google/cloud/bigquery/datatransfer/v1/data_transfer_connection.h +++ b/google/cloud/bigquery/datatransfer/v1/data_transfer_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace bigquery_datatransfer_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DataTransferServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_datatransfer_v1_internal::DataTransferServiceRetryTraits>; +/// The retry policy for `DataTransferServiceConnection`. +class DataTransferServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DataTransferServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataTransferServiceLimitedErrorCountRetryPolicy + : public DataTransferServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DataTransferServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DataTransferServiceLimitedErrorCountRetryPolicy( + DataTransferServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DataTransferServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + DataTransferServiceLimitedErrorCountRetryPolicy( + DataTransferServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DataTransferServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataTransferServiceRetryPolicy; -using DataTransferServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_datatransfer_v1_internal::DataTransferServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_datatransfer_v1_internal::DataTransferServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `DataTransferServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataTransferServiceLimitedTimeRetryPolicy + : public DataTransferServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DataTransferServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DataTransferServiceLimitedTimeRetryPolicy( + DataTransferServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DataTransferServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DataTransferServiceLimitedTimeRetryPolicy( + DataTransferServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DataTransferServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DataTransferServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_datatransfer_v1_internal::DataTransferServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataTransferServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_datatransfer_v1_internal::DataTransferServiceRetryTraits> + impl_; +}; /** * The `DataTransferServiceConnection` object for `DataTransferServiceClient`. diff --git a/google/cloud/bigquery/migration/v2/migration_connection.h b/google/cloud/bigquery/migration/v2/migration_connection.h index 7691b6947f0e4..773edbb66cbef 100644 --- a/google/cloud/bigquery/migration/v2/migration_connection.h +++ b/google/cloud/bigquery/migration/v2/migration_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace bigquery_migration_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MigrationServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_migration_v2_internal::MigrationServiceRetryTraits>; +/// The retry policy for `MigrationServiceConnection`. +class MigrationServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using MigrationServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_migration_v2_internal::MigrationServiceRetryTraits>; +/** + * A retry policy for `MigrationServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MigrationServiceLimitedErrorCountRetryPolicy + : public MigrationServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MigrationServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MigrationServiceLimitedErrorCountRetryPolicy( + MigrationServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : MigrationServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MigrationServiceLimitedErrorCountRetryPolicy( + MigrationServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : MigrationServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MigrationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_migration_v2_internal::MigrationServiceRetryTraits> + impl_; +}; -using MigrationServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_migration_v2_internal::MigrationServiceRetryTraits>; +/** + * A retry policy for `MigrationServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MigrationServiceLimitedTimeRetryPolicy + : public MigrationServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MigrationServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MigrationServiceLimitedTimeRetryPolicy( + MigrationServiceLimitedTimeRetryPolicy&& rhs) noexcept + : MigrationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MigrationServiceLimitedTimeRetryPolicy( + MigrationServiceLimitedTimeRetryPolicy const& rhs) noexcept + : MigrationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MigrationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_migration_v2_internal::MigrationServiceRetryTraits> + impl_; +}; /** * The `MigrationServiceConnection` object for `MigrationServiceClient`. diff --git a/google/cloud/bigquery/reservation/v1/reservation_connection.h b/google/cloud/bigquery/reservation/v1/reservation_connection.h index 35aec1a6dc076..e0eebb61a4c52 100644 --- a/google/cloud/bigquery/reservation/v1/reservation_connection.h +++ b/google/cloud/bigquery/reservation/v1/reservation_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace bigquery_reservation_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ReservationServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_reservation_v1_internal::ReservationServiceRetryTraits>; +/// The retry policy for `ReservationServiceConnection`. +class ReservationServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ReservationServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_reservation_v1_internal::ReservationServiceRetryTraits>; +/** + * A retry policy for `ReservationServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ReservationServiceLimitedErrorCountRetryPolicy + : public ReservationServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ReservationServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ReservationServiceLimitedErrorCountRetryPolicy( + ReservationServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ReservationServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + ReservationServiceLimitedErrorCountRetryPolicy( + ReservationServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ReservationServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ReservationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_reservation_v1_internal::ReservationServiceRetryTraits> + impl_; +}; -using ReservationServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_reservation_v1_internal::ReservationServiceRetryTraits>; +/** + * A retry policy for `ReservationServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ReservationServiceLimitedTimeRetryPolicy + : public ReservationServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ReservationServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ReservationServiceLimitedTimeRetryPolicy( + ReservationServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ReservationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ReservationServiceLimitedTimeRetryPolicy( + ReservationServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ReservationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ReservationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_reservation_v1_internal::ReservationServiceRetryTraits> + impl_; +}; /** * The `ReservationServiceConnection` object for `ReservationServiceClient`. diff --git a/google/cloud/bigquery/storage/v1/bigquery_read_connection.h b/google/cloud/bigquery/storage/v1/bigquery_read_connection.h index 1235c1fcdec38..63a7245212169 100644 --- a/google/cloud/bigquery/storage/v1/bigquery_read_connection.h +++ b/google/cloud/bigquery/storage/v1/bigquery_read_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace bigquery_storage_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BigQueryReadRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_storage_v1_internal::BigQueryReadRetryTraits>; +/// The retry policy for `BigQueryReadConnection`. +class BigQueryReadRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `BigQueryReadConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BigQueryReadLimitedErrorCountRetryPolicy + : public BigQueryReadRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BigQueryReadLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BigQueryReadLimitedErrorCountRetryPolicy( + BigQueryReadLimitedErrorCountRetryPolicy&& rhs) noexcept + : BigQueryReadLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BigQueryReadLimitedErrorCountRetryPolicy( + BigQueryReadLimitedErrorCountRetryPolicy const& rhs) noexcept + : BigQueryReadLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BigQueryReadRetryPolicy; -using BigQueryReadLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_storage_v1_internal::BigQueryReadRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_storage_v1_internal::BigQueryReadRetryTraits> + impl_; +}; + +/** + * A retry policy for `BigQueryReadConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BigQueryReadLimitedTimeRetryPolicy : public BigQueryReadRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BigQueryReadLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BigQueryReadLimitedTimeRetryPolicy( + BigQueryReadLimitedTimeRetryPolicy&& rhs) noexcept + : BigQueryReadLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BigQueryReadLimitedTimeRetryPolicy( + BigQueryReadLimitedTimeRetryPolicy const& rhs) noexcept + : BigQueryReadLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using BigQueryReadLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_storage_v1_internal::BigQueryReadRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BigQueryReadRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_storage_v1_internal::BigQueryReadRetryTraits> + impl_; +}; /** * The `BigQueryReadConnection` object for `BigQueryReadClient`. diff --git a/google/cloud/bigquery/storage/v1/bigquery_write_connection.h b/google/cloud/bigquery/storage/v1/bigquery_write_connection.h index 0ecc5f956ea9a..a2dd1c8ee5550 100644 --- a/google/cloud/bigquery/storage/v1/bigquery_write_connection.h +++ b/google/cloud/bigquery/storage/v1/bigquery_write_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace bigquery_storage_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BigQueryWriteRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigquery_storage_v1_internal::BigQueryWriteRetryTraits>; +/// The retry policy for `BigQueryWriteConnection`. +class BigQueryWriteRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BigQueryWriteLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigquery_storage_v1_internal::BigQueryWriteRetryTraits>; +/** + * A retry policy for `BigQueryWriteConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BigQueryWriteLimitedErrorCountRetryPolicy + : public BigQueryWriteRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BigQueryWriteLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BigQueryWriteLimitedErrorCountRetryPolicy( + BigQueryWriteLimitedErrorCountRetryPolicy&& rhs) noexcept + : BigQueryWriteLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BigQueryWriteLimitedErrorCountRetryPolicy( + BigQueryWriteLimitedErrorCountRetryPolicy const& rhs) noexcept + : BigQueryWriteLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BigQueryWriteRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_storage_v1_internal::BigQueryWriteRetryTraits> + impl_; +}; -using BigQueryWriteLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigquery_storage_v1_internal::BigQueryWriteRetryTraits>; +/** + * A retry policy for `BigQueryWriteConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BigQueryWriteLimitedTimeRetryPolicy : public BigQueryWriteRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BigQueryWriteLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BigQueryWriteLimitedTimeRetryPolicy( + BigQueryWriteLimitedTimeRetryPolicy&& rhs) noexcept + : BigQueryWriteLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BigQueryWriteLimitedTimeRetryPolicy( + BigQueryWriteLimitedTimeRetryPolicy const& rhs) noexcept + : BigQueryWriteLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BigQueryWriteRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_storage_v1_internal::BigQueryWriteRetryTraits> + impl_; +}; /** * The `BigQueryWriteConnection` object for `BigQueryWriteClient`. diff --git a/google/cloud/bigtable/admin/bigtable_instance_admin_connection.h b/google/cloud/bigtable/admin/bigtable_instance_admin_connection.h index f0756e752e70c..45b723ab38d46 100644 --- a/google/cloud/bigtable/admin/bigtable_instance_admin_connection.h +++ b/google/cloud/bigtable/admin/bigtable_instance_admin_connection.h @@ -38,17 +38,141 @@ namespace cloud { namespace bigtable_admin { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BigtableInstanceAdminRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigtable_admin_internal::BigtableInstanceAdminRetryTraits>; +/// The retry policy for `BigtableInstanceAdminConnection`. +class BigtableInstanceAdminRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BigtableInstanceAdminLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigtable_admin_internal::BigtableInstanceAdminRetryTraits>; +/** + * A retry policy for `BigtableInstanceAdminConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kAborted`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BigtableInstanceAdminLimitedErrorCountRetryPolicy + : public BigtableInstanceAdminRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BigtableInstanceAdminLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + BigtableInstanceAdminLimitedErrorCountRetryPolicy( + BigtableInstanceAdminLimitedErrorCountRetryPolicy&& rhs) noexcept + : BigtableInstanceAdminLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + BigtableInstanceAdminLimitedErrorCountRetryPolicy( + BigtableInstanceAdminLimitedErrorCountRetryPolicy const& rhs) noexcept + : BigtableInstanceAdminLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BigtableInstanceAdminRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigtable_admin_internal::BigtableInstanceAdminRetryTraits> + impl_; +}; -using BigtableInstanceAdminLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigtable_admin_internal::BigtableInstanceAdminRetryTraits>; +/** + * A retry policy for `BigtableInstanceAdminConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kAborted`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BigtableInstanceAdminLimitedTimeRetryPolicy + : public BigtableInstanceAdminRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BigtableInstanceAdminLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BigtableInstanceAdminLimitedTimeRetryPolicy( + BigtableInstanceAdminLimitedTimeRetryPolicy&& rhs) noexcept + : BigtableInstanceAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BigtableInstanceAdminLimitedTimeRetryPolicy( + BigtableInstanceAdminLimitedTimeRetryPolicy const& rhs) noexcept + : BigtableInstanceAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BigtableInstanceAdminRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigtable_admin_internal::BigtableInstanceAdminRetryTraits> + impl_; +}; /** * The `BigtableInstanceAdminConnection` object for diff --git a/google/cloud/bigtable/admin/bigtable_table_admin_connection.h b/google/cloud/bigtable/admin/bigtable_table_admin_connection.h index f63a058428094..663e51e9bf6e7 100644 --- a/google/cloud/bigtable/admin/bigtable_table_admin_connection.h +++ b/google/cloud/bigtable/admin/bigtable_table_admin_connection.h @@ -38,17 +38,139 @@ namespace cloud { namespace bigtable_admin { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BigtableTableAdminRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - bigtable_admin_internal::BigtableTableAdminRetryTraits>; +/// The retry policy for `BigtableTableAdminConnection`. +class BigtableTableAdminRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BigtableTableAdminLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - bigtable_admin_internal::BigtableTableAdminRetryTraits>; +/** + * A retry policy for `BigtableTableAdminConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kAborted`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BigtableTableAdminLimitedErrorCountRetryPolicy + : public BigtableTableAdminRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BigtableTableAdminLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BigtableTableAdminLimitedErrorCountRetryPolicy( + BigtableTableAdminLimitedErrorCountRetryPolicy&& rhs) noexcept + : BigtableTableAdminLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + BigtableTableAdminLimitedErrorCountRetryPolicy( + BigtableTableAdminLimitedErrorCountRetryPolicy const& rhs) noexcept + : BigtableTableAdminLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BigtableTableAdminRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigtable_admin_internal::BigtableTableAdminRetryTraits> + impl_; +}; -using BigtableTableAdminLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - bigtable_admin_internal::BigtableTableAdminRetryTraits>; +/** + * A retry policy for `BigtableTableAdminConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kAborted`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BigtableTableAdminLimitedTimeRetryPolicy + : public BigtableTableAdminRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BigtableTableAdminLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BigtableTableAdminLimitedTimeRetryPolicy( + BigtableTableAdminLimitedTimeRetryPolicy&& rhs) noexcept + : BigtableTableAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BigtableTableAdminLimitedTimeRetryPolicy( + BigtableTableAdminLimitedTimeRetryPolicy const& rhs) noexcept + : BigtableTableAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BigtableTableAdminRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigtable_admin_internal::BigtableTableAdminRetryTraits> + impl_; +}; /** * The `BigtableTableAdminConnection` object for `BigtableTableAdminClient`. diff --git a/google/cloud/billing/budgets/v1/budget_connection.h b/google/cloud/billing/budgets/v1/budget_connection.h index 793d83c6d3773..043e149ecd36b 100644 --- a/google/cloud/billing/budgets/v1/budget_connection.h +++ b/google/cloud/billing/budgets/v1/budget_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace billing_budgets_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BudgetServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - billing_budgets_v1_internal::BudgetServiceRetryTraits>; +/// The retry policy for `BudgetServiceConnection`. +class BudgetServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BudgetServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - billing_budgets_v1_internal::BudgetServiceRetryTraits>; +/** + * A retry policy for `BudgetServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BudgetServiceLimitedErrorCountRetryPolicy + : public BudgetServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BudgetServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BudgetServiceLimitedErrorCountRetryPolicy( + BudgetServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : BudgetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BudgetServiceLimitedErrorCountRetryPolicy( + BudgetServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : BudgetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BudgetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + billing_budgets_v1_internal::BudgetServiceRetryTraits> + impl_; +}; -using BudgetServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - billing_budgets_v1_internal::BudgetServiceRetryTraits>; +/** + * A retry policy for `BudgetServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BudgetServiceLimitedTimeRetryPolicy : public BudgetServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BudgetServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BudgetServiceLimitedTimeRetryPolicy( + BudgetServiceLimitedTimeRetryPolicy&& rhs) noexcept + : BudgetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BudgetServiceLimitedTimeRetryPolicy( + BudgetServiceLimitedTimeRetryPolicy const& rhs) noexcept + : BudgetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BudgetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + billing_budgets_v1_internal::BudgetServiceRetryTraits> + impl_; +}; /** * The `BudgetServiceConnection` object for `BudgetServiceClient`. diff --git a/google/cloud/billing/v1/cloud_billing_connection.h b/google/cloud/billing/v1/cloud_billing_connection.h index 51e28fa6cf0ec..fce3a08c100f2 100644 --- a/google/cloud/billing/v1/cloud_billing_connection.h +++ b/google/cloud/billing/v1/cloud_billing_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace billing_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudBillingRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - billing_v1_internal::CloudBillingRetryTraits>; +/// The retry policy for `CloudBillingConnection`. +class CloudBillingRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CloudBillingLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - billing_v1_internal::CloudBillingRetryTraits>; +/** + * A retry policy for `CloudBillingConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudBillingLimitedErrorCountRetryPolicy + : public CloudBillingRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudBillingLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudBillingLimitedErrorCountRetryPolicy( + CloudBillingLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudBillingLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudBillingLimitedErrorCountRetryPolicy( + CloudBillingLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudBillingLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudBillingRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + billing_v1_internal::CloudBillingRetryTraits> + impl_; +}; -using CloudBillingLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - billing_v1_internal::CloudBillingRetryTraits>; +/** + * A retry policy for `CloudBillingConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudBillingLimitedTimeRetryPolicy : public CloudBillingRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudBillingLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudBillingLimitedTimeRetryPolicy( + CloudBillingLimitedTimeRetryPolicy&& rhs) noexcept + : CloudBillingLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudBillingLimitedTimeRetryPolicy( + CloudBillingLimitedTimeRetryPolicy const& rhs) noexcept + : CloudBillingLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudBillingRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + billing_v1_internal::CloudBillingRetryTraits> + impl_; +}; /** * The `CloudBillingConnection` object for `CloudBillingClient`. diff --git a/google/cloud/billing/v1/cloud_catalog_connection.h b/google/cloud/billing/v1/cloud_catalog_connection.h index fe99eb19e7bac..3f7af5098a5b4 100644 --- a/google/cloud/billing/v1/cloud_catalog_connection.h +++ b/google/cloud/billing/v1/cloud_catalog_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace billing_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudCatalogRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - billing_v1_internal::CloudCatalogRetryTraits>; +/// The retry policy for `CloudCatalogConnection`. +class CloudCatalogRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CloudCatalogConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudCatalogLimitedErrorCountRetryPolicy + : public CloudCatalogRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudCatalogLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudCatalogLimitedErrorCountRetryPolicy( + CloudCatalogLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudCatalogLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudCatalogLimitedErrorCountRetryPolicy( + CloudCatalogLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudCatalogLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudCatalogRetryPolicy; -using CloudCatalogLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - billing_v1_internal::CloudCatalogRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + billing_v1_internal::CloudCatalogRetryTraits> + impl_; +}; + +/** + * A retry policy for `CloudCatalogConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudCatalogLimitedTimeRetryPolicy : public CloudCatalogRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudCatalogLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudCatalogLimitedTimeRetryPolicy( + CloudCatalogLimitedTimeRetryPolicy&& rhs) noexcept + : CloudCatalogLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudCatalogLimitedTimeRetryPolicy( + CloudCatalogLimitedTimeRetryPolicy const& rhs) noexcept + : CloudCatalogLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CloudCatalogLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - billing_v1_internal::CloudCatalogRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudCatalogRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + billing_v1_internal::CloudCatalogRetryTraits> + impl_; +}; /** * The `CloudCatalogConnection` object for `CloudCatalogClient`. diff --git a/google/cloud/binaryauthorization/v1/binauthz_management_service_v1_connection.h b/google/cloud/binaryauthorization/v1/binauthz_management_service_v1_connection.h index 6cfde79c44214..db4fffc36869d 100644 --- a/google/cloud/binaryauthorization/v1/binauthz_management_service_v1_connection.h +++ b/google/cloud/binaryauthorization/v1/binauthz_management_service_v1_connection.h @@ -35,20 +35,148 @@ namespace cloud { namespace binaryauthorization_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BinauthzManagementServiceV1RetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - binaryauthorization_v1_internal:: - BinauthzManagementServiceV1RetryTraits>; - -using BinauthzManagementServiceV1LimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - binaryauthorization_v1_internal:: - BinauthzManagementServiceV1RetryTraits>; - -using BinauthzManagementServiceV1LimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - binaryauthorization_v1_internal:: - BinauthzManagementServiceV1RetryTraits>; +/// The retry policy for `BinauthzManagementServiceV1Connection`. +class BinauthzManagementServiceV1RetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `BinauthzManagementServiceV1Connection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BinauthzManagementServiceV1LimitedErrorCountRetryPolicy + : public BinauthzManagementServiceV1RetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BinauthzManagementServiceV1LimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + BinauthzManagementServiceV1LimitedErrorCountRetryPolicy( + BinauthzManagementServiceV1LimitedErrorCountRetryPolicy&& rhs) noexcept + : BinauthzManagementServiceV1LimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + BinauthzManagementServiceV1LimitedErrorCountRetryPolicy( + BinauthzManagementServiceV1LimitedErrorCountRetryPolicy const& + rhs) noexcept + : BinauthzManagementServiceV1LimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + BinauthzManagementServiceV1LimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BinauthzManagementServiceV1RetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + binaryauthorization_v1_internal::BinauthzManagementServiceV1RetryTraits> + impl_; +}; + +/** + * A retry policy for `BinauthzManagementServiceV1Connection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BinauthzManagementServiceV1LimitedTimeRetryPolicy + : public BinauthzManagementServiceV1RetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BinauthzManagementServiceV1LimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BinauthzManagementServiceV1LimitedTimeRetryPolicy( + BinauthzManagementServiceV1LimitedTimeRetryPolicy&& rhs) noexcept + : BinauthzManagementServiceV1LimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + BinauthzManagementServiceV1LimitedTimeRetryPolicy( + BinauthzManagementServiceV1LimitedTimeRetryPolicy const& rhs) noexcept + : BinauthzManagementServiceV1LimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BinauthzManagementServiceV1RetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + binaryauthorization_v1_internal::BinauthzManagementServiceV1RetryTraits> + impl_; +}; /** * The `BinauthzManagementServiceV1Connection` object for diff --git a/google/cloud/binaryauthorization/v1/system_policy_v1_connection.h b/google/cloud/binaryauthorization/v1/system_policy_v1_connection.h index 1b7c0df24b5b3..e290a300a0200 100644 --- a/google/cloud/binaryauthorization/v1/system_policy_v1_connection.h +++ b/google/cloud/binaryauthorization/v1/system_policy_v1_connection.h @@ -34,17 +34,134 @@ namespace cloud { namespace binaryauthorization_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SystemPolicyV1RetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - binaryauthorization_v1_internal::SystemPolicyV1RetryTraits>; +/// The retry policy for `SystemPolicyV1Connection`. +class SystemPolicyV1RetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SystemPolicyV1Connection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SystemPolicyV1LimitedErrorCountRetryPolicy + : public SystemPolicyV1RetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SystemPolicyV1LimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SystemPolicyV1LimitedErrorCountRetryPolicy( + SystemPolicyV1LimitedErrorCountRetryPolicy&& rhs) noexcept + : SystemPolicyV1LimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SystemPolicyV1LimitedErrorCountRetryPolicy( + SystemPolicyV1LimitedErrorCountRetryPolicy const& rhs) noexcept + : SystemPolicyV1LimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SystemPolicyV1RetryPolicy; -using SystemPolicyV1LimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - binaryauthorization_v1_internal::SystemPolicyV1RetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + binaryauthorization_v1_internal::SystemPolicyV1RetryTraits> + impl_; +}; + +/** + * A retry policy for `SystemPolicyV1Connection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SystemPolicyV1LimitedTimeRetryPolicy : public SystemPolicyV1RetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SystemPolicyV1LimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SystemPolicyV1LimitedTimeRetryPolicy( + SystemPolicyV1LimitedTimeRetryPolicy&& rhs) noexcept + : SystemPolicyV1LimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SystemPolicyV1LimitedTimeRetryPolicy( + SystemPolicyV1LimitedTimeRetryPolicy const& rhs) noexcept + : SystemPolicyV1LimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SystemPolicyV1LimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - binaryauthorization_v1_internal::SystemPolicyV1RetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SystemPolicyV1RetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + binaryauthorization_v1_internal::SystemPolicyV1RetryTraits> + impl_; +}; /** * The `SystemPolicyV1Connection` object for `SystemPolicyV1Client`. diff --git a/google/cloud/binaryauthorization/v1/validation_helper_v1_connection.h b/google/cloud/binaryauthorization/v1/validation_helper_v1_connection.h index 8ef1b5c37664d..2813a6ff98716 100644 --- a/google/cloud/binaryauthorization/v1/validation_helper_v1_connection.h +++ b/google/cloud/binaryauthorization/v1/validation_helper_v1_connection.h @@ -34,17 +34,137 @@ namespace cloud { namespace binaryauthorization_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ValidationHelperV1RetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - binaryauthorization_v1_internal::ValidationHelperV1RetryTraits>; +/// The retry policy for `ValidationHelperV1Connection`. +class ValidationHelperV1RetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ValidationHelperV1Connection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ValidationHelperV1LimitedErrorCountRetryPolicy + : public ValidationHelperV1RetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ValidationHelperV1LimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ValidationHelperV1LimitedErrorCountRetryPolicy( + ValidationHelperV1LimitedErrorCountRetryPolicy&& rhs) noexcept + : ValidationHelperV1LimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + ValidationHelperV1LimitedErrorCountRetryPolicy( + ValidationHelperV1LimitedErrorCountRetryPolicy const& rhs) noexcept + : ValidationHelperV1LimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ValidationHelperV1RetryPolicy; -using ValidationHelperV1LimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - binaryauthorization_v1_internal::ValidationHelperV1RetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + binaryauthorization_v1_internal::ValidationHelperV1RetryTraits> + impl_; +}; + +/** + * A retry policy for `ValidationHelperV1Connection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ValidationHelperV1LimitedTimeRetryPolicy + : public ValidationHelperV1RetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ValidationHelperV1LimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ValidationHelperV1LimitedTimeRetryPolicy( + ValidationHelperV1LimitedTimeRetryPolicy&& rhs) noexcept + : ValidationHelperV1LimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ValidationHelperV1LimitedTimeRetryPolicy( + ValidationHelperV1LimitedTimeRetryPolicy const& rhs) noexcept + : ValidationHelperV1LimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ValidationHelperV1LimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - binaryauthorization_v1_internal::ValidationHelperV1RetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ValidationHelperV1RetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + binaryauthorization_v1_internal::ValidationHelperV1RetryTraits> + impl_; +}; /** * The `ValidationHelperV1Connection` object for `ValidationHelperV1Client`. diff --git a/google/cloud/certificatemanager/v1/certificate_manager_connection.h b/google/cloud/certificatemanager/v1/certificate_manager_connection.h index ad00fbfe7ba81..b76bfc09926b0 100644 --- a/google/cloud/certificatemanager/v1/certificate_manager_connection.h +++ b/google/cloud/certificatemanager/v1/certificate_manager_connection.h @@ -38,17 +38,137 @@ namespace cloud { namespace certificatemanager_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CertificateManagerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - certificatemanager_v1_internal::CertificateManagerRetryTraits>; +/// The retry policy for `CertificateManagerConnection`. +class CertificateManagerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CertificateManagerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - certificatemanager_v1_internal::CertificateManagerRetryTraits>; +/** + * A retry policy for `CertificateManagerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CertificateManagerLimitedErrorCountRetryPolicy + : public CertificateManagerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CertificateManagerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CertificateManagerLimitedErrorCountRetryPolicy( + CertificateManagerLimitedErrorCountRetryPolicy&& rhs) noexcept + : CertificateManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + CertificateManagerLimitedErrorCountRetryPolicy( + CertificateManagerLimitedErrorCountRetryPolicy const& rhs) noexcept + : CertificateManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CertificateManagerRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + certificatemanager_v1_internal::CertificateManagerRetryTraits> + impl_; +}; -using CertificateManagerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - certificatemanager_v1_internal::CertificateManagerRetryTraits>; +/** + * A retry policy for `CertificateManagerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CertificateManagerLimitedTimeRetryPolicy + : public CertificateManagerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CertificateManagerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CertificateManagerLimitedTimeRetryPolicy( + CertificateManagerLimitedTimeRetryPolicy&& rhs) noexcept + : CertificateManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CertificateManagerLimitedTimeRetryPolicy( + CertificateManagerLimitedTimeRetryPolicy const& rhs) noexcept + : CertificateManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CertificateManagerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + certificatemanager_v1_internal::CertificateManagerRetryTraits> + impl_; +}; /** * The `CertificateManagerConnection` object for `CertificateManagerClient`. diff --git a/google/cloud/channel/v1/cloud_channel_connection.h b/google/cloud/channel/v1/cloud_channel_connection.h index 188d3f0cce381..44fe07433b0c5 100644 --- a/google/cloud/channel/v1/cloud_channel_connection.h +++ b/google/cloud/channel/v1/cloud_channel_connection.h @@ -39,17 +39,137 @@ namespace cloud { namespace channel_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudChannelServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - channel_v1_internal::CloudChannelServiceRetryTraits>; +/// The retry policy for `CloudChannelServiceConnection`. +class CloudChannelServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CloudChannelServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - channel_v1_internal::CloudChannelServiceRetryTraits>; +/** + * A retry policy for `CloudChannelServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudChannelServiceLimitedErrorCountRetryPolicy + : public CloudChannelServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudChannelServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudChannelServiceLimitedErrorCountRetryPolicy( + CloudChannelServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudChannelServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + CloudChannelServiceLimitedErrorCountRetryPolicy( + CloudChannelServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudChannelServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudChannelServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + channel_v1_internal::CloudChannelServiceRetryTraits> + impl_; +}; -using CloudChannelServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - channel_v1_internal::CloudChannelServiceRetryTraits>; +/** + * A retry policy for `CloudChannelServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudChannelServiceLimitedTimeRetryPolicy + : public CloudChannelServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudChannelServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudChannelServiceLimitedTimeRetryPolicy( + CloudChannelServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CloudChannelServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudChannelServiceLimitedTimeRetryPolicy( + CloudChannelServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CloudChannelServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudChannelServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + channel_v1_internal::CloudChannelServiceRetryTraits> + impl_; +}; /** * The `CloudChannelServiceConnection` object for `CloudChannelServiceClient`. diff --git a/google/cloud/cloudbuild/v1/cloud_build_connection.h b/google/cloud/cloudbuild/v1/cloud_build_connection.h index d7e5500051007..1ea0c833f672b 100644 --- a/google/cloud/cloudbuild/v1/cloud_build_connection.h +++ b/google/cloud/cloudbuild/v1/cloud_build_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace cloudbuild_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudBuildRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - cloudbuild_v1_internal::CloudBuildRetryTraits>; +/// The retry policy for `CloudBuildConnection`. +class CloudBuildRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CloudBuildConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudBuildLimitedErrorCountRetryPolicy : public CloudBuildRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudBuildLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudBuildLimitedErrorCountRetryPolicy( + CloudBuildLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudBuildLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudBuildLimitedErrorCountRetryPolicy( + CloudBuildLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudBuildLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudBuildRetryPolicy; -using CloudBuildLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - cloudbuild_v1_internal::CloudBuildRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + cloudbuild_v1_internal::CloudBuildRetryTraits> + impl_; +}; + +/** + * A retry policy for `CloudBuildConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudBuildLimitedTimeRetryPolicy : public CloudBuildRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudBuildLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudBuildLimitedTimeRetryPolicy( + CloudBuildLimitedTimeRetryPolicy&& rhs) noexcept + : CloudBuildLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudBuildLimitedTimeRetryPolicy( + CloudBuildLimitedTimeRetryPolicy const& rhs) noexcept + : CloudBuildLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CloudBuildLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - cloudbuild_v1_internal::CloudBuildRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudBuildRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + cloudbuild_v1_internal::CloudBuildRetryTraits> + impl_; +}; /** * The `CloudBuildConnection` object for `CloudBuildClient`. diff --git a/google/cloud/cloudbuild/v2/repository_manager_connection.h b/google/cloud/cloudbuild/v2/repository_manager_connection.h index 49dabb64feee5..48d2d33624e84 100644 --- a/google/cloud/cloudbuild/v2/repository_manager_connection.h +++ b/google/cloud/cloudbuild/v2/repository_manager_connection.h @@ -40,17 +40,135 @@ namespace cloud { namespace cloudbuild_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RepositoryManagerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - cloudbuild_v2_internal::RepositoryManagerRetryTraits>; +/// The retry policy for `RepositoryManagerConnection`. +class RepositoryManagerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RepositoryManagerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RepositoryManagerLimitedErrorCountRetryPolicy + : public RepositoryManagerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RepositoryManagerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RepositoryManagerLimitedErrorCountRetryPolicy( + RepositoryManagerLimitedErrorCountRetryPolicy&& rhs) noexcept + : RepositoryManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RepositoryManagerLimitedErrorCountRetryPolicy( + RepositoryManagerLimitedErrorCountRetryPolicy const& rhs) noexcept + : RepositoryManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RepositoryManagerRetryPolicy; -using RepositoryManagerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - cloudbuild_v2_internal::RepositoryManagerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + cloudbuild_v2_internal::RepositoryManagerRetryTraits> + impl_; +}; + +/** + * A retry policy for `RepositoryManagerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RepositoryManagerLimitedTimeRetryPolicy + : public RepositoryManagerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RepositoryManagerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RepositoryManagerLimitedTimeRetryPolicy( + RepositoryManagerLimitedTimeRetryPolicy&& rhs) noexcept + : RepositoryManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RepositoryManagerLimitedTimeRetryPolicy( + RepositoryManagerLimitedTimeRetryPolicy const& rhs) noexcept + : RepositoryManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RepositoryManagerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - cloudbuild_v2_internal::RepositoryManagerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RepositoryManagerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + cloudbuild_v2_internal::RepositoryManagerRetryTraits> + impl_; +}; /** * The `RepositoryManagerConnection` object for `RepositoryManagerClient`. diff --git a/google/cloud/composer/v1/environments_connection.h b/google/cloud/composer/v1/environments_connection.h index c4b8befd46d0c..19ceb8693bfab 100644 --- a/google/cloud/composer/v1/environments_connection.h +++ b/google/cloud/composer/v1/environments_connection.h @@ -39,17 +39,134 @@ namespace cloud { namespace composer_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EnvironmentsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - composer_v1_internal::EnvironmentsRetryTraits>; +/// The retry policy for `EnvironmentsConnection`. +class EnvironmentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `EnvironmentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EnvironmentsLimitedErrorCountRetryPolicy + : public EnvironmentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EnvironmentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EnvironmentsLimitedErrorCountRetryPolicy( + EnvironmentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : EnvironmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EnvironmentsLimitedErrorCountRetryPolicy( + EnvironmentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : EnvironmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EnvironmentsRetryPolicy; -using EnvironmentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - composer_v1_internal::EnvironmentsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + composer_v1_internal::EnvironmentsRetryTraits> + impl_; +}; + +/** + * A retry policy for `EnvironmentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EnvironmentsLimitedTimeRetryPolicy : public EnvironmentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EnvironmentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EnvironmentsLimitedTimeRetryPolicy( + EnvironmentsLimitedTimeRetryPolicy&& rhs) noexcept + : EnvironmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EnvironmentsLimitedTimeRetryPolicy( + EnvironmentsLimitedTimeRetryPolicy const& rhs) noexcept + : EnvironmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using EnvironmentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - composer_v1_internal::EnvironmentsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EnvironmentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + composer_v1_internal::EnvironmentsRetryTraits> + impl_; +}; /** * The `EnvironmentsConnection` object for `EnvironmentsClient`. diff --git a/google/cloud/composer/v1/image_versions_connection.h b/google/cloud/composer/v1/image_versions_connection.h index ddd44ef2ac6b0..cd883f8230410 100644 --- a/google/cloud/composer/v1/image_versions_connection.h +++ b/google/cloud/composer/v1/image_versions_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace composer_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ImageVersionsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - composer_v1_internal::ImageVersionsRetryTraits>; +/// The retry policy for `ImageVersionsConnection`. +class ImageVersionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ImageVersionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ImageVersionsLimitedErrorCountRetryPolicy + : public ImageVersionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ImageVersionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ImageVersionsLimitedErrorCountRetryPolicy( + ImageVersionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ImageVersionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ImageVersionsLimitedErrorCountRetryPolicy( + ImageVersionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ImageVersionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ImageVersionsRetryPolicy; -using ImageVersionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - composer_v1_internal::ImageVersionsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + composer_v1_internal::ImageVersionsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ImageVersionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ImageVersionsLimitedTimeRetryPolicy : public ImageVersionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ImageVersionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ImageVersionsLimitedTimeRetryPolicy( + ImageVersionsLimitedTimeRetryPolicy&& rhs) noexcept + : ImageVersionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ImageVersionsLimitedTimeRetryPolicy( + ImageVersionsLimitedTimeRetryPolicy const& rhs) noexcept + : ImageVersionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ImageVersionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - composer_v1_internal::ImageVersionsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ImageVersionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + composer_v1_internal::ImageVersionsRetryTraits> + impl_; +}; /** * The `ImageVersionsConnection` object for `ImageVersionsClient`. diff --git a/google/cloud/compute/accelerator_types/v1/accelerator_types_connection.h b/google/cloud/compute/accelerator_types/v1/accelerator_types_connection.h index 37a46d5132762..13f685b0c3635 100644 --- a/google/cloud/compute/accelerator_types/v1/accelerator_types_connection.h +++ b/google/cloud/compute/accelerator_types/v1/accelerator_types_connection.h @@ -36,17 +36,135 @@ namespace cloud { namespace compute_accelerator_types_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AcceleratorTypesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_accelerator_types_v1_internal::AcceleratorTypesRetryTraits>; +/// The retry policy for `AcceleratorTypesConnection`. +class AcceleratorTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AcceleratorTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AcceleratorTypesLimitedErrorCountRetryPolicy + : public AcceleratorTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AcceleratorTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AcceleratorTypesLimitedErrorCountRetryPolicy( + AcceleratorTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : AcceleratorTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AcceleratorTypesLimitedErrorCountRetryPolicy( + AcceleratorTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : AcceleratorTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AcceleratorTypesRetryPolicy; -using AcceleratorTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_accelerator_types_v1_internal::AcceleratorTypesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_accelerator_types_v1_internal::AcceleratorTypesRetryTraits> + impl_; +}; + +/** + * A retry policy for `AcceleratorTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AcceleratorTypesLimitedTimeRetryPolicy + : public AcceleratorTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AcceleratorTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AcceleratorTypesLimitedTimeRetryPolicy( + AcceleratorTypesLimitedTimeRetryPolicy&& rhs) noexcept + : AcceleratorTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AcceleratorTypesLimitedTimeRetryPolicy( + AcceleratorTypesLimitedTimeRetryPolicy const& rhs) noexcept + : AcceleratorTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AcceleratorTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_accelerator_types_v1_internal::AcceleratorTypesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AcceleratorTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_accelerator_types_v1_internal::AcceleratorTypesRetryTraits> + impl_; +}; /** * The `AcceleratorTypesConnection` object for `AcceleratorTypesClient`. diff --git a/google/cloud/compute/addresses/v1/addresses_connection.h b/google/cloud/compute/addresses/v1/addresses_connection.h index 8c0c3936f3206..e96effe814ede 100644 --- a/google/cloud/compute/addresses/v1/addresses_connection.h +++ b/google/cloud/compute/addresses/v1/addresses_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_addresses_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AddressesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_addresses_v1_internal::AddressesRetryTraits>; +/// The retry policy for `AddressesConnection`. +class AddressesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AddressesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_addresses_v1_internal::AddressesRetryTraits>; +/** + * A retry policy for `AddressesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AddressesLimitedErrorCountRetryPolicy : public AddressesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AddressesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AddressesLimitedErrorCountRetryPolicy( + AddressesLimitedErrorCountRetryPolicy&& rhs) noexcept + : AddressesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AddressesLimitedErrorCountRetryPolicy( + AddressesLimitedErrorCountRetryPolicy const& rhs) noexcept + : AddressesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AddressesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_addresses_v1_internal::AddressesRetryTraits> + impl_; +}; -using AddressesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_addresses_v1_internal::AddressesRetryTraits>; +/** + * A retry policy for `AddressesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AddressesLimitedTimeRetryPolicy : public AddressesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AddressesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AddressesLimitedTimeRetryPolicy( + AddressesLimitedTimeRetryPolicy&& rhs) noexcept + : AddressesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AddressesLimitedTimeRetryPolicy( + AddressesLimitedTimeRetryPolicy const& rhs) noexcept + : AddressesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AddressesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_addresses_v1_internal::AddressesRetryTraits> + impl_; +}; /** * The `AddressesConnection` object for `AddressesClient`. diff --git a/google/cloud/compute/autoscalers/v1/autoscalers_connection.h b/google/cloud/compute/autoscalers/v1/autoscalers_connection.h index db6ef608efe26..7314e5fc292b6 100644 --- a/google/cloud/compute/autoscalers/v1/autoscalers_connection.h +++ b/google/cloud/compute/autoscalers/v1/autoscalers_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_autoscalers_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AutoscalersRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_autoscalers_v1_internal::AutoscalersRetryTraits>; +/// The retry policy for `AutoscalersConnection`. +class AutoscalersRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AutoscalersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_autoscalers_v1_internal::AutoscalersRetryTraits>; +/** + * A retry policy for `AutoscalersConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AutoscalersLimitedErrorCountRetryPolicy : public AutoscalersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AutoscalersLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AutoscalersLimitedErrorCountRetryPolicy( + AutoscalersLimitedErrorCountRetryPolicy&& rhs) noexcept + : AutoscalersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AutoscalersLimitedErrorCountRetryPolicy( + AutoscalersLimitedErrorCountRetryPolicy const& rhs) noexcept + : AutoscalersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AutoscalersRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_autoscalers_v1_internal::AutoscalersRetryTraits> + impl_; +}; -using AutoscalersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_autoscalers_v1_internal::AutoscalersRetryTraits>; +/** + * A retry policy for `AutoscalersConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AutoscalersLimitedTimeRetryPolicy : public AutoscalersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AutoscalersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AutoscalersLimitedTimeRetryPolicy( + AutoscalersLimitedTimeRetryPolicy&& rhs) noexcept + : AutoscalersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AutoscalersLimitedTimeRetryPolicy( + AutoscalersLimitedTimeRetryPolicy const& rhs) noexcept + : AutoscalersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AutoscalersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_autoscalers_v1_internal::AutoscalersRetryTraits> + impl_; +}; /** * The `AutoscalersConnection` object for `AutoscalersClient`. diff --git a/google/cloud/compute/backend_buckets/v1/backend_buckets_connection.h b/google/cloud/compute/backend_buckets/v1/backend_buckets_connection.h index fc933025551f3..54bc895ae737b 100644 --- a/google/cloud/compute/backend_buckets/v1/backend_buckets_connection.h +++ b/google/cloud/compute/backend_buckets/v1/backend_buckets_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace compute_backend_buckets_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BackendBucketsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_backend_buckets_v1_internal::BackendBucketsRetryTraits>; +/// The retry policy for `BackendBucketsConnection`. +class BackendBucketsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BackendBucketsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_backend_buckets_v1_internal::BackendBucketsRetryTraits>; +/** + * A retry policy for `BackendBucketsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BackendBucketsLimitedErrorCountRetryPolicy + : public BackendBucketsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BackendBucketsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BackendBucketsLimitedErrorCountRetryPolicy( + BackendBucketsLimitedErrorCountRetryPolicy&& rhs) noexcept + : BackendBucketsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BackendBucketsLimitedErrorCountRetryPolicy( + BackendBucketsLimitedErrorCountRetryPolicy const& rhs) noexcept + : BackendBucketsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BackendBucketsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_backend_buckets_v1_internal::BackendBucketsRetryTraits> + impl_; +}; -using BackendBucketsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_backend_buckets_v1_internal::BackendBucketsRetryTraits>; +/** + * A retry policy for `BackendBucketsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BackendBucketsLimitedTimeRetryPolicy : public BackendBucketsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BackendBucketsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BackendBucketsLimitedTimeRetryPolicy( + BackendBucketsLimitedTimeRetryPolicy&& rhs) noexcept + : BackendBucketsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BackendBucketsLimitedTimeRetryPolicy( + BackendBucketsLimitedTimeRetryPolicy const& rhs) noexcept + : BackendBucketsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BackendBucketsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_backend_buckets_v1_internal::BackendBucketsRetryTraits> + impl_; +}; /** * The `BackendBucketsConnection` object for `BackendBucketsClient`. diff --git a/google/cloud/compute/backend_services/v1/backend_services_connection.h b/google/cloud/compute/backend_services/v1/backend_services_connection.h index 81880db4adeab..243cc2319f5bf 100644 --- a/google/cloud/compute/backend_services/v1/backend_services_connection.h +++ b/google/cloud/compute/backend_services/v1/backend_services_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_backend_services_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BackendServicesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_backend_services_v1_internal::BackendServicesRetryTraits>; +/// The retry policy for `BackendServicesConnection`. +class BackendServicesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BackendServicesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_backend_services_v1_internal::BackendServicesRetryTraits>; +/** + * A retry policy for `BackendServicesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BackendServicesLimitedErrorCountRetryPolicy + : public BackendServicesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BackendServicesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BackendServicesLimitedErrorCountRetryPolicy( + BackendServicesLimitedErrorCountRetryPolicy&& rhs) noexcept + : BackendServicesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BackendServicesLimitedErrorCountRetryPolicy( + BackendServicesLimitedErrorCountRetryPolicy const& rhs) noexcept + : BackendServicesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BackendServicesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_backend_services_v1_internal::BackendServicesRetryTraits> + impl_; +}; -using BackendServicesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_backend_services_v1_internal::BackendServicesRetryTraits>; +/** + * A retry policy for `BackendServicesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BackendServicesLimitedTimeRetryPolicy + : public BackendServicesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BackendServicesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BackendServicesLimitedTimeRetryPolicy( + BackendServicesLimitedTimeRetryPolicy&& rhs) noexcept + : BackendServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BackendServicesLimitedTimeRetryPolicy( + BackendServicesLimitedTimeRetryPolicy const& rhs) noexcept + : BackendServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BackendServicesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_backend_services_v1_internal::BackendServicesRetryTraits> + impl_; +}; /** * The `BackendServicesConnection` object for `BackendServicesClient`. diff --git a/google/cloud/compute/disk_types/v1/disk_types_connection.h b/google/cloud/compute/disk_types/v1/disk_types_connection.h index 1031ea7237dac..a5c57b2b2588d 100644 --- a/google/cloud/compute/disk_types/v1/disk_types_connection.h +++ b/google/cloud/compute/disk_types/v1/disk_types_connection.h @@ -36,16 +36,133 @@ namespace cloud { namespace compute_disk_types_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DiskTypesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_disk_types_v1_internal::DiskTypesRetryTraits>; +/// The retry policy for `DiskTypesConnection`. +class DiskTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DiskTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DiskTypesLimitedErrorCountRetryPolicy : public DiskTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DiskTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DiskTypesLimitedErrorCountRetryPolicy( + DiskTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : DiskTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DiskTypesLimitedErrorCountRetryPolicy( + DiskTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : DiskTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DiskTypesRetryPolicy; -using DiskTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_disk_types_v1_internal::DiskTypesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_disk_types_v1_internal::DiskTypesRetryTraits> + impl_; +}; + +/** + * A retry policy for `DiskTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DiskTypesLimitedTimeRetryPolicy : public DiskTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DiskTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DiskTypesLimitedTimeRetryPolicy( + DiskTypesLimitedTimeRetryPolicy&& rhs) noexcept + : DiskTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DiskTypesLimitedTimeRetryPolicy( + DiskTypesLimitedTimeRetryPolicy const& rhs) noexcept + : DiskTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DiskTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_disk_types_v1_internal::DiskTypesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DiskTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_disk_types_v1_internal::DiskTypesRetryTraits> + impl_; +}; /** * The `DiskTypesConnection` object for `DiskTypesClient`. diff --git a/google/cloud/compute/disks/v1/disks_connection.h b/google/cloud/compute/disks/v1/disks_connection.h index 83be0586a0b5d..14916ccc99033 100644 --- a/google/cloud/compute/disks/v1/disks_connection.h +++ b/google/cloud/compute/disks/v1/disks_connection.h @@ -38,16 +38,130 @@ namespace cloud { namespace compute_disks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DisksRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_disks_v1_internal::DisksRetryTraits>; +/// The retry policy for `DisksConnection`. +class DisksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DisksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_disks_v1_internal::DisksRetryTraits>; +/** + * A retry policy for `DisksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DisksLimitedErrorCountRetryPolicy : public DisksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DisksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DisksLimitedErrorCountRetryPolicy( + DisksLimitedErrorCountRetryPolicy&& rhs) noexcept + : DisksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DisksLimitedErrorCountRetryPolicy( + DisksLimitedErrorCountRetryPolicy const& rhs) noexcept + : DisksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DisksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_disks_v1_internal::DisksRetryTraits> + impl_; +}; -using DisksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_disks_v1_internal::DisksRetryTraits>; +/** + * A retry policy for `DisksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DisksLimitedTimeRetryPolicy : public DisksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DisksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DisksLimitedTimeRetryPolicy(DisksLimitedTimeRetryPolicy&& rhs) noexcept + : DisksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DisksLimitedTimeRetryPolicy(DisksLimitedTimeRetryPolicy const& rhs) noexcept + : DisksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DisksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_disks_v1_internal::DisksRetryTraits> + impl_; +}; /** * The `DisksConnection` object for `DisksClient`. diff --git a/google/cloud/compute/external_vpn_gateways/v1/external_vpn_gateways_connection.h b/google/cloud/compute/external_vpn_gateways/v1/external_vpn_gateways_connection.h index 2633a711db304..c7d287aba39b0 100644 --- a/google/cloud/compute/external_vpn_gateways/v1/external_vpn_gateways_connection.h +++ b/google/cloud/compute/external_vpn_gateways/v1/external_vpn_gateways_connection.h @@ -39,20 +39,137 @@ namespace cloud { namespace compute_external_vpn_gateways_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ExternalVpnGatewaysRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_external_vpn_gateways_v1_internal:: - ExternalVpnGatewaysRetryTraits>; - -using ExternalVpnGatewaysLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_external_vpn_gateways_v1_internal:: - ExternalVpnGatewaysRetryTraits>; - -using ExternalVpnGatewaysLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_external_vpn_gateways_v1_internal:: - ExternalVpnGatewaysRetryTraits>; +/// The retry policy for `ExternalVpnGatewaysConnection`. +class ExternalVpnGatewaysRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ExternalVpnGatewaysConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ExternalVpnGatewaysLimitedErrorCountRetryPolicy + : public ExternalVpnGatewaysRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ExternalVpnGatewaysLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ExternalVpnGatewaysLimitedErrorCountRetryPolicy( + ExternalVpnGatewaysLimitedErrorCountRetryPolicy&& rhs) noexcept + : ExternalVpnGatewaysLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ExternalVpnGatewaysLimitedErrorCountRetryPolicy( + ExternalVpnGatewaysLimitedErrorCountRetryPolicy const& rhs) noexcept + : ExternalVpnGatewaysLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ExternalVpnGatewaysRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_external_vpn_gateways_v1_internal::ExternalVpnGatewaysRetryTraits> + impl_; +}; + +/** + * A retry policy for `ExternalVpnGatewaysConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ExternalVpnGatewaysLimitedTimeRetryPolicy + : public ExternalVpnGatewaysRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ExternalVpnGatewaysLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ExternalVpnGatewaysLimitedTimeRetryPolicy( + ExternalVpnGatewaysLimitedTimeRetryPolicy&& rhs) noexcept + : ExternalVpnGatewaysLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ExternalVpnGatewaysLimitedTimeRetryPolicy( + ExternalVpnGatewaysLimitedTimeRetryPolicy const& rhs) noexcept + : ExternalVpnGatewaysLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ExternalVpnGatewaysRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_external_vpn_gateways_v1_internal::ExternalVpnGatewaysRetryTraits> + impl_; +}; /** * The `ExternalVpnGatewaysConnection` object for `ExternalVpnGatewaysClient`. diff --git a/google/cloud/compute/firewall_policies/v1/firewall_policies_connection.h b/google/cloud/compute/firewall_policies/v1/firewall_policies_connection.h index e5c115d192bd2..c24da274195aa 100644 --- a/google/cloud/compute/firewall_policies/v1/firewall_policies_connection.h +++ b/google/cloud/compute/firewall_policies/v1/firewall_policies_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_firewall_policies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FirewallPoliciesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_firewall_policies_v1_internal::FirewallPoliciesRetryTraits>; +/// The retry policy for `FirewallPoliciesConnection`. +class FirewallPoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `FirewallPoliciesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FirewallPoliciesLimitedErrorCountRetryPolicy + : public FirewallPoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FirewallPoliciesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + FirewallPoliciesLimitedErrorCountRetryPolicy( + FirewallPoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : FirewallPoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + FirewallPoliciesLimitedErrorCountRetryPolicy( + FirewallPoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : FirewallPoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FirewallPoliciesRetryPolicy; -using FirewallPoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_firewall_policies_v1_internal::FirewallPoliciesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_firewall_policies_v1_internal::FirewallPoliciesRetryTraits> + impl_; +}; + +/** + * A retry policy for `FirewallPoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FirewallPoliciesLimitedTimeRetryPolicy + : public FirewallPoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FirewallPoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FirewallPoliciesLimitedTimeRetryPolicy( + FirewallPoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : FirewallPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + FirewallPoliciesLimitedTimeRetryPolicy( + FirewallPoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : FirewallPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using FirewallPoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_firewall_policies_v1_internal::FirewallPoliciesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FirewallPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_firewall_policies_v1_internal::FirewallPoliciesRetryTraits> + impl_; +}; /** * The `FirewallPoliciesConnection` object for `FirewallPoliciesClient`. diff --git a/google/cloud/compute/firewalls/v1/firewalls_connection.h b/google/cloud/compute/firewalls/v1/firewalls_connection.h index eba457c18b7e5..155e52d8c1ba7 100644 --- a/google/cloud/compute/firewalls/v1/firewalls_connection.h +++ b/google/cloud/compute/firewalls/v1/firewalls_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_firewalls_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FirewallsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_firewalls_v1_internal::FirewallsRetryTraits>; +/// The retry policy for `FirewallsConnection`. +class FirewallsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using FirewallsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_firewalls_v1_internal::FirewallsRetryTraits>; +/** + * A retry policy for `FirewallsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FirewallsLimitedErrorCountRetryPolicy : public FirewallsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FirewallsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + FirewallsLimitedErrorCountRetryPolicy( + FirewallsLimitedErrorCountRetryPolicy&& rhs) noexcept + : FirewallsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + FirewallsLimitedErrorCountRetryPolicy( + FirewallsLimitedErrorCountRetryPolicy const& rhs) noexcept + : FirewallsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FirewallsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_firewalls_v1_internal::FirewallsRetryTraits> + impl_; +}; -using FirewallsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_firewalls_v1_internal::FirewallsRetryTraits>; +/** + * A retry policy for `FirewallsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FirewallsLimitedTimeRetryPolicy : public FirewallsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FirewallsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FirewallsLimitedTimeRetryPolicy( + FirewallsLimitedTimeRetryPolicy&& rhs) noexcept + : FirewallsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + FirewallsLimitedTimeRetryPolicy( + FirewallsLimitedTimeRetryPolicy const& rhs) noexcept + : FirewallsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FirewallsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_firewalls_v1_internal::FirewallsRetryTraits> + impl_; +}; /** * The `FirewallsConnection` object for `FirewallsClient`. diff --git a/google/cloud/compute/forwarding_rules/v1/forwarding_rules_connection.h b/google/cloud/compute/forwarding_rules/v1/forwarding_rules_connection.h index d09e234f49df1..3f33e1331ae8e 100644 --- a/google/cloud/compute/forwarding_rules/v1/forwarding_rules_connection.h +++ b/google/cloud/compute/forwarding_rules/v1/forwarding_rules_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_forwarding_rules_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ForwardingRulesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_forwarding_rules_v1_internal::ForwardingRulesRetryTraits>; +/// The retry policy for `ForwardingRulesConnection`. +class ForwardingRulesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ForwardingRulesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_forwarding_rules_v1_internal::ForwardingRulesRetryTraits>; +/** + * A retry policy for `ForwardingRulesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ForwardingRulesLimitedErrorCountRetryPolicy + : public ForwardingRulesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ForwardingRulesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ForwardingRulesLimitedErrorCountRetryPolicy( + ForwardingRulesLimitedErrorCountRetryPolicy&& rhs) noexcept + : ForwardingRulesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ForwardingRulesLimitedErrorCountRetryPolicy( + ForwardingRulesLimitedErrorCountRetryPolicy const& rhs) noexcept + : ForwardingRulesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ForwardingRulesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_forwarding_rules_v1_internal::ForwardingRulesRetryTraits> + impl_; +}; -using ForwardingRulesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_forwarding_rules_v1_internal::ForwardingRulesRetryTraits>; +/** + * A retry policy for `ForwardingRulesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ForwardingRulesLimitedTimeRetryPolicy + : public ForwardingRulesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ForwardingRulesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ForwardingRulesLimitedTimeRetryPolicy( + ForwardingRulesLimitedTimeRetryPolicy&& rhs) noexcept + : ForwardingRulesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ForwardingRulesLimitedTimeRetryPolicy( + ForwardingRulesLimitedTimeRetryPolicy const& rhs) noexcept + : ForwardingRulesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ForwardingRulesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_forwarding_rules_v1_internal::ForwardingRulesRetryTraits> + impl_; +}; /** * The `ForwardingRulesConnection` object for `ForwardingRulesClient`. diff --git a/google/cloud/compute/global_addresses/v1/global_addresses_connection.h b/google/cloud/compute/global_addresses/v1/global_addresses_connection.h index 3f8d1bf3b8dcd..43298784547fa 100644 --- a/google/cloud/compute/global_addresses/v1/global_addresses_connection.h +++ b/google/cloud/compute/global_addresses/v1/global_addresses_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_global_addresses_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GlobalAddressesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_global_addresses_v1_internal::GlobalAddressesRetryTraits>; +/// The retry policy for `GlobalAddressesConnection`. +class GlobalAddressesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using GlobalAddressesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_global_addresses_v1_internal::GlobalAddressesRetryTraits>; +/** + * A retry policy for `GlobalAddressesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalAddressesLimitedErrorCountRetryPolicy + : public GlobalAddressesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GlobalAddressesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + GlobalAddressesLimitedErrorCountRetryPolicy( + GlobalAddressesLimitedErrorCountRetryPolicy&& rhs) noexcept + : GlobalAddressesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + GlobalAddressesLimitedErrorCountRetryPolicy( + GlobalAddressesLimitedErrorCountRetryPolicy const& rhs) noexcept + : GlobalAddressesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalAddressesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_global_addresses_v1_internal::GlobalAddressesRetryTraits> + impl_; +}; -using GlobalAddressesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_global_addresses_v1_internal::GlobalAddressesRetryTraits>; +/** + * A retry policy for `GlobalAddressesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalAddressesLimitedTimeRetryPolicy + : public GlobalAddressesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GlobalAddressesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GlobalAddressesLimitedTimeRetryPolicy( + GlobalAddressesLimitedTimeRetryPolicy&& rhs) noexcept + : GlobalAddressesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + GlobalAddressesLimitedTimeRetryPolicy( + GlobalAddressesLimitedTimeRetryPolicy const& rhs) noexcept + : GlobalAddressesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalAddressesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_global_addresses_v1_internal::GlobalAddressesRetryTraits> + impl_; +}; /** * The `GlobalAddressesConnection` object for `GlobalAddressesClient`. diff --git a/google/cloud/compute/global_forwarding_rules/v1/global_forwarding_rules_connection.h b/google/cloud/compute/global_forwarding_rules/v1/global_forwarding_rules_connection.h index 002a0326126af..8185498fb56b1 100644 --- a/google/cloud/compute/global_forwarding_rules/v1/global_forwarding_rules_connection.h +++ b/google/cloud/compute/global_forwarding_rules/v1/global_forwarding_rules_connection.h @@ -39,20 +39,141 @@ namespace cloud { namespace compute_global_forwarding_rules_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GlobalForwardingRulesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_global_forwarding_rules_v1_internal:: - GlobalForwardingRulesRetryTraits>; - -using GlobalForwardingRulesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_global_forwarding_rules_v1_internal:: - GlobalForwardingRulesRetryTraits>; - -using GlobalForwardingRulesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_global_forwarding_rules_v1_internal:: - GlobalForwardingRulesRetryTraits>; +/// The retry policy for `GlobalForwardingRulesConnection`. +class GlobalForwardingRulesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `GlobalForwardingRulesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalForwardingRulesLimitedErrorCountRetryPolicy + : public GlobalForwardingRulesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GlobalForwardingRulesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + GlobalForwardingRulesLimitedErrorCountRetryPolicy( + GlobalForwardingRulesLimitedErrorCountRetryPolicy&& rhs) noexcept + : GlobalForwardingRulesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + GlobalForwardingRulesLimitedErrorCountRetryPolicy( + GlobalForwardingRulesLimitedErrorCountRetryPolicy const& rhs) noexcept + : GlobalForwardingRulesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalForwardingRulesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_global_forwarding_rules_v1_internal:: + GlobalForwardingRulesRetryTraits> + impl_; +}; + +/** + * A retry policy for `GlobalForwardingRulesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalForwardingRulesLimitedTimeRetryPolicy + : public GlobalForwardingRulesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GlobalForwardingRulesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GlobalForwardingRulesLimitedTimeRetryPolicy( + GlobalForwardingRulesLimitedTimeRetryPolicy&& rhs) noexcept + : GlobalForwardingRulesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + GlobalForwardingRulesLimitedTimeRetryPolicy( + GlobalForwardingRulesLimitedTimeRetryPolicy const& rhs) noexcept + : GlobalForwardingRulesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalForwardingRulesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_global_forwarding_rules_v1_internal:: + GlobalForwardingRulesRetryTraits> + impl_; +}; /** * The `GlobalForwardingRulesConnection` object for diff --git a/google/cloud/compute/global_network_endpoint_groups/v1/global_network_endpoint_groups_connection.h b/google/cloud/compute/global_network_endpoint_groups/v1/global_network_endpoint_groups_connection.h index c923485701505..2fbe95c59ce45 100644 --- a/google/cloud/compute/global_network_endpoint_groups/v1/global_network_endpoint_groups_connection.h +++ b/google/cloud/compute/global_network_endpoint_groups/v1/global_network_endpoint_groups_connection.h @@ -39,20 +39,150 @@ namespace cloud { namespace compute_global_network_endpoint_groups_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GlobalNetworkEndpointGroupsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_global_network_endpoint_groups_v1_internal:: - GlobalNetworkEndpointGroupsRetryTraits>; - -using GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_global_network_endpoint_groups_v1_internal:: - GlobalNetworkEndpointGroupsRetryTraits>; - -using GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_global_network_endpoint_groups_v1_internal:: - GlobalNetworkEndpointGroupsRetryTraits>; +/// The retry policy for `GlobalNetworkEndpointGroupsConnection`. +class GlobalNetworkEndpointGroupsRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `GlobalNetworkEndpointGroupsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy + : public GlobalNetworkEndpointGroupsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy&& rhs) noexcept + : GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy const& + rhs) noexcept + : GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + GlobalNetworkEndpointGroupsLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalNetworkEndpointGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_global_network_endpoint_groups_v1_internal:: + GlobalNetworkEndpointGroupsRetryTraits> + impl_; +}; + +/** + * A retry policy for `GlobalNetworkEndpointGroupsConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy + : public GlobalNetworkEndpointGroupsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy( + GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy&& rhs) noexcept + : GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy( + GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy const& rhs) noexcept + : GlobalNetworkEndpointGroupsLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalNetworkEndpointGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_global_network_endpoint_groups_v1_internal:: + GlobalNetworkEndpointGroupsRetryTraits> + impl_; +}; /** * The `GlobalNetworkEndpointGroupsConnection` object for diff --git a/google/cloud/compute/global_operations/v1/global_operations_connection.h b/google/cloud/compute/global_operations/v1/global_operations_connection.h index 241269390b7db..6cd396a6ba6d3 100644 --- a/google/cloud/compute/global_operations/v1/global_operations_connection.h +++ b/google/cloud/compute/global_operations/v1/global_operations_connection.h @@ -36,17 +36,135 @@ namespace cloud { namespace compute_global_operations_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GlobalOperationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_global_operations_v1_internal::GlobalOperationsRetryTraits>; +/// The retry policy for `GlobalOperationsConnection`. +class GlobalOperationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using GlobalOperationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_global_operations_v1_internal::GlobalOperationsRetryTraits>; +/** + * A retry policy for `GlobalOperationsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalOperationsLimitedErrorCountRetryPolicy + : public GlobalOperationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GlobalOperationsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + GlobalOperationsLimitedErrorCountRetryPolicy( + GlobalOperationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : GlobalOperationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + GlobalOperationsLimitedErrorCountRetryPolicy( + GlobalOperationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : GlobalOperationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalOperationsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_global_operations_v1_internal::GlobalOperationsRetryTraits> + impl_; +}; -using GlobalOperationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_global_operations_v1_internal::GlobalOperationsRetryTraits>; +/** + * A retry policy for `GlobalOperationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalOperationsLimitedTimeRetryPolicy + : public GlobalOperationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GlobalOperationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GlobalOperationsLimitedTimeRetryPolicy( + GlobalOperationsLimitedTimeRetryPolicy&& rhs) noexcept + : GlobalOperationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + GlobalOperationsLimitedTimeRetryPolicy( + GlobalOperationsLimitedTimeRetryPolicy const& rhs) noexcept + : GlobalOperationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalOperationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_global_operations_v1_internal::GlobalOperationsRetryTraits> + impl_; +}; /** * The `GlobalOperationsConnection` object for `GlobalOperationsClient`. diff --git a/google/cloud/compute/global_organization_operations/v1/global_organization_operations_connection.h b/google/cloud/compute/global_organization_operations/v1/global_organization_operations_connection.h index eb3bc3c50f31b..de28200913a58 100644 --- a/google/cloud/compute/global_organization_operations/v1/global_organization_operations_connection.h +++ b/google/cloud/compute/global_organization_operations/v1/global_organization_operations_connection.h @@ -37,20 +37,150 @@ namespace cloud { namespace compute_global_organization_operations_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GlobalOrganizationOperationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_global_organization_operations_v1_internal:: - GlobalOrganizationOperationsRetryTraits>; - -using GlobalOrganizationOperationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_global_organization_operations_v1_internal:: - GlobalOrganizationOperationsRetryTraits>; - -using GlobalOrganizationOperationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_global_organization_operations_v1_internal:: - GlobalOrganizationOperationsRetryTraits>; +/// The retry policy for `GlobalOrganizationOperationsConnection`. +class GlobalOrganizationOperationsRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `GlobalOrganizationOperationsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalOrganizationOperationsLimitedErrorCountRetryPolicy + : public GlobalOrganizationOperationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GlobalOrganizationOperationsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + GlobalOrganizationOperationsLimitedErrorCountRetryPolicy( + GlobalOrganizationOperationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : GlobalOrganizationOperationsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + GlobalOrganizationOperationsLimitedErrorCountRetryPolicy( + GlobalOrganizationOperationsLimitedErrorCountRetryPolicy const& + rhs) noexcept + : GlobalOrganizationOperationsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + GlobalOrganizationOperationsLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalOrganizationOperationsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_global_organization_operations_v1_internal:: + GlobalOrganizationOperationsRetryTraits> + impl_; +}; + +/** + * A retry policy for `GlobalOrganizationOperationsConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalOrganizationOperationsLimitedTimeRetryPolicy + : public GlobalOrganizationOperationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GlobalOrganizationOperationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GlobalOrganizationOperationsLimitedTimeRetryPolicy( + GlobalOrganizationOperationsLimitedTimeRetryPolicy&& rhs) noexcept + : GlobalOrganizationOperationsLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + GlobalOrganizationOperationsLimitedTimeRetryPolicy( + GlobalOrganizationOperationsLimitedTimeRetryPolicy const& rhs) noexcept + : GlobalOrganizationOperationsLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalOrganizationOperationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_global_organization_operations_v1_internal:: + GlobalOrganizationOperationsRetryTraits> + impl_; +}; /** * The `GlobalOrganizationOperationsConnection` object for diff --git a/google/cloud/compute/global_public_delegated_prefixes/v1/global_public_delegated_prefixes_connection.h b/google/cloud/compute/global_public_delegated_prefixes/v1/global_public_delegated_prefixes_connection.h index 92eb5632f13ee..842221d6cc646 100644 --- a/google/cloud/compute/global_public_delegated_prefixes/v1/global_public_delegated_prefixes_connection.h +++ b/google/cloud/compute/global_public_delegated_prefixes/v1/global_public_delegated_prefixes_connection.h @@ -39,20 +39,151 @@ namespace cloud { namespace compute_global_public_delegated_prefixes_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GlobalPublicDelegatedPrefixesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_global_public_delegated_prefixes_v1_internal:: - GlobalPublicDelegatedPrefixesRetryTraits>; - -using GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_global_public_delegated_prefixes_v1_internal:: - GlobalPublicDelegatedPrefixesRetryTraits>; - -using GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_global_public_delegated_prefixes_v1_internal:: - GlobalPublicDelegatedPrefixesRetryTraits>; +/// The retry policy for `GlobalPublicDelegatedPrefixesConnection`. +class GlobalPublicDelegatedPrefixesRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `GlobalPublicDelegatedPrefixesConnection` based on + * counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy + : public GlobalPublicDelegatedPrefixesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy&& rhs) noexcept + : GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy const& + rhs) noexcept + : GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + GlobalPublicDelegatedPrefixesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalPublicDelegatedPrefixesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_global_public_delegated_prefixes_v1_internal:: + GlobalPublicDelegatedPrefixesRetryTraits> + impl_; +}; + +/** + * A retry policy for `GlobalPublicDelegatedPrefixesConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy + : public GlobalPublicDelegatedPrefixesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy( + GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy&& rhs) noexcept + : GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy( + GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy const& rhs) noexcept + : GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + GlobalPublicDelegatedPrefixesLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GlobalPublicDelegatedPrefixesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_global_public_delegated_prefixes_v1_internal:: + GlobalPublicDelegatedPrefixesRetryTraits> + impl_; +}; /** * The `GlobalPublicDelegatedPrefixesConnection` object for diff --git a/google/cloud/compute/health_checks/v1/health_checks_connection.h b/google/cloud/compute/health_checks/v1/health_checks_connection.h index 6ffe146b3e2cc..f175ff00c23b8 100644 --- a/google/cloud/compute/health_checks/v1/health_checks_connection.h +++ b/google/cloud/compute/health_checks/v1/health_checks_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace compute_health_checks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using HealthChecksRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_health_checks_v1_internal::HealthChecksRetryTraits>; +/// The retry policy for `HealthChecksConnection`. +class HealthChecksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using HealthChecksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_health_checks_v1_internal::HealthChecksRetryTraits>; +/** + * A retry policy for `HealthChecksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class HealthChecksLimitedErrorCountRetryPolicy + : public HealthChecksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit HealthChecksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + HealthChecksLimitedErrorCountRetryPolicy( + HealthChecksLimitedErrorCountRetryPolicy&& rhs) noexcept + : HealthChecksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + HealthChecksLimitedErrorCountRetryPolicy( + HealthChecksLimitedErrorCountRetryPolicy const& rhs) noexcept + : HealthChecksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = HealthChecksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_health_checks_v1_internal::HealthChecksRetryTraits> + impl_; +}; -using HealthChecksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_health_checks_v1_internal::HealthChecksRetryTraits>; +/** + * A retry policy for `HealthChecksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class HealthChecksLimitedTimeRetryPolicy : public HealthChecksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit HealthChecksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + HealthChecksLimitedTimeRetryPolicy( + HealthChecksLimitedTimeRetryPolicy&& rhs) noexcept + : HealthChecksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + HealthChecksLimitedTimeRetryPolicy( + HealthChecksLimitedTimeRetryPolicy const& rhs) noexcept + : HealthChecksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = HealthChecksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_health_checks_v1_internal::HealthChecksRetryTraits> + impl_; +}; /** * The `HealthChecksConnection` object for `HealthChecksClient`. diff --git a/google/cloud/compute/http_health_checks/v1/http_health_checks_connection.h b/google/cloud/compute/http_health_checks/v1/http_health_checks_connection.h index 194088c769c0d..7a4250a7504af 100644 --- a/google/cloud/compute/http_health_checks/v1/http_health_checks_connection.h +++ b/google/cloud/compute/http_health_checks/v1/http_health_checks_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_http_health_checks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using HttpHealthChecksRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_http_health_checks_v1_internal::HttpHealthChecksRetryTraits>; +/// The retry policy for `HttpHealthChecksConnection`. +class HttpHealthChecksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using HttpHealthChecksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_http_health_checks_v1_internal::HttpHealthChecksRetryTraits>; +/** + * A retry policy for `HttpHealthChecksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class HttpHealthChecksLimitedErrorCountRetryPolicy + : public HttpHealthChecksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit HttpHealthChecksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + HttpHealthChecksLimitedErrorCountRetryPolicy( + HttpHealthChecksLimitedErrorCountRetryPolicy&& rhs) noexcept + : HttpHealthChecksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + HttpHealthChecksLimitedErrorCountRetryPolicy( + HttpHealthChecksLimitedErrorCountRetryPolicy const& rhs) noexcept + : HttpHealthChecksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = HttpHealthChecksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_http_health_checks_v1_internal::HttpHealthChecksRetryTraits> + impl_; +}; -using HttpHealthChecksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_http_health_checks_v1_internal::HttpHealthChecksRetryTraits>; +/** + * A retry policy for `HttpHealthChecksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class HttpHealthChecksLimitedTimeRetryPolicy + : public HttpHealthChecksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit HttpHealthChecksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + HttpHealthChecksLimitedTimeRetryPolicy( + HttpHealthChecksLimitedTimeRetryPolicy&& rhs) noexcept + : HttpHealthChecksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + HttpHealthChecksLimitedTimeRetryPolicy( + HttpHealthChecksLimitedTimeRetryPolicy const& rhs) noexcept + : HttpHealthChecksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = HttpHealthChecksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_http_health_checks_v1_internal::HttpHealthChecksRetryTraits> + impl_; +}; /** * The `HttpHealthChecksConnection` object for `HttpHealthChecksClient`. diff --git a/google/cloud/compute/https_health_checks/v1/https_health_checks_connection.h b/google/cloud/compute/https_health_checks/v1/https_health_checks_connection.h index 3d6f680ccd745..d05c8455997ef 100644 --- a/google/cloud/compute/https_health_checks/v1/https_health_checks_connection.h +++ b/google/cloud/compute/https_health_checks/v1/https_health_checks_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_https_health_checks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using HttpsHealthChecksRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_https_health_checks_v1_internal::HttpsHealthChecksRetryTraits>; +/// The retry policy for `HttpsHealthChecksConnection`. +class HttpsHealthChecksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using HttpsHealthChecksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_https_health_checks_v1_internal::HttpsHealthChecksRetryTraits>; +/** + * A retry policy for `HttpsHealthChecksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class HttpsHealthChecksLimitedErrorCountRetryPolicy + : public HttpsHealthChecksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit HttpsHealthChecksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + HttpsHealthChecksLimitedErrorCountRetryPolicy( + HttpsHealthChecksLimitedErrorCountRetryPolicy&& rhs) noexcept + : HttpsHealthChecksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + HttpsHealthChecksLimitedErrorCountRetryPolicy( + HttpsHealthChecksLimitedErrorCountRetryPolicy const& rhs) noexcept + : HttpsHealthChecksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = HttpsHealthChecksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_https_health_checks_v1_internal::HttpsHealthChecksRetryTraits> + impl_; +}; -using HttpsHealthChecksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_https_health_checks_v1_internal::HttpsHealthChecksRetryTraits>; +/** + * A retry policy for `HttpsHealthChecksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class HttpsHealthChecksLimitedTimeRetryPolicy + : public HttpsHealthChecksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit HttpsHealthChecksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + HttpsHealthChecksLimitedTimeRetryPolicy( + HttpsHealthChecksLimitedTimeRetryPolicy&& rhs) noexcept + : HttpsHealthChecksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + HttpsHealthChecksLimitedTimeRetryPolicy( + HttpsHealthChecksLimitedTimeRetryPolicy const& rhs) noexcept + : HttpsHealthChecksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = HttpsHealthChecksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_https_health_checks_v1_internal::HttpsHealthChecksRetryTraits> + impl_; +}; /** * The `HttpsHealthChecksConnection` object for `HttpsHealthChecksClient`. diff --git a/google/cloud/compute/image_family_views/v1/image_family_views_connection.h b/google/cloud/compute/image_family_views/v1/image_family_views_connection.h index 56c348a7d0c2a..095a975a32832 100644 --- a/google/cloud/compute/image_family_views/v1/image_family_views_connection.h +++ b/google/cloud/compute/image_family_views/v1/image_family_views_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace compute_image_family_views_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ImageFamilyViewsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_image_family_views_v1_internal::ImageFamilyViewsRetryTraits>; +/// The retry policy for `ImageFamilyViewsConnection`. +class ImageFamilyViewsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ImageFamilyViewsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ImageFamilyViewsLimitedErrorCountRetryPolicy + : public ImageFamilyViewsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ImageFamilyViewsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ImageFamilyViewsLimitedErrorCountRetryPolicy( + ImageFamilyViewsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ImageFamilyViewsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ImageFamilyViewsLimitedErrorCountRetryPolicy( + ImageFamilyViewsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ImageFamilyViewsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ImageFamilyViewsRetryPolicy; -using ImageFamilyViewsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_image_family_views_v1_internal::ImageFamilyViewsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_image_family_views_v1_internal::ImageFamilyViewsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ImageFamilyViewsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ImageFamilyViewsLimitedTimeRetryPolicy + : public ImageFamilyViewsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ImageFamilyViewsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ImageFamilyViewsLimitedTimeRetryPolicy( + ImageFamilyViewsLimitedTimeRetryPolicy&& rhs) noexcept + : ImageFamilyViewsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ImageFamilyViewsLimitedTimeRetryPolicy( + ImageFamilyViewsLimitedTimeRetryPolicy const& rhs) noexcept + : ImageFamilyViewsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ImageFamilyViewsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_image_family_views_v1_internal::ImageFamilyViewsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ImageFamilyViewsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_image_family_views_v1_internal::ImageFamilyViewsRetryTraits> + impl_; +}; /** * The `ImageFamilyViewsConnection` object for `ImageFamilyViewsClient`. diff --git a/google/cloud/compute/images/v1/images_connection.h b/google/cloud/compute/images/v1/images_connection.h index 10421a37f9b14..5c3cc9404093f 100644 --- a/google/cloud/compute/images/v1/images_connection.h +++ b/google/cloud/compute/images/v1/images_connection.h @@ -38,16 +38,130 @@ namespace cloud { namespace compute_images_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ImagesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_images_v1_internal::ImagesRetryTraits>; +/// The retry policy for `ImagesConnection`. +class ImagesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ImagesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_images_v1_internal::ImagesRetryTraits>; +/** + * A retry policy for `ImagesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ImagesLimitedErrorCountRetryPolicy : public ImagesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ImagesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ImagesLimitedErrorCountRetryPolicy( + ImagesLimitedErrorCountRetryPolicy&& rhs) noexcept + : ImagesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ImagesLimitedErrorCountRetryPolicy( + ImagesLimitedErrorCountRetryPolicy const& rhs) noexcept + : ImagesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ImagesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_images_v1_internal::ImagesRetryTraits> + impl_; +}; -using ImagesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_images_v1_internal::ImagesRetryTraits>; +/** + * A retry policy for `ImagesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ImagesLimitedTimeRetryPolicy : public ImagesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ImagesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ImagesLimitedTimeRetryPolicy(ImagesLimitedTimeRetryPolicy&& rhs) noexcept + : ImagesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ImagesLimitedTimeRetryPolicy(ImagesLimitedTimeRetryPolicy const& rhs) noexcept + : ImagesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ImagesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_images_v1_internal::ImagesRetryTraits> + impl_; +}; /** * The `ImagesConnection` object for `ImagesClient`. diff --git a/google/cloud/compute/instance_group_managers/v1/instance_group_managers_connection.h b/google/cloud/compute/instance_group_managers/v1/instance_group_managers_connection.h index 13d8b5cd0ba69..9b4f2f59dac39 100644 --- a/google/cloud/compute/instance_group_managers/v1/instance_group_managers_connection.h +++ b/google/cloud/compute/instance_group_managers/v1/instance_group_managers_connection.h @@ -39,20 +39,141 @@ namespace cloud { namespace compute_instance_group_managers_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InstanceGroupManagersRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_instance_group_managers_v1_internal:: - InstanceGroupManagersRetryTraits>; - -using InstanceGroupManagersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_instance_group_managers_v1_internal:: - InstanceGroupManagersRetryTraits>; - -using InstanceGroupManagersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_instance_group_managers_v1_internal:: - InstanceGroupManagersRetryTraits>; +/// The retry policy for `InstanceGroupManagersConnection`. +class InstanceGroupManagersRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `InstanceGroupManagersConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstanceGroupManagersLimitedErrorCountRetryPolicy + : public InstanceGroupManagersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InstanceGroupManagersLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + InstanceGroupManagersLimitedErrorCountRetryPolicy( + InstanceGroupManagersLimitedErrorCountRetryPolicy&& rhs) noexcept + : InstanceGroupManagersLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + InstanceGroupManagersLimitedErrorCountRetryPolicy( + InstanceGroupManagersLimitedErrorCountRetryPolicy const& rhs) noexcept + : InstanceGroupManagersLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstanceGroupManagersRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_instance_group_managers_v1_internal:: + InstanceGroupManagersRetryTraits> + impl_; +}; + +/** + * A retry policy for `InstanceGroupManagersConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstanceGroupManagersLimitedTimeRetryPolicy + : public InstanceGroupManagersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InstanceGroupManagersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InstanceGroupManagersLimitedTimeRetryPolicy( + InstanceGroupManagersLimitedTimeRetryPolicy&& rhs) noexcept + : InstanceGroupManagersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InstanceGroupManagersLimitedTimeRetryPolicy( + InstanceGroupManagersLimitedTimeRetryPolicy const& rhs) noexcept + : InstanceGroupManagersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstanceGroupManagersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_instance_group_managers_v1_internal:: + InstanceGroupManagersRetryTraits> + impl_; +}; /** * The `InstanceGroupManagersConnection` object for diff --git a/google/cloud/compute/instance_groups/v1/instance_groups_connection.h b/google/cloud/compute/instance_groups/v1/instance_groups_connection.h index 75427ea5764a5..bb9594745ae4b 100644 --- a/google/cloud/compute/instance_groups/v1/instance_groups_connection.h +++ b/google/cloud/compute/instance_groups/v1/instance_groups_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace compute_instance_groups_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InstanceGroupsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_instance_groups_v1_internal::InstanceGroupsRetryTraits>; +/// The retry policy for `InstanceGroupsConnection`. +class InstanceGroupsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using InstanceGroupsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_instance_groups_v1_internal::InstanceGroupsRetryTraits>; +/** + * A retry policy for `InstanceGroupsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstanceGroupsLimitedErrorCountRetryPolicy + : public InstanceGroupsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InstanceGroupsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + InstanceGroupsLimitedErrorCountRetryPolicy( + InstanceGroupsLimitedErrorCountRetryPolicy&& rhs) noexcept + : InstanceGroupsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + InstanceGroupsLimitedErrorCountRetryPolicy( + InstanceGroupsLimitedErrorCountRetryPolicy const& rhs) noexcept + : InstanceGroupsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstanceGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_instance_groups_v1_internal::InstanceGroupsRetryTraits> + impl_; +}; -using InstanceGroupsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_instance_groups_v1_internal::InstanceGroupsRetryTraits>; +/** + * A retry policy for `InstanceGroupsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstanceGroupsLimitedTimeRetryPolicy : public InstanceGroupsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InstanceGroupsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InstanceGroupsLimitedTimeRetryPolicy( + InstanceGroupsLimitedTimeRetryPolicy&& rhs) noexcept + : InstanceGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InstanceGroupsLimitedTimeRetryPolicy( + InstanceGroupsLimitedTimeRetryPolicy const& rhs) noexcept + : InstanceGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstanceGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_instance_groups_v1_internal::InstanceGroupsRetryTraits> + impl_; +}; /** * The `InstanceGroupsConnection` object for `InstanceGroupsClient`. diff --git a/google/cloud/compute/instance_templates/v1/instance_templates_connection.h b/google/cloud/compute/instance_templates/v1/instance_templates_connection.h index a05fbc8e5df94..97bd123c44662 100644 --- a/google/cloud/compute/instance_templates/v1/instance_templates_connection.h +++ b/google/cloud/compute/instance_templates/v1/instance_templates_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_instance_templates_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InstanceTemplatesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_instance_templates_v1_internal::InstanceTemplatesRetryTraits>; +/// The retry policy for `InstanceTemplatesConnection`. +class InstanceTemplatesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using InstanceTemplatesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_instance_templates_v1_internal::InstanceTemplatesRetryTraits>; +/** + * A retry policy for `InstanceTemplatesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstanceTemplatesLimitedErrorCountRetryPolicy + : public InstanceTemplatesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InstanceTemplatesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + InstanceTemplatesLimitedErrorCountRetryPolicy( + InstanceTemplatesLimitedErrorCountRetryPolicy&& rhs) noexcept + : InstanceTemplatesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + InstanceTemplatesLimitedErrorCountRetryPolicy( + InstanceTemplatesLimitedErrorCountRetryPolicy const& rhs) noexcept + : InstanceTemplatesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstanceTemplatesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_instance_templates_v1_internal::InstanceTemplatesRetryTraits> + impl_; +}; -using InstanceTemplatesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_instance_templates_v1_internal::InstanceTemplatesRetryTraits>; +/** + * A retry policy for `InstanceTemplatesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstanceTemplatesLimitedTimeRetryPolicy + : public InstanceTemplatesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InstanceTemplatesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InstanceTemplatesLimitedTimeRetryPolicy( + InstanceTemplatesLimitedTimeRetryPolicy&& rhs) noexcept + : InstanceTemplatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InstanceTemplatesLimitedTimeRetryPolicy( + InstanceTemplatesLimitedTimeRetryPolicy const& rhs) noexcept + : InstanceTemplatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstanceTemplatesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_instance_templates_v1_internal::InstanceTemplatesRetryTraits> + impl_; +}; /** * The `InstanceTemplatesConnection` object for `InstanceTemplatesClient`. diff --git a/google/cloud/compute/instances/v1/instances_connection.h b/google/cloud/compute/instances/v1/instances_connection.h index 20542114a996b..faf4d75e59e0f 100644 --- a/google/cloud/compute/instances/v1/instances_connection.h +++ b/google/cloud/compute/instances/v1/instances_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_instances_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InstancesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_instances_v1_internal::InstancesRetryTraits>; +/// The retry policy for `InstancesConnection`. +class InstancesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using InstancesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_instances_v1_internal::InstancesRetryTraits>; +/** + * A retry policy for `InstancesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstancesLimitedErrorCountRetryPolicy : public InstancesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InstancesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + InstancesLimitedErrorCountRetryPolicy( + InstancesLimitedErrorCountRetryPolicy&& rhs) noexcept + : InstancesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + InstancesLimitedErrorCountRetryPolicy( + InstancesLimitedErrorCountRetryPolicy const& rhs) noexcept + : InstancesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstancesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_instances_v1_internal::InstancesRetryTraits> + impl_; +}; -using InstancesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_instances_v1_internal::InstancesRetryTraits>; +/** + * A retry policy for `InstancesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstancesLimitedTimeRetryPolicy : public InstancesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InstancesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InstancesLimitedTimeRetryPolicy( + InstancesLimitedTimeRetryPolicy&& rhs) noexcept + : InstancesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InstancesLimitedTimeRetryPolicy( + InstancesLimitedTimeRetryPolicy const& rhs) noexcept + : InstancesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstancesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_instances_v1_internal::InstancesRetryTraits> + impl_; +}; /** * The `InstancesConnection` object for `InstancesClient`. diff --git a/google/cloud/compute/interconnect_attachments/v1/interconnect_attachments_connection.h b/google/cloud/compute/interconnect_attachments/v1/interconnect_attachments_connection.h index 9b3b70ad6f959..1e8f914106c7c 100644 --- a/google/cloud/compute/interconnect_attachments/v1/interconnect_attachments_connection.h +++ b/google/cloud/compute/interconnect_attachments/v1/interconnect_attachments_connection.h @@ -39,20 +39,142 @@ namespace cloud { namespace compute_interconnect_attachments_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InterconnectAttachmentsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_interconnect_attachments_v1_internal:: - InterconnectAttachmentsRetryTraits>; - -using InterconnectAttachmentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_interconnect_attachments_v1_internal:: - InterconnectAttachmentsRetryTraits>; - -using InterconnectAttachmentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_interconnect_attachments_v1_internal:: - InterconnectAttachmentsRetryTraits>; +/// The retry policy for `InterconnectAttachmentsConnection`. +class InterconnectAttachmentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `InterconnectAttachmentsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InterconnectAttachmentsLimitedErrorCountRetryPolicy + : public InterconnectAttachmentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InterconnectAttachmentsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + InterconnectAttachmentsLimitedErrorCountRetryPolicy( + InterconnectAttachmentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : InterconnectAttachmentsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + InterconnectAttachmentsLimitedErrorCountRetryPolicy( + InterconnectAttachmentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : InterconnectAttachmentsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + InterconnectAttachmentsLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InterconnectAttachmentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_interconnect_attachments_v1_internal:: + InterconnectAttachmentsRetryTraits> + impl_; +}; + +/** + * A retry policy for `InterconnectAttachmentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InterconnectAttachmentsLimitedTimeRetryPolicy + : public InterconnectAttachmentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InterconnectAttachmentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InterconnectAttachmentsLimitedTimeRetryPolicy( + InterconnectAttachmentsLimitedTimeRetryPolicy&& rhs) noexcept + : InterconnectAttachmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InterconnectAttachmentsLimitedTimeRetryPolicy( + InterconnectAttachmentsLimitedTimeRetryPolicy const& rhs) noexcept + : InterconnectAttachmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InterconnectAttachmentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_interconnect_attachments_v1_internal:: + InterconnectAttachmentsRetryTraits> + impl_; +}; /** * The `InterconnectAttachmentsConnection` object for diff --git a/google/cloud/compute/interconnect_locations/v1/interconnect_locations_connection.h b/google/cloud/compute/interconnect_locations/v1/interconnect_locations_connection.h index e789bedb19152..aa32bee9153d1 100644 --- a/google/cloud/compute/interconnect_locations/v1/interconnect_locations_connection.h +++ b/google/cloud/compute/interconnect_locations/v1/interconnect_locations_connection.h @@ -37,20 +37,141 @@ namespace cloud { namespace compute_interconnect_locations_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InterconnectLocationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_interconnect_locations_v1_internal:: - InterconnectLocationsRetryTraits>; - -using InterconnectLocationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_interconnect_locations_v1_internal:: - InterconnectLocationsRetryTraits>; - -using InterconnectLocationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_interconnect_locations_v1_internal:: - InterconnectLocationsRetryTraits>; +/// The retry policy for `InterconnectLocationsConnection`. +class InterconnectLocationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `InterconnectLocationsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InterconnectLocationsLimitedErrorCountRetryPolicy + : public InterconnectLocationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InterconnectLocationsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + InterconnectLocationsLimitedErrorCountRetryPolicy( + InterconnectLocationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : InterconnectLocationsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + InterconnectLocationsLimitedErrorCountRetryPolicy( + InterconnectLocationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : InterconnectLocationsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InterconnectLocationsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_interconnect_locations_v1_internal:: + InterconnectLocationsRetryTraits> + impl_; +}; + +/** + * A retry policy for `InterconnectLocationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InterconnectLocationsLimitedTimeRetryPolicy + : public InterconnectLocationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InterconnectLocationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InterconnectLocationsLimitedTimeRetryPolicy( + InterconnectLocationsLimitedTimeRetryPolicy&& rhs) noexcept + : InterconnectLocationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InterconnectLocationsLimitedTimeRetryPolicy( + InterconnectLocationsLimitedTimeRetryPolicy const& rhs) noexcept + : InterconnectLocationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InterconnectLocationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_interconnect_locations_v1_internal:: + InterconnectLocationsRetryTraits> + impl_; +}; /** * The `InterconnectLocationsConnection` object for diff --git a/google/cloud/compute/interconnects/v1/interconnects_connection.h b/google/cloud/compute/interconnects/v1/interconnects_connection.h index ec3c7f8aac7c0..ca1fa49eb1dd8 100644 --- a/google/cloud/compute/interconnects/v1/interconnects_connection.h +++ b/google/cloud/compute/interconnects/v1/interconnects_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace compute_interconnects_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InterconnectsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_interconnects_v1_internal::InterconnectsRetryTraits>; +/// The retry policy for `InterconnectsConnection`. +class InterconnectsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using InterconnectsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_interconnects_v1_internal::InterconnectsRetryTraits>; +/** + * A retry policy for `InterconnectsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InterconnectsLimitedErrorCountRetryPolicy + : public InterconnectsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InterconnectsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + InterconnectsLimitedErrorCountRetryPolicy( + InterconnectsLimitedErrorCountRetryPolicy&& rhs) noexcept + : InterconnectsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + InterconnectsLimitedErrorCountRetryPolicy( + InterconnectsLimitedErrorCountRetryPolicy const& rhs) noexcept + : InterconnectsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InterconnectsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_interconnects_v1_internal::InterconnectsRetryTraits> + impl_; +}; -using InterconnectsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_interconnects_v1_internal::InterconnectsRetryTraits>; +/** + * A retry policy for `InterconnectsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InterconnectsLimitedTimeRetryPolicy : public InterconnectsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InterconnectsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InterconnectsLimitedTimeRetryPolicy( + InterconnectsLimitedTimeRetryPolicy&& rhs) noexcept + : InterconnectsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InterconnectsLimitedTimeRetryPolicy( + InterconnectsLimitedTimeRetryPolicy const& rhs) noexcept + : InterconnectsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InterconnectsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_interconnects_v1_internal::InterconnectsRetryTraits> + impl_; +}; /** * The `InterconnectsConnection` object for `InterconnectsClient`. diff --git a/google/cloud/compute/license_codes/v1/license_codes_connection.h b/google/cloud/compute/license_codes/v1/license_codes_connection.h index 5c932582ad92f..d5867f2d4e2b5 100644 --- a/google/cloud/compute/license_codes/v1/license_codes_connection.h +++ b/google/cloud/compute/license_codes/v1/license_codes_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace compute_license_codes_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using LicenseCodesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_license_codes_v1_internal::LicenseCodesRetryTraits>; +/// The retry policy for `LicenseCodesConnection`. +class LicenseCodesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `LicenseCodesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LicenseCodesLimitedErrorCountRetryPolicy + : public LicenseCodesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit LicenseCodesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + LicenseCodesLimitedErrorCountRetryPolicy( + LicenseCodesLimitedErrorCountRetryPolicy&& rhs) noexcept + : LicenseCodesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + LicenseCodesLimitedErrorCountRetryPolicy( + LicenseCodesLimitedErrorCountRetryPolicy const& rhs) noexcept + : LicenseCodesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = LicenseCodesRetryPolicy; -using LicenseCodesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_license_codes_v1_internal::LicenseCodesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_license_codes_v1_internal::LicenseCodesRetryTraits> + impl_; +}; + +/** + * A retry policy for `LicenseCodesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LicenseCodesLimitedTimeRetryPolicy : public LicenseCodesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit LicenseCodesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + LicenseCodesLimitedTimeRetryPolicy( + LicenseCodesLimitedTimeRetryPolicy&& rhs) noexcept + : LicenseCodesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + LicenseCodesLimitedTimeRetryPolicy( + LicenseCodesLimitedTimeRetryPolicy const& rhs) noexcept + : LicenseCodesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using LicenseCodesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_license_codes_v1_internal::LicenseCodesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = LicenseCodesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_license_codes_v1_internal::LicenseCodesRetryTraits> + impl_; +}; /** * The `LicenseCodesConnection` object for `LicenseCodesClient`. diff --git a/google/cloud/compute/licenses/v1/licenses_connection.h b/google/cloud/compute/licenses/v1/licenses_connection.h index f9dd4a431375b..ce87301ee79ca 100644 --- a/google/cloud/compute/licenses/v1/licenses_connection.h +++ b/google/cloud/compute/licenses/v1/licenses_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace compute_licenses_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using LicensesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_licenses_v1_internal::LicensesRetryTraits>; +/// The retry policy for `LicensesConnection`. +class LicensesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using LicensesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_licenses_v1_internal::LicensesRetryTraits>; +/** + * A retry policy for `LicensesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LicensesLimitedErrorCountRetryPolicy : public LicensesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit LicensesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + LicensesLimitedErrorCountRetryPolicy( + LicensesLimitedErrorCountRetryPolicy&& rhs) noexcept + : LicensesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + LicensesLimitedErrorCountRetryPolicy( + LicensesLimitedErrorCountRetryPolicy const& rhs) noexcept + : LicensesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = LicensesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_licenses_v1_internal::LicensesRetryTraits> + impl_; +}; -using LicensesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_licenses_v1_internal::LicensesRetryTraits>; +/** + * A retry policy for `LicensesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LicensesLimitedTimeRetryPolicy : public LicensesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit LicensesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + LicensesLimitedTimeRetryPolicy(LicensesLimitedTimeRetryPolicy&& rhs) noexcept + : LicensesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + LicensesLimitedTimeRetryPolicy( + LicensesLimitedTimeRetryPolicy const& rhs) noexcept + : LicensesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = LicensesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_licenses_v1_internal::LicensesRetryTraits> + impl_; +}; /** * The `LicensesConnection` object for `LicensesClient`. diff --git a/google/cloud/compute/machine_images/v1/machine_images_connection.h b/google/cloud/compute/machine_images/v1/machine_images_connection.h index 7efb44a13c069..b11feeef2d150 100644 --- a/google/cloud/compute/machine_images/v1/machine_images_connection.h +++ b/google/cloud/compute/machine_images/v1/machine_images_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace compute_machine_images_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MachineImagesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_machine_images_v1_internal::MachineImagesRetryTraits>; +/// The retry policy for `MachineImagesConnection`. +class MachineImagesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using MachineImagesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_machine_images_v1_internal::MachineImagesRetryTraits>; +/** + * A retry policy for `MachineImagesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MachineImagesLimitedErrorCountRetryPolicy + : public MachineImagesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MachineImagesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MachineImagesLimitedErrorCountRetryPolicy( + MachineImagesLimitedErrorCountRetryPolicy&& rhs) noexcept + : MachineImagesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MachineImagesLimitedErrorCountRetryPolicy( + MachineImagesLimitedErrorCountRetryPolicy const& rhs) noexcept + : MachineImagesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MachineImagesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_machine_images_v1_internal::MachineImagesRetryTraits> + impl_; +}; -using MachineImagesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_machine_images_v1_internal::MachineImagesRetryTraits>; +/** + * A retry policy for `MachineImagesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MachineImagesLimitedTimeRetryPolicy : public MachineImagesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MachineImagesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MachineImagesLimitedTimeRetryPolicy( + MachineImagesLimitedTimeRetryPolicy&& rhs) noexcept + : MachineImagesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MachineImagesLimitedTimeRetryPolicy( + MachineImagesLimitedTimeRetryPolicy const& rhs) noexcept + : MachineImagesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MachineImagesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_machine_images_v1_internal::MachineImagesRetryTraits> + impl_; +}; /** * The `MachineImagesConnection` object for `MachineImagesClient`. diff --git a/google/cloud/compute/machine_types/v1/machine_types_connection.h b/google/cloud/compute/machine_types/v1/machine_types_connection.h index 33ca3a526e1ec..f3be054739d55 100644 --- a/google/cloud/compute/machine_types/v1/machine_types_connection.h +++ b/google/cloud/compute/machine_types/v1/machine_types_connection.h @@ -36,17 +36,134 @@ namespace cloud { namespace compute_machine_types_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MachineTypesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_machine_types_v1_internal::MachineTypesRetryTraits>; +/// The retry policy for `MachineTypesConnection`. +class MachineTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `MachineTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MachineTypesLimitedErrorCountRetryPolicy + : public MachineTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MachineTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MachineTypesLimitedErrorCountRetryPolicy( + MachineTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : MachineTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MachineTypesLimitedErrorCountRetryPolicy( + MachineTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : MachineTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MachineTypesRetryPolicy; -using MachineTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_machine_types_v1_internal::MachineTypesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_machine_types_v1_internal::MachineTypesRetryTraits> + impl_; +}; + +/** + * A retry policy for `MachineTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MachineTypesLimitedTimeRetryPolicy : public MachineTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MachineTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MachineTypesLimitedTimeRetryPolicy( + MachineTypesLimitedTimeRetryPolicy&& rhs) noexcept + : MachineTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MachineTypesLimitedTimeRetryPolicy( + MachineTypesLimitedTimeRetryPolicy const& rhs) noexcept + : MachineTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using MachineTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_machine_types_v1_internal::MachineTypesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MachineTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_machine_types_v1_internal::MachineTypesRetryTraits> + impl_; +}; /** * The `MachineTypesConnection` object for `MachineTypesClient`. diff --git a/google/cloud/compute/network_attachments/v1/network_attachments_connection.h b/google/cloud/compute/network_attachments/v1/network_attachments_connection.h index a48c8ed8a0064..e7ac6c32f443e 100644 --- a/google/cloud/compute/network_attachments/v1/network_attachments_connection.h +++ b/google/cloud/compute/network_attachments/v1/network_attachments_connection.h @@ -38,17 +38,137 @@ namespace cloud { namespace compute_network_attachments_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NetworkAttachmentsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_network_attachments_v1_internal::NetworkAttachmentsRetryTraits>; +/// The retry policy for `NetworkAttachmentsConnection`. +class NetworkAttachmentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using NetworkAttachmentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_network_attachments_v1_internal::NetworkAttachmentsRetryTraits>; +/** + * A retry policy for `NetworkAttachmentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkAttachmentsLimitedErrorCountRetryPolicy + : public NetworkAttachmentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NetworkAttachmentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + NetworkAttachmentsLimitedErrorCountRetryPolicy( + NetworkAttachmentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : NetworkAttachmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + NetworkAttachmentsLimitedErrorCountRetryPolicy( + NetworkAttachmentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : NetworkAttachmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkAttachmentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_network_attachments_v1_internal::NetworkAttachmentsRetryTraits> + impl_; +}; -using NetworkAttachmentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_network_attachments_v1_internal::NetworkAttachmentsRetryTraits>; +/** + * A retry policy for `NetworkAttachmentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkAttachmentsLimitedTimeRetryPolicy + : public NetworkAttachmentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NetworkAttachmentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NetworkAttachmentsLimitedTimeRetryPolicy( + NetworkAttachmentsLimitedTimeRetryPolicy&& rhs) noexcept + : NetworkAttachmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NetworkAttachmentsLimitedTimeRetryPolicy( + NetworkAttachmentsLimitedTimeRetryPolicy const& rhs) noexcept + : NetworkAttachmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkAttachmentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_network_attachments_v1_internal::NetworkAttachmentsRetryTraits> + impl_; +}; /** * The `NetworkAttachmentsConnection` object for `NetworkAttachmentsClient`. diff --git a/google/cloud/compute/network_edge_security_services/v1/network_edge_security_services_connection.h b/google/cloud/compute/network_edge_security_services/v1/network_edge_security_services_connection.h index 07765e055f311..4cfe6a7e6eadf 100644 --- a/google/cloud/compute/network_edge_security_services/v1/network_edge_security_services_connection.h +++ b/google/cloud/compute/network_edge_security_services/v1/network_edge_security_services_connection.h @@ -38,20 +38,150 @@ namespace cloud { namespace compute_network_edge_security_services_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NetworkEdgeSecurityServicesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_network_edge_security_services_v1_internal:: - NetworkEdgeSecurityServicesRetryTraits>; - -using NetworkEdgeSecurityServicesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_network_edge_security_services_v1_internal:: - NetworkEdgeSecurityServicesRetryTraits>; - -using NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_network_edge_security_services_v1_internal:: - NetworkEdgeSecurityServicesRetryTraits>; +/// The retry policy for `NetworkEdgeSecurityServicesConnection`. +class NetworkEdgeSecurityServicesRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `NetworkEdgeSecurityServicesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy + : public NetworkEdgeSecurityServicesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy( + NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy&& rhs) noexcept + : NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy( + NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy const& + rhs) noexcept + : NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + NetworkEdgeSecurityServicesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkEdgeSecurityServicesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_network_edge_security_services_v1_internal:: + NetworkEdgeSecurityServicesRetryTraits> + impl_; +}; + +/** + * A retry policy for `NetworkEdgeSecurityServicesConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkEdgeSecurityServicesLimitedTimeRetryPolicy + : public NetworkEdgeSecurityServicesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NetworkEdgeSecurityServicesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NetworkEdgeSecurityServicesLimitedTimeRetryPolicy( + NetworkEdgeSecurityServicesLimitedTimeRetryPolicy&& rhs) noexcept + : NetworkEdgeSecurityServicesLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + NetworkEdgeSecurityServicesLimitedTimeRetryPolicy( + NetworkEdgeSecurityServicesLimitedTimeRetryPolicy const& rhs) noexcept + : NetworkEdgeSecurityServicesLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkEdgeSecurityServicesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_network_edge_security_services_v1_internal:: + NetworkEdgeSecurityServicesRetryTraits> + impl_; +}; /** * The `NetworkEdgeSecurityServicesConnection` object for diff --git a/google/cloud/compute/network_endpoint_groups/v1/network_endpoint_groups_connection.h b/google/cloud/compute/network_endpoint_groups/v1/network_endpoint_groups_connection.h index 84562392c595e..ede670dd4aa00 100644 --- a/google/cloud/compute/network_endpoint_groups/v1/network_endpoint_groups_connection.h +++ b/google/cloud/compute/network_endpoint_groups/v1/network_endpoint_groups_connection.h @@ -39,20 +39,141 @@ namespace cloud { namespace compute_network_endpoint_groups_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NetworkEndpointGroupsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_network_endpoint_groups_v1_internal:: - NetworkEndpointGroupsRetryTraits>; - -using NetworkEndpointGroupsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_network_endpoint_groups_v1_internal:: - NetworkEndpointGroupsRetryTraits>; - -using NetworkEndpointGroupsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_network_endpoint_groups_v1_internal:: - NetworkEndpointGroupsRetryTraits>; +/// The retry policy for `NetworkEndpointGroupsConnection`. +class NetworkEndpointGroupsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `NetworkEndpointGroupsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkEndpointGroupsLimitedErrorCountRetryPolicy + : public NetworkEndpointGroupsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NetworkEndpointGroupsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + NetworkEndpointGroupsLimitedErrorCountRetryPolicy( + NetworkEndpointGroupsLimitedErrorCountRetryPolicy&& rhs) noexcept + : NetworkEndpointGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + NetworkEndpointGroupsLimitedErrorCountRetryPolicy( + NetworkEndpointGroupsLimitedErrorCountRetryPolicy const& rhs) noexcept + : NetworkEndpointGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkEndpointGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_network_endpoint_groups_v1_internal:: + NetworkEndpointGroupsRetryTraits> + impl_; +}; + +/** + * A retry policy for `NetworkEndpointGroupsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkEndpointGroupsLimitedTimeRetryPolicy + : public NetworkEndpointGroupsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NetworkEndpointGroupsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NetworkEndpointGroupsLimitedTimeRetryPolicy( + NetworkEndpointGroupsLimitedTimeRetryPolicy&& rhs) noexcept + : NetworkEndpointGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NetworkEndpointGroupsLimitedTimeRetryPolicy( + NetworkEndpointGroupsLimitedTimeRetryPolicy const& rhs) noexcept + : NetworkEndpointGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkEndpointGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_network_endpoint_groups_v1_internal:: + NetworkEndpointGroupsRetryTraits> + impl_; +}; /** * The `NetworkEndpointGroupsConnection` object for diff --git a/google/cloud/compute/network_firewall_policies/v1/network_firewall_policies_connection.h b/google/cloud/compute/network_firewall_policies/v1/network_firewall_policies_connection.h index 20bead9be64af..2359b77bfe89e 100644 --- a/google/cloud/compute/network_firewall_policies/v1/network_firewall_policies_connection.h +++ b/google/cloud/compute/network_firewall_policies/v1/network_firewall_policies_connection.h @@ -39,20 +39,142 @@ namespace cloud { namespace compute_network_firewall_policies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NetworkFirewallPoliciesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_network_firewall_policies_v1_internal:: - NetworkFirewallPoliciesRetryTraits>; - -using NetworkFirewallPoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_network_firewall_policies_v1_internal:: - NetworkFirewallPoliciesRetryTraits>; - -using NetworkFirewallPoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_network_firewall_policies_v1_internal:: - NetworkFirewallPoliciesRetryTraits>; +/// The retry policy for `NetworkFirewallPoliciesConnection`. +class NetworkFirewallPoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `NetworkFirewallPoliciesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkFirewallPoliciesLimitedErrorCountRetryPolicy + : public NetworkFirewallPoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + NetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + NetworkFirewallPoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : NetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + NetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + NetworkFirewallPoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : NetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + NetworkFirewallPoliciesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkFirewallPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_network_firewall_policies_v1_internal:: + NetworkFirewallPoliciesRetryTraits> + impl_; +}; + +/** + * A retry policy for `NetworkFirewallPoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkFirewallPoliciesLimitedTimeRetryPolicy + : public NetworkFirewallPoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NetworkFirewallPoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NetworkFirewallPoliciesLimitedTimeRetryPolicy( + NetworkFirewallPoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : NetworkFirewallPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NetworkFirewallPoliciesLimitedTimeRetryPolicy( + NetworkFirewallPoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : NetworkFirewallPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkFirewallPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_network_firewall_policies_v1_internal:: + NetworkFirewallPoliciesRetryTraits> + impl_; +}; /** * The `NetworkFirewallPoliciesConnection` object for diff --git a/google/cloud/compute/networks/v1/networks_connection.h b/google/cloud/compute/networks/v1/networks_connection.h index ceadd132614fc..d2ab5544f94f5 100644 --- a/google/cloud/compute/networks/v1/networks_connection.h +++ b/google/cloud/compute/networks/v1/networks_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace compute_networks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NetworksRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_networks_v1_internal::NetworksRetryTraits>; +/// The retry policy for `NetworksConnection`. +class NetworksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using NetworksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_networks_v1_internal::NetworksRetryTraits>; +/** + * A retry policy for `NetworksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworksLimitedErrorCountRetryPolicy : public NetworksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NetworksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + NetworksLimitedErrorCountRetryPolicy( + NetworksLimitedErrorCountRetryPolicy&& rhs) noexcept + : NetworksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + NetworksLimitedErrorCountRetryPolicy( + NetworksLimitedErrorCountRetryPolicy const& rhs) noexcept + : NetworksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_networks_v1_internal::NetworksRetryTraits> + impl_; +}; -using NetworksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_networks_v1_internal::NetworksRetryTraits>; +/** + * A retry policy for `NetworksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworksLimitedTimeRetryPolicy : public NetworksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NetworksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NetworksLimitedTimeRetryPolicy(NetworksLimitedTimeRetryPolicy&& rhs) noexcept + : NetworksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NetworksLimitedTimeRetryPolicy( + NetworksLimitedTimeRetryPolicy const& rhs) noexcept + : NetworksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_networks_v1_internal::NetworksRetryTraits> + impl_; +}; /** * The `NetworksConnection` object for `NetworksClient`. diff --git a/google/cloud/compute/node_groups/v1/node_groups_connection.h b/google/cloud/compute/node_groups/v1/node_groups_connection.h index 6f6cd7c27b34d..d6fad8ab8dd3e 100644 --- a/google/cloud/compute/node_groups/v1/node_groups_connection.h +++ b/google/cloud/compute/node_groups/v1/node_groups_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_node_groups_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NodeGroupsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_node_groups_v1_internal::NodeGroupsRetryTraits>; +/// The retry policy for `NodeGroupsConnection`. +class NodeGroupsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using NodeGroupsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_node_groups_v1_internal::NodeGroupsRetryTraits>; +/** + * A retry policy for `NodeGroupsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NodeGroupsLimitedErrorCountRetryPolicy : public NodeGroupsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NodeGroupsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + NodeGroupsLimitedErrorCountRetryPolicy( + NodeGroupsLimitedErrorCountRetryPolicy&& rhs) noexcept + : NodeGroupsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + NodeGroupsLimitedErrorCountRetryPolicy( + NodeGroupsLimitedErrorCountRetryPolicy const& rhs) noexcept + : NodeGroupsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NodeGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_node_groups_v1_internal::NodeGroupsRetryTraits> + impl_; +}; -using NodeGroupsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_node_groups_v1_internal::NodeGroupsRetryTraits>; +/** + * A retry policy for `NodeGroupsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NodeGroupsLimitedTimeRetryPolicy : public NodeGroupsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NodeGroupsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NodeGroupsLimitedTimeRetryPolicy( + NodeGroupsLimitedTimeRetryPolicy&& rhs) noexcept + : NodeGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NodeGroupsLimitedTimeRetryPolicy( + NodeGroupsLimitedTimeRetryPolicy const& rhs) noexcept + : NodeGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NodeGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_node_groups_v1_internal::NodeGroupsRetryTraits> + impl_; +}; /** * The `NodeGroupsConnection` object for `NodeGroupsClient`. diff --git a/google/cloud/compute/node_templates/v1/node_templates_connection.h b/google/cloud/compute/node_templates/v1/node_templates_connection.h index 3d4499b62de1b..094193bd89447 100644 --- a/google/cloud/compute/node_templates/v1/node_templates_connection.h +++ b/google/cloud/compute/node_templates/v1/node_templates_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace compute_node_templates_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NodeTemplatesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_node_templates_v1_internal::NodeTemplatesRetryTraits>; +/// The retry policy for `NodeTemplatesConnection`. +class NodeTemplatesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using NodeTemplatesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_node_templates_v1_internal::NodeTemplatesRetryTraits>; +/** + * A retry policy for `NodeTemplatesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NodeTemplatesLimitedErrorCountRetryPolicy + : public NodeTemplatesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NodeTemplatesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + NodeTemplatesLimitedErrorCountRetryPolicy( + NodeTemplatesLimitedErrorCountRetryPolicy&& rhs) noexcept + : NodeTemplatesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + NodeTemplatesLimitedErrorCountRetryPolicy( + NodeTemplatesLimitedErrorCountRetryPolicy const& rhs) noexcept + : NodeTemplatesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NodeTemplatesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_node_templates_v1_internal::NodeTemplatesRetryTraits> + impl_; +}; -using NodeTemplatesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_node_templates_v1_internal::NodeTemplatesRetryTraits>; +/** + * A retry policy for `NodeTemplatesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NodeTemplatesLimitedTimeRetryPolicy : public NodeTemplatesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NodeTemplatesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NodeTemplatesLimitedTimeRetryPolicy( + NodeTemplatesLimitedTimeRetryPolicy&& rhs) noexcept + : NodeTemplatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NodeTemplatesLimitedTimeRetryPolicy( + NodeTemplatesLimitedTimeRetryPolicy const& rhs) noexcept + : NodeTemplatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NodeTemplatesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_node_templates_v1_internal::NodeTemplatesRetryTraits> + impl_; +}; /** * The `NodeTemplatesConnection` object for `NodeTemplatesClient`. diff --git a/google/cloud/compute/node_types/v1/node_types_connection.h b/google/cloud/compute/node_types/v1/node_types_connection.h index 83cd5712b9ec8..2f7b573235bc7 100644 --- a/google/cloud/compute/node_types/v1/node_types_connection.h +++ b/google/cloud/compute/node_types/v1/node_types_connection.h @@ -36,16 +36,133 @@ namespace cloud { namespace compute_node_types_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NodeTypesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_node_types_v1_internal::NodeTypesRetryTraits>; +/// The retry policy for `NodeTypesConnection`. +class NodeTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `NodeTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NodeTypesLimitedErrorCountRetryPolicy : public NodeTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NodeTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + NodeTypesLimitedErrorCountRetryPolicy( + NodeTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : NodeTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + NodeTypesLimitedErrorCountRetryPolicy( + NodeTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : NodeTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NodeTypesRetryPolicy; -using NodeTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_node_types_v1_internal::NodeTypesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_node_types_v1_internal::NodeTypesRetryTraits> + impl_; +}; + +/** + * A retry policy for `NodeTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NodeTypesLimitedTimeRetryPolicy : public NodeTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NodeTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NodeTypesLimitedTimeRetryPolicy( + NodeTypesLimitedTimeRetryPolicy&& rhs) noexcept + : NodeTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NodeTypesLimitedTimeRetryPolicy( + NodeTypesLimitedTimeRetryPolicy const& rhs) noexcept + : NodeTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using NodeTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_node_types_v1_internal::NodeTypesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NodeTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_node_types_v1_internal::NodeTypesRetryTraits> + impl_; +}; /** * The `NodeTypesConnection` object for `NodeTypesClient`. diff --git a/google/cloud/compute/packet_mirrorings/v1/packet_mirrorings_connection.h b/google/cloud/compute/packet_mirrorings/v1/packet_mirrorings_connection.h index 6b292ab427b85..3a4f535f1dec4 100644 --- a/google/cloud/compute/packet_mirrorings/v1/packet_mirrorings_connection.h +++ b/google/cloud/compute/packet_mirrorings/v1/packet_mirrorings_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_packet_mirrorings_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PacketMirroringsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_packet_mirrorings_v1_internal::PacketMirroringsRetryTraits>; +/// The retry policy for `PacketMirroringsConnection`. +class PacketMirroringsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using PacketMirroringsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_packet_mirrorings_v1_internal::PacketMirroringsRetryTraits>; +/** + * A retry policy for `PacketMirroringsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PacketMirroringsLimitedErrorCountRetryPolicy + : public PacketMirroringsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PacketMirroringsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PacketMirroringsLimitedErrorCountRetryPolicy( + PacketMirroringsLimitedErrorCountRetryPolicy&& rhs) noexcept + : PacketMirroringsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PacketMirroringsLimitedErrorCountRetryPolicy( + PacketMirroringsLimitedErrorCountRetryPolicy const& rhs) noexcept + : PacketMirroringsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PacketMirroringsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_packet_mirrorings_v1_internal::PacketMirroringsRetryTraits> + impl_; +}; -using PacketMirroringsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_packet_mirrorings_v1_internal::PacketMirroringsRetryTraits>; +/** + * A retry policy for `PacketMirroringsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PacketMirroringsLimitedTimeRetryPolicy + : public PacketMirroringsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PacketMirroringsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PacketMirroringsLimitedTimeRetryPolicy( + PacketMirroringsLimitedTimeRetryPolicy&& rhs) noexcept + : PacketMirroringsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PacketMirroringsLimitedTimeRetryPolicy( + PacketMirroringsLimitedTimeRetryPolicy const& rhs) noexcept + : PacketMirroringsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PacketMirroringsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_packet_mirrorings_v1_internal::PacketMirroringsRetryTraits> + impl_; +}; /** * The `PacketMirroringsConnection` object for `PacketMirroringsClient`. diff --git a/google/cloud/compute/projects/v1/projects_connection.h b/google/cloud/compute/projects/v1/projects_connection.h index 5d670e07725ff..196a4ffcadef6 100644 --- a/google/cloud/compute/projects/v1/projects_connection.h +++ b/google/cloud/compute/projects/v1/projects_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace compute_projects_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ProjectsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_projects_v1_internal::ProjectsRetryTraits>; +/// The retry policy for `ProjectsConnection`. +class ProjectsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ProjectsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_projects_v1_internal::ProjectsRetryTraits>; +/** + * A retry policy for `ProjectsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProjectsLimitedErrorCountRetryPolicy : public ProjectsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ProjectsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ProjectsLimitedErrorCountRetryPolicy( + ProjectsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ProjectsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ProjectsLimitedErrorCountRetryPolicy( + ProjectsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ProjectsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProjectsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_projects_v1_internal::ProjectsRetryTraits> + impl_; +}; -using ProjectsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_projects_v1_internal::ProjectsRetryTraits>; +/** + * A retry policy for `ProjectsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProjectsLimitedTimeRetryPolicy : public ProjectsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ProjectsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ProjectsLimitedTimeRetryPolicy(ProjectsLimitedTimeRetryPolicy&& rhs) noexcept + : ProjectsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ProjectsLimitedTimeRetryPolicy( + ProjectsLimitedTimeRetryPolicy const& rhs) noexcept + : ProjectsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProjectsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_projects_v1_internal::ProjectsRetryTraits> + impl_; +}; /** * The `ProjectsConnection` object for `ProjectsClient`. diff --git a/google/cloud/compute/public_advertised_prefixes/v1/public_advertised_prefixes_connection.h b/google/cloud/compute/public_advertised_prefixes/v1/public_advertised_prefixes_connection.h index 293bfaddd507f..d4c302b89bd81 100644 --- a/google/cloud/compute/public_advertised_prefixes/v1/public_advertised_prefixes_connection.h +++ b/google/cloud/compute/public_advertised_prefixes/v1/public_advertised_prefixes_connection.h @@ -39,20 +39,147 @@ namespace cloud { namespace compute_public_advertised_prefixes_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PublicAdvertisedPrefixesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_public_advertised_prefixes_v1_internal:: - PublicAdvertisedPrefixesRetryTraits>; - -using PublicAdvertisedPrefixesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_public_advertised_prefixes_v1_internal:: - PublicAdvertisedPrefixesRetryTraits>; - -using PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_public_advertised_prefixes_v1_internal:: - PublicAdvertisedPrefixesRetryTraits>; +/// The retry policy for `PublicAdvertisedPrefixesConnection`. +class PublicAdvertisedPrefixesRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `PublicAdvertisedPrefixesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy + : public PublicAdvertisedPrefixesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy( + PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy&& rhs) noexcept + : PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy( + PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy const& rhs) noexcept + : PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + PublicAdvertisedPrefixesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PublicAdvertisedPrefixesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_public_advertised_prefixes_v1_internal:: + PublicAdvertisedPrefixesRetryTraits> + impl_; +}; + +/** + * A retry policy for `PublicAdvertisedPrefixesConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PublicAdvertisedPrefixesLimitedTimeRetryPolicy + : public PublicAdvertisedPrefixesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PublicAdvertisedPrefixesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PublicAdvertisedPrefixesLimitedTimeRetryPolicy( + PublicAdvertisedPrefixesLimitedTimeRetryPolicy&& rhs) noexcept + : PublicAdvertisedPrefixesLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + PublicAdvertisedPrefixesLimitedTimeRetryPolicy( + PublicAdvertisedPrefixesLimitedTimeRetryPolicy const& rhs) noexcept + : PublicAdvertisedPrefixesLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PublicAdvertisedPrefixesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_public_advertised_prefixes_v1_internal:: + PublicAdvertisedPrefixesRetryTraits> + impl_; +}; /** * The `PublicAdvertisedPrefixesConnection` object for diff --git a/google/cloud/compute/public_delegated_prefixes/v1/public_delegated_prefixes_connection.h b/google/cloud/compute/public_delegated_prefixes/v1/public_delegated_prefixes_connection.h index 760ce9f984e3f..d7b8cafd27426 100644 --- a/google/cloud/compute/public_delegated_prefixes/v1/public_delegated_prefixes_connection.h +++ b/google/cloud/compute/public_delegated_prefixes/v1/public_delegated_prefixes_connection.h @@ -39,20 +39,142 @@ namespace cloud { namespace compute_public_delegated_prefixes_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PublicDelegatedPrefixesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_public_delegated_prefixes_v1_internal:: - PublicDelegatedPrefixesRetryTraits>; - -using PublicDelegatedPrefixesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_public_delegated_prefixes_v1_internal:: - PublicDelegatedPrefixesRetryTraits>; - -using PublicDelegatedPrefixesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_public_delegated_prefixes_v1_internal:: - PublicDelegatedPrefixesRetryTraits>; +/// The retry policy for `PublicDelegatedPrefixesConnection`. +class PublicDelegatedPrefixesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PublicDelegatedPrefixesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PublicDelegatedPrefixesLimitedErrorCountRetryPolicy + : public PublicDelegatedPrefixesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + PublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + PublicDelegatedPrefixesLimitedErrorCountRetryPolicy&& rhs) noexcept + : PublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + PublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + PublicDelegatedPrefixesLimitedErrorCountRetryPolicy const& rhs) noexcept + : PublicDelegatedPrefixesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + PublicDelegatedPrefixesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PublicDelegatedPrefixesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_public_delegated_prefixes_v1_internal:: + PublicDelegatedPrefixesRetryTraits> + impl_; +}; + +/** + * A retry policy for `PublicDelegatedPrefixesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PublicDelegatedPrefixesLimitedTimeRetryPolicy + : public PublicDelegatedPrefixesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PublicDelegatedPrefixesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PublicDelegatedPrefixesLimitedTimeRetryPolicy( + PublicDelegatedPrefixesLimitedTimeRetryPolicy&& rhs) noexcept + : PublicDelegatedPrefixesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PublicDelegatedPrefixesLimitedTimeRetryPolicy( + PublicDelegatedPrefixesLimitedTimeRetryPolicy const& rhs) noexcept + : PublicDelegatedPrefixesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PublicDelegatedPrefixesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_public_delegated_prefixes_v1_internal:: + PublicDelegatedPrefixesRetryTraits> + impl_; +}; /** * The `PublicDelegatedPrefixesConnection` object for diff --git a/google/cloud/compute/region_autoscalers/v1/region_autoscalers_connection.h b/google/cloud/compute/region_autoscalers/v1/region_autoscalers_connection.h index 9f09641f6a3c0..dee59d2a99dd7 100644 --- a/google/cloud/compute/region_autoscalers/v1/region_autoscalers_connection.h +++ b/google/cloud/compute/region_autoscalers/v1/region_autoscalers_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_region_autoscalers_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionAutoscalersRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_autoscalers_v1_internal::RegionAutoscalersRetryTraits>; +/// The retry policy for `RegionAutoscalersConnection`. +class RegionAutoscalersRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using RegionAutoscalersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_autoscalers_v1_internal::RegionAutoscalersRetryTraits>; +/** + * A retry policy for `RegionAutoscalersConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionAutoscalersLimitedErrorCountRetryPolicy + : public RegionAutoscalersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionAutoscalersLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionAutoscalersLimitedErrorCountRetryPolicy( + RegionAutoscalersLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionAutoscalersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionAutoscalersLimitedErrorCountRetryPolicy( + RegionAutoscalersLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionAutoscalersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionAutoscalersRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_autoscalers_v1_internal::RegionAutoscalersRetryTraits> + impl_; +}; -using RegionAutoscalersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_autoscalers_v1_internal::RegionAutoscalersRetryTraits>; +/** + * A retry policy for `RegionAutoscalersConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionAutoscalersLimitedTimeRetryPolicy + : public RegionAutoscalersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionAutoscalersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionAutoscalersLimitedTimeRetryPolicy( + RegionAutoscalersLimitedTimeRetryPolicy&& rhs) noexcept + : RegionAutoscalersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionAutoscalersLimitedTimeRetryPolicy( + RegionAutoscalersLimitedTimeRetryPolicy const& rhs) noexcept + : RegionAutoscalersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionAutoscalersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_autoscalers_v1_internal::RegionAutoscalersRetryTraits> + impl_; +}; /** * The `RegionAutoscalersConnection` object for `RegionAutoscalersClient`. diff --git a/google/cloud/compute/region_backend_services/v1/region_backend_services_connection.h b/google/cloud/compute/region_backend_services/v1/region_backend_services_connection.h index 04499b6dcc829..c7326a342726c 100644 --- a/google/cloud/compute/region_backend_services/v1/region_backend_services_connection.h +++ b/google/cloud/compute/region_backend_services/v1/region_backend_services_connection.h @@ -39,20 +39,141 @@ namespace cloud { namespace compute_region_backend_services_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionBackendServicesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_backend_services_v1_internal:: - RegionBackendServicesRetryTraits>; - -using RegionBackendServicesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_backend_services_v1_internal:: - RegionBackendServicesRetryTraits>; - -using RegionBackendServicesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_backend_services_v1_internal:: - RegionBackendServicesRetryTraits>; +/// The retry policy for `RegionBackendServicesConnection`. +class RegionBackendServicesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionBackendServicesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionBackendServicesLimitedErrorCountRetryPolicy + : public RegionBackendServicesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionBackendServicesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionBackendServicesLimitedErrorCountRetryPolicy( + RegionBackendServicesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionBackendServicesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionBackendServicesLimitedErrorCountRetryPolicy( + RegionBackendServicesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionBackendServicesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionBackendServicesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_backend_services_v1_internal:: + RegionBackendServicesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionBackendServicesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionBackendServicesLimitedTimeRetryPolicy + : public RegionBackendServicesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionBackendServicesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionBackendServicesLimitedTimeRetryPolicy( + RegionBackendServicesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionBackendServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionBackendServicesLimitedTimeRetryPolicy( + RegionBackendServicesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionBackendServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionBackendServicesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_backend_services_v1_internal:: + RegionBackendServicesRetryTraits> + impl_; +}; /** * The `RegionBackendServicesConnection` object for diff --git a/google/cloud/compute/region_commitments/v1/region_commitments_connection.h b/google/cloud/compute/region_commitments/v1/region_commitments_connection.h index f7d6f36335f24..95ec0da77eaa7 100644 --- a/google/cloud/compute/region_commitments/v1/region_commitments_connection.h +++ b/google/cloud/compute/region_commitments/v1/region_commitments_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_region_commitments_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionCommitmentsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_commitments_v1_internal::RegionCommitmentsRetryTraits>; +/// The retry policy for `RegionCommitmentsConnection`. +class RegionCommitmentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using RegionCommitmentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_commitments_v1_internal::RegionCommitmentsRetryTraits>; +/** + * A retry policy for `RegionCommitmentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionCommitmentsLimitedErrorCountRetryPolicy + : public RegionCommitmentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionCommitmentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionCommitmentsLimitedErrorCountRetryPolicy( + RegionCommitmentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionCommitmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionCommitmentsLimitedErrorCountRetryPolicy( + RegionCommitmentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionCommitmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionCommitmentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_commitments_v1_internal::RegionCommitmentsRetryTraits> + impl_; +}; -using RegionCommitmentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_commitments_v1_internal::RegionCommitmentsRetryTraits>; +/** + * A retry policy for `RegionCommitmentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionCommitmentsLimitedTimeRetryPolicy + : public RegionCommitmentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionCommitmentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionCommitmentsLimitedTimeRetryPolicy( + RegionCommitmentsLimitedTimeRetryPolicy&& rhs) noexcept + : RegionCommitmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionCommitmentsLimitedTimeRetryPolicy( + RegionCommitmentsLimitedTimeRetryPolicy const& rhs) noexcept + : RegionCommitmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionCommitmentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_commitments_v1_internal::RegionCommitmentsRetryTraits> + impl_; +}; /** * The `RegionCommitmentsConnection` object for `RegionCommitmentsClient`. diff --git a/google/cloud/compute/region_disk_types/v1/region_disk_types_connection.h b/google/cloud/compute/region_disk_types/v1/region_disk_types_connection.h index 2764034769bd2..7bb92a4b52a3b 100644 --- a/google/cloud/compute/region_disk_types/v1/region_disk_types_connection.h +++ b/google/cloud/compute/region_disk_types/v1/region_disk_types_connection.h @@ -36,17 +36,135 @@ namespace cloud { namespace compute_region_disk_types_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionDiskTypesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_disk_types_v1_internal::RegionDiskTypesRetryTraits>; +/// The retry policy for `RegionDiskTypesConnection`. +class RegionDiskTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionDiskTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionDiskTypesLimitedErrorCountRetryPolicy + : public RegionDiskTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionDiskTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionDiskTypesLimitedErrorCountRetryPolicy( + RegionDiskTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionDiskTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionDiskTypesLimitedErrorCountRetryPolicy( + RegionDiskTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionDiskTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionDiskTypesRetryPolicy; -using RegionDiskTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_disk_types_v1_internal::RegionDiskTypesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_disk_types_v1_internal::RegionDiskTypesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionDiskTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionDiskTypesLimitedTimeRetryPolicy + : public RegionDiskTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionDiskTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionDiskTypesLimitedTimeRetryPolicy( + RegionDiskTypesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionDiskTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionDiskTypesLimitedTimeRetryPolicy( + RegionDiskTypesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionDiskTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RegionDiskTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_disk_types_v1_internal::RegionDiskTypesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionDiskTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_disk_types_v1_internal::RegionDiskTypesRetryTraits> + impl_; +}; /** * The `RegionDiskTypesConnection` object for `RegionDiskTypesClient`. diff --git a/google/cloud/compute/region_disks/v1/region_disks_connection.h b/google/cloud/compute/region_disks/v1/region_disks_connection.h index d7dd6c89d44f8..2af0bf4313c3e 100644 --- a/google/cloud/compute/region_disks/v1/region_disks_connection.h +++ b/google/cloud/compute/region_disks/v1/region_disks_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_region_disks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionDisksRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_disks_v1_internal::RegionDisksRetryTraits>; +/// The retry policy for `RegionDisksConnection`. +class RegionDisksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using RegionDisksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_disks_v1_internal::RegionDisksRetryTraits>; +/** + * A retry policy for `RegionDisksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionDisksLimitedErrorCountRetryPolicy : public RegionDisksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionDisksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionDisksLimitedErrorCountRetryPolicy( + RegionDisksLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionDisksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionDisksLimitedErrorCountRetryPolicy( + RegionDisksLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionDisksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionDisksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_disks_v1_internal::RegionDisksRetryTraits> + impl_; +}; -using RegionDisksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_disks_v1_internal::RegionDisksRetryTraits>; +/** + * A retry policy for `RegionDisksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionDisksLimitedTimeRetryPolicy : public RegionDisksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionDisksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionDisksLimitedTimeRetryPolicy( + RegionDisksLimitedTimeRetryPolicy&& rhs) noexcept + : RegionDisksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionDisksLimitedTimeRetryPolicy( + RegionDisksLimitedTimeRetryPolicy const& rhs) noexcept + : RegionDisksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionDisksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_disks_v1_internal::RegionDisksRetryTraits> + impl_; +}; /** * The `RegionDisksConnection` object for `RegionDisksClient`. diff --git a/google/cloud/compute/region_health_check_services/v1/region_health_check_services_connection.h b/google/cloud/compute/region_health_check_services/v1/region_health_check_services_connection.h index 8927cc3879a7b..c79c793f97527 100644 --- a/google/cloud/compute/region_health_check_services/v1/region_health_check_services_connection.h +++ b/google/cloud/compute/region_health_check_services/v1/region_health_check_services_connection.h @@ -39,20 +39,147 @@ namespace cloud { namespace compute_region_health_check_services_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionHealthCheckServicesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_health_check_services_v1_internal:: - RegionHealthCheckServicesRetryTraits>; - -using RegionHealthCheckServicesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_health_check_services_v1_internal:: - RegionHealthCheckServicesRetryTraits>; - -using RegionHealthCheckServicesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_health_check_services_v1_internal:: - RegionHealthCheckServicesRetryTraits>; +/// The retry policy for `RegionHealthCheckServicesConnection`. +class RegionHealthCheckServicesRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `RegionHealthCheckServicesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionHealthCheckServicesLimitedErrorCountRetryPolicy + : public RegionHealthCheckServicesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionHealthCheckServicesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionHealthCheckServicesLimitedErrorCountRetryPolicy( + RegionHealthCheckServicesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionHealthCheckServicesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionHealthCheckServicesLimitedErrorCountRetryPolicy( + RegionHealthCheckServicesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionHealthCheckServicesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + RegionHealthCheckServicesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionHealthCheckServicesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_health_check_services_v1_internal:: + RegionHealthCheckServicesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionHealthCheckServicesConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionHealthCheckServicesLimitedTimeRetryPolicy + : public RegionHealthCheckServicesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionHealthCheckServicesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionHealthCheckServicesLimitedTimeRetryPolicy( + RegionHealthCheckServicesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionHealthCheckServicesLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + RegionHealthCheckServicesLimitedTimeRetryPolicy( + RegionHealthCheckServicesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionHealthCheckServicesLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionHealthCheckServicesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_health_check_services_v1_internal:: + RegionHealthCheckServicesRetryTraits> + impl_; +}; /** * The `RegionHealthCheckServicesConnection` object for diff --git a/google/cloud/compute/region_health_checks/v1/region_health_checks_connection.h b/google/cloud/compute/region_health_checks/v1/region_health_checks_connection.h index a2349ea4919c2..8d473aed6b600 100644 --- a/google/cloud/compute/region_health_checks/v1/region_health_checks_connection.h +++ b/google/cloud/compute/region_health_checks/v1/region_health_checks_connection.h @@ -39,20 +39,137 @@ namespace cloud { namespace compute_region_health_checks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionHealthChecksRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_health_checks_v1_internal:: - RegionHealthChecksRetryTraits>; - -using RegionHealthChecksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_health_checks_v1_internal:: - RegionHealthChecksRetryTraits>; - -using RegionHealthChecksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_health_checks_v1_internal:: - RegionHealthChecksRetryTraits>; +/// The retry policy for `RegionHealthChecksConnection`. +class RegionHealthChecksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionHealthChecksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionHealthChecksLimitedErrorCountRetryPolicy + : public RegionHealthChecksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionHealthChecksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionHealthChecksLimitedErrorCountRetryPolicy( + RegionHealthChecksLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionHealthChecksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + RegionHealthChecksLimitedErrorCountRetryPolicy( + RegionHealthChecksLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionHealthChecksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionHealthChecksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_health_checks_v1_internal::RegionHealthChecksRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionHealthChecksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionHealthChecksLimitedTimeRetryPolicy + : public RegionHealthChecksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionHealthChecksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionHealthChecksLimitedTimeRetryPolicy( + RegionHealthChecksLimitedTimeRetryPolicy&& rhs) noexcept + : RegionHealthChecksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionHealthChecksLimitedTimeRetryPolicy( + RegionHealthChecksLimitedTimeRetryPolicy const& rhs) noexcept + : RegionHealthChecksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionHealthChecksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_health_checks_v1_internal::RegionHealthChecksRetryTraits> + impl_; +}; /** * The `RegionHealthChecksConnection` object for `RegionHealthChecksClient`. diff --git a/google/cloud/compute/region_instance_group_managers/v1/region_instance_group_managers_connection.h b/google/cloud/compute/region_instance_group_managers/v1/region_instance_group_managers_connection.h index 27acca12f3c74..5003a7c2cacbc 100644 --- a/google/cloud/compute/region_instance_group_managers/v1/region_instance_group_managers_connection.h +++ b/google/cloud/compute/region_instance_group_managers/v1/region_instance_group_managers_connection.h @@ -39,20 +39,150 @@ namespace cloud { namespace compute_region_instance_group_managers_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionInstanceGroupManagersRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_instance_group_managers_v1_internal:: - RegionInstanceGroupManagersRetryTraits>; - -using RegionInstanceGroupManagersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_instance_group_managers_v1_internal:: - RegionInstanceGroupManagersRetryTraits>; - -using RegionInstanceGroupManagersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_instance_group_managers_v1_internal:: - RegionInstanceGroupManagersRetryTraits>; +/// The retry policy for `RegionInstanceGroupManagersConnection`. +class RegionInstanceGroupManagersRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `RegionInstanceGroupManagersConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionInstanceGroupManagersLimitedErrorCountRetryPolicy + : public RegionInstanceGroupManagersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionInstanceGroupManagersLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionInstanceGroupManagersLimitedErrorCountRetryPolicy( + RegionInstanceGroupManagersLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionInstanceGroupManagersLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionInstanceGroupManagersLimitedErrorCountRetryPolicy( + RegionInstanceGroupManagersLimitedErrorCountRetryPolicy const& + rhs) noexcept + : RegionInstanceGroupManagersLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + RegionInstanceGroupManagersLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionInstanceGroupManagersRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_instance_group_managers_v1_internal:: + RegionInstanceGroupManagersRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionInstanceGroupManagersConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionInstanceGroupManagersLimitedTimeRetryPolicy + : public RegionInstanceGroupManagersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionInstanceGroupManagersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionInstanceGroupManagersLimitedTimeRetryPolicy( + RegionInstanceGroupManagersLimitedTimeRetryPolicy&& rhs) noexcept + : RegionInstanceGroupManagersLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + RegionInstanceGroupManagersLimitedTimeRetryPolicy( + RegionInstanceGroupManagersLimitedTimeRetryPolicy const& rhs) noexcept + : RegionInstanceGroupManagersLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionInstanceGroupManagersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_instance_group_managers_v1_internal:: + RegionInstanceGroupManagersRetryTraits> + impl_; +}; /** * The `RegionInstanceGroupManagersConnection` object for diff --git a/google/cloud/compute/region_instance_groups/v1/region_instance_groups_connection.h b/google/cloud/compute/region_instance_groups/v1/region_instance_groups_connection.h index a7639440cda69..0fd74748d985c 100644 --- a/google/cloud/compute/region_instance_groups/v1/region_instance_groups_connection.h +++ b/google/cloud/compute/region_instance_groups/v1/region_instance_groups_connection.h @@ -39,20 +39,140 @@ namespace cloud { namespace compute_region_instance_groups_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionInstanceGroupsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_instance_groups_v1_internal:: - RegionInstanceGroupsRetryTraits>; - -using RegionInstanceGroupsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_instance_groups_v1_internal:: - RegionInstanceGroupsRetryTraits>; - -using RegionInstanceGroupsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_instance_groups_v1_internal:: - RegionInstanceGroupsRetryTraits>; +/// The retry policy for `RegionInstanceGroupsConnection`. +class RegionInstanceGroupsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionInstanceGroupsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionInstanceGroupsLimitedErrorCountRetryPolicy + : public RegionInstanceGroupsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionInstanceGroupsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionInstanceGroupsLimitedErrorCountRetryPolicy( + RegionInstanceGroupsLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionInstanceGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionInstanceGroupsLimitedErrorCountRetryPolicy( + RegionInstanceGroupsLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionInstanceGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionInstanceGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_instance_groups_v1_internal:: + RegionInstanceGroupsRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionInstanceGroupsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionInstanceGroupsLimitedTimeRetryPolicy + : public RegionInstanceGroupsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionInstanceGroupsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionInstanceGroupsLimitedTimeRetryPolicy( + RegionInstanceGroupsLimitedTimeRetryPolicy&& rhs) noexcept + : RegionInstanceGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionInstanceGroupsLimitedTimeRetryPolicy( + RegionInstanceGroupsLimitedTimeRetryPolicy const& rhs) noexcept + : RegionInstanceGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionInstanceGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_instance_groups_v1_internal:: + RegionInstanceGroupsRetryTraits> + impl_; +}; /** * The `RegionInstanceGroupsConnection` object for `RegionInstanceGroupsClient`. diff --git a/google/cloud/compute/region_instance_templates/v1/region_instance_templates_connection.h b/google/cloud/compute/region_instance_templates/v1/region_instance_templates_connection.h index e99746afe6ee1..76119e35edd2c 100644 --- a/google/cloud/compute/region_instance_templates/v1/region_instance_templates_connection.h +++ b/google/cloud/compute/region_instance_templates/v1/region_instance_templates_connection.h @@ -39,20 +39,142 @@ namespace cloud { namespace compute_region_instance_templates_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionInstanceTemplatesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_instance_templates_v1_internal:: - RegionInstanceTemplatesRetryTraits>; - -using RegionInstanceTemplatesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_instance_templates_v1_internal:: - RegionInstanceTemplatesRetryTraits>; - -using RegionInstanceTemplatesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_instance_templates_v1_internal:: - RegionInstanceTemplatesRetryTraits>; +/// The retry policy for `RegionInstanceTemplatesConnection`. +class RegionInstanceTemplatesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionInstanceTemplatesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionInstanceTemplatesLimitedErrorCountRetryPolicy + : public RegionInstanceTemplatesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionInstanceTemplatesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionInstanceTemplatesLimitedErrorCountRetryPolicy( + RegionInstanceTemplatesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionInstanceTemplatesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionInstanceTemplatesLimitedErrorCountRetryPolicy( + RegionInstanceTemplatesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionInstanceTemplatesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + RegionInstanceTemplatesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionInstanceTemplatesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_instance_templates_v1_internal:: + RegionInstanceTemplatesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionInstanceTemplatesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionInstanceTemplatesLimitedTimeRetryPolicy + : public RegionInstanceTemplatesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionInstanceTemplatesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionInstanceTemplatesLimitedTimeRetryPolicy( + RegionInstanceTemplatesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionInstanceTemplatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionInstanceTemplatesLimitedTimeRetryPolicy( + RegionInstanceTemplatesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionInstanceTemplatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionInstanceTemplatesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_instance_templates_v1_internal:: + RegionInstanceTemplatesRetryTraits> + impl_; +}; /** * The `RegionInstanceTemplatesConnection` object for diff --git a/google/cloud/compute/region_instances/v1/region_instances_connection.h b/google/cloud/compute/region_instances/v1/region_instances_connection.h index eb05097c03e91..e49395bd1738f 100644 --- a/google/cloud/compute/region_instances/v1/region_instances_connection.h +++ b/google/cloud/compute/region_instances/v1/region_instances_connection.h @@ -37,17 +37,135 @@ namespace cloud { namespace compute_region_instances_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionInstancesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_instances_v1_internal::RegionInstancesRetryTraits>; +/// The retry policy for `RegionInstancesConnection`. +class RegionInstancesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionInstancesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionInstancesLimitedErrorCountRetryPolicy + : public RegionInstancesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionInstancesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionInstancesLimitedErrorCountRetryPolicy( + RegionInstancesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionInstancesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionInstancesLimitedErrorCountRetryPolicy( + RegionInstancesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionInstancesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionInstancesRetryPolicy; -using RegionInstancesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_instances_v1_internal::RegionInstancesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_instances_v1_internal::RegionInstancesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionInstancesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionInstancesLimitedTimeRetryPolicy + : public RegionInstancesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionInstancesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionInstancesLimitedTimeRetryPolicy( + RegionInstancesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionInstancesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionInstancesLimitedTimeRetryPolicy( + RegionInstancesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionInstancesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RegionInstancesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_instances_v1_internal::RegionInstancesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionInstancesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_instances_v1_internal::RegionInstancesRetryTraits> + impl_; +}; /** * The `RegionInstancesConnection` object for `RegionInstancesClient`. diff --git a/google/cloud/compute/region_network_endpoint_groups/v1/region_network_endpoint_groups_connection.h b/google/cloud/compute/region_network_endpoint_groups/v1/region_network_endpoint_groups_connection.h index 61aaee1ea27ae..624efd78bc291 100644 --- a/google/cloud/compute/region_network_endpoint_groups/v1/region_network_endpoint_groups_connection.h +++ b/google/cloud/compute/region_network_endpoint_groups/v1/region_network_endpoint_groups_connection.h @@ -39,20 +39,150 @@ namespace cloud { namespace compute_region_network_endpoint_groups_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionNetworkEndpointGroupsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_network_endpoint_groups_v1_internal:: - RegionNetworkEndpointGroupsRetryTraits>; - -using RegionNetworkEndpointGroupsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_network_endpoint_groups_v1_internal:: - RegionNetworkEndpointGroupsRetryTraits>; - -using RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_network_endpoint_groups_v1_internal:: - RegionNetworkEndpointGroupsRetryTraits>; +/// The retry policy for `RegionNetworkEndpointGroupsConnection`. +class RegionNetworkEndpointGroupsRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `RegionNetworkEndpointGroupsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy + : public RegionNetworkEndpointGroupsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy const& + rhs) noexcept + : RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + RegionNetworkEndpointGroupsLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionNetworkEndpointGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_network_endpoint_groups_v1_internal:: + RegionNetworkEndpointGroupsRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionNetworkEndpointGroupsConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionNetworkEndpointGroupsLimitedTimeRetryPolicy + : public RegionNetworkEndpointGroupsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionNetworkEndpointGroupsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionNetworkEndpointGroupsLimitedTimeRetryPolicy( + RegionNetworkEndpointGroupsLimitedTimeRetryPolicy&& rhs) noexcept + : RegionNetworkEndpointGroupsLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + RegionNetworkEndpointGroupsLimitedTimeRetryPolicy( + RegionNetworkEndpointGroupsLimitedTimeRetryPolicy const& rhs) noexcept + : RegionNetworkEndpointGroupsLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionNetworkEndpointGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_network_endpoint_groups_v1_internal:: + RegionNetworkEndpointGroupsRetryTraits> + impl_; +}; /** * The `RegionNetworkEndpointGroupsConnection` object for diff --git a/google/cloud/compute/region_network_firewall_policies/v1/region_network_firewall_policies_connection.h b/google/cloud/compute/region_network_firewall_policies/v1/region_network_firewall_policies_connection.h index fe2b93c7c2434..058d4baecd56d 100644 --- a/google/cloud/compute/region_network_firewall_policies/v1/region_network_firewall_policies_connection.h +++ b/google/cloud/compute/region_network_firewall_policies/v1/region_network_firewall_policies_connection.h @@ -39,20 +39,151 @@ namespace cloud { namespace compute_region_network_firewall_policies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionNetworkFirewallPoliciesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_network_firewall_policies_v1_internal:: - RegionNetworkFirewallPoliciesRetryTraits>; - -using RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_network_firewall_policies_v1_internal:: - RegionNetworkFirewallPoliciesRetryTraits>; - -using RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_network_firewall_policies_v1_internal:: - RegionNetworkFirewallPoliciesRetryTraits>; +/// The retry policy for `RegionNetworkFirewallPoliciesConnection`. +class RegionNetworkFirewallPoliciesRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `RegionNetworkFirewallPoliciesConnection` based on + * counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy + : public RegionNetworkFirewallPoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy const& + rhs) noexcept + : RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + RegionNetworkFirewallPoliciesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionNetworkFirewallPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_network_firewall_policies_v1_internal:: + RegionNetworkFirewallPoliciesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionNetworkFirewallPoliciesConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy + : public RegionNetworkFirewallPoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy( + RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy( + RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + RegionNetworkFirewallPoliciesLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionNetworkFirewallPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_network_firewall_policies_v1_internal:: + RegionNetworkFirewallPoliciesRetryTraits> + impl_; +}; /** * The `RegionNetworkFirewallPoliciesConnection` object for diff --git a/google/cloud/compute/region_notification_endpoints/v1/region_notification_endpoints_connection.h b/google/cloud/compute/region_notification_endpoints/v1/region_notification_endpoints_connection.h index 59287a02975fc..596436d5525e4 100644 --- a/google/cloud/compute/region_notification_endpoints/v1/region_notification_endpoints_connection.h +++ b/google/cloud/compute/region_notification_endpoints/v1/region_notification_endpoints_connection.h @@ -39,20 +39,150 @@ namespace cloud { namespace compute_region_notification_endpoints_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionNotificationEndpointsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_notification_endpoints_v1_internal:: - RegionNotificationEndpointsRetryTraits>; - -using RegionNotificationEndpointsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_notification_endpoints_v1_internal:: - RegionNotificationEndpointsRetryTraits>; - -using RegionNotificationEndpointsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_notification_endpoints_v1_internal:: - RegionNotificationEndpointsRetryTraits>; +/// The retry policy for `RegionNotificationEndpointsConnection`. +class RegionNotificationEndpointsRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `RegionNotificationEndpointsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionNotificationEndpointsLimitedErrorCountRetryPolicy + : public RegionNotificationEndpointsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionNotificationEndpointsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionNotificationEndpointsLimitedErrorCountRetryPolicy( + RegionNotificationEndpointsLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionNotificationEndpointsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionNotificationEndpointsLimitedErrorCountRetryPolicy( + RegionNotificationEndpointsLimitedErrorCountRetryPolicy const& + rhs) noexcept + : RegionNotificationEndpointsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + RegionNotificationEndpointsLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionNotificationEndpointsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_notification_endpoints_v1_internal:: + RegionNotificationEndpointsRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionNotificationEndpointsConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionNotificationEndpointsLimitedTimeRetryPolicy + : public RegionNotificationEndpointsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionNotificationEndpointsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionNotificationEndpointsLimitedTimeRetryPolicy( + RegionNotificationEndpointsLimitedTimeRetryPolicy&& rhs) noexcept + : RegionNotificationEndpointsLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + RegionNotificationEndpointsLimitedTimeRetryPolicy( + RegionNotificationEndpointsLimitedTimeRetryPolicy const& rhs) noexcept + : RegionNotificationEndpointsLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionNotificationEndpointsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_notification_endpoints_v1_internal:: + RegionNotificationEndpointsRetryTraits> + impl_; +}; /** * The `RegionNotificationEndpointsConnection` object for diff --git a/google/cloud/compute/region_operations/v1/region_operations_connection.h b/google/cloud/compute/region_operations/v1/region_operations_connection.h index 576349a07d0bd..44adfd34aa0c6 100644 --- a/google/cloud/compute/region_operations/v1/region_operations_connection.h +++ b/google/cloud/compute/region_operations/v1/region_operations_connection.h @@ -36,17 +36,135 @@ namespace cloud { namespace compute_region_operations_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionOperationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_operations_v1_internal::RegionOperationsRetryTraits>; +/// The retry policy for `RegionOperationsConnection`. +class RegionOperationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionOperationsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionOperationsLimitedErrorCountRetryPolicy + : public RegionOperationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionOperationsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionOperationsLimitedErrorCountRetryPolicy( + RegionOperationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionOperationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionOperationsLimitedErrorCountRetryPolicy( + RegionOperationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionOperationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionOperationsRetryPolicy; -using RegionOperationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_operations_v1_internal::RegionOperationsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_operations_v1_internal::RegionOperationsRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionOperationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionOperationsLimitedTimeRetryPolicy + : public RegionOperationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionOperationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionOperationsLimitedTimeRetryPolicy( + RegionOperationsLimitedTimeRetryPolicy&& rhs) noexcept + : RegionOperationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionOperationsLimitedTimeRetryPolicy( + RegionOperationsLimitedTimeRetryPolicy const& rhs) noexcept + : RegionOperationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RegionOperationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_operations_v1_internal::RegionOperationsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionOperationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_operations_v1_internal::RegionOperationsRetryTraits> + impl_; +}; /** * The `RegionOperationsConnection` object for `RegionOperationsClient`. diff --git a/google/cloud/compute/region_security_policies/v1/region_security_policies_connection.h b/google/cloud/compute/region_security_policies/v1/region_security_policies_connection.h index 1a03b65f553be..a2ac9b4de8dd6 100644 --- a/google/cloud/compute/region_security_policies/v1/region_security_policies_connection.h +++ b/google/cloud/compute/region_security_policies/v1/region_security_policies_connection.h @@ -39,20 +39,141 @@ namespace cloud { namespace compute_region_security_policies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionSecurityPoliciesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_security_policies_v1_internal:: - RegionSecurityPoliciesRetryTraits>; - -using RegionSecurityPoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_security_policies_v1_internal:: - RegionSecurityPoliciesRetryTraits>; - -using RegionSecurityPoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_security_policies_v1_internal:: - RegionSecurityPoliciesRetryTraits>; +/// The retry policy for `RegionSecurityPoliciesConnection`. +class RegionSecurityPoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionSecurityPoliciesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionSecurityPoliciesLimitedErrorCountRetryPolicy + : public RegionSecurityPoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionSecurityPoliciesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionSecurityPoliciesLimitedErrorCountRetryPolicy( + RegionSecurityPoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionSecurityPoliciesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionSecurityPoliciesLimitedErrorCountRetryPolicy( + RegionSecurityPoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionSecurityPoliciesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionSecurityPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_security_policies_v1_internal:: + RegionSecurityPoliciesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionSecurityPoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionSecurityPoliciesLimitedTimeRetryPolicy + : public RegionSecurityPoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionSecurityPoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionSecurityPoliciesLimitedTimeRetryPolicy( + RegionSecurityPoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionSecurityPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionSecurityPoliciesLimitedTimeRetryPolicy( + RegionSecurityPoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionSecurityPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionSecurityPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_security_policies_v1_internal:: + RegionSecurityPoliciesRetryTraits> + impl_; +}; /** * The `RegionSecurityPoliciesConnection` object for diff --git a/google/cloud/compute/region_ssl_certificates/v1/region_ssl_certificates_connection.h b/google/cloud/compute/region_ssl_certificates/v1/region_ssl_certificates_connection.h index e74a972d4bf8d..151a4c928f52d 100644 --- a/google/cloud/compute/region_ssl_certificates/v1/region_ssl_certificates_connection.h +++ b/google/cloud/compute/region_ssl_certificates/v1/region_ssl_certificates_connection.h @@ -39,20 +39,141 @@ namespace cloud { namespace compute_region_ssl_certificates_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionSslCertificatesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_ssl_certificates_v1_internal:: - RegionSslCertificatesRetryTraits>; - -using RegionSslCertificatesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_ssl_certificates_v1_internal:: - RegionSslCertificatesRetryTraits>; - -using RegionSslCertificatesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_ssl_certificates_v1_internal:: - RegionSslCertificatesRetryTraits>; +/// The retry policy for `RegionSslCertificatesConnection`. +class RegionSslCertificatesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionSslCertificatesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionSslCertificatesLimitedErrorCountRetryPolicy + : public RegionSslCertificatesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionSslCertificatesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionSslCertificatesLimitedErrorCountRetryPolicy( + RegionSslCertificatesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionSslCertificatesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionSslCertificatesLimitedErrorCountRetryPolicy( + RegionSslCertificatesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionSslCertificatesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionSslCertificatesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_ssl_certificates_v1_internal:: + RegionSslCertificatesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionSslCertificatesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionSslCertificatesLimitedTimeRetryPolicy + : public RegionSslCertificatesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionSslCertificatesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionSslCertificatesLimitedTimeRetryPolicy( + RegionSslCertificatesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionSslCertificatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionSslCertificatesLimitedTimeRetryPolicy( + RegionSslCertificatesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionSslCertificatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionSslCertificatesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_ssl_certificates_v1_internal:: + RegionSslCertificatesRetryTraits> + impl_; +}; /** * The `RegionSslCertificatesConnection` object for diff --git a/google/cloud/compute/region_ssl_policies/v1/region_ssl_policies_connection.h b/google/cloud/compute/region_ssl_policies/v1/region_ssl_policies_connection.h index 11f6319fb3787..71b8493a4b010 100644 --- a/google/cloud/compute/region_ssl_policies/v1/region_ssl_policies_connection.h +++ b/google/cloud/compute/region_ssl_policies/v1/region_ssl_policies_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_region_ssl_policies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionSslPoliciesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_ssl_policies_v1_internal::RegionSslPoliciesRetryTraits>; +/// The retry policy for `RegionSslPoliciesConnection`. +class RegionSslPoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using RegionSslPoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_ssl_policies_v1_internal::RegionSslPoliciesRetryTraits>; +/** + * A retry policy for `RegionSslPoliciesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionSslPoliciesLimitedErrorCountRetryPolicy + : public RegionSslPoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionSslPoliciesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionSslPoliciesLimitedErrorCountRetryPolicy( + RegionSslPoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionSslPoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionSslPoliciesLimitedErrorCountRetryPolicy( + RegionSslPoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionSslPoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionSslPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_ssl_policies_v1_internal::RegionSslPoliciesRetryTraits> + impl_; +}; -using RegionSslPoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_ssl_policies_v1_internal::RegionSslPoliciesRetryTraits>; +/** + * A retry policy for `RegionSslPoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionSslPoliciesLimitedTimeRetryPolicy + : public RegionSslPoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionSslPoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionSslPoliciesLimitedTimeRetryPolicy( + RegionSslPoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionSslPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionSslPoliciesLimitedTimeRetryPolicy( + RegionSslPoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionSslPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionSslPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_ssl_policies_v1_internal::RegionSslPoliciesRetryTraits> + impl_; +}; /** * The `RegionSslPoliciesConnection` object for `RegionSslPoliciesClient`. diff --git a/google/cloud/compute/region_target_http_proxies/v1/region_target_http_proxies_connection.h b/google/cloud/compute/region_target_http_proxies/v1/region_target_http_proxies_connection.h index 16870e37fe09a..593fd4b47d0aa 100644 --- a/google/cloud/compute/region_target_http_proxies/v1/region_target_http_proxies_connection.h +++ b/google/cloud/compute/region_target_http_proxies/v1/region_target_http_proxies_connection.h @@ -39,20 +39,142 @@ namespace cloud { namespace compute_region_target_http_proxies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionTargetHttpProxiesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_target_http_proxies_v1_internal:: - RegionTargetHttpProxiesRetryTraits>; - -using RegionTargetHttpProxiesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_target_http_proxies_v1_internal:: - RegionTargetHttpProxiesRetryTraits>; - -using RegionTargetHttpProxiesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_target_http_proxies_v1_internal:: - RegionTargetHttpProxiesRetryTraits>; +/// The retry policy for `RegionTargetHttpProxiesConnection`. +class RegionTargetHttpProxiesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionTargetHttpProxiesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionTargetHttpProxiesLimitedErrorCountRetryPolicy + : public RegionTargetHttpProxiesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionTargetHttpProxiesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionTargetHttpProxiesLimitedErrorCountRetryPolicy( + RegionTargetHttpProxiesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionTargetHttpProxiesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionTargetHttpProxiesLimitedErrorCountRetryPolicy( + RegionTargetHttpProxiesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionTargetHttpProxiesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + RegionTargetHttpProxiesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionTargetHttpProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_target_http_proxies_v1_internal:: + RegionTargetHttpProxiesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionTargetHttpProxiesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionTargetHttpProxiesLimitedTimeRetryPolicy + : public RegionTargetHttpProxiesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionTargetHttpProxiesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionTargetHttpProxiesLimitedTimeRetryPolicy( + RegionTargetHttpProxiesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionTargetHttpProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionTargetHttpProxiesLimitedTimeRetryPolicy( + RegionTargetHttpProxiesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionTargetHttpProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionTargetHttpProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_target_http_proxies_v1_internal:: + RegionTargetHttpProxiesRetryTraits> + impl_; +}; /** * The `RegionTargetHttpProxiesConnection` object for diff --git a/google/cloud/compute/region_target_https_proxies/v1/region_target_https_proxies_connection.h b/google/cloud/compute/region_target_https_proxies/v1/region_target_https_proxies_connection.h index 3e319cfc406de..fbe45cba30d9a 100644 --- a/google/cloud/compute/region_target_https_proxies/v1/region_target_https_proxies_connection.h +++ b/google/cloud/compute/region_target_https_proxies/v1/region_target_https_proxies_connection.h @@ -39,20 +39,147 @@ namespace cloud { namespace compute_region_target_https_proxies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionTargetHttpsProxiesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_target_https_proxies_v1_internal:: - RegionTargetHttpsProxiesRetryTraits>; - -using RegionTargetHttpsProxiesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_target_https_proxies_v1_internal:: - RegionTargetHttpsProxiesRetryTraits>; - -using RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_target_https_proxies_v1_internal:: - RegionTargetHttpsProxiesRetryTraits>; +/// The retry policy for `RegionTargetHttpsProxiesConnection`. +class RegionTargetHttpsProxiesRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `RegionTargetHttpsProxiesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy + : public RegionTargetHttpsProxiesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy( + RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy( + RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + RegionTargetHttpsProxiesLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionTargetHttpsProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_target_https_proxies_v1_internal:: + RegionTargetHttpsProxiesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionTargetHttpsProxiesConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionTargetHttpsProxiesLimitedTimeRetryPolicy + : public RegionTargetHttpsProxiesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionTargetHttpsProxiesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionTargetHttpsProxiesLimitedTimeRetryPolicy( + RegionTargetHttpsProxiesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionTargetHttpsProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + RegionTargetHttpsProxiesLimitedTimeRetryPolicy( + RegionTargetHttpsProxiesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionTargetHttpsProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionTargetHttpsProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_target_https_proxies_v1_internal:: + RegionTargetHttpsProxiesRetryTraits> + impl_; +}; /** * The `RegionTargetHttpsProxiesConnection` object for diff --git a/google/cloud/compute/region_target_tcp_proxies/v1/region_target_tcp_proxies_connection.h b/google/cloud/compute/region_target_tcp_proxies/v1/region_target_tcp_proxies_connection.h index 41e2aa6012e89..87bddd27d9b36 100644 --- a/google/cloud/compute/region_target_tcp_proxies/v1/region_target_tcp_proxies_connection.h +++ b/google/cloud/compute/region_target_tcp_proxies/v1/region_target_tcp_proxies_connection.h @@ -39,20 +39,141 @@ namespace cloud { namespace compute_region_target_tcp_proxies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionTargetTcpProxiesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_target_tcp_proxies_v1_internal:: - RegionTargetTcpProxiesRetryTraits>; - -using RegionTargetTcpProxiesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_target_tcp_proxies_v1_internal:: - RegionTargetTcpProxiesRetryTraits>; - -using RegionTargetTcpProxiesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_target_tcp_proxies_v1_internal:: - RegionTargetTcpProxiesRetryTraits>; +/// The retry policy for `RegionTargetTcpProxiesConnection`. +class RegionTargetTcpProxiesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionTargetTcpProxiesConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionTargetTcpProxiesLimitedErrorCountRetryPolicy + : public RegionTargetTcpProxiesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionTargetTcpProxiesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RegionTargetTcpProxiesLimitedErrorCountRetryPolicy( + RegionTargetTcpProxiesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionTargetTcpProxiesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegionTargetTcpProxiesLimitedErrorCountRetryPolicy( + RegionTargetTcpProxiesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionTargetTcpProxiesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionTargetTcpProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_target_tcp_proxies_v1_internal:: + RegionTargetTcpProxiesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionTargetTcpProxiesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionTargetTcpProxiesLimitedTimeRetryPolicy + : public RegionTargetTcpProxiesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionTargetTcpProxiesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionTargetTcpProxiesLimitedTimeRetryPolicy( + RegionTargetTcpProxiesLimitedTimeRetryPolicy&& rhs) noexcept + : RegionTargetTcpProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionTargetTcpProxiesLimitedTimeRetryPolicy( + RegionTargetTcpProxiesLimitedTimeRetryPolicy const& rhs) noexcept + : RegionTargetTcpProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionTargetTcpProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_target_tcp_proxies_v1_internal:: + RegionTargetTcpProxiesRetryTraits> + impl_; +}; /** * The `RegionTargetTcpProxiesConnection` object for diff --git a/google/cloud/compute/region_url_maps/v1/region_url_maps_connection.h b/google/cloud/compute/region_url_maps/v1/region_url_maps_connection.h index d958b308fc179..55deb0de241dd 100644 --- a/google/cloud/compute/region_url_maps/v1/region_url_maps_connection.h +++ b/google/cloud/compute/region_url_maps/v1/region_url_maps_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace compute_region_url_maps_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionUrlMapsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_region_url_maps_v1_internal::RegionUrlMapsRetryTraits>; +/// The retry policy for `RegionUrlMapsConnection`. +class RegionUrlMapsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using RegionUrlMapsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_region_url_maps_v1_internal::RegionUrlMapsRetryTraits>; +/** + * A retry policy for `RegionUrlMapsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionUrlMapsLimitedErrorCountRetryPolicy + : public RegionUrlMapsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionUrlMapsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionUrlMapsLimitedErrorCountRetryPolicy( + RegionUrlMapsLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionUrlMapsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionUrlMapsLimitedErrorCountRetryPolicy( + RegionUrlMapsLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionUrlMapsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionUrlMapsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_region_url_maps_v1_internal::RegionUrlMapsRetryTraits> + impl_; +}; -using RegionUrlMapsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_region_url_maps_v1_internal::RegionUrlMapsRetryTraits>; +/** + * A retry policy for `RegionUrlMapsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionUrlMapsLimitedTimeRetryPolicy : public RegionUrlMapsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionUrlMapsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionUrlMapsLimitedTimeRetryPolicy( + RegionUrlMapsLimitedTimeRetryPolicy&& rhs) noexcept + : RegionUrlMapsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionUrlMapsLimitedTimeRetryPolicy( + RegionUrlMapsLimitedTimeRetryPolicy const& rhs) noexcept + : RegionUrlMapsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionUrlMapsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_region_url_maps_v1_internal::RegionUrlMapsRetryTraits> + impl_; +}; /** * The `RegionUrlMapsConnection` object for `RegionUrlMapsClient`. diff --git a/google/cloud/compute/regions/v1/regions_connection.h b/google/cloud/compute/regions/v1/regions_connection.h index 17425e6d722d2..b12639a322ea4 100644 --- a/google/cloud/compute/regions/v1/regions_connection.h +++ b/google/cloud/compute/regions/v1/regions_connection.h @@ -36,16 +36,131 @@ namespace cloud { namespace compute_regions_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegionsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_regions_v1_internal::RegionsRetryTraits>; +/// The retry policy for `RegionsConnection`. +class RegionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionsLimitedErrorCountRetryPolicy : public RegionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegionsLimitedErrorCountRetryPolicy( + RegionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RegionsLimitedErrorCountRetryPolicy( + RegionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionsRetryPolicy; -using RegionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_regions_v1_internal::RegionsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_regions_v1_internal::RegionsRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RegionsLimitedTimeRetryPolicy : public RegionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegionsLimitedTimeRetryPolicy(RegionsLimitedTimeRetryPolicy&& rhs) noexcept + : RegionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegionsLimitedTimeRetryPolicy( + RegionsLimitedTimeRetryPolicy const& rhs) noexcept + : RegionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RegionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_regions_v1_internal::RegionsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_regions_v1_internal::RegionsRetryTraits> + impl_; +}; /** * The `RegionsConnection` object for `RegionsClient`. diff --git a/google/cloud/compute/reservations/v1/reservations_connection.h b/google/cloud/compute/reservations/v1/reservations_connection.h index 5b4de19d84555..8e3e29cb07573 100644 --- a/google/cloud/compute/reservations/v1/reservations_connection.h +++ b/google/cloud/compute/reservations/v1/reservations_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace compute_reservations_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ReservationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_reservations_v1_internal::ReservationsRetryTraits>; +/// The retry policy for `ReservationsConnection`. +class ReservationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ReservationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_reservations_v1_internal::ReservationsRetryTraits>; +/** + * A retry policy for `ReservationsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ReservationsLimitedErrorCountRetryPolicy + : public ReservationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ReservationsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ReservationsLimitedErrorCountRetryPolicy( + ReservationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ReservationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ReservationsLimitedErrorCountRetryPolicy( + ReservationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ReservationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ReservationsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_reservations_v1_internal::ReservationsRetryTraits> + impl_; +}; -using ReservationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_reservations_v1_internal::ReservationsRetryTraits>; +/** + * A retry policy for `ReservationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ReservationsLimitedTimeRetryPolicy : public ReservationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ReservationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ReservationsLimitedTimeRetryPolicy( + ReservationsLimitedTimeRetryPolicy&& rhs) noexcept + : ReservationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ReservationsLimitedTimeRetryPolicy( + ReservationsLimitedTimeRetryPolicy const& rhs) noexcept + : ReservationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ReservationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_reservations_v1_internal::ReservationsRetryTraits> + impl_; +}; /** * The `ReservationsConnection` object for `ReservationsClient`. diff --git a/google/cloud/compute/resource_policies/v1/resource_policies_connection.h b/google/cloud/compute/resource_policies/v1/resource_policies_connection.h index daa8f543f2154..c23264aebd06c 100644 --- a/google/cloud/compute/resource_policies/v1/resource_policies_connection.h +++ b/google/cloud/compute/resource_policies/v1/resource_policies_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_resource_policies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ResourcePoliciesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_resource_policies_v1_internal::ResourcePoliciesRetryTraits>; +/// The retry policy for `ResourcePoliciesConnection`. +class ResourcePoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ResourcePoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_resource_policies_v1_internal::ResourcePoliciesRetryTraits>; +/** + * A retry policy for `ResourcePoliciesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ResourcePoliciesLimitedErrorCountRetryPolicy + : public ResourcePoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ResourcePoliciesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ResourcePoliciesLimitedErrorCountRetryPolicy( + ResourcePoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : ResourcePoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ResourcePoliciesLimitedErrorCountRetryPolicy( + ResourcePoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : ResourcePoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ResourcePoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_resource_policies_v1_internal::ResourcePoliciesRetryTraits> + impl_; +}; -using ResourcePoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_resource_policies_v1_internal::ResourcePoliciesRetryTraits>; +/** + * A retry policy for `ResourcePoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ResourcePoliciesLimitedTimeRetryPolicy + : public ResourcePoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ResourcePoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ResourcePoliciesLimitedTimeRetryPolicy( + ResourcePoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : ResourcePoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ResourcePoliciesLimitedTimeRetryPolicy( + ResourcePoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : ResourcePoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ResourcePoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_resource_policies_v1_internal::ResourcePoliciesRetryTraits> + impl_; +}; /** * The `ResourcePoliciesConnection` object for `ResourcePoliciesClient`. diff --git a/google/cloud/compute/routers/v1/routers_connection.h b/google/cloud/compute/routers/v1/routers_connection.h index d2b5944ab5871..ded1074ae6017 100644 --- a/google/cloud/compute/routers/v1/routers_connection.h +++ b/google/cloud/compute/routers/v1/routers_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace compute_routers_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RoutersRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_routers_v1_internal::RoutersRetryTraits>; +/// The retry policy for `RoutersConnection`. +class RoutersRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using RoutersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_routers_v1_internal::RoutersRetryTraits>; +/** + * A retry policy for `RoutersConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RoutersLimitedErrorCountRetryPolicy : public RoutersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RoutersLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RoutersLimitedErrorCountRetryPolicy( + RoutersLimitedErrorCountRetryPolicy&& rhs) noexcept + : RoutersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RoutersLimitedErrorCountRetryPolicy( + RoutersLimitedErrorCountRetryPolicy const& rhs) noexcept + : RoutersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RoutersRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_routers_v1_internal::RoutersRetryTraits> + impl_; +}; -using RoutersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_routers_v1_internal::RoutersRetryTraits>; +/** + * A retry policy for `RoutersConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RoutersLimitedTimeRetryPolicy : public RoutersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RoutersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RoutersLimitedTimeRetryPolicy(RoutersLimitedTimeRetryPolicy&& rhs) noexcept + : RoutersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RoutersLimitedTimeRetryPolicy( + RoutersLimitedTimeRetryPolicy const& rhs) noexcept + : RoutersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RoutersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_routers_v1_internal::RoutersRetryTraits> + impl_; +}; /** * The `RoutersConnection` object for `RoutersClient`. diff --git a/google/cloud/compute/routes/v1/routes_connection.h b/google/cloud/compute/routes/v1/routes_connection.h index 1ec71c7738489..a6927cfbfe304 100644 --- a/google/cloud/compute/routes/v1/routes_connection.h +++ b/google/cloud/compute/routes/v1/routes_connection.h @@ -38,16 +38,130 @@ namespace cloud { namespace compute_routes_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RoutesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_routes_v1_internal::RoutesRetryTraits>; +/// The retry policy for `RoutesConnection`. +class RoutesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RoutesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RoutesLimitedErrorCountRetryPolicy : public RoutesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RoutesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RoutesLimitedErrorCountRetryPolicy( + RoutesLimitedErrorCountRetryPolicy&& rhs) noexcept + : RoutesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RoutesLimitedErrorCountRetryPolicy( + RoutesLimitedErrorCountRetryPolicy const& rhs) noexcept + : RoutesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RoutesRetryPolicy; -using RoutesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_routes_v1_internal::RoutesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_routes_v1_internal::RoutesRetryTraits> + impl_; +}; + +/** + * A retry policy for `RoutesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RoutesLimitedTimeRetryPolicy : public RoutesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RoutesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RoutesLimitedTimeRetryPolicy(RoutesLimitedTimeRetryPolicy&& rhs) noexcept + : RoutesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RoutesLimitedTimeRetryPolicy(RoutesLimitedTimeRetryPolicy const& rhs) noexcept + : RoutesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RoutesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_routes_v1_internal::RoutesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RoutesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_routes_v1_internal::RoutesRetryTraits> + impl_; +}; /** * The `RoutesConnection` object for `RoutesClient`. diff --git a/google/cloud/compute/security_policies/v1/security_policies_connection.h b/google/cloud/compute/security_policies/v1/security_policies_connection.h index 4c675d70cb632..2598b4abee4fe 100644 --- a/google/cloud/compute/security_policies/v1/security_policies_connection.h +++ b/google/cloud/compute/security_policies/v1/security_policies_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_security_policies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SecurityPoliciesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_security_policies_v1_internal::SecurityPoliciesRetryTraits>; +/// The retry policy for `SecurityPoliciesConnection`. +class SecurityPoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SecurityPoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_security_policies_v1_internal::SecurityPoliciesRetryTraits>; +/** + * A retry policy for `SecurityPoliciesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SecurityPoliciesLimitedErrorCountRetryPolicy + : public SecurityPoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SecurityPoliciesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SecurityPoliciesLimitedErrorCountRetryPolicy( + SecurityPoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : SecurityPoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SecurityPoliciesLimitedErrorCountRetryPolicy( + SecurityPoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : SecurityPoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SecurityPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_security_policies_v1_internal::SecurityPoliciesRetryTraits> + impl_; +}; -using SecurityPoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_security_policies_v1_internal::SecurityPoliciesRetryTraits>; +/** + * A retry policy for `SecurityPoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SecurityPoliciesLimitedTimeRetryPolicy + : public SecurityPoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SecurityPoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SecurityPoliciesLimitedTimeRetryPolicy( + SecurityPoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : SecurityPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SecurityPoliciesLimitedTimeRetryPolicy( + SecurityPoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : SecurityPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SecurityPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_security_policies_v1_internal::SecurityPoliciesRetryTraits> + impl_; +}; /** * The `SecurityPoliciesConnection` object for `SecurityPoliciesClient`. diff --git a/google/cloud/compute/service_attachments/v1/service_attachments_connection.h b/google/cloud/compute/service_attachments/v1/service_attachments_connection.h index 091483e29b218..ebac6f54cf4e4 100644 --- a/google/cloud/compute/service_attachments/v1/service_attachments_connection.h +++ b/google/cloud/compute/service_attachments/v1/service_attachments_connection.h @@ -38,17 +38,137 @@ namespace cloud { namespace compute_service_attachments_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ServiceAttachmentsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_service_attachments_v1_internal::ServiceAttachmentsRetryTraits>; +/// The retry policy for `ServiceAttachmentsConnection`. +class ServiceAttachmentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ServiceAttachmentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_service_attachments_v1_internal::ServiceAttachmentsRetryTraits>; +/** + * A retry policy for `ServiceAttachmentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceAttachmentsLimitedErrorCountRetryPolicy + : public ServiceAttachmentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ServiceAttachmentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ServiceAttachmentsLimitedErrorCountRetryPolicy( + ServiceAttachmentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ServiceAttachmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + ServiceAttachmentsLimitedErrorCountRetryPolicy( + ServiceAttachmentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ServiceAttachmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceAttachmentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_service_attachments_v1_internal::ServiceAttachmentsRetryTraits> + impl_; +}; -using ServiceAttachmentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_service_attachments_v1_internal::ServiceAttachmentsRetryTraits>; +/** + * A retry policy for `ServiceAttachmentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceAttachmentsLimitedTimeRetryPolicy + : public ServiceAttachmentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ServiceAttachmentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ServiceAttachmentsLimitedTimeRetryPolicy( + ServiceAttachmentsLimitedTimeRetryPolicy&& rhs) noexcept + : ServiceAttachmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ServiceAttachmentsLimitedTimeRetryPolicy( + ServiceAttachmentsLimitedTimeRetryPolicy const& rhs) noexcept + : ServiceAttachmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceAttachmentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_service_attachments_v1_internal::ServiceAttachmentsRetryTraits> + impl_; +}; /** * The `ServiceAttachmentsConnection` object for `ServiceAttachmentsClient`. diff --git a/google/cloud/compute/snapshots/v1/snapshots_connection.h b/google/cloud/compute/snapshots/v1/snapshots_connection.h index ac7e1d92a214a..86af37da3dc85 100644 --- a/google/cloud/compute/snapshots/v1/snapshots_connection.h +++ b/google/cloud/compute/snapshots/v1/snapshots_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_snapshots_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SnapshotsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_snapshots_v1_internal::SnapshotsRetryTraits>; +/// The retry policy for `SnapshotsConnection`. +class SnapshotsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SnapshotsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_snapshots_v1_internal::SnapshotsRetryTraits>; +/** + * A retry policy for `SnapshotsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SnapshotsLimitedErrorCountRetryPolicy : public SnapshotsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SnapshotsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SnapshotsLimitedErrorCountRetryPolicy( + SnapshotsLimitedErrorCountRetryPolicy&& rhs) noexcept + : SnapshotsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SnapshotsLimitedErrorCountRetryPolicy( + SnapshotsLimitedErrorCountRetryPolicy const& rhs) noexcept + : SnapshotsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SnapshotsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_snapshots_v1_internal::SnapshotsRetryTraits> + impl_; +}; -using SnapshotsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_snapshots_v1_internal::SnapshotsRetryTraits>; +/** + * A retry policy for `SnapshotsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SnapshotsLimitedTimeRetryPolicy : public SnapshotsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SnapshotsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SnapshotsLimitedTimeRetryPolicy( + SnapshotsLimitedTimeRetryPolicy&& rhs) noexcept + : SnapshotsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SnapshotsLimitedTimeRetryPolicy( + SnapshotsLimitedTimeRetryPolicy const& rhs) noexcept + : SnapshotsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SnapshotsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_snapshots_v1_internal::SnapshotsRetryTraits> + impl_; +}; /** * The `SnapshotsConnection` object for `SnapshotsClient`. diff --git a/google/cloud/compute/ssl_certificates/v1/ssl_certificates_connection.h b/google/cloud/compute/ssl_certificates/v1/ssl_certificates_connection.h index 8f1f03c91759b..c7e8e33c3b083 100644 --- a/google/cloud/compute/ssl_certificates/v1/ssl_certificates_connection.h +++ b/google/cloud/compute/ssl_certificates/v1/ssl_certificates_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_ssl_certificates_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SslCertificatesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_ssl_certificates_v1_internal::SslCertificatesRetryTraits>; +/// The retry policy for `SslCertificatesConnection`. +class SslCertificatesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SslCertificatesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_ssl_certificates_v1_internal::SslCertificatesRetryTraits>; +/** + * A retry policy for `SslCertificatesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SslCertificatesLimitedErrorCountRetryPolicy + : public SslCertificatesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SslCertificatesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SslCertificatesLimitedErrorCountRetryPolicy( + SslCertificatesLimitedErrorCountRetryPolicy&& rhs) noexcept + : SslCertificatesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SslCertificatesLimitedErrorCountRetryPolicy( + SslCertificatesLimitedErrorCountRetryPolicy const& rhs) noexcept + : SslCertificatesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SslCertificatesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_ssl_certificates_v1_internal::SslCertificatesRetryTraits> + impl_; +}; -using SslCertificatesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_ssl_certificates_v1_internal::SslCertificatesRetryTraits>; +/** + * A retry policy for `SslCertificatesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SslCertificatesLimitedTimeRetryPolicy + : public SslCertificatesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SslCertificatesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SslCertificatesLimitedTimeRetryPolicy( + SslCertificatesLimitedTimeRetryPolicy&& rhs) noexcept + : SslCertificatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SslCertificatesLimitedTimeRetryPolicy( + SslCertificatesLimitedTimeRetryPolicy const& rhs) noexcept + : SslCertificatesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SslCertificatesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_ssl_certificates_v1_internal::SslCertificatesRetryTraits> + impl_; +}; /** * The `SslCertificatesConnection` object for `SslCertificatesClient`. diff --git a/google/cloud/compute/ssl_policies/v1/ssl_policies_connection.h b/google/cloud/compute/ssl_policies/v1/ssl_policies_connection.h index 2872b1445670f..a2f28d5b1e22b 100644 --- a/google/cloud/compute/ssl_policies/v1/ssl_policies_connection.h +++ b/google/cloud/compute/ssl_policies/v1/ssl_policies_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_ssl_policies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SslPoliciesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_ssl_policies_v1_internal::SslPoliciesRetryTraits>; +/// The retry policy for `SslPoliciesConnection`. +class SslPoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SslPoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_ssl_policies_v1_internal::SslPoliciesRetryTraits>; +/** + * A retry policy for `SslPoliciesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SslPoliciesLimitedErrorCountRetryPolicy : public SslPoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SslPoliciesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SslPoliciesLimitedErrorCountRetryPolicy( + SslPoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : SslPoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SslPoliciesLimitedErrorCountRetryPolicy( + SslPoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : SslPoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SslPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_ssl_policies_v1_internal::SslPoliciesRetryTraits> + impl_; +}; -using SslPoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_ssl_policies_v1_internal::SslPoliciesRetryTraits>; +/** + * A retry policy for `SslPoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SslPoliciesLimitedTimeRetryPolicy : public SslPoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SslPoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SslPoliciesLimitedTimeRetryPolicy( + SslPoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : SslPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SslPoliciesLimitedTimeRetryPolicy( + SslPoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : SslPoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SslPoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_ssl_policies_v1_internal::SslPoliciesRetryTraits> + impl_; +}; /** * The `SslPoliciesConnection` object for `SslPoliciesClient`. diff --git a/google/cloud/compute/subnetworks/v1/subnetworks_connection.h b/google/cloud/compute/subnetworks/v1/subnetworks_connection.h index de140d8343276..6d6a440193bc3 100644 --- a/google/cloud/compute/subnetworks/v1/subnetworks_connection.h +++ b/google/cloud/compute/subnetworks/v1/subnetworks_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_subnetworks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SubnetworksRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_subnetworks_v1_internal::SubnetworksRetryTraits>; +/// The retry policy for `SubnetworksConnection`. +class SubnetworksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SubnetworksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_subnetworks_v1_internal::SubnetworksRetryTraits>; +/** + * A retry policy for `SubnetworksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SubnetworksLimitedErrorCountRetryPolicy : public SubnetworksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SubnetworksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SubnetworksLimitedErrorCountRetryPolicy( + SubnetworksLimitedErrorCountRetryPolicy&& rhs) noexcept + : SubnetworksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SubnetworksLimitedErrorCountRetryPolicy( + SubnetworksLimitedErrorCountRetryPolicy const& rhs) noexcept + : SubnetworksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SubnetworksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_subnetworks_v1_internal::SubnetworksRetryTraits> + impl_; +}; -using SubnetworksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_subnetworks_v1_internal::SubnetworksRetryTraits>; +/** + * A retry policy for `SubnetworksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SubnetworksLimitedTimeRetryPolicy : public SubnetworksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SubnetworksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SubnetworksLimitedTimeRetryPolicy( + SubnetworksLimitedTimeRetryPolicy&& rhs) noexcept + : SubnetworksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SubnetworksLimitedTimeRetryPolicy( + SubnetworksLimitedTimeRetryPolicy const& rhs) noexcept + : SubnetworksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SubnetworksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_subnetworks_v1_internal::SubnetworksRetryTraits> + impl_; +}; /** * The `SubnetworksConnection` object for `SubnetworksClient`. diff --git a/google/cloud/compute/target_grpc_proxies/v1/target_grpc_proxies_connection.h b/google/cloud/compute/target_grpc_proxies/v1/target_grpc_proxies_connection.h index 6ae074097bad7..b12c6ef96466c 100644 --- a/google/cloud/compute/target_grpc_proxies/v1/target_grpc_proxies_connection.h +++ b/google/cloud/compute/target_grpc_proxies/v1/target_grpc_proxies_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_target_grpc_proxies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TargetGrpcProxiesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_target_grpc_proxies_v1_internal::TargetGrpcProxiesRetryTraits>; +/// The retry policy for `TargetGrpcProxiesConnection`. +class TargetGrpcProxiesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TargetGrpcProxiesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_target_grpc_proxies_v1_internal::TargetGrpcProxiesRetryTraits>; +/** + * A retry policy for `TargetGrpcProxiesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetGrpcProxiesLimitedErrorCountRetryPolicy + : public TargetGrpcProxiesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TargetGrpcProxiesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TargetGrpcProxiesLimitedErrorCountRetryPolicy( + TargetGrpcProxiesLimitedErrorCountRetryPolicy&& rhs) noexcept + : TargetGrpcProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TargetGrpcProxiesLimitedErrorCountRetryPolicy( + TargetGrpcProxiesLimitedErrorCountRetryPolicy const& rhs) noexcept + : TargetGrpcProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetGrpcProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_target_grpc_proxies_v1_internal::TargetGrpcProxiesRetryTraits> + impl_; +}; -using TargetGrpcProxiesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_target_grpc_proxies_v1_internal::TargetGrpcProxiesRetryTraits>; +/** + * A retry policy for `TargetGrpcProxiesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetGrpcProxiesLimitedTimeRetryPolicy + : public TargetGrpcProxiesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TargetGrpcProxiesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TargetGrpcProxiesLimitedTimeRetryPolicy( + TargetGrpcProxiesLimitedTimeRetryPolicy&& rhs) noexcept + : TargetGrpcProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TargetGrpcProxiesLimitedTimeRetryPolicy( + TargetGrpcProxiesLimitedTimeRetryPolicy const& rhs) noexcept + : TargetGrpcProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetGrpcProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_target_grpc_proxies_v1_internal::TargetGrpcProxiesRetryTraits> + impl_; +}; /** * The `TargetGrpcProxiesConnection` object for `TargetGrpcProxiesClient`. diff --git a/google/cloud/compute/target_http_proxies/v1/target_http_proxies_connection.h b/google/cloud/compute/target_http_proxies/v1/target_http_proxies_connection.h index d70213de26f1b..1647f75d8f504 100644 --- a/google/cloud/compute/target_http_proxies/v1/target_http_proxies_connection.h +++ b/google/cloud/compute/target_http_proxies/v1/target_http_proxies_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_target_http_proxies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TargetHttpProxiesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_target_http_proxies_v1_internal::TargetHttpProxiesRetryTraits>; +/// The retry policy for `TargetHttpProxiesConnection`. +class TargetHttpProxiesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TargetHttpProxiesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_target_http_proxies_v1_internal::TargetHttpProxiesRetryTraits>; +/** + * A retry policy for `TargetHttpProxiesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetHttpProxiesLimitedErrorCountRetryPolicy + : public TargetHttpProxiesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TargetHttpProxiesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TargetHttpProxiesLimitedErrorCountRetryPolicy( + TargetHttpProxiesLimitedErrorCountRetryPolicy&& rhs) noexcept + : TargetHttpProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TargetHttpProxiesLimitedErrorCountRetryPolicy( + TargetHttpProxiesLimitedErrorCountRetryPolicy const& rhs) noexcept + : TargetHttpProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetHttpProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_target_http_proxies_v1_internal::TargetHttpProxiesRetryTraits> + impl_; +}; -using TargetHttpProxiesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_target_http_proxies_v1_internal::TargetHttpProxiesRetryTraits>; +/** + * A retry policy for `TargetHttpProxiesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetHttpProxiesLimitedTimeRetryPolicy + : public TargetHttpProxiesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TargetHttpProxiesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TargetHttpProxiesLimitedTimeRetryPolicy( + TargetHttpProxiesLimitedTimeRetryPolicy&& rhs) noexcept + : TargetHttpProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TargetHttpProxiesLimitedTimeRetryPolicy( + TargetHttpProxiesLimitedTimeRetryPolicy const& rhs) noexcept + : TargetHttpProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetHttpProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_target_http_proxies_v1_internal::TargetHttpProxiesRetryTraits> + impl_; +}; /** * The `TargetHttpProxiesConnection` object for `TargetHttpProxiesClient`. diff --git a/google/cloud/compute/target_https_proxies/v1/target_https_proxies_connection.h b/google/cloud/compute/target_https_proxies/v1/target_https_proxies_connection.h index 02bea70fce635..a14a736f59671 100644 --- a/google/cloud/compute/target_https_proxies/v1/target_https_proxies_connection.h +++ b/google/cloud/compute/target_https_proxies/v1/target_https_proxies_connection.h @@ -39,20 +39,137 @@ namespace cloud { namespace compute_target_https_proxies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TargetHttpsProxiesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_target_https_proxies_v1_internal:: - TargetHttpsProxiesRetryTraits>; - -using TargetHttpsProxiesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_target_https_proxies_v1_internal:: - TargetHttpsProxiesRetryTraits>; - -using TargetHttpsProxiesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_target_https_proxies_v1_internal:: - TargetHttpsProxiesRetryTraits>; +/// The retry policy for `TargetHttpsProxiesConnection`. +class TargetHttpsProxiesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TargetHttpsProxiesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetHttpsProxiesLimitedErrorCountRetryPolicy + : public TargetHttpsProxiesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TargetHttpsProxiesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TargetHttpsProxiesLimitedErrorCountRetryPolicy( + TargetHttpsProxiesLimitedErrorCountRetryPolicy&& rhs) noexcept + : TargetHttpsProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + TargetHttpsProxiesLimitedErrorCountRetryPolicy( + TargetHttpsProxiesLimitedErrorCountRetryPolicy const& rhs) noexcept + : TargetHttpsProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetHttpsProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_target_https_proxies_v1_internal::TargetHttpsProxiesRetryTraits> + impl_; +}; + +/** + * A retry policy for `TargetHttpsProxiesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetHttpsProxiesLimitedTimeRetryPolicy + : public TargetHttpsProxiesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TargetHttpsProxiesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TargetHttpsProxiesLimitedTimeRetryPolicy( + TargetHttpsProxiesLimitedTimeRetryPolicy&& rhs) noexcept + : TargetHttpsProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TargetHttpsProxiesLimitedTimeRetryPolicy( + TargetHttpsProxiesLimitedTimeRetryPolicy const& rhs) noexcept + : TargetHttpsProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetHttpsProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_target_https_proxies_v1_internal::TargetHttpsProxiesRetryTraits> + impl_; +}; /** * The `TargetHttpsProxiesConnection` object for `TargetHttpsProxiesClient`. diff --git a/google/cloud/compute/target_instances/v1/target_instances_connection.h b/google/cloud/compute/target_instances/v1/target_instances_connection.h index 5fe4634ce634c..138cde94bb430 100644 --- a/google/cloud/compute/target_instances/v1/target_instances_connection.h +++ b/google/cloud/compute/target_instances/v1/target_instances_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_target_instances_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TargetInstancesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_target_instances_v1_internal::TargetInstancesRetryTraits>; +/// The retry policy for `TargetInstancesConnection`. +class TargetInstancesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TargetInstancesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_target_instances_v1_internal::TargetInstancesRetryTraits>; +/** + * A retry policy for `TargetInstancesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetInstancesLimitedErrorCountRetryPolicy + : public TargetInstancesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TargetInstancesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TargetInstancesLimitedErrorCountRetryPolicy( + TargetInstancesLimitedErrorCountRetryPolicy&& rhs) noexcept + : TargetInstancesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TargetInstancesLimitedErrorCountRetryPolicy( + TargetInstancesLimitedErrorCountRetryPolicy const& rhs) noexcept + : TargetInstancesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetInstancesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_target_instances_v1_internal::TargetInstancesRetryTraits> + impl_; +}; -using TargetInstancesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_target_instances_v1_internal::TargetInstancesRetryTraits>; +/** + * A retry policy for `TargetInstancesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetInstancesLimitedTimeRetryPolicy + : public TargetInstancesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TargetInstancesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TargetInstancesLimitedTimeRetryPolicy( + TargetInstancesLimitedTimeRetryPolicy&& rhs) noexcept + : TargetInstancesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TargetInstancesLimitedTimeRetryPolicy( + TargetInstancesLimitedTimeRetryPolicy const& rhs) noexcept + : TargetInstancesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetInstancesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_target_instances_v1_internal::TargetInstancesRetryTraits> + impl_; +}; /** * The `TargetInstancesConnection` object for `TargetInstancesClient`. diff --git a/google/cloud/compute/target_pools/v1/target_pools_connection.h b/google/cloud/compute/target_pools/v1/target_pools_connection.h index 0ba7c986549e5..5b64691fb4051 100644 --- a/google/cloud/compute/target_pools/v1/target_pools_connection.h +++ b/google/cloud/compute/target_pools/v1/target_pools_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_target_pools_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TargetPoolsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_target_pools_v1_internal::TargetPoolsRetryTraits>; +/// The retry policy for `TargetPoolsConnection`. +class TargetPoolsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TargetPoolsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_target_pools_v1_internal::TargetPoolsRetryTraits>; +/** + * A retry policy for `TargetPoolsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetPoolsLimitedErrorCountRetryPolicy : public TargetPoolsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TargetPoolsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TargetPoolsLimitedErrorCountRetryPolicy( + TargetPoolsLimitedErrorCountRetryPolicy&& rhs) noexcept + : TargetPoolsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TargetPoolsLimitedErrorCountRetryPolicy( + TargetPoolsLimitedErrorCountRetryPolicy const& rhs) noexcept + : TargetPoolsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetPoolsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_target_pools_v1_internal::TargetPoolsRetryTraits> + impl_; +}; -using TargetPoolsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_target_pools_v1_internal::TargetPoolsRetryTraits>; +/** + * A retry policy for `TargetPoolsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetPoolsLimitedTimeRetryPolicy : public TargetPoolsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TargetPoolsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TargetPoolsLimitedTimeRetryPolicy( + TargetPoolsLimitedTimeRetryPolicy&& rhs) noexcept + : TargetPoolsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TargetPoolsLimitedTimeRetryPolicy( + TargetPoolsLimitedTimeRetryPolicy const& rhs) noexcept + : TargetPoolsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetPoolsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_target_pools_v1_internal::TargetPoolsRetryTraits> + impl_; +}; /** * The `TargetPoolsConnection` object for `TargetPoolsClient`. diff --git a/google/cloud/compute/target_ssl_proxies/v1/target_ssl_proxies_connection.h b/google/cloud/compute/target_ssl_proxies/v1/target_ssl_proxies_connection.h index 0944bd7fe1b7c..edeb1eeea9102 100644 --- a/google/cloud/compute/target_ssl_proxies/v1/target_ssl_proxies_connection.h +++ b/google/cloud/compute/target_ssl_proxies/v1/target_ssl_proxies_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_target_ssl_proxies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TargetSslProxiesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_target_ssl_proxies_v1_internal::TargetSslProxiesRetryTraits>; +/// The retry policy for `TargetSslProxiesConnection`. +class TargetSslProxiesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TargetSslProxiesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_target_ssl_proxies_v1_internal::TargetSslProxiesRetryTraits>; +/** + * A retry policy for `TargetSslProxiesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetSslProxiesLimitedErrorCountRetryPolicy + : public TargetSslProxiesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TargetSslProxiesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TargetSslProxiesLimitedErrorCountRetryPolicy( + TargetSslProxiesLimitedErrorCountRetryPolicy&& rhs) noexcept + : TargetSslProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TargetSslProxiesLimitedErrorCountRetryPolicy( + TargetSslProxiesLimitedErrorCountRetryPolicy const& rhs) noexcept + : TargetSslProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetSslProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_target_ssl_proxies_v1_internal::TargetSslProxiesRetryTraits> + impl_; +}; -using TargetSslProxiesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_target_ssl_proxies_v1_internal::TargetSslProxiesRetryTraits>; +/** + * A retry policy for `TargetSslProxiesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetSslProxiesLimitedTimeRetryPolicy + : public TargetSslProxiesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TargetSslProxiesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TargetSslProxiesLimitedTimeRetryPolicy( + TargetSslProxiesLimitedTimeRetryPolicy&& rhs) noexcept + : TargetSslProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TargetSslProxiesLimitedTimeRetryPolicy( + TargetSslProxiesLimitedTimeRetryPolicy const& rhs) noexcept + : TargetSslProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetSslProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_target_ssl_proxies_v1_internal::TargetSslProxiesRetryTraits> + impl_; +}; /** * The `TargetSslProxiesConnection` object for `TargetSslProxiesClient`. diff --git a/google/cloud/compute/target_tcp_proxies/v1/target_tcp_proxies_connection.h b/google/cloud/compute/target_tcp_proxies/v1/target_tcp_proxies_connection.h index 9629e5dcd8901..11b46cd0f10c7 100644 --- a/google/cloud/compute/target_tcp_proxies/v1/target_tcp_proxies_connection.h +++ b/google/cloud/compute/target_tcp_proxies/v1/target_tcp_proxies_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_target_tcp_proxies_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TargetTcpProxiesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_target_tcp_proxies_v1_internal::TargetTcpProxiesRetryTraits>; +/// The retry policy for `TargetTcpProxiesConnection`. +class TargetTcpProxiesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TargetTcpProxiesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_target_tcp_proxies_v1_internal::TargetTcpProxiesRetryTraits>; +/** + * A retry policy for `TargetTcpProxiesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetTcpProxiesLimitedErrorCountRetryPolicy + : public TargetTcpProxiesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TargetTcpProxiesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TargetTcpProxiesLimitedErrorCountRetryPolicy( + TargetTcpProxiesLimitedErrorCountRetryPolicy&& rhs) noexcept + : TargetTcpProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TargetTcpProxiesLimitedErrorCountRetryPolicy( + TargetTcpProxiesLimitedErrorCountRetryPolicy const& rhs) noexcept + : TargetTcpProxiesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetTcpProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_target_tcp_proxies_v1_internal::TargetTcpProxiesRetryTraits> + impl_; +}; -using TargetTcpProxiesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_target_tcp_proxies_v1_internal::TargetTcpProxiesRetryTraits>; +/** + * A retry policy for `TargetTcpProxiesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetTcpProxiesLimitedTimeRetryPolicy + : public TargetTcpProxiesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TargetTcpProxiesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TargetTcpProxiesLimitedTimeRetryPolicy( + TargetTcpProxiesLimitedTimeRetryPolicy&& rhs) noexcept + : TargetTcpProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TargetTcpProxiesLimitedTimeRetryPolicy( + TargetTcpProxiesLimitedTimeRetryPolicy const& rhs) noexcept + : TargetTcpProxiesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetTcpProxiesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_target_tcp_proxies_v1_internal::TargetTcpProxiesRetryTraits> + impl_; +}; /** * The `TargetTcpProxiesConnection` object for `TargetTcpProxiesClient`. diff --git a/google/cloud/compute/target_vpn_gateways/v1/target_vpn_gateways_connection.h b/google/cloud/compute/target_vpn_gateways/v1/target_vpn_gateways_connection.h index 632b37dbffc5b..089922898bea4 100644 --- a/google/cloud/compute/target_vpn_gateways/v1/target_vpn_gateways_connection.h +++ b/google/cloud/compute/target_vpn_gateways/v1/target_vpn_gateways_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace compute_target_vpn_gateways_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TargetVpnGatewaysRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_target_vpn_gateways_v1_internal::TargetVpnGatewaysRetryTraits>; +/// The retry policy for `TargetVpnGatewaysConnection`. +class TargetVpnGatewaysRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TargetVpnGatewaysLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_target_vpn_gateways_v1_internal::TargetVpnGatewaysRetryTraits>; +/** + * A retry policy for `TargetVpnGatewaysConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetVpnGatewaysLimitedErrorCountRetryPolicy + : public TargetVpnGatewaysRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TargetVpnGatewaysLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TargetVpnGatewaysLimitedErrorCountRetryPolicy( + TargetVpnGatewaysLimitedErrorCountRetryPolicy&& rhs) noexcept + : TargetVpnGatewaysLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TargetVpnGatewaysLimitedErrorCountRetryPolicy( + TargetVpnGatewaysLimitedErrorCountRetryPolicy const& rhs) noexcept + : TargetVpnGatewaysLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetVpnGatewaysRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_target_vpn_gateways_v1_internal::TargetVpnGatewaysRetryTraits> + impl_; +}; -using TargetVpnGatewaysLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_target_vpn_gateways_v1_internal::TargetVpnGatewaysRetryTraits>; +/** + * A retry policy for `TargetVpnGatewaysConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TargetVpnGatewaysLimitedTimeRetryPolicy + : public TargetVpnGatewaysRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TargetVpnGatewaysLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TargetVpnGatewaysLimitedTimeRetryPolicy( + TargetVpnGatewaysLimitedTimeRetryPolicy&& rhs) noexcept + : TargetVpnGatewaysLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TargetVpnGatewaysLimitedTimeRetryPolicy( + TargetVpnGatewaysLimitedTimeRetryPolicy const& rhs) noexcept + : TargetVpnGatewaysLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TargetVpnGatewaysRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_target_vpn_gateways_v1_internal::TargetVpnGatewaysRetryTraits> + impl_; +}; /** * The `TargetVpnGatewaysConnection` object for `TargetVpnGatewaysClient`. diff --git a/google/cloud/compute/url_maps/v1/url_maps_connection.h b/google/cloud/compute/url_maps/v1/url_maps_connection.h index 374612510c9c0..423ac6cbc5177 100644 --- a/google/cloud/compute/url_maps/v1/url_maps_connection.h +++ b/google/cloud/compute/url_maps/v1/url_maps_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace compute_url_maps_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using UrlMapsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_url_maps_v1_internal::UrlMapsRetryTraits>; +/// The retry policy for `UrlMapsConnection`. +class UrlMapsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using UrlMapsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_url_maps_v1_internal::UrlMapsRetryTraits>; +/** + * A retry policy for `UrlMapsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class UrlMapsLimitedErrorCountRetryPolicy : public UrlMapsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit UrlMapsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + UrlMapsLimitedErrorCountRetryPolicy( + UrlMapsLimitedErrorCountRetryPolicy&& rhs) noexcept + : UrlMapsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + UrlMapsLimitedErrorCountRetryPolicy( + UrlMapsLimitedErrorCountRetryPolicy const& rhs) noexcept + : UrlMapsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = UrlMapsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_url_maps_v1_internal::UrlMapsRetryTraits> + impl_; +}; -using UrlMapsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_url_maps_v1_internal::UrlMapsRetryTraits>; +/** + * A retry policy for `UrlMapsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class UrlMapsLimitedTimeRetryPolicy : public UrlMapsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit UrlMapsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + UrlMapsLimitedTimeRetryPolicy(UrlMapsLimitedTimeRetryPolicy&& rhs) noexcept + : UrlMapsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + UrlMapsLimitedTimeRetryPolicy( + UrlMapsLimitedTimeRetryPolicy const& rhs) noexcept + : UrlMapsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = UrlMapsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_url_maps_v1_internal::UrlMapsRetryTraits> + impl_; +}; /** * The `UrlMapsConnection` object for `UrlMapsClient`. diff --git a/google/cloud/compute/vpn_gateways/v1/vpn_gateways_connection.h b/google/cloud/compute/vpn_gateways/v1/vpn_gateways_connection.h index 28f36ae5cdff0..7104526bc713c 100644 --- a/google/cloud/compute/vpn_gateways/v1/vpn_gateways_connection.h +++ b/google/cloud/compute/vpn_gateways/v1/vpn_gateways_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_vpn_gateways_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VpnGatewaysRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_vpn_gateways_v1_internal::VpnGatewaysRetryTraits>; +/// The retry policy for `VpnGatewaysConnection`. +class VpnGatewaysRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VpnGatewaysLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_vpn_gateways_v1_internal::VpnGatewaysRetryTraits>; +/** + * A retry policy for `VpnGatewaysConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VpnGatewaysLimitedErrorCountRetryPolicy : public VpnGatewaysRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VpnGatewaysLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VpnGatewaysLimitedErrorCountRetryPolicy( + VpnGatewaysLimitedErrorCountRetryPolicy&& rhs) noexcept + : VpnGatewaysLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VpnGatewaysLimitedErrorCountRetryPolicy( + VpnGatewaysLimitedErrorCountRetryPolicy const& rhs) noexcept + : VpnGatewaysLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VpnGatewaysRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_vpn_gateways_v1_internal::VpnGatewaysRetryTraits> + impl_; +}; -using VpnGatewaysLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_vpn_gateways_v1_internal::VpnGatewaysRetryTraits>; +/** + * A retry policy for `VpnGatewaysConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VpnGatewaysLimitedTimeRetryPolicy : public VpnGatewaysRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VpnGatewaysLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VpnGatewaysLimitedTimeRetryPolicy( + VpnGatewaysLimitedTimeRetryPolicy&& rhs) noexcept + : VpnGatewaysLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VpnGatewaysLimitedTimeRetryPolicy( + VpnGatewaysLimitedTimeRetryPolicy const& rhs) noexcept + : VpnGatewaysLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VpnGatewaysRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_vpn_gateways_v1_internal::VpnGatewaysRetryTraits> + impl_; +}; /** * The `VpnGatewaysConnection` object for `VpnGatewaysClient`. diff --git a/google/cloud/compute/vpn_tunnels/v1/vpn_tunnels_connection.h b/google/cloud/compute/vpn_tunnels/v1/vpn_tunnels_connection.h index 1d32053a7390d..d8567f5f90996 100644 --- a/google/cloud/compute/vpn_tunnels/v1/vpn_tunnels_connection.h +++ b/google/cloud/compute/vpn_tunnels/v1/vpn_tunnels_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace compute_vpn_tunnels_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VpnTunnelsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_vpn_tunnels_v1_internal::VpnTunnelsRetryTraits>; +/// The retry policy for `VpnTunnelsConnection`. +class VpnTunnelsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VpnTunnelsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_vpn_tunnels_v1_internal::VpnTunnelsRetryTraits>; +/** + * A retry policy for `VpnTunnelsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VpnTunnelsLimitedErrorCountRetryPolicy : public VpnTunnelsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VpnTunnelsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VpnTunnelsLimitedErrorCountRetryPolicy( + VpnTunnelsLimitedErrorCountRetryPolicy&& rhs) noexcept + : VpnTunnelsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VpnTunnelsLimitedErrorCountRetryPolicy( + VpnTunnelsLimitedErrorCountRetryPolicy const& rhs) noexcept + : VpnTunnelsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VpnTunnelsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_vpn_tunnels_v1_internal::VpnTunnelsRetryTraits> + impl_; +}; -using VpnTunnelsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_vpn_tunnels_v1_internal::VpnTunnelsRetryTraits>; +/** + * A retry policy for `VpnTunnelsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VpnTunnelsLimitedTimeRetryPolicy : public VpnTunnelsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VpnTunnelsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VpnTunnelsLimitedTimeRetryPolicy( + VpnTunnelsLimitedTimeRetryPolicy&& rhs) noexcept + : VpnTunnelsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VpnTunnelsLimitedTimeRetryPolicy( + VpnTunnelsLimitedTimeRetryPolicy const& rhs) noexcept + : VpnTunnelsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VpnTunnelsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_vpn_tunnels_v1_internal::VpnTunnelsRetryTraits> + impl_; +}; /** * The `VpnTunnelsConnection` object for `VpnTunnelsClient`. diff --git a/google/cloud/compute/zone_operations/v1/zone_operations_connection.h b/google/cloud/compute/zone_operations/v1/zone_operations_connection.h index 8a3ff7e42eecd..38d40125eceed 100644 --- a/google/cloud/compute/zone_operations/v1/zone_operations_connection.h +++ b/google/cloud/compute/zone_operations/v1/zone_operations_connection.h @@ -36,17 +36,134 @@ namespace cloud { namespace compute_zone_operations_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ZoneOperationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - compute_zone_operations_v1_internal::ZoneOperationsRetryTraits>; +/// The retry policy for `ZoneOperationsConnection`. +class ZoneOperationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ZoneOperationsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ZoneOperationsLimitedErrorCountRetryPolicy + : public ZoneOperationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ZoneOperationsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ZoneOperationsLimitedErrorCountRetryPolicy( + ZoneOperationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ZoneOperationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ZoneOperationsLimitedErrorCountRetryPolicy( + ZoneOperationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ZoneOperationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ZoneOperationsRetryPolicy; -using ZoneOperationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_zone_operations_v1_internal::ZoneOperationsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_zone_operations_v1_internal::ZoneOperationsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ZoneOperationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ZoneOperationsLimitedTimeRetryPolicy : public ZoneOperationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ZoneOperationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ZoneOperationsLimitedTimeRetryPolicy( + ZoneOperationsLimitedTimeRetryPolicy&& rhs) noexcept + : ZoneOperationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ZoneOperationsLimitedTimeRetryPolicy( + ZoneOperationsLimitedTimeRetryPolicy const& rhs) noexcept + : ZoneOperationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ZoneOperationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_zone_operations_v1_internal::ZoneOperationsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ZoneOperationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_zone_operations_v1_internal::ZoneOperationsRetryTraits> + impl_; +}; /** * The `ZoneOperationsConnection` object for `ZoneOperationsClient`. diff --git a/google/cloud/compute/zones/v1/zones_connection.h b/google/cloud/compute/zones/v1/zones_connection.h index ecb97bf5ac448..b0d5dfc92b35a 100644 --- a/google/cloud/compute/zones/v1/zones_connection.h +++ b/google/cloud/compute/zones/v1/zones_connection.h @@ -36,16 +36,130 @@ namespace cloud { namespace compute_zones_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ZonesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - compute_zones_v1_internal::ZonesRetryTraits>; +/// The retry policy for `ZonesConnection`. +class ZonesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ZonesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ZonesLimitedErrorCountRetryPolicy : public ZonesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ZonesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ZonesLimitedErrorCountRetryPolicy( + ZonesLimitedErrorCountRetryPolicy&& rhs) noexcept + : ZonesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ZonesLimitedErrorCountRetryPolicy( + ZonesLimitedErrorCountRetryPolicy const& rhs) noexcept + : ZonesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ZonesRetryPolicy; -using ZonesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - compute_zones_v1_internal::ZonesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + compute_zones_v1_internal::ZonesRetryTraits> + impl_; +}; + +/** + * A retry policy for `ZonesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ZonesLimitedTimeRetryPolicy : public ZonesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ZonesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ZonesLimitedTimeRetryPolicy(ZonesLimitedTimeRetryPolicy&& rhs) noexcept + : ZonesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ZonesLimitedTimeRetryPolicy(ZonesLimitedTimeRetryPolicy const& rhs) noexcept + : ZonesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ZonesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - compute_zones_v1_internal::ZonesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ZonesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + compute_zones_v1_internal::ZonesRetryTraits> + impl_; +}; /** * The `ZonesConnection` object for `ZonesClient`. diff --git a/google/cloud/confidentialcomputing/v1/confidential_computing_connection.h b/google/cloud/confidentialcomputing/v1/confidential_computing_connection.h index 1ed4230d95a7d..36f4a71d686ce 100644 --- a/google/cloud/confidentialcomputing/v1/confidential_computing_connection.h +++ b/google/cloud/confidentialcomputing/v1/confidential_computing_connection.h @@ -34,17 +34,139 @@ namespace cloud { namespace confidentialcomputing_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ConfidentialComputingRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - confidentialcomputing_v1_internal::ConfidentialComputingRetryTraits>; +/// The retry policy for `ConfidentialComputingConnection`. +class ConfidentialComputingRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ConfidentialComputingConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConfidentialComputingLimitedErrorCountRetryPolicy + : public ConfidentialComputingRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ConfidentialComputingLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ConfidentialComputingLimitedErrorCountRetryPolicy( + ConfidentialComputingLimitedErrorCountRetryPolicy&& rhs) noexcept + : ConfidentialComputingLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ConfidentialComputingLimitedErrorCountRetryPolicy( + ConfidentialComputingLimitedErrorCountRetryPolicy const& rhs) noexcept + : ConfidentialComputingLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConfidentialComputingRetryPolicy; -using ConfidentialComputingLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - confidentialcomputing_v1_internal::ConfidentialComputingRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + confidentialcomputing_v1_internal::ConfidentialComputingRetryTraits> + impl_; +}; + +/** + * A retry policy for `ConfidentialComputingConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConfidentialComputingLimitedTimeRetryPolicy + : public ConfidentialComputingRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ConfidentialComputingLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ConfidentialComputingLimitedTimeRetryPolicy( + ConfidentialComputingLimitedTimeRetryPolicy&& rhs) noexcept + : ConfidentialComputingLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ConfidentialComputingLimitedTimeRetryPolicy( + ConfidentialComputingLimitedTimeRetryPolicy const& rhs) noexcept + : ConfidentialComputingLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ConfidentialComputingLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - confidentialcomputing_v1_internal::ConfidentialComputingRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConfidentialComputingRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + confidentialcomputing_v1_internal::ConfidentialComputingRetryTraits> + impl_; +}; /** * The `ConfidentialComputingConnection` object for diff --git a/google/cloud/connectors/v1/connectors_connection.h b/google/cloud/connectors/v1/connectors_connection.h index b8e3cdabf357a..d545f74725a8a 100644 --- a/google/cloud/connectors/v1/connectors_connection.h +++ b/google/cloud/connectors/v1/connectors_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace connectors_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ConnectorsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - connectors_v1_internal::ConnectorsRetryTraits>; +/// The retry policy for `ConnectorsConnection`. +class ConnectorsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ConnectorsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConnectorsLimitedErrorCountRetryPolicy : public ConnectorsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ConnectorsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ConnectorsLimitedErrorCountRetryPolicy( + ConnectorsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ConnectorsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ConnectorsLimitedErrorCountRetryPolicy( + ConnectorsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ConnectorsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConnectorsRetryPolicy; -using ConnectorsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - connectors_v1_internal::ConnectorsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + connectors_v1_internal::ConnectorsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ConnectorsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConnectorsLimitedTimeRetryPolicy : public ConnectorsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ConnectorsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ConnectorsLimitedTimeRetryPolicy( + ConnectorsLimitedTimeRetryPolicy&& rhs) noexcept + : ConnectorsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ConnectorsLimitedTimeRetryPolicy( + ConnectorsLimitedTimeRetryPolicy const& rhs) noexcept + : ConnectorsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ConnectorsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - connectors_v1_internal::ConnectorsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConnectorsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + connectors_v1_internal::ConnectorsRetryTraits> + impl_; +}; /** * The `ConnectorsConnection` object for `ConnectorsClient`. diff --git a/google/cloud/contactcenterinsights/v1/contact_center_insights_connection.h b/google/cloud/contactcenterinsights/v1/contact_center_insights_connection.h index 2743c214c16ec..5db52f2105382 100644 --- a/google/cloud/contactcenterinsights/v1/contact_center_insights_connection.h +++ b/google/cloud/contactcenterinsights/v1/contact_center_insights_connection.h @@ -38,17 +38,139 @@ namespace cloud { namespace contactcenterinsights_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ContactCenterInsightsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - contactcenterinsights_v1_internal::ContactCenterInsightsRetryTraits>; +/// The retry policy for `ContactCenterInsightsConnection`. +class ContactCenterInsightsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ContactCenterInsightsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - contactcenterinsights_v1_internal::ContactCenterInsightsRetryTraits>; +/** + * A retry policy for `ContactCenterInsightsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ContactCenterInsightsLimitedErrorCountRetryPolicy + : public ContactCenterInsightsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ContactCenterInsightsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ContactCenterInsightsLimitedErrorCountRetryPolicy( + ContactCenterInsightsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ContactCenterInsightsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ContactCenterInsightsLimitedErrorCountRetryPolicy( + ContactCenterInsightsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ContactCenterInsightsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ContactCenterInsightsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + contactcenterinsights_v1_internal::ContactCenterInsightsRetryTraits> + impl_; +}; -using ContactCenterInsightsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - contactcenterinsights_v1_internal::ContactCenterInsightsRetryTraits>; +/** + * A retry policy for `ContactCenterInsightsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ContactCenterInsightsLimitedTimeRetryPolicy + : public ContactCenterInsightsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ContactCenterInsightsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ContactCenterInsightsLimitedTimeRetryPolicy( + ContactCenterInsightsLimitedTimeRetryPolicy&& rhs) noexcept + : ContactCenterInsightsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ContactCenterInsightsLimitedTimeRetryPolicy( + ContactCenterInsightsLimitedTimeRetryPolicy const& rhs) noexcept + : ContactCenterInsightsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ContactCenterInsightsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + contactcenterinsights_v1_internal::ContactCenterInsightsRetryTraits> + impl_; +}; /** * The `ContactCenterInsightsConnection` object for diff --git a/google/cloud/container/v1/cluster_manager_connection.h b/google/cloud/container/v1/cluster_manager_connection.h index 44be670573a28..9697611e4838b 100644 --- a/google/cloud/container/v1/cluster_manager_connection.h +++ b/google/cloud/container/v1/cluster_manager_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace container_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ClusterManagerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - container_v1_internal::ClusterManagerRetryTraits>; +/// The retry policy for `ClusterManagerConnection`. +class ClusterManagerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ClusterManagerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - container_v1_internal::ClusterManagerRetryTraits>; +/** + * A retry policy for `ClusterManagerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ClusterManagerLimitedErrorCountRetryPolicy + : public ClusterManagerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ClusterManagerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ClusterManagerLimitedErrorCountRetryPolicy( + ClusterManagerLimitedErrorCountRetryPolicy&& rhs) noexcept + : ClusterManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ClusterManagerLimitedErrorCountRetryPolicy( + ClusterManagerLimitedErrorCountRetryPolicy const& rhs) noexcept + : ClusterManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ClusterManagerRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + container_v1_internal::ClusterManagerRetryTraits> + impl_; +}; -using ClusterManagerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - container_v1_internal::ClusterManagerRetryTraits>; +/** + * A retry policy for `ClusterManagerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ClusterManagerLimitedTimeRetryPolicy : public ClusterManagerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ClusterManagerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ClusterManagerLimitedTimeRetryPolicy( + ClusterManagerLimitedTimeRetryPolicy&& rhs) noexcept + : ClusterManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ClusterManagerLimitedTimeRetryPolicy( + ClusterManagerLimitedTimeRetryPolicy const& rhs) noexcept + : ClusterManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ClusterManagerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + container_v1_internal::ClusterManagerRetryTraits> + impl_; +}; /** * The `ClusterManagerConnection` object for `ClusterManagerClient`. diff --git a/google/cloud/containeranalysis/v1/container_analysis_connection.h b/google/cloud/containeranalysis/v1/container_analysis_connection.h index 154fa60b9da87..972f5ee22ab4c 100644 --- a/google/cloud/containeranalysis/v1/container_analysis_connection.h +++ b/google/cloud/containeranalysis/v1/container_analysis_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace containeranalysis_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ContainerAnalysisRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - containeranalysis_v1_internal::ContainerAnalysisRetryTraits>; +/// The retry policy for `ContainerAnalysisConnection`. +class ContainerAnalysisRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ContainerAnalysisLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - containeranalysis_v1_internal::ContainerAnalysisRetryTraits>; +/** + * A retry policy for `ContainerAnalysisConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ContainerAnalysisLimitedErrorCountRetryPolicy + : public ContainerAnalysisRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ContainerAnalysisLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ContainerAnalysisLimitedErrorCountRetryPolicy( + ContainerAnalysisLimitedErrorCountRetryPolicy&& rhs) noexcept + : ContainerAnalysisLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ContainerAnalysisLimitedErrorCountRetryPolicy( + ContainerAnalysisLimitedErrorCountRetryPolicy const& rhs) noexcept + : ContainerAnalysisLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ContainerAnalysisRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + containeranalysis_v1_internal::ContainerAnalysisRetryTraits> + impl_; +}; -using ContainerAnalysisLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - containeranalysis_v1_internal::ContainerAnalysisRetryTraits>; +/** + * A retry policy for `ContainerAnalysisConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ContainerAnalysisLimitedTimeRetryPolicy + : public ContainerAnalysisRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ContainerAnalysisLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ContainerAnalysisLimitedTimeRetryPolicy( + ContainerAnalysisLimitedTimeRetryPolicy&& rhs) noexcept + : ContainerAnalysisLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ContainerAnalysisLimitedTimeRetryPolicy( + ContainerAnalysisLimitedTimeRetryPolicy const& rhs) noexcept + : ContainerAnalysisLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ContainerAnalysisRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + containeranalysis_v1_internal::ContainerAnalysisRetryTraits> + impl_; +}; /** * The `ContainerAnalysisConnection` object for `ContainerAnalysisClient`. diff --git a/google/cloud/containeranalysis/v1/grafeas_connection.h b/google/cloud/containeranalysis/v1/grafeas_connection.h index 720c32b61e3e6..c5a86effc70f4 100644 --- a/google/cloud/containeranalysis/v1/grafeas_connection.h +++ b/google/cloud/containeranalysis/v1/grafeas_connection.h @@ -35,16 +35,131 @@ namespace cloud { namespace containeranalysis_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GrafeasRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - containeranalysis_v1_internal::GrafeasRetryTraits>; +/// The retry policy for `GrafeasConnection`. +class GrafeasRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using GrafeasLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - containeranalysis_v1_internal::GrafeasRetryTraits>; +/** + * A retry policy for `GrafeasConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GrafeasLimitedErrorCountRetryPolicy : public GrafeasRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GrafeasLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + GrafeasLimitedErrorCountRetryPolicy( + GrafeasLimitedErrorCountRetryPolicy&& rhs) noexcept + : GrafeasLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + GrafeasLimitedErrorCountRetryPolicy( + GrafeasLimitedErrorCountRetryPolicy const& rhs) noexcept + : GrafeasLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GrafeasRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + containeranalysis_v1_internal::GrafeasRetryTraits> + impl_; +}; -using GrafeasLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - containeranalysis_v1_internal::GrafeasRetryTraits>; +/** + * A retry policy for `GrafeasConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GrafeasLimitedTimeRetryPolicy : public GrafeasRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GrafeasLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GrafeasLimitedTimeRetryPolicy(GrafeasLimitedTimeRetryPolicy&& rhs) noexcept + : GrafeasLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + GrafeasLimitedTimeRetryPolicy( + GrafeasLimitedTimeRetryPolicy const& rhs) noexcept + : GrafeasLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GrafeasRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + containeranalysis_v1_internal::GrafeasRetryTraits> + impl_; +}; /** * The `GrafeasConnection` object for `GrafeasClient`. diff --git a/google/cloud/contentwarehouse/v1/document_connection.h b/google/cloud/contentwarehouse/v1/document_connection.h index 720458a0b96ff..77b53c930ebfc 100644 --- a/google/cloud/contentwarehouse/v1/document_connection.h +++ b/google/cloud/contentwarehouse/v1/document_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace contentwarehouse_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DocumentServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - contentwarehouse_v1_internal::DocumentServiceRetryTraits>; +/// The retry policy for `DocumentServiceConnection`. +class DocumentServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DocumentServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - contentwarehouse_v1_internal::DocumentServiceRetryTraits>; +/** + * A retry policy for `DocumentServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentServiceLimitedErrorCountRetryPolicy + : public DocumentServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DocumentServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DocumentServiceLimitedErrorCountRetryPolicy( + DocumentServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DocumentServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DocumentServiceLimitedErrorCountRetryPolicy( + DocumentServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DocumentServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + contentwarehouse_v1_internal::DocumentServiceRetryTraits> + impl_; +}; -using DocumentServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - contentwarehouse_v1_internal::DocumentServiceRetryTraits>; +/** + * A retry policy for `DocumentServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentServiceLimitedTimeRetryPolicy + : public DocumentServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DocumentServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DocumentServiceLimitedTimeRetryPolicy( + DocumentServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DocumentServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DocumentServiceLimitedTimeRetryPolicy( + DocumentServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DocumentServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + contentwarehouse_v1_internal::DocumentServiceRetryTraits> + impl_; +}; /** * The `DocumentServiceConnection` object for `DocumentServiceClient`. diff --git a/google/cloud/contentwarehouse/v1/document_link_connection.h b/google/cloud/contentwarehouse/v1/document_link_connection.h index 1172b6cc62673..60df6bb141413 100644 --- a/google/cloud/contentwarehouse/v1/document_link_connection.h +++ b/google/cloud/contentwarehouse/v1/document_link_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace contentwarehouse_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DocumentLinkServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - contentwarehouse_v1_internal::DocumentLinkServiceRetryTraits>; +/// The retry policy for `DocumentLinkServiceConnection`. +class DocumentLinkServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DocumentLinkServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - contentwarehouse_v1_internal::DocumentLinkServiceRetryTraits>; +/** + * A retry policy for `DocumentLinkServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentLinkServiceLimitedErrorCountRetryPolicy + : public DocumentLinkServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DocumentLinkServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DocumentLinkServiceLimitedErrorCountRetryPolicy( + DocumentLinkServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DocumentLinkServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + DocumentLinkServiceLimitedErrorCountRetryPolicy( + DocumentLinkServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DocumentLinkServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentLinkServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + contentwarehouse_v1_internal::DocumentLinkServiceRetryTraits> + impl_; +}; -using DocumentLinkServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - contentwarehouse_v1_internal::DocumentLinkServiceRetryTraits>; +/** + * A retry policy for `DocumentLinkServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentLinkServiceLimitedTimeRetryPolicy + : public DocumentLinkServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DocumentLinkServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DocumentLinkServiceLimitedTimeRetryPolicy( + DocumentLinkServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DocumentLinkServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DocumentLinkServiceLimitedTimeRetryPolicy( + DocumentLinkServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DocumentLinkServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentLinkServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + contentwarehouse_v1_internal::DocumentLinkServiceRetryTraits> + impl_; +}; /** * The `DocumentLinkServiceConnection` object for `DocumentLinkServiceClient`. diff --git a/google/cloud/contentwarehouse/v1/document_schema_connection.h b/google/cloud/contentwarehouse/v1/document_schema_connection.h index 26a4cb723b58c..c0be62ed766c0 100644 --- a/google/cloud/contentwarehouse/v1/document_schema_connection.h +++ b/google/cloud/contentwarehouse/v1/document_schema_connection.h @@ -35,17 +35,139 @@ namespace cloud { namespace contentwarehouse_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DocumentSchemaServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - contentwarehouse_v1_internal::DocumentSchemaServiceRetryTraits>; +/// The retry policy for `DocumentSchemaServiceConnection`. +class DocumentSchemaServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DocumentSchemaServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - contentwarehouse_v1_internal::DocumentSchemaServiceRetryTraits>; +/** + * A retry policy for `DocumentSchemaServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentSchemaServiceLimitedErrorCountRetryPolicy + : public DocumentSchemaServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DocumentSchemaServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + DocumentSchemaServiceLimitedErrorCountRetryPolicy( + DocumentSchemaServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DocumentSchemaServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + DocumentSchemaServiceLimitedErrorCountRetryPolicy( + DocumentSchemaServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DocumentSchemaServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentSchemaServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + contentwarehouse_v1_internal::DocumentSchemaServiceRetryTraits> + impl_; +}; -using DocumentSchemaServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - contentwarehouse_v1_internal::DocumentSchemaServiceRetryTraits>; +/** + * A retry policy for `DocumentSchemaServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentSchemaServiceLimitedTimeRetryPolicy + : public DocumentSchemaServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DocumentSchemaServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DocumentSchemaServiceLimitedTimeRetryPolicy( + DocumentSchemaServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DocumentSchemaServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DocumentSchemaServiceLimitedTimeRetryPolicy( + DocumentSchemaServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DocumentSchemaServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentSchemaServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + contentwarehouse_v1_internal::DocumentSchemaServiceRetryTraits> + impl_; +}; /** * The `DocumentSchemaServiceConnection` object for diff --git a/google/cloud/contentwarehouse/v1/rule_set_connection.h b/google/cloud/contentwarehouse/v1/rule_set_connection.h index 0344c733ada5e..9413fb5d04040 100644 --- a/google/cloud/contentwarehouse/v1/rule_set_connection.h +++ b/google/cloud/contentwarehouse/v1/rule_set_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace contentwarehouse_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RuleSetServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - contentwarehouse_v1_internal::RuleSetServiceRetryTraits>; +/// The retry policy for `RuleSetServiceConnection`. +class RuleSetServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using RuleSetServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - contentwarehouse_v1_internal::RuleSetServiceRetryTraits>; +/** + * A retry policy for `RuleSetServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RuleSetServiceLimitedErrorCountRetryPolicy + : public RuleSetServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RuleSetServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RuleSetServiceLimitedErrorCountRetryPolicy( + RuleSetServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : RuleSetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RuleSetServiceLimitedErrorCountRetryPolicy( + RuleSetServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : RuleSetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RuleSetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + contentwarehouse_v1_internal::RuleSetServiceRetryTraits> + impl_; +}; -using RuleSetServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - contentwarehouse_v1_internal::RuleSetServiceRetryTraits>; +/** + * A retry policy for `RuleSetServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RuleSetServiceLimitedTimeRetryPolicy : public RuleSetServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RuleSetServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RuleSetServiceLimitedTimeRetryPolicy( + RuleSetServiceLimitedTimeRetryPolicy&& rhs) noexcept + : RuleSetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RuleSetServiceLimitedTimeRetryPolicy( + RuleSetServiceLimitedTimeRetryPolicy const& rhs) noexcept + : RuleSetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RuleSetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + contentwarehouse_v1_internal::RuleSetServiceRetryTraits> + impl_; +}; /** * The `RuleSetServiceConnection` object for `RuleSetServiceClient`. diff --git a/google/cloud/contentwarehouse/v1/synonym_set_connection.h b/google/cloud/contentwarehouse/v1/synonym_set_connection.h index 68f4bb15640f2..73dcf8fac465e 100644 --- a/google/cloud/contentwarehouse/v1/synonym_set_connection.h +++ b/google/cloud/contentwarehouse/v1/synonym_set_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace contentwarehouse_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SynonymSetServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - contentwarehouse_v1_internal::SynonymSetServiceRetryTraits>; +/// The retry policy for `SynonymSetServiceConnection`. +class SynonymSetServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SynonymSetServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - contentwarehouse_v1_internal::SynonymSetServiceRetryTraits>; +/** + * A retry policy for `SynonymSetServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SynonymSetServiceLimitedErrorCountRetryPolicy + : public SynonymSetServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SynonymSetServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SynonymSetServiceLimitedErrorCountRetryPolicy( + SynonymSetServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SynonymSetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SynonymSetServiceLimitedErrorCountRetryPolicy( + SynonymSetServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SynonymSetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SynonymSetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + contentwarehouse_v1_internal::SynonymSetServiceRetryTraits> + impl_; +}; -using SynonymSetServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - contentwarehouse_v1_internal::SynonymSetServiceRetryTraits>; +/** + * A retry policy for `SynonymSetServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SynonymSetServiceLimitedTimeRetryPolicy + : public SynonymSetServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SynonymSetServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SynonymSetServiceLimitedTimeRetryPolicy( + SynonymSetServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SynonymSetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SynonymSetServiceLimitedTimeRetryPolicy( + SynonymSetServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SynonymSetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SynonymSetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + contentwarehouse_v1_internal::SynonymSetServiceRetryTraits> + impl_; +}; /** * The `SynonymSetServiceConnection` object for `SynonymSetServiceClient`. diff --git a/google/cloud/datacatalog/lineage/v1/lineage_connection.h b/google/cloud/datacatalog/lineage/v1/lineage_connection.h index 1b723e58d926b..a7a88947ee543 100644 --- a/google/cloud/datacatalog/lineage/v1/lineage_connection.h +++ b/google/cloud/datacatalog/lineage/v1/lineage_connection.h @@ -39,16 +39,131 @@ namespace cloud { namespace datacatalog_lineage_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using LineageRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - datacatalog_lineage_v1_internal::LineageRetryTraits>; +/// The retry policy for `LineageConnection`. +class LineageRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `LineageConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LineageLimitedErrorCountRetryPolicy : public LineageRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit LineageLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + LineageLimitedErrorCountRetryPolicy( + LineageLimitedErrorCountRetryPolicy&& rhs) noexcept + : LineageLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + LineageLimitedErrorCountRetryPolicy( + LineageLimitedErrorCountRetryPolicy const& rhs) noexcept + : LineageLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = LineageRetryPolicy; -using LineageLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - datacatalog_lineage_v1_internal::LineageRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + datacatalog_lineage_v1_internal::LineageRetryTraits> + impl_; +}; + +/** + * A retry policy for `LineageConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LineageLimitedTimeRetryPolicy : public LineageRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit LineageLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + LineageLimitedTimeRetryPolicy(LineageLimitedTimeRetryPolicy&& rhs) noexcept + : LineageLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + LineageLimitedTimeRetryPolicy( + LineageLimitedTimeRetryPolicy const& rhs) noexcept + : LineageLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using LineageLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - datacatalog_lineage_v1_internal::LineageRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = LineageRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + datacatalog_lineage_v1_internal::LineageRetryTraits> + impl_; +}; /** * The `LineageConnection` object for `LineageClient`. diff --git a/google/cloud/datacatalog/v1/data_catalog_connection.h b/google/cloud/datacatalog/v1/data_catalog_connection.h index eb46688922828..3deadecd268b7 100644 --- a/google/cloud/datacatalog/v1/data_catalog_connection.h +++ b/google/cloud/datacatalog/v1/data_catalog_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace datacatalog_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DataCatalogRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - datacatalog_v1_internal::DataCatalogRetryTraits>; +/// The retry policy for `DataCatalogConnection`. +class DataCatalogRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DataCatalogLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - datacatalog_v1_internal::DataCatalogRetryTraits>; +/** + * A retry policy for `DataCatalogConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataCatalogLimitedErrorCountRetryPolicy : public DataCatalogRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DataCatalogLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DataCatalogLimitedErrorCountRetryPolicy( + DataCatalogLimitedErrorCountRetryPolicy&& rhs) noexcept + : DataCatalogLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DataCatalogLimitedErrorCountRetryPolicy( + DataCatalogLimitedErrorCountRetryPolicy const& rhs) noexcept + : DataCatalogLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataCatalogRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + datacatalog_v1_internal::DataCatalogRetryTraits> + impl_; +}; -using DataCatalogLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - datacatalog_v1_internal::DataCatalogRetryTraits>; +/** + * A retry policy for `DataCatalogConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataCatalogLimitedTimeRetryPolicy : public DataCatalogRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DataCatalogLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DataCatalogLimitedTimeRetryPolicy( + DataCatalogLimitedTimeRetryPolicy&& rhs) noexcept + : DataCatalogLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DataCatalogLimitedTimeRetryPolicy( + DataCatalogLimitedTimeRetryPolicy const& rhs) noexcept + : DataCatalogLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataCatalogRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + datacatalog_v1_internal::DataCatalogRetryTraits> + impl_; +}; /** * The `DataCatalogConnection` object for `DataCatalogClient`. diff --git a/google/cloud/datacatalog/v1/policy_tag_manager_connection.h b/google/cloud/datacatalog/v1/policy_tag_manager_connection.h index e9f1ec3bd3550..532a53b50332e 100644 --- a/google/cloud/datacatalog/v1/policy_tag_manager_connection.h +++ b/google/cloud/datacatalog/v1/policy_tag_manager_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace datacatalog_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PolicyTagManagerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - datacatalog_v1_internal::PolicyTagManagerRetryTraits>; +/// The retry policy for `PolicyTagManagerConnection`. +class PolicyTagManagerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PolicyTagManagerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PolicyTagManagerLimitedErrorCountRetryPolicy + : public PolicyTagManagerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PolicyTagManagerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PolicyTagManagerLimitedErrorCountRetryPolicy( + PolicyTagManagerLimitedErrorCountRetryPolicy&& rhs) noexcept + : PolicyTagManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PolicyTagManagerLimitedErrorCountRetryPolicy( + PolicyTagManagerLimitedErrorCountRetryPolicy const& rhs) noexcept + : PolicyTagManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PolicyTagManagerRetryPolicy; -using PolicyTagManagerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - datacatalog_v1_internal::PolicyTagManagerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + datacatalog_v1_internal::PolicyTagManagerRetryTraits> + impl_; +}; + +/** + * A retry policy for `PolicyTagManagerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PolicyTagManagerLimitedTimeRetryPolicy + : public PolicyTagManagerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PolicyTagManagerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PolicyTagManagerLimitedTimeRetryPolicy( + PolicyTagManagerLimitedTimeRetryPolicy&& rhs) noexcept + : PolicyTagManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PolicyTagManagerLimitedTimeRetryPolicy( + PolicyTagManagerLimitedTimeRetryPolicy const& rhs) noexcept + : PolicyTagManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using PolicyTagManagerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - datacatalog_v1_internal::PolicyTagManagerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PolicyTagManagerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + datacatalog_v1_internal::PolicyTagManagerRetryTraits> + impl_; +}; /** * The `PolicyTagManagerConnection` object for `PolicyTagManagerClient`. diff --git a/google/cloud/datacatalog/v1/policy_tag_manager_serialization_connection.h b/google/cloud/datacatalog/v1/policy_tag_manager_serialization_connection.h index 41ff32bdc00e9..381416bbfe55d 100644 --- a/google/cloud/datacatalog/v1/policy_tag_manager_serialization_connection.h +++ b/google/cloud/datacatalog/v1/policy_tag_manager_serialization_connection.h @@ -34,17 +34,149 @@ namespace cloud { namespace datacatalog_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PolicyTagManagerSerializationRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - datacatalog_v1_internal::PolicyTagManagerSerializationRetryTraits>; +/// The retry policy for `PolicyTagManagerSerializationConnection`. +class PolicyTagManagerSerializationRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `PolicyTagManagerSerializationConnection` based on + * counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PolicyTagManagerSerializationLimitedErrorCountRetryPolicy + : public PolicyTagManagerSerializationRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PolicyTagManagerSerializationLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + PolicyTagManagerSerializationLimitedErrorCountRetryPolicy( + PolicyTagManagerSerializationLimitedErrorCountRetryPolicy&& rhs) noexcept + : PolicyTagManagerSerializationLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + PolicyTagManagerSerializationLimitedErrorCountRetryPolicy( + PolicyTagManagerSerializationLimitedErrorCountRetryPolicy const& + rhs) noexcept + : PolicyTagManagerSerializationLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + PolicyTagManagerSerializationLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PolicyTagManagerSerializationRetryPolicy; -using PolicyTagManagerSerializationLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - datacatalog_v1_internal::PolicyTagManagerSerializationRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + datacatalog_v1_internal::PolicyTagManagerSerializationRetryTraits> + impl_; +}; + +/** + * A retry policy for `PolicyTagManagerSerializationConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PolicyTagManagerSerializationLimitedTimeRetryPolicy + : public PolicyTagManagerSerializationRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PolicyTagManagerSerializationLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PolicyTagManagerSerializationLimitedTimeRetryPolicy( + PolicyTagManagerSerializationLimitedTimeRetryPolicy&& rhs) noexcept + : PolicyTagManagerSerializationLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + PolicyTagManagerSerializationLimitedTimeRetryPolicy( + PolicyTagManagerSerializationLimitedTimeRetryPolicy const& rhs) noexcept + : PolicyTagManagerSerializationLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using PolicyTagManagerSerializationLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - datacatalog_v1_internal::PolicyTagManagerSerializationRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + PolicyTagManagerSerializationLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PolicyTagManagerSerializationRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + datacatalog_v1_internal::PolicyTagManagerSerializationRetryTraits> + impl_; +}; /** * The `PolicyTagManagerSerializationConnection` object for diff --git a/google/cloud/datafusion/v1/data_fusion_connection.h b/google/cloud/datafusion/v1/data_fusion_connection.h index 0b7ccee067dc6..e1ca181c65403 100644 --- a/google/cloud/datafusion/v1/data_fusion_connection.h +++ b/google/cloud/datafusion/v1/data_fusion_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace datafusion_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DataFusionRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - datafusion_v1_internal::DataFusionRetryTraits>; +/// The retry policy for `DataFusionConnection`. +class DataFusionRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DataFusionLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - datafusion_v1_internal::DataFusionRetryTraits>; +/** + * A retry policy for `DataFusionConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataFusionLimitedErrorCountRetryPolicy : public DataFusionRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DataFusionLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DataFusionLimitedErrorCountRetryPolicy( + DataFusionLimitedErrorCountRetryPolicy&& rhs) noexcept + : DataFusionLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DataFusionLimitedErrorCountRetryPolicy( + DataFusionLimitedErrorCountRetryPolicy const& rhs) noexcept + : DataFusionLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataFusionRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + datafusion_v1_internal::DataFusionRetryTraits> + impl_; +}; -using DataFusionLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - datafusion_v1_internal::DataFusionRetryTraits>; +/** + * A retry policy for `DataFusionConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataFusionLimitedTimeRetryPolicy : public DataFusionRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DataFusionLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DataFusionLimitedTimeRetryPolicy( + DataFusionLimitedTimeRetryPolicy&& rhs) noexcept + : DataFusionLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DataFusionLimitedTimeRetryPolicy( + DataFusionLimitedTimeRetryPolicy const& rhs) noexcept + : DataFusionLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataFusionRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + datafusion_v1_internal::DataFusionRetryTraits> + impl_; +}; /** * The `DataFusionConnection` object for `DataFusionClient`. diff --git a/google/cloud/datamigration/v1/data_migration_connection.h b/google/cloud/datamigration/v1/data_migration_connection.h index b79f4c6d24c25..815a0348606e6 100644 --- a/google/cloud/datamigration/v1/data_migration_connection.h +++ b/google/cloud/datamigration/v1/data_migration_connection.h @@ -38,17 +38,138 @@ namespace cloud { namespace datamigration_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DataMigrationServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - datamigration_v1_internal::DataMigrationServiceRetryTraits>; +/// The retry policy for `DataMigrationServiceConnection`. +class DataMigrationServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DataMigrationServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - datamigration_v1_internal::DataMigrationServiceRetryTraits>; +/** + * A retry policy for `DataMigrationServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataMigrationServiceLimitedErrorCountRetryPolicy + : public DataMigrationServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DataMigrationServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + DataMigrationServiceLimitedErrorCountRetryPolicy( + DataMigrationServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DataMigrationServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + DataMigrationServiceLimitedErrorCountRetryPolicy( + DataMigrationServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DataMigrationServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataMigrationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + datamigration_v1_internal::DataMigrationServiceRetryTraits> + impl_; +}; -using DataMigrationServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - datamigration_v1_internal::DataMigrationServiceRetryTraits>; +/** + * A retry policy for `DataMigrationServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataMigrationServiceLimitedTimeRetryPolicy + : public DataMigrationServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DataMigrationServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DataMigrationServiceLimitedTimeRetryPolicy( + DataMigrationServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DataMigrationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DataMigrationServiceLimitedTimeRetryPolicy( + DataMigrationServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DataMigrationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataMigrationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + datamigration_v1_internal::DataMigrationServiceRetryTraits> + impl_; +}; /** * The `DataMigrationServiceConnection` object for `DataMigrationServiceClient`. diff --git a/google/cloud/dataplex/v1/content_connection.h b/google/cloud/dataplex/v1/content_connection.h index 14188c820fbf8..1cf961ce482b8 100644 --- a/google/cloud/dataplex/v1/content_connection.h +++ b/google/cloud/dataplex/v1/content_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace dataplex_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ContentServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dataplex_v1_internal::ContentServiceRetryTraits>; +/// The retry policy for `ContentServiceConnection`. +class ContentServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ContentServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dataplex_v1_internal::ContentServiceRetryTraits>; +/** + * A retry policy for `ContentServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ContentServiceLimitedErrorCountRetryPolicy + : public ContentServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ContentServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ContentServiceLimitedErrorCountRetryPolicy( + ContentServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ContentServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ContentServiceLimitedErrorCountRetryPolicy( + ContentServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ContentServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ContentServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dataplex_v1_internal::ContentServiceRetryTraits> + impl_; +}; -using ContentServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dataplex_v1_internal::ContentServiceRetryTraits>; +/** + * A retry policy for `ContentServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ContentServiceLimitedTimeRetryPolicy : public ContentServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ContentServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ContentServiceLimitedTimeRetryPolicy( + ContentServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ContentServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ContentServiceLimitedTimeRetryPolicy( + ContentServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ContentServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ContentServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dataplex_v1_internal::ContentServiceRetryTraits> + impl_; +}; /** * The `ContentServiceConnection` object for `ContentServiceClient`. diff --git a/google/cloud/dataplex/v1/dataplex_connection.h b/google/cloud/dataplex/v1/dataplex_connection.h index 878e5dd00f0fa..3b8a6336cbf6c 100644 --- a/google/cloud/dataplex/v1/dataplex_connection.h +++ b/google/cloud/dataplex/v1/dataplex_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace dataplex_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DataplexServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dataplex_v1_internal::DataplexServiceRetryTraits>; +/// The retry policy for `DataplexServiceConnection`. +class DataplexServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DataplexServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dataplex_v1_internal::DataplexServiceRetryTraits>; +/** + * A retry policy for `DataplexServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataplexServiceLimitedErrorCountRetryPolicy + : public DataplexServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DataplexServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DataplexServiceLimitedErrorCountRetryPolicy( + DataplexServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DataplexServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DataplexServiceLimitedErrorCountRetryPolicy( + DataplexServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DataplexServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataplexServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dataplex_v1_internal::DataplexServiceRetryTraits> + impl_; +}; -using DataplexServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dataplex_v1_internal::DataplexServiceRetryTraits>; +/** + * A retry policy for `DataplexServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataplexServiceLimitedTimeRetryPolicy + : public DataplexServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DataplexServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DataplexServiceLimitedTimeRetryPolicy( + DataplexServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DataplexServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DataplexServiceLimitedTimeRetryPolicy( + DataplexServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DataplexServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataplexServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dataplex_v1_internal::DataplexServiceRetryTraits> + impl_; +}; /** * The `DataplexServiceConnection` object for `DataplexServiceClient`. diff --git a/google/cloud/dataplex/v1/metadata_connection.h b/google/cloud/dataplex/v1/metadata_connection.h index 8187fce710f52..9838e701e1670 100644 --- a/google/cloud/dataplex/v1/metadata_connection.h +++ b/google/cloud/dataplex/v1/metadata_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace dataplex_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MetadataServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dataplex_v1_internal::MetadataServiceRetryTraits>; +/// The retry policy for `MetadataServiceConnection`. +class MetadataServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using MetadataServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dataplex_v1_internal::MetadataServiceRetryTraits>; +/** + * A retry policy for `MetadataServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetadataServiceLimitedErrorCountRetryPolicy + : public MetadataServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MetadataServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MetadataServiceLimitedErrorCountRetryPolicy( + MetadataServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : MetadataServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MetadataServiceLimitedErrorCountRetryPolicy( + MetadataServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : MetadataServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetadataServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dataplex_v1_internal::MetadataServiceRetryTraits> + impl_; +}; -using MetadataServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dataplex_v1_internal::MetadataServiceRetryTraits>; +/** + * A retry policy for `MetadataServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetadataServiceLimitedTimeRetryPolicy + : public MetadataServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MetadataServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MetadataServiceLimitedTimeRetryPolicy( + MetadataServiceLimitedTimeRetryPolicy&& rhs) noexcept + : MetadataServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MetadataServiceLimitedTimeRetryPolicy( + MetadataServiceLimitedTimeRetryPolicy const& rhs) noexcept + : MetadataServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetadataServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dataplex_v1_internal::MetadataServiceRetryTraits> + impl_; +}; /** * The `MetadataServiceConnection` object for `MetadataServiceClient`. diff --git a/google/cloud/dataproc/v1/autoscaling_policy_connection.h b/google/cloud/dataproc/v1/autoscaling_policy_connection.h index e276c13088091..84d4b14706311 100644 --- a/google/cloud/dataproc/v1/autoscaling_policy_connection.h +++ b/google/cloud/dataproc/v1/autoscaling_policy_connection.h @@ -36,17 +36,145 @@ namespace cloud { namespace dataproc_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AutoscalingPolicyServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dataproc_v1_internal::AutoscalingPolicyServiceRetryTraits>; +/// The retry policy for `AutoscalingPolicyServiceConnection`. +class AutoscalingPolicyServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `AutoscalingPolicyServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AutoscalingPolicyServiceLimitedErrorCountRetryPolicy + : public AutoscalingPolicyServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AutoscalingPolicyServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + AutoscalingPolicyServiceLimitedErrorCountRetryPolicy( + AutoscalingPolicyServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AutoscalingPolicyServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AutoscalingPolicyServiceLimitedErrorCountRetryPolicy( + AutoscalingPolicyServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AutoscalingPolicyServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + AutoscalingPolicyServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AutoscalingPolicyServiceRetryPolicy; -using AutoscalingPolicyServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dataproc_v1_internal::AutoscalingPolicyServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dataproc_v1_internal::AutoscalingPolicyServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `AutoscalingPolicyServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AutoscalingPolicyServiceLimitedTimeRetryPolicy + : public AutoscalingPolicyServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AutoscalingPolicyServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AutoscalingPolicyServiceLimitedTimeRetryPolicy( + AutoscalingPolicyServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AutoscalingPolicyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + AutoscalingPolicyServiceLimitedTimeRetryPolicy( + AutoscalingPolicyServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AutoscalingPolicyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AutoscalingPolicyServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dataproc_v1_internal::AutoscalingPolicyServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AutoscalingPolicyServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dataproc_v1_internal::AutoscalingPolicyServiceRetryTraits> + impl_; +}; /** * The `AutoscalingPolicyServiceConnection` object for diff --git a/google/cloud/dataproc/v1/batch_controller_connection.h b/google/cloud/dataproc/v1/batch_controller_connection.h index 198ce3f28432d..1540addc2f57c 100644 --- a/google/cloud/dataproc/v1/batch_controller_connection.h +++ b/google/cloud/dataproc/v1/batch_controller_connection.h @@ -40,17 +40,135 @@ namespace cloud { namespace dataproc_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BatchControllerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dataproc_v1_internal::BatchControllerRetryTraits>; +/// The retry policy for `BatchControllerConnection`. +class BatchControllerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BatchControllerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dataproc_v1_internal::BatchControllerRetryTraits>; +/** + * A retry policy for `BatchControllerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BatchControllerLimitedErrorCountRetryPolicy + : public BatchControllerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BatchControllerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BatchControllerLimitedErrorCountRetryPolicy( + BatchControllerLimitedErrorCountRetryPolicy&& rhs) noexcept + : BatchControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BatchControllerLimitedErrorCountRetryPolicy( + BatchControllerLimitedErrorCountRetryPolicy const& rhs) noexcept + : BatchControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BatchControllerRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dataproc_v1_internal::BatchControllerRetryTraits> + impl_; +}; -using BatchControllerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dataproc_v1_internal::BatchControllerRetryTraits>; +/** + * A retry policy for `BatchControllerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BatchControllerLimitedTimeRetryPolicy + : public BatchControllerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BatchControllerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BatchControllerLimitedTimeRetryPolicy( + BatchControllerLimitedTimeRetryPolicy&& rhs) noexcept + : BatchControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BatchControllerLimitedTimeRetryPolicy( + BatchControllerLimitedTimeRetryPolicy const& rhs) noexcept + : BatchControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BatchControllerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dataproc_v1_internal::BatchControllerRetryTraits> + impl_; +}; /** * The `BatchControllerConnection` object for `BatchControllerClient`. diff --git a/google/cloud/dataproc/v1/cluster_controller_connection.h b/google/cloud/dataproc/v1/cluster_controller_connection.h index da32ade408467..f384a232318e6 100644 --- a/google/cloud/dataproc/v1/cluster_controller_connection.h +++ b/google/cloud/dataproc/v1/cluster_controller_connection.h @@ -40,17 +40,135 @@ namespace cloud { namespace dataproc_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ClusterControllerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dataproc_v1_internal::ClusterControllerRetryTraits>; +/// The retry policy for `ClusterControllerConnection`. +class ClusterControllerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ClusterControllerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ClusterControllerLimitedErrorCountRetryPolicy + : public ClusterControllerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ClusterControllerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ClusterControllerLimitedErrorCountRetryPolicy( + ClusterControllerLimitedErrorCountRetryPolicy&& rhs) noexcept + : ClusterControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ClusterControllerLimitedErrorCountRetryPolicy( + ClusterControllerLimitedErrorCountRetryPolicy const& rhs) noexcept + : ClusterControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ClusterControllerRetryPolicy; -using ClusterControllerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dataproc_v1_internal::ClusterControllerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dataproc_v1_internal::ClusterControllerRetryTraits> + impl_; +}; + +/** + * A retry policy for `ClusterControllerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ClusterControllerLimitedTimeRetryPolicy + : public ClusterControllerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ClusterControllerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ClusterControllerLimitedTimeRetryPolicy( + ClusterControllerLimitedTimeRetryPolicy&& rhs) noexcept + : ClusterControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ClusterControllerLimitedTimeRetryPolicy( + ClusterControllerLimitedTimeRetryPolicy const& rhs) noexcept + : ClusterControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ClusterControllerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dataproc_v1_internal::ClusterControllerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ClusterControllerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dataproc_v1_internal::ClusterControllerRetryTraits> + impl_; +}; /** * The `ClusterControllerConnection` object for `ClusterControllerClient`. diff --git a/google/cloud/dataproc/v1/job_controller_connection.h b/google/cloud/dataproc/v1/job_controller_connection.h index 9c2f2758761ad..7eec132fe5022 100644 --- a/google/cloud/dataproc/v1/job_controller_connection.h +++ b/google/cloud/dataproc/v1/job_controller_connection.h @@ -39,17 +39,134 @@ namespace cloud { namespace dataproc_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using JobControllerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dataproc_v1_internal::JobControllerRetryTraits>; +/// The retry policy for `JobControllerConnection`. +class JobControllerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using JobControllerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dataproc_v1_internal::JobControllerRetryTraits>; +/** + * A retry policy for `JobControllerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class JobControllerLimitedErrorCountRetryPolicy + : public JobControllerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit JobControllerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + JobControllerLimitedErrorCountRetryPolicy( + JobControllerLimitedErrorCountRetryPolicy&& rhs) noexcept + : JobControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + JobControllerLimitedErrorCountRetryPolicy( + JobControllerLimitedErrorCountRetryPolicy const& rhs) noexcept + : JobControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = JobControllerRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dataproc_v1_internal::JobControllerRetryTraits> + impl_; +}; -using JobControllerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dataproc_v1_internal::JobControllerRetryTraits>; +/** + * A retry policy for `JobControllerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class JobControllerLimitedTimeRetryPolicy : public JobControllerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit JobControllerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + JobControllerLimitedTimeRetryPolicy( + JobControllerLimitedTimeRetryPolicy&& rhs) noexcept + : JobControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + JobControllerLimitedTimeRetryPolicy( + JobControllerLimitedTimeRetryPolicy const& rhs) noexcept + : JobControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = JobControllerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dataproc_v1_internal::JobControllerRetryTraits> + impl_; +}; /** * The `JobControllerConnection` object for `JobControllerClient`. diff --git a/google/cloud/dataproc/v1/workflow_template_connection.h b/google/cloud/dataproc/v1/workflow_template_connection.h index 309b8d0c00c53..ac458dc98c819 100644 --- a/google/cloud/dataproc/v1/workflow_template_connection.h +++ b/google/cloud/dataproc/v1/workflow_template_connection.h @@ -39,17 +39,140 @@ namespace cloud { namespace dataproc_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using WorkflowTemplateServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dataproc_v1_internal::WorkflowTemplateServiceRetryTraits>; +/// The retry policy for `WorkflowTemplateServiceConnection`. +class WorkflowTemplateServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `WorkflowTemplateServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WorkflowTemplateServiceLimitedErrorCountRetryPolicy + : public WorkflowTemplateServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit WorkflowTemplateServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + WorkflowTemplateServiceLimitedErrorCountRetryPolicy( + WorkflowTemplateServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : WorkflowTemplateServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + WorkflowTemplateServiceLimitedErrorCountRetryPolicy( + WorkflowTemplateServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : WorkflowTemplateServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + WorkflowTemplateServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = WorkflowTemplateServiceRetryPolicy; -using WorkflowTemplateServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dataproc_v1_internal::WorkflowTemplateServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dataproc_v1_internal::WorkflowTemplateServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `WorkflowTemplateServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WorkflowTemplateServiceLimitedTimeRetryPolicy + : public WorkflowTemplateServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit WorkflowTemplateServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + WorkflowTemplateServiceLimitedTimeRetryPolicy( + WorkflowTemplateServiceLimitedTimeRetryPolicy&& rhs) noexcept + : WorkflowTemplateServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + WorkflowTemplateServiceLimitedTimeRetryPolicy( + WorkflowTemplateServiceLimitedTimeRetryPolicy const& rhs) noexcept + : WorkflowTemplateServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using WorkflowTemplateServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dataproc_v1_internal::WorkflowTemplateServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = WorkflowTemplateServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dataproc_v1_internal::WorkflowTemplateServiceRetryTraits> + impl_; +}; /** * The `WorkflowTemplateServiceConnection` object for diff --git a/google/cloud/datastream/v1/datastream_connection.h b/google/cloud/datastream/v1/datastream_connection.h index ef29667cc2c76..5f840c2349fc5 100644 --- a/google/cloud/datastream/v1/datastream_connection.h +++ b/google/cloud/datastream/v1/datastream_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace datastream_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DatastreamRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - datastream_v1_internal::DatastreamRetryTraits>; +/// The retry policy for `DatastreamConnection`. +class DatastreamRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DatastreamLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - datastream_v1_internal::DatastreamRetryTraits>; +/** + * A retry policy for `DatastreamConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DatastreamLimitedErrorCountRetryPolicy : public DatastreamRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DatastreamLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DatastreamLimitedErrorCountRetryPolicy( + DatastreamLimitedErrorCountRetryPolicy&& rhs) noexcept + : DatastreamLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DatastreamLimitedErrorCountRetryPolicy( + DatastreamLimitedErrorCountRetryPolicy const& rhs) noexcept + : DatastreamLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DatastreamRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + datastream_v1_internal::DatastreamRetryTraits> + impl_; +}; -using DatastreamLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - datastream_v1_internal::DatastreamRetryTraits>; +/** + * A retry policy for `DatastreamConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DatastreamLimitedTimeRetryPolicy : public DatastreamRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DatastreamLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DatastreamLimitedTimeRetryPolicy( + DatastreamLimitedTimeRetryPolicy&& rhs) noexcept + : DatastreamLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DatastreamLimitedTimeRetryPolicy( + DatastreamLimitedTimeRetryPolicy const& rhs) noexcept + : DatastreamLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DatastreamRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + datastream_v1_internal::DatastreamRetryTraits> + impl_; +}; /** * The `DatastreamConnection` object for `DatastreamClient`. diff --git a/google/cloud/deploy/v1/cloud_deploy_connection.h b/google/cloud/deploy/v1/cloud_deploy_connection.h index 359e94969ec96..5e8808f68dc6a 100644 --- a/google/cloud/deploy/v1/cloud_deploy_connection.h +++ b/google/cloud/deploy/v1/cloud_deploy_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace deploy_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudDeployRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - deploy_v1_internal::CloudDeployRetryTraits>; +/// The retry policy for `CloudDeployConnection`. +class CloudDeployRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CloudDeployLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - deploy_v1_internal::CloudDeployRetryTraits>; +/** + * A retry policy for `CloudDeployConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudDeployLimitedErrorCountRetryPolicy : public CloudDeployRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudDeployLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudDeployLimitedErrorCountRetryPolicy( + CloudDeployLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudDeployLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudDeployLimitedErrorCountRetryPolicy( + CloudDeployLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudDeployLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudDeployRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + deploy_v1_internal::CloudDeployRetryTraits> + impl_; +}; -using CloudDeployLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - deploy_v1_internal::CloudDeployRetryTraits>; +/** + * A retry policy for `CloudDeployConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudDeployLimitedTimeRetryPolicy : public CloudDeployRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudDeployLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudDeployLimitedTimeRetryPolicy( + CloudDeployLimitedTimeRetryPolicy&& rhs) noexcept + : CloudDeployLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudDeployLimitedTimeRetryPolicy( + CloudDeployLimitedTimeRetryPolicy const& rhs) noexcept + : CloudDeployLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudDeployRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + deploy_v1_internal::CloudDeployRetryTraits> + impl_; +}; /** * The `CloudDeployConnection` object for `CloudDeployClient`. diff --git a/google/cloud/dialogflow_cx/agents_connection.h b/google/cloud/dialogflow_cx/agents_connection.h index 7009a89da92d7..28464d841712a 100644 --- a/google/cloud/dialogflow_cx/agents_connection.h +++ b/google/cloud/dialogflow_cx/agents_connection.h @@ -40,16 +40,130 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AgentsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::AgentsRetryTraits>; +/// The retry policy for `AgentsConnection`. +class AgentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AgentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AgentsLimitedErrorCountRetryPolicy : public AgentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AgentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AgentsLimitedErrorCountRetryPolicy( + AgentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : AgentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AgentsLimitedErrorCountRetryPolicy( + AgentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : AgentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AgentsRetryPolicy; -using AgentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::AgentsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::AgentsRetryTraits> + impl_; +}; + +/** + * A retry policy for `AgentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AgentsLimitedTimeRetryPolicy : public AgentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AgentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AgentsLimitedTimeRetryPolicy(AgentsLimitedTimeRetryPolicy&& rhs) noexcept + : AgentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AgentsLimitedTimeRetryPolicy(AgentsLimitedTimeRetryPolicy const& rhs) noexcept + : AgentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AgentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::AgentsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AgentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::AgentsRetryTraits> + impl_; +}; /** * The `AgentsConnection` object for `AgentsClient`. diff --git a/google/cloud/dialogflow_cx/changelogs_connection.h b/google/cloud/dialogflow_cx/changelogs_connection.h index 4931bd7e9c448..1d594efccdca8 100644 --- a/google/cloud/dialogflow_cx/changelogs_connection.h +++ b/google/cloud/dialogflow_cx/changelogs_connection.h @@ -36,16 +36,133 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ChangelogsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::ChangelogsRetryTraits>; +/// The retry policy for `ChangelogsConnection`. +class ChangelogsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ChangelogsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ChangelogsLimitedErrorCountRetryPolicy : public ChangelogsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ChangelogsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ChangelogsLimitedErrorCountRetryPolicy( + ChangelogsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ChangelogsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ChangelogsLimitedErrorCountRetryPolicy( + ChangelogsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ChangelogsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ChangelogsRetryPolicy; -using ChangelogsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::ChangelogsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::ChangelogsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ChangelogsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ChangelogsLimitedTimeRetryPolicy : public ChangelogsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ChangelogsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ChangelogsLimitedTimeRetryPolicy( + ChangelogsLimitedTimeRetryPolicy&& rhs) noexcept + : ChangelogsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ChangelogsLimitedTimeRetryPolicy( + ChangelogsLimitedTimeRetryPolicy const& rhs) noexcept + : ChangelogsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ChangelogsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::ChangelogsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ChangelogsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::ChangelogsRetryTraits> + impl_; +}; /** * The `ChangelogsConnection` object for `ChangelogsClient`. diff --git a/google/cloud/dialogflow_cx/deployments_connection.h b/google/cloud/dialogflow_cx/deployments_connection.h index b30aac443bee1..a92b6cb310413 100644 --- a/google/cloud/dialogflow_cx/deployments_connection.h +++ b/google/cloud/dialogflow_cx/deployments_connection.h @@ -36,16 +36,133 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DeploymentsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::DeploymentsRetryTraits>; +/// The retry policy for `DeploymentsConnection`. +class DeploymentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DeploymentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DeploymentsLimitedErrorCountRetryPolicy : public DeploymentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DeploymentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DeploymentsLimitedErrorCountRetryPolicy( + DeploymentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : DeploymentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DeploymentsLimitedErrorCountRetryPolicy( + DeploymentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : DeploymentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DeploymentsRetryPolicy; -using DeploymentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::DeploymentsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::DeploymentsRetryTraits> + impl_; +}; + +/** + * A retry policy for `DeploymentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DeploymentsLimitedTimeRetryPolicy : public DeploymentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DeploymentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DeploymentsLimitedTimeRetryPolicy( + DeploymentsLimitedTimeRetryPolicy&& rhs) noexcept + : DeploymentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DeploymentsLimitedTimeRetryPolicy( + DeploymentsLimitedTimeRetryPolicy const& rhs) noexcept + : DeploymentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DeploymentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::DeploymentsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DeploymentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::DeploymentsRetryTraits> + impl_; +}; /** * The `DeploymentsConnection` object for `DeploymentsClient`. diff --git a/google/cloud/dialogflow_cx/entity_types_connection.h b/google/cloud/dialogflow_cx/entity_types_connection.h index 62426ad1a5964..6ddc88fef58e7 100644 --- a/google/cloud/dialogflow_cx/entity_types_connection.h +++ b/google/cloud/dialogflow_cx/entity_types_connection.h @@ -36,16 +36,133 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EntityTypesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::EntityTypesRetryTraits>; +/// The retry policy for `EntityTypesConnection`. +class EntityTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using EntityTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::EntityTypesRetryTraits>; +/** + * A retry policy for `EntityTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EntityTypesLimitedErrorCountRetryPolicy : public EntityTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EntityTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EntityTypesLimitedErrorCountRetryPolicy( + EntityTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : EntityTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EntityTypesLimitedErrorCountRetryPolicy( + EntityTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : EntityTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EntityTypesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::EntityTypesRetryTraits> + impl_; +}; -using EntityTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::EntityTypesRetryTraits>; +/** + * A retry policy for `EntityTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EntityTypesLimitedTimeRetryPolicy : public EntityTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EntityTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EntityTypesLimitedTimeRetryPolicy( + EntityTypesLimitedTimeRetryPolicy&& rhs) noexcept + : EntityTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EntityTypesLimitedTimeRetryPolicy( + EntityTypesLimitedTimeRetryPolicy const& rhs) noexcept + : EntityTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EntityTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::EntityTypesRetryTraits> + impl_; +}; /** * The `EntityTypesConnection` object for `EntityTypesClient`. diff --git a/google/cloud/dialogflow_cx/environments_connection.h b/google/cloud/dialogflow_cx/environments_connection.h index 3d1f7335239fb..e3cc5c7d08bd1 100644 --- a/google/cloud/dialogflow_cx/environments_connection.h +++ b/google/cloud/dialogflow_cx/environments_connection.h @@ -40,17 +40,134 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EnvironmentsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::EnvironmentsRetryTraits>; +/// The retry policy for `EnvironmentsConnection`. +class EnvironmentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `EnvironmentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EnvironmentsLimitedErrorCountRetryPolicy + : public EnvironmentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EnvironmentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EnvironmentsLimitedErrorCountRetryPolicy( + EnvironmentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : EnvironmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EnvironmentsLimitedErrorCountRetryPolicy( + EnvironmentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : EnvironmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EnvironmentsRetryPolicy; -using EnvironmentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::EnvironmentsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::EnvironmentsRetryTraits> + impl_; +}; + +/** + * A retry policy for `EnvironmentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EnvironmentsLimitedTimeRetryPolicy : public EnvironmentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EnvironmentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EnvironmentsLimitedTimeRetryPolicy( + EnvironmentsLimitedTimeRetryPolicy&& rhs) noexcept + : EnvironmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EnvironmentsLimitedTimeRetryPolicy( + EnvironmentsLimitedTimeRetryPolicy const& rhs) noexcept + : EnvironmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using EnvironmentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::EnvironmentsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EnvironmentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::EnvironmentsRetryTraits> + impl_; +}; /** * The `EnvironmentsConnection` object for `EnvironmentsClient`. diff --git a/google/cloud/dialogflow_cx/experiments_connection.h b/google/cloud/dialogflow_cx/experiments_connection.h index 4f1bc3a007106..681dc6804f690 100644 --- a/google/cloud/dialogflow_cx/experiments_connection.h +++ b/google/cloud/dialogflow_cx/experiments_connection.h @@ -36,16 +36,133 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ExperimentsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::ExperimentsRetryTraits>; +/// The retry policy for `ExperimentsConnection`. +class ExperimentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ExperimentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::ExperimentsRetryTraits>; +/** + * A retry policy for `ExperimentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ExperimentsLimitedErrorCountRetryPolicy : public ExperimentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ExperimentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ExperimentsLimitedErrorCountRetryPolicy( + ExperimentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ExperimentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ExperimentsLimitedErrorCountRetryPolicy( + ExperimentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ExperimentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ExperimentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::ExperimentsRetryTraits> + impl_; +}; -using ExperimentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::ExperimentsRetryTraits>; +/** + * A retry policy for `ExperimentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ExperimentsLimitedTimeRetryPolicy : public ExperimentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ExperimentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ExperimentsLimitedTimeRetryPolicy( + ExperimentsLimitedTimeRetryPolicy&& rhs) noexcept + : ExperimentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ExperimentsLimitedTimeRetryPolicy( + ExperimentsLimitedTimeRetryPolicy const& rhs) noexcept + : ExperimentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ExperimentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::ExperimentsRetryTraits> + impl_; +}; /** * The `ExperimentsConnection` object for `ExperimentsClient`. diff --git a/google/cloud/dialogflow_cx/flows_connection.h b/google/cloud/dialogflow_cx/flows_connection.h index 4310ec2ef460f..fa9ffe0af9556 100644 --- a/google/cloud/dialogflow_cx/flows_connection.h +++ b/google/cloud/dialogflow_cx/flows_connection.h @@ -40,16 +40,130 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FlowsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::FlowsRetryTraits>; +/// The retry policy for `FlowsConnection`. +class FlowsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `FlowsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FlowsLimitedErrorCountRetryPolicy : public FlowsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FlowsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + FlowsLimitedErrorCountRetryPolicy( + FlowsLimitedErrorCountRetryPolicy&& rhs) noexcept + : FlowsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + FlowsLimitedErrorCountRetryPolicy( + FlowsLimitedErrorCountRetryPolicy const& rhs) noexcept + : FlowsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FlowsRetryPolicy; -using FlowsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::FlowsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::FlowsRetryTraits> + impl_; +}; + +/** + * A retry policy for `FlowsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FlowsLimitedTimeRetryPolicy : public FlowsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FlowsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FlowsLimitedTimeRetryPolicy(FlowsLimitedTimeRetryPolicy&& rhs) noexcept + : FlowsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + FlowsLimitedTimeRetryPolicy(FlowsLimitedTimeRetryPolicy const& rhs) noexcept + : FlowsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using FlowsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::FlowsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FlowsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::FlowsRetryTraits> + impl_; +}; /** * The `FlowsConnection` object for `FlowsClient`. diff --git a/google/cloud/dialogflow_cx/intents_connection.h b/google/cloud/dialogflow_cx/intents_connection.h index bb6ae14e8b07d..8a0285684826b 100644 --- a/google/cloud/dialogflow_cx/intents_connection.h +++ b/google/cloud/dialogflow_cx/intents_connection.h @@ -36,16 +36,131 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IntentsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::IntentsRetryTraits>; +/// The retry policy for `IntentsConnection`. +class IntentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using IntentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::IntentsRetryTraits>; +/** + * A retry policy for `IntentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IntentsLimitedErrorCountRetryPolicy : public IntentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IntentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + IntentsLimitedErrorCountRetryPolicy( + IntentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : IntentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + IntentsLimitedErrorCountRetryPolicy( + IntentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : IntentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IntentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::IntentsRetryTraits> + impl_; +}; -using IntentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::IntentsRetryTraits>; +/** + * A retry policy for `IntentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IntentsLimitedTimeRetryPolicy : public IntentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IntentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IntentsLimitedTimeRetryPolicy(IntentsLimitedTimeRetryPolicy&& rhs) noexcept + : IntentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IntentsLimitedTimeRetryPolicy( + IntentsLimitedTimeRetryPolicy const& rhs) noexcept + : IntentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IntentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::IntentsRetryTraits> + impl_; +}; /** * The `IntentsConnection` object for `IntentsClient`. diff --git a/google/cloud/dialogflow_cx/pages_connection.h b/google/cloud/dialogflow_cx/pages_connection.h index ae9c08211507c..eaa72ef1aa03f 100644 --- a/google/cloud/dialogflow_cx/pages_connection.h +++ b/google/cloud/dialogflow_cx/pages_connection.h @@ -36,16 +36,130 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PagesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::PagesRetryTraits>; +/// The retry policy for `PagesConnection`. +class PagesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using PagesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::PagesRetryTraits>; +/** + * A retry policy for `PagesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PagesLimitedErrorCountRetryPolicy : public PagesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PagesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PagesLimitedErrorCountRetryPolicy( + PagesLimitedErrorCountRetryPolicy&& rhs) noexcept + : PagesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PagesLimitedErrorCountRetryPolicy( + PagesLimitedErrorCountRetryPolicy const& rhs) noexcept + : PagesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PagesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::PagesRetryTraits> + impl_; +}; -using PagesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::PagesRetryTraits>; +/** + * A retry policy for `PagesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PagesLimitedTimeRetryPolicy : public PagesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PagesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PagesLimitedTimeRetryPolicy(PagesLimitedTimeRetryPolicy&& rhs) noexcept + : PagesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PagesLimitedTimeRetryPolicy(PagesLimitedTimeRetryPolicy const& rhs) noexcept + : PagesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PagesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::PagesRetryTraits> + impl_; +}; /** * The `PagesConnection` object for `PagesClient`. diff --git a/google/cloud/dialogflow_cx/security_settings_connection.h b/google/cloud/dialogflow_cx/security_settings_connection.h index b2f1dc0a263c8..283e05e7874d0 100644 --- a/google/cloud/dialogflow_cx/security_settings_connection.h +++ b/google/cloud/dialogflow_cx/security_settings_connection.h @@ -36,17 +36,140 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SecuritySettingsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::SecuritySettingsServiceRetryTraits>; +/// The retry policy for `SecuritySettingsServiceConnection`. +class SecuritySettingsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SecuritySettingsServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SecuritySettingsServiceLimitedErrorCountRetryPolicy + : public SecuritySettingsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SecuritySettingsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + SecuritySettingsServiceLimitedErrorCountRetryPolicy( + SecuritySettingsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SecuritySettingsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + SecuritySettingsServiceLimitedErrorCountRetryPolicy( + SecuritySettingsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SecuritySettingsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + SecuritySettingsServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SecuritySettingsServiceRetryPolicy; -using SecuritySettingsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::SecuritySettingsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::SecuritySettingsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SecuritySettingsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SecuritySettingsServiceLimitedTimeRetryPolicy + : public SecuritySettingsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SecuritySettingsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SecuritySettingsServiceLimitedTimeRetryPolicy( + SecuritySettingsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SecuritySettingsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SecuritySettingsServiceLimitedTimeRetryPolicy( + SecuritySettingsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SecuritySettingsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SecuritySettingsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::SecuritySettingsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SecuritySettingsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::SecuritySettingsServiceRetryTraits> + impl_; +}; /** * The `SecuritySettingsServiceConnection` object for diff --git a/google/cloud/dialogflow_cx/session_entity_types_connection.h b/google/cloud/dialogflow_cx/session_entity_types_connection.h index 61a07b74edb7a..352c04b3a2dc4 100644 --- a/google/cloud/dialogflow_cx/session_entity_types_connection.h +++ b/google/cloud/dialogflow_cx/session_entity_types_connection.h @@ -36,17 +36,137 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SessionEntityTypesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::SessionEntityTypesRetryTraits>; +/// The retry policy for `SessionEntityTypesConnection`. +class SessionEntityTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SessionEntityTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::SessionEntityTypesRetryTraits>; +/** + * A retry policy for `SessionEntityTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SessionEntityTypesLimitedErrorCountRetryPolicy + : public SessionEntityTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SessionEntityTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SessionEntityTypesLimitedErrorCountRetryPolicy( + SessionEntityTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : SessionEntityTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + SessionEntityTypesLimitedErrorCountRetryPolicy( + SessionEntityTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : SessionEntityTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SessionEntityTypesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::SessionEntityTypesRetryTraits> + impl_; +}; -using SessionEntityTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::SessionEntityTypesRetryTraits>; +/** + * A retry policy for `SessionEntityTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SessionEntityTypesLimitedTimeRetryPolicy + : public SessionEntityTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SessionEntityTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SessionEntityTypesLimitedTimeRetryPolicy( + SessionEntityTypesLimitedTimeRetryPolicy&& rhs) noexcept + : SessionEntityTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SessionEntityTypesLimitedTimeRetryPolicy( + SessionEntityTypesLimitedTimeRetryPolicy const& rhs) noexcept + : SessionEntityTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SessionEntityTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::SessionEntityTypesRetryTraits> + impl_; +}; /** * The `SessionEntityTypesConnection` object for `SessionEntityTypesClient`. diff --git a/google/cloud/dialogflow_cx/sessions_connection.h b/google/cloud/dialogflow_cx/sessions_connection.h index df83fcdfc620a..0f8b2e7edc1b1 100644 --- a/google/cloud/dialogflow_cx/sessions_connection.h +++ b/google/cloud/dialogflow_cx/sessions_connection.h @@ -36,16 +36,131 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SessionsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::SessionsRetryTraits>; +/// The retry policy for `SessionsConnection`. +class SessionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SessionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::SessionsRetryTraits>; +/** + * A retry policy for `SessionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SessionsLimitedErrorCountRetryPolicy : public SessionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SessionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SessionsLimitedErrorCountRetryPolicy( + SessionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : SessionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SessionsLimitedErrorCountRetryPolicy( + SessionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : SessionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SessionsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::SessionsRetryTraits> + impl_; +}; -using SessionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::SessionsRetryTraits>; +/** + * A retry policy for `SessionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SessionsLimitedTimeRetryPolicy : public SessionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SessionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SessionsLimitedTimeRetryPolicy(SessionsLimitedTimeRetryPolicy&& rhs) noexcept + : SessionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SessionsLimitedTimeRetryPolicy( + SessionsLimitedTimeRetryPolicy const& rhs) noexcept + : SessionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SessionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::SessionsRetryTraits> + impl_; +}; /** * The `SessionsConnection` object for `SessionsClient`. diff --git a/google/cloud/dialogflow_cx/test_cases_connection.h b/google/cloud/dialogflow_cx/test_cases_connection.h index 8ef84088a3cc7..753e92275090c 100644 --- a/google/cloud/dialogflow_cx/test_cases_connection.h +++ b/google/cloud/dialogflow_cx/test_cases_connection.h @@ -39,16 +39,133 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TestCasesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::TestCasesRetryTraits>; +/// The retry policy for `TestCasesConnection`. +class TestCasesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TestCasesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TestCasesLimitedErrorCountRetryPolicy : public TestCasesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TestCasesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TestCasesLimitedErrorCountRetryPolicy( + TestCasesLimitedErrorCountRetryPolicy&& rhs) noexcept + : TestCasesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TestCasesLimitedErrorCountRetryPolicy( + TestCasesLimitedErrorCountRetryPolicy const& rhs) noexcept + : TestCasesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TestCasesRetryPolicy; -using TestCasesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::TestCasesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::TestCasesRetryTraits> + impl_; +}; + +/** + * A retry policy for `TestCasesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TestCasesLimitedTimeRetryPolicy : public TestCasesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TestCasesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TestCasesLimitedTimeRetryPolicy( + TestCasesLimitedTimeRetryPolicy&& rhs) noexcept + : TestCasesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TestCasesLimitedTimeRetryPolicy( + TestCasesLimitedTimeRetryPolicy const& rhs) noexcept + : TestCasesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using TestCasesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::TestCasesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TestCasesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::TestCasesRetryTraits> + impl_; +}; /** * The `TestCasesConnection` object for `TestCasesClient`. diff --git a/google/cloud/dialogflow_cx/transition_route_groups_connection.h b/google/cloud/dialogflow_cx/transition_route_groups_connection.h index 53afac101e421..bf86c676c35c5 100644 --- a/google/cloud/dialogflow_cx/transition_route_groups_connection.h +++ b/google/cloud/dialogflow_cx/transition_route_groups_connection.h @@ -36,17 +36,139 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TransitionRouteGroupsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::TransitionRouteGroupsRetryTraits>; +/// The retry policy for `TransitionRouteGroupsConnection`. +class TransitionRouteGroupsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TransitionRouteGroupsConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TransitionRouteGroupsLimitedErrorCountRetryPolicy + : public TransitionRouteGroupsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TransitionRouteGroupsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + TransitionRouteGroupsLimitedErrorCountRetryPolicy( + TransitionRouteGroupsLimitedErrorCountRetryPolicy&& rhs) noexcept + : TransitionRouteGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + TransitionRouteGroupsLimitedErrorCountRetryPolicy( + TransitionRouteGroupsLimitedErrorCountRetryPolicy const& rhs) noexcept + : TransitionRouteGroupsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TransitionRouteGroupsRetryPolicy; -using TransitionRouteGroupsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::TransitionRouteGroupsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::TransitionRouteGroupsRetryTraits> + impl_; +}; + +/** + * A retry policy for `TransitionRouteGroupsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TransitionRouteGroupsLimitedTimeRetryPolicy + : public TransitionRouteGroupsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TransitionRouteGroupsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TransitionRouteGroupsLimitedTimeRetryPolicy( + TransitionRouteGroupsLimitedTimeRetryPolicy&& rhs) noexcept + : TransitionRouteGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TransitionRouteGroupsLimitedTimeRetryPolicy( + TransitionRouteGroupsLimitedTimeRetryPolicy const& rhs) noexcept + : TransitionRouteGroupsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using TransitionRouteGroupsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::TransitionRouteGroupsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TransitionRouteGroupsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::TransitionRouteGroupsRetryTraits> + impl_; +}; /** * The `TransitionRouteGroupsConnection` object for diff --git a/google/cloud/dialogflow_cx/versions_connection.h b/google/cloud/dialogflow_cx/versions_connection.h index e740fa621a7ae..5332971451d66 100644 --- a/google/cloud/dialogflow_cx/versions_connection.h +++ b/google/cloud/dialogflow_cx/versions_connection.h @@ -40,16 +40,131 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VersionsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::VersionsRetryTraits>; +/// The retry policy for `VersionsConnection`. +class VersionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VersionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::VersionsRetryTraits>; +/** + * A retry policy for `VersionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VersionsLimitedErrorCountRetryPolicy : public VersionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VersionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VersionsLimitedErrorCountRetryPolicy( + VersionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : VersionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VersionsLimitedErrorCountRetryPolicy( + VersionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : VersionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VersionsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::VersionsRetryTraits> + impl_; +}; -using VersionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::VersionsRetryTraits>; +/** + * A retry policy for `VersionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VersionsLimitedTimeRetryPolicy : public VersionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VersionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VersionsLimitedTimeRetryPolicy(VersionsLimitedTimeRetryPolicy&& rhs) noexcept + : VersionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VersionsLimitedTimeRetryPolicy( + VersionsLimitedTimeRetryPolicy const& rhs) noexcept + : VersionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VersionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::VersionsRetryTraits> + impl_; +}; /** * The `VersionsConnection` object for `VersionsClient`. diff --git a/google/cloud/dialogflow_cx/webhooks_connection.h b/google/cloud/dialogflow_cx/webhooks_connection.h index 67a77087a6692..c02f7da6c323a 100644 --- a/google/cloud/dialogflow_cx/webhooks_connection.h +++ b/google/cloud/dialogflow_cx/webhooks_connection.h @@ -36,16 +36,131 @@ namespace cloud { namespace dialogflow_cx { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using WebhooksRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_cx_internal::WebhooksRetryTraits>; +/// The retry policy for `WebhooksConnection`. +class WebhooksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using WebhooksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_cx_internal::WebhooksRetryTraits>; +/** + * A retry policy for `WebhooksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WebhooksLimitedErrorCountRetryPolicy : public WebhooksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit WebhooksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + WebhooksLimitedErrorCountRetryPolicy( + WebhooksLimitedErrorCountRetryPolicy&& rhs) noexcept + : WebhooksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + WebhooksLimitedErrorCountRetryPolicy( + WebhooksLimitedErrorCountRetryPolicy const& rhs) noexcept + : WebhooksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = WebhooksRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_cx_internal::WebhooksRetryTraits> + impl_; +}; -using WebhooksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_cx_internal::WebhooksRetryTraits>; +/** + * A retry policy for `WebhooksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WebhooksLimitedTimeRetryPolicy : public WebhooksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit WebhooksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + WebhooksLimitedTimeRetryPolicy(WebhooksLimitedTimeRetryPolicy&& rhs) noexcept + : WebhooksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + WebhooksLimitedTimeRetryPolicy( + WebhooksLimitedTimeRetryPolicy const& rhs) noexcept + : WebhooksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = WebhooksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_cx_internal::WebhooksRetryTraits> + impl_; +}; /** * The `WebhooksConnection` object for `WebhooksClient`. diff --git a/google/cloud/dialogflow_es/agents_connection.h b/google/cloud/dialogflow_es/agents_connection.h index 3793ba608cfd6..a2694532f5bf8 100644 --- a/google/cloud/dialogflow_es/agents_connection.h +++ b/google/cloud/dialogflow_es/agents_connection.h @@ -40,16 +40,130 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AgentsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::AgentsRetryTraits>; +/// The retry policy for `AgentsConnection`. +class AgentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AgentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::AgentsRetryTraits>; +/** + * A retry policy for `AgentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AgentsLimitedErrorCountRetryPolicy : public AgentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AgentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AgentsLimitedErrorCountRetryPolicy( + AgentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : AgentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AgentsLimitedErrorCountRetryPolicy( + AgentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : AgentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AgentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::AgentsRetryTraits> + impl_; +}; -using AgentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::AgentsRetryTraits>; +/** + * A retry policy for `AgentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AgentsLimitedTimeRetryPolicy : public AgentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AgentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AgentsLimitedTimeRetryPolicy(AgentsLimitedTimeRetryPolicy&& rhs) noexcept + : AgentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AgentsLimitedTimeRetryPolicy(AgentsLimitedTimeRetryPolicy const& rhs) noexcept + : AgentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AgentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::AgentsRetryTraits> + impl_; +}; /** * The `AgentsConnection` object for `AgentsClient`. diff --git a/google/cloud/dialogflow_es/answer_records_connection.h b/google/cloud/dialogflow_es/answer_records_connection.h index 11d70ceb6939f..b7eeccdb48a09 100644 --- a/google/cloud/dialogflow_es/answer_records_connection.h +++ b/google/cloud/dialogflow_es/answer_records_connection.h @@ -36,17 +36,134 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AnswerRecordsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::AnswerRecordsRetryTraits>; +/// The retry policy for `AnswerRecordsConnection`. +class AnswerRecordsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AnswerRecordsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AnswerRecordsLimitedErrorCountRetryPolicy + : public AnswerRecordsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AnswerRecordsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AnswerRecordsLimitedErrorCountRetryPolicy( + AnswerRecordsLimitedErrorCountRetryPolicy&& rhs) noexcept + : AnswerRecordsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AnswerRecordsLimitedErrorCountRetryPolicy( + AnswerRecordsLimitedErrorCountRetryPolicy const& rhs) noexcept + : AnswerRecordsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AnswerRecordsRetryPolicy; -using AnswerRecordsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::AnswerRecordsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::AnswerRecordsRetryTraits> + impl_; +}; + +/** + * A retry policy for `AnswerRecordsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AnswerRecordsLimitedTimeRetryPolicy : public AnswerRecordsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AnswerRecordsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AnswerRecordsLimitedTimeRetryPolicy( + AnswerRecordsLimitedTimeRetryPolicy&& rhs) noexcept + : AnswerRecordsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AnswerRecordsLimitedTimeRetryPolicy( + AnswerRecordsLimitedTimeRetryPolicy const& rhs) noexcept + : AnswerRecordsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AnswerRecordsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::AnswerRecordsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AnswerRecordsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::AnswerRecordsRetryTraits> + impl_; +}; /** * The `AnswerRecordsConnection` object for `AnswerRecordsClient`. diff --git a/google/cloud/dialogflow_es/contexts_connection.h b/google/cloud/dialogflow_es/contexts_connection.h index 5df9f6939a874..bac57adb46b87 100644 --- a/google/cloud/dialogflow_es/contexts_connection.h +++ b/google/cloud/dialogflow_es/contexts_connection.h @@ -36,16 +36,131 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ContextsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::ContextsRetryTraits>; +/// The retry policy for `ContextsConnection`. +class ContextsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ContextsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::ContextsRetryTraits>; +/** + * A retry policy for `ContextsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ContextsLimitedErrorCountRetryPolicy : public ContextsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ContextsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ContextsLimitedErrorCountRetryPolicy( + ContextsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ContextsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ContextsLimitedErrorCountRetryPolicy( + ContextsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ContextsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ContextsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::ContextsRetryTraits> + impl_; +}; -using ContextsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::ContextsRetryTraits>; +/** + * A retry policy for `ContextsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ContextsLimitedTimeRetryPolicy : public ContextsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ContextsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ContextsLimitedTimeRetryPolicy(ContextsLimitedTimeRetryPolicy&& rhs) noexcept + : ContextsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ContextsLimitedTimeRetryPolicy( + ContextsLimitedTimeRetryPolicy const& rhs) noexcept + : ContextsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ContextsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::ContextsRetryTraits> + impl_; +}; /** * The `ContextsConnection` object for `ContextsClient`. diff --git a/google/cloud/dialogflow_es/conversation_datasets_connection.h b/google/cloud/dialogflow_es/conversation_datasets_connection.h index 1f146cea30980..b05623fc4a246 100644 --- a/google/cloud/dialogflow_es/conversation_datasets_connection.h +++ b/google/cloud/dialogflow_es/conversation_datasets_connection.h @@ -39,17 +39,138 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ConversationDatasetsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::ConversationDatasetsRetryTraits>; +/// The retry policy for `ConversationDatasetsConnection`. +class ConversationDatasetsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ConversationDatasetsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConversationDatasetsLimitedErrorCountRetryPolicy + : public ConversationDatasetsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ConversationDatasetsLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ConversationDatasetsLimitedErrorCountRetryPolicy( + ConversationDatasetsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ConversationDatasetsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ConversationDatasetsLimitedErrorCountRetryPolicy( + ConversationDatasetsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ConversationDatasetsLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConversationDatasetsRetryPolicy; -using ConversationDatasetsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::ConversationDatasetsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::ConversationDatasetsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ConversationDatasetsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConversationDatasetsLimitedTimeRetryPolicy + : public ConversationDatasetsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ConversationDatasetsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ConversationDatasetsLimitedTimeRetryPolicy( + ConversationDatasetsLimitedTimeRetryPolicy&& rhs) noexcept + : ConversationDatasetsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ConversationDatasetsLimitedTimeRetryPolicy( + ConversationDatasetsLimitedTimeRetryPolicy const& rhs) noexcept + : ConversationDatasetsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ConversationDatasetsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::ConversationDatasetsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConversationDatasetsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::ConversationDatasetsRetryTraits> + impl_; +}; /** * The `ConversationDatasetsConnection` object for `ConversationDatasetsClient`. diff --git a/google/cloud/dialogflow_es/conversation_models_connection.h b/google/cloud/dialogflow_es/conversation_models_connection.h index f75667b68976f..39bcd11c54993 100644 --- a/google/cloud/dialogflow_es/conversation_models_connection.h +++ b/google/cloud/dialogflow_es/conversation_models_connection.h @@ -39,17 +39,137 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ConversationModelsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::ConversationModelsRetryTraits>; +/// The retry policy for `ConversationModelsConnection`. +class ConversationModelsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ConversationModelsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConversationModelsLimitedErrorCountRetryPolicy + : public ConversationModelsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ConversationModelsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ConversationModelsLimitedErrorCountRetryPolicy( + ConversationModelsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ConversationModelsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + ConversationModelsLimitedErrorCountRetryPolicy( + ConversationModelsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ConversationModelsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConversationModelsRetryPolicy; -using ConversationModelsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::ConversationModelsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::ConversationModelsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ConversationModelsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConversationModelsLimitedTimeRetryPolicy + : public ConversationModelsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ConversationModelsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ConversationModelsLimitedTimeRetryPolicy( + ConversationModelsLimitedTimeRetryPolicy&& rhs) noexcept + : ConversationModelsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ConversationModelsLimitedTimeRetryPolicy( + ConversationModelsLimitedTimeRetryPolicy const& rhs) noexcept + : ConversationModelsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ConversationModelsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::ConversationModelsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConversationModelsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::ConversationModelsRetryTraits> + impl_; +}; /** * The `ConversationModelsConnection` object for `ConversationModelsClient`. diff --git a/google/cloud/dialogflow_es/conversation_profiles_connection.h b/google/cloud/dialogflow_es/conversation_profiles_connection.h index 61bf8f1068410..3d42e57bd4ddb 100644 --- a/google/cloud/dialogflow_es/conversation_profiles_connection.h +++ b/google/cloud/dialogflow_es/conversation_profiles_connection.h @@ -39,17 +39,138 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ConversationProfilesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::ConversationProfilesRetryTraits>; +/// The retry policy for `ConversationProfilesConnection`. +class ConversationProfilesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ConversationProfilesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConversationProfilesLimitedErrorCountRetryPolicy + : public ConversationProfilesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ConversationProfilesLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ConversationProfilesLimitedErrorCountRetryPolicy( + ConversationProfilesLimitedErrorCountRetryPolicy&& rhs) noexcept + : ConversationProfilesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ConversationProfilesLimitedErrorCountRetryPolicy( + ConversationProfilesLimitedErrorCountRetryPolicy const& rhs) noexcept + : ConversationProfilesLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConversationProfilesRetryPolicy; -using ConversationProfilesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::ConversationProfilesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::ConversationProfilesRetryTraits> + impl_; +}; + +/** + * A retry policy for `ConversationProfilesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConversationProfilesLimitedTimeRetryPolicy + : public ConversationProfilesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ConversationProfilesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ConversationProfilesLimitedTimeRetryPolicy( + ConversationProfilesLimitedTimeRetryPolicy&& rhs) noexcept + : ConversationProfilesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ConversationProfilesLimitedTimeRetryPolicy( + ConversationProfilesLimitedTimeRetryPolicy const& rhs) noexcept + : ConversationProfilesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ConversationProfilesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::ConversationProfilesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConversationProfilesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::ConversationProfilesRetryTraits> + impl_; +}; /** * The `ConversationProfilesConnection` object for `ConversationProfilesClient`. diff --git a/google/cloud/dialogflow_es/conversations_connection.h b/google/cloud/dialogflow_es/conversations_connection.h index 7c3c0b6ca81aa..098b168192160 100644 --- a/google/cloud/dialogflow_es/conversations_connection.h +++ b/google/cloud/dialogflow_es/conversations_connection.h @@ -36,17 +36,134 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ConversationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::ConversationsRetryTraits>; +/// The retry policy for `ConversationsConnection`. +class ConversationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ConversationsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConversationsLimitedErrorCountRetryPolicy + : public ConversationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ConversationsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ConversationsLimitedErrorCountRetryPolicy( + ConversationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ConversationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ConversationsLimitedErrorCountRetryPolicy( + ConversationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ConversationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConversationsRetryPolicy; -using ConversationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::ConversationsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::ConversationsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ConversationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ConversationsLimitedTimeRetryPolicy : public ConversationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ConversationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ConversationsLimitedTimeRetryPolicy( + ConversationsLimitedTimeRetryPolicy&& rhs) noexcept + : ConversationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ConversationsLimitedTimeRetryPolicy( + ConversationsLimitedTimeRetryPolicy const& rhs) noexcept + : ConversationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ConversationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::ConversationsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ConversationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::ConversationsRetryTraits> + impl_; +}; /** * The `ConversationsConnection` object for `ConversationsClient`. diff --git a/google/cloud/dialogflow_es/documents_connection.h b/google/cloud/dialogflow_es/documents_connection.h index 565db503530f4..e32ba4495a022 100644 --- a/google/cloud/dialogflow_es/documents_connection.h +++ b/google/cloud/dialogflow_es/documents_connection.h @@ -39,16 +39,133 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DocumentsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::DocumentsRetryTraits>; +/// The retry policy for `DocumentsConnection`. +class DocumentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DocumentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentsLimitedErrorCountRetryPolicy : public DocumentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DocumentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DocumentsLimitedErrorCountRetryPolicy( + DocumentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : DocumentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DocumentsLimitedErrorCountRetryPolicy( + DocumentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : DocumentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentsRetryPolicy; -using DocumentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::DocumentsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::DocumentsRetryTraits> + impl_; +}; + +/** + * A retry policy for `DocumentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentsLimitedTimeRetryPolicy : public DocumentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DocumentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DocumentsLimitedTimeRetryPolicy( + DocumentsLimitedTimeRetryPolicy&& rhs) noexcept + : DocumentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DocumentsLimitedTimeRetryPolicy( + DocumentsLimitedTimeRetryPolicy const& rhs) noexcept + : DocumentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DocumentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::DocumentsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::DocumentsRetryTraits> + impl_; +}; /** * The `DocumentsConnection` object for `DocumentsClient`. diff --git a/google/cloud/dialogflow_es/entity_types_connection.h b/google/cloud/dialogflow_es/entity_types_connection.h index 5c3465a2a734a..1a23244c7d3f6 100644 --- a/google/cloud/dialogflow_es/entity_types_connection.h +++ b/google/cloud/dialogflow_es/entity_types_connection.h @@ -40,16 +40,133 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EntityTypesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::EntityTypesRetryTraits>; +/// The retry policy for `EntityTypesConnection`. +class EntityTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `EntityTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EntityTypesLimitedErrorCountRetryPolicy : public EntityTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EntityTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EntityTypesLimitedErrorCountRetryPolicy( + EntityTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : EntityTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EntityTypesLimitedErrorCountRetryPolicy( + EntityTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : EntityTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EntityTypesRetryPolicy; -using EntityTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::EntityTypesRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::EntityTypesRetryTraits> + impl_; +}; + +/** + * A retry policy for `EntityTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EntityTypesLimitedTimeRetryPolicy : public EntityTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EntityTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EntityTypesLimitedTimeRetryPolicy( + EntityTypesLimitedTimeRetryPolicy&& rhs) noexcept + : EntityTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EntityTypesLimitedTimeRetryPolicy( + EntityTypesLimitedTimeRetryPolicy const& rhs) noexcept + : EntityTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using EntityTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::EntityTypesRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EntityTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::EntityTypesRetryTraits> + impl_; +}; /** * The `EntityTypesConnection` object for `EntityTypesClient`. diff --git a/google/cloud/dialogflow_es/environments_connection.h b/google/cloud/dialogflow_es/environments_connection.h index f259e374c8533..4fdd7a0282244 100644 --- a/google/cloud/dialogflow_es/environments_connection.h +++ b/google/cloud/dialogflow_es/environments_connection.h @@ -36,17 +36,134 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EnvironmentsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::EnvironmentsRetryTraits>; +/// The retry policy for `EnvironmentsConnection`. +class EnvironmentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using EnvironmentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::EnvironmentsRetryTraits>; +/** + * A retry policy for `EnvironmentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EnvironmentsLimitedErrorCountRetryPolicy + : public EnvironmentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EnvironmentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EnvironmentsLimitedErrorCountRetryPolicy( + EnvironmentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : EnvironmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EnvironmentsLimitedErrorCountRetryPolicy( + EnvironmentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : EnvironmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EnvironmentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::EnvironmentsRetryTraits> + impl_; +}; -using EnvironmentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::EnvironmentsRetryTraits>; +/** + * A retry policy for `EnvironmentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EnvironmentsLimitedTimeRetryPolicy : public EnvironmentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EnvironmentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EnvironmentsLimitedTimeRetryPolicy( + EnvironmentsLimitedTimeRetryPolicy&& rhs) noexcept + : EnvironmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EnvironmentsLimitedTimeRetryPolicy( + EnvironmentsLimitedTimeRetryPolicy const& rhs) noexcept + : EnvironmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EnvironmentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::EnvironmentsRetryTraits> + impl_; +}; /** * The `EnvironmentsConnection` object for `EnvironmentsClient`. diff --git a/google/cloud/dialogflow_es/fulfillments_connection.h b/google/cloud/dialogflow_es/fulfillments_connection.h index 498dca9bb35e6..c501b35263f52 100644 --- a/google/cloud/dialogflow_es/fulfillments_connection.h +++ b/google/cloud/dialogflow_es/fulfillments_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FulfillmentsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::FulfillmentsRetryTraits>; +/// The retry policy for `FulfillmentsConnection`. +class FulfillmentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `FulfillmentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FulfillmentsLimitedErrorCountRetryPolicy + : public FulfillmentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FulfillmentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + FulfillmentsLimitedErrorCountRetryPolicy( + FulfillmentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : FulfillmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + FulfillmentsLimitedErrorCountRetryPolicy( + FulfillmentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : FulfillmentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FulfillmentsRetryPolicy; -using FulfillmentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::FulfillmentsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::FulfillmentsRetryTraits> + impl_; +}; + +/** + * A retry policy for `FulfillmentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FulfillmentsLimitedTimeRetryPolicy : public FulfillmentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FulfillmentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FulfillmentsLimitedTimeRetryPolicy( + FulfillmentsLimitedTimeRetryPolicy&& rhs) noexcept + : FulfillmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + FulfillmentsLimitedTimeRetryPolicy( + FulfillmentsLimitedTimeRetryPolicy const& rhs) noexcept + : FulfillmentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using FulfillmentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::FulfillmentsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FulfillmentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::FulfillmentsRetryTraits> + impl_; +}; /** * The `FulfillmentsConnection` object for `FulfillmentsClient`. diff --git a/google/cloud/dialogflow_es/intents_connection.h b/google/cloud/dialogflow_es/intents_connection.h index 9139dede28c51..ca215754840fe 100644 --- a/google/cloud/dialogflow_es/intents_connection.h +++ b/google/cloud/dialogflow_es/intents_connection.h @@ -40,16 +40,131 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IntentsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::IntentsRetryTraits>; +/// The retry policy for `IntentsConnection`. +class IntentsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using IntentsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::IntentsRetryTraits>; +/** + * A retry policy for `IntentsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IntentsLimitedErrorCountRetryPolicy : public IntentsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IntentsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + IntentsLimitedErrorCountRetryPolicy( + IntentsLimitedErrorCountRetryPolicy&& rhs) noexcept + : IntentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + IntentsLimitedErrorCountRetryPolicy( + IntentsLimitedErrorCountRetryPolicy const& rhs) noexcept + : IntentsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IntentsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::IntentsRetryTraits> + impl_; +}; -using IntentsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::IntentsRetryTraits>; +/** + * A retry policy for `IntentsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IntentsLimitedTimeRetryPolicy : public IntentsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IntentsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IntentsLimitedTimeRetryPolicy(IntentsLimitedTimeRetryPolicy&& rhs) noexcept + : IntentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IntentsLimitedTimeRetryPolicy( + IntentsLimitedTimeRetryPolicy const& rhs) noexcept + : IntentsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IntentsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::IntentsRetryTraits> + impl_; +}; /** * The `IntentsConnection` object for `IntentsClient`. diff --git a/google/cloud/dialogflow_es/knowledge_bases_connection.h b/google/cloud/dialogflow_es/knowledge_bases_connection.h index b57eddf6e226a..0d628d8ca65ad 100644 --- a/google/cloud/dialogflow_es/knowledge_bases_connection.h +++ b/google/cloud/dialogflow_es/knowledge_bases_connection.h @@ -36,17 +36,134 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using KnowledgeBasesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::KnowledgeBasesRetryTraits>; +/// The retry policy for `KnowledgeBasesConnection`. +class KnowledgeBasesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using KnowledgeBasesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::KnowledgeBasesRetryTraits>; +/** + * A retry policy for `KnowledgeBasesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class KnowledgeBasesLimitedErrorCountRetryPolicy + : public KnowledgeBasesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit KnowledgeBasesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + KnowledgeBasesLimitedErrorCountRetryPolicy( + KnowledgeBasesLimitedErrorCountRetryPolicy&& rhs) noexcept + : KnowledgeBasesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + KnowledgeBasesLimitedErrorCountRetryPolicy( + KnowledgeBasesLimitedErrorCountRetryPolicy const& rhs) noexcept + : KnowledgeBasesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = KnowledgeBasesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::KnowledgeBasesRetryTraits> + impl_; +}; -using KnowledgeBasesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::KnowledgeBasesRetryTraits>; +/** + * A retry policy for `KnowledgeBasesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class KnowledgeBasesLimitedTimeRetryPolicy : public KnowledgeBasesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit KnowledgeBasesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + KnowledgeBasesLimitedTimeRetryPolicy( + KnowledgeBasesLimitedTimeRetryPolicy&& rhs) noexcept + : KnowledgeBasesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + KnowledgeBasesLimitedTimeRetryPolicy( + KnowledgeBasesLimitedTimeRetryPolicy const& rhs) noexcept + : KnowledgeBasesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = KnowledgeBasesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::KnowledgeBasesRetryTraits> + impl_; +}; /** * The `KnowledgeBasesConnection` object for `KnowledgeBasesClient`. diff --git a/google/cloud/dialogflow_es/participants_connection.h b/google/cloud/dialogflow_es/participants_connection.h index 389d958a9e936..a87ef70bb0fd8 100644 --- a/google/cloud/dialogflow_es/participants_connection.h +++ b/google/cloud/dialogflow_es/participants_connection.h @@ -37,17 +37,134 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ParticipantsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::ParticipantsRetryTraits>; +/// The retry policy for `ParticipantsConnection`. +class ParticipantsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ParticipantsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ParticipantsLimitedErrorCountRetryPolicy + : public ParticipantsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ParticipantsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ParticipantsLimitedErrorCountRetryPolicy( + ParticipantsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ParticipantsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ParticipantsLimitedErrorCountRetryPolicy( + ParticipantsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ParticipantsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ParticipantsRetryPolicy; -using ParticipantsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::ParticipantsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::ParticipantsRetryTraits> + impl_; +}; + +/** + * A retry policy for `ParticipantsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ParticipantsLimitedTimeRetryPolicy : public ParticipantsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ParticipantsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ParticipantsLimitedTimeRetryPolicy( + ParticipantsLimitedTimeRetryPolicy&& rhs) noexcept + : ParticipantsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ParticipantsLimitedTimeRetryPolicy( + ParticipantsLimitedTimeRetryPolicy const& rhs) noexcept + : ParticipantsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ParticipantsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::ParticipantsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ParticipantsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::ParticipantsRetryTraits> + impl_; +}; /** * The `ParticipantsConnection` object for `ParticipantsClient`. diff --git a/google/cloud/dialogflow_es/session_entity_types_connection.h b/google/cloud/dialogflow_es/session_entity_types_connection.h index 30f686d236d48..77c1559d6763d 100644 --- a/google/cloud/dialogflow_es/session_entity_types_connection.h +++ b/google/cloud/dialogflow_es/session_entity_types_connection.h @@ -36,17 +36,137 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SessionEntityTypesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::SessionEntityTypesRetryTraits>; +/// The retry policy for `SessionEntityTypesConnection`. +class SessionEntityTypesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SessionEntityTypesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::SessionEntityTypesRetryTraits>; +/** + * A retry policy for `SessionEntityTypesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SessionEntityTypesLimitedErrorCountRetryPolicy + : public SessionEntityTypesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SessionEntityTypesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SessionEntityTypesLimitedErrorCountRetryPolicy( + SessionEntityTypesLimitedErrorCountRetryPolicy&& rhs) noexcept + : SessionEntityTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + SessionEntityTypesLimitedErrorCountRetryPolicy( + SessionEntityTypesLimitedErrorCountRetryPolicy const& rhs) noexcept + : SessionEntityTypesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SessionEntityTypesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::SessionEntityTypesRetryTraits> + impl_; +}; -using SessionEntityTypesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::SessionEntityTypesRetryTraits>; +/** + * A retry policy for `SessionEntityTypesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SessionEntityTypesLimitedTimeRetryPolicy + : public SessionEntityTypesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SessionEntityTypesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SessionEntityTypesLimitedTimeRetryPolicy( + SessionEntityTypesLimitedTimeRetryPolicy&& rhs) noexcept + : SessionEntityTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SessionEntityTypesLimitedTimeRetryPolicy( + SessionEntityTypesLimitedTimeRetryPolicy const& rhs) noexcept + : SessionEntityTypesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SessionEntityTypesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::SessionEntityTypesRetryTraits> + impl_; +}; /** * The `SessionEntityTypesConnection` object for `SessionEntityTypesClient`. diff --git a/google/cloud/dialogflow_es/sessions_connection.h b/google/cloud/dialogflow_es/sessions_connection.h index f9fa278ae2dc0..d217e3bcbefed 100644 --- a/google/cloud/dialogflow_es/sessions_connection.h +++ b/google/cloud/dialogflow_es/sessions_connection.h @@ -36,16 +36,131 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SessionsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::SessionsRetryTraits>; +/// The retry policy for `SessionsConnection`. +class SessionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SessionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SessionsLimitedErrorCountRetryPolicy : public SessionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SessionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SessionsLimitedErrorCountRetryPolicy( + SessionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : SessionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SessionsLimitedErrorCountRetryPolicy( + SessionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : SessionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SessionsRetryPolicy; -using SessionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::SessionsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::SessionsRetryTraits> + impl_; +}; + +/** + * A retry policy for `SessionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SessionsLimitedTimeRetryPolicy : public SessionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SessionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SessionsLimitedTimeRetryPolicy(SessionsLimitedTimeRetryPolicy&& rhs) noexcept + : SessionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SessionsLimitedTimeRetryPolicy( + SessionsLimitedTimeRetryPolicy const& rhs) noexcept + : SessionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SessionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::SessionsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SessionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::SessionsRetryTraits> + impl_; +}; /** * The `SessionsConnection` object for `SessionsClient`. diff --git a/google/cloud/dialogflow_es/versions_connection.h b/google/cloud/dialogflow_es/versions_connection.h index aefd078ccf877..3250742045d4a 100644 --- a/google/cloud/dialogflow_es/versions_connection.h +++ b/google/cloud/dialogflow_es/versions_connection.h @@ -36,16 +36,131 @@ namespace cloud { namespace dialogflow_es { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VersionsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dialogflow_es_internal::VersionsRetryTraits>; +/// The retry policy for `VersionsConnection`. +class VersionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VersionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dialogflow_es_internal::VersionsRetryTraits>; +/** + * A retry policy for `VersionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VersionsLimitedErrorCountRetryPolicy : public VersionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VersionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VersionsLimitedErrorCountRetryPolicy( + VersionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : VersionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VersionsLimitedErrorCountRetryPolicy( + VersionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : VersionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VersionsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dialogflow_es_internal::VersionsRetryTraits> + impl_; +}; -using VersionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dialogflow_es_internal::VersionsRetryTraits>; +/** + * A retry policy for `VersionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VersionsLimitedTimeRetryPolicy : public VersionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VersionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VersionsLimitedTimeRetryPolicy(VersionsLimitedTimeRetryPolicy&& rhs) noexcept + : VersionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VersionsLimitedTimeRetryPolicy( + VersionsLimitedTimeRetryPolicy const& rhs) noexcept + : VersionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VersionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dialogflow_es_internal::VersionsRetryTraits> + impl_; +}; /** * The `VersionsConnection` object for `VersionsClient`. diff --git a/google/cloud/dlp/v2/dlp_connection.h b/google/cloud/dlp/v2/dlp_connection.h index e2da1a378f111..da9cd5c9d62f8 100644 --- a/google/cloud/dlp/v2/dlp_connection.h +++ b/google/cloud/dlp/v2/dlp_connection.h @@ -35,16 +35,133 @@ namespace cloud { namespace dlp_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DlpServiceRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - dlp_v2_internal::DlpServiceRetryTraits>; +/// The retry policy for `DlpServiceConnection`. +class DlpServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DlpServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - dlp_v2_internal::DlpServiceRetryTraits>; +/** + * A retry policy for `DlpServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DlpServiceLimitedErrorCountRetryPolicy : public DlpServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DlpServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DlpServiceLimitedErrorCountRetryPolicy( + DlpServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DlpServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DlpServiceLimitedErrorCountRetryPolicy( + DlpServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DlpServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DlpServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + dlp_v2_internal::DlpServiceRetryTraits> + impl_; +}; -using DlpServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - dlp_v2_internal::DlpServiceRetryTraits>; +/** + * A retry policy for `DlpServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DlpServiceLimitedTimeRetryPolicy : public DlpServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DlpServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DlpServiceLimitedTimeRetryPolicy( + DlpServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DlpServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DlpServiceLimitedTimeRetryPolicy( + DlpServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DlpServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DlpServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + dlp_v2_internal::DlpServiceRetryTraits> + impl_; +}; /** * The `DlpServiceConnection` object for `DlpServiceClient`. diff --git a/google/cloud/documentai/v1/document_processor_connection.h b/google/cloud/documentai/v1/document_processor_connection.h index b2d48d9342df8..54565960c37fa 100644 --- a/google/cloud/documentai/v1/document_processor_connection.h +++ b/google/cloud/documentai/v1/document_processor_connection.h @@ -39,17 +39,145 @@ namespace cloud { namespace documentai_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DocumentProcessorServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - documentai_v1_internal::DocumentProcessorServiceRetryTraits>; +/// The retry policy for `DocumentProcessorServiceConnection`. +class DocumentProcessorServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; -using DocumentProcessorServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - documentai_v1_internal::DocumentProcessorServiceRetryTraits>; +/** + * A retry policy for `DocumentProcessorServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentProcessorServiceLimitedErrorCountRetryPolicy + : public DocumentProcessorServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DocumentProcessorServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + DocumentProcessorServiceLimitedErrorCountRetryPolicy( + DocumentProcessorServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DocumentProcessorServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + DocumentProcessorServiceLimitedErrorCountRetryPolicy( + DocumentProcessorServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DocumentProcessorServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + DocumentProcessorServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentProcessorServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + documentai_v1_internal::DocumentProcessorServiceRetryTraits> + impl_; +}; -using DocumentProcessorServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - documentai_v1_internal::DocumentProcessorServiceRetryTraits>; +/** + * A retry policy for `DocumentProcessorServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DocumentProcessorServiceLimitedTimeRetryPolicy + : public DocumentProcessorServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DocumentProcessorServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DocumentProcessorServiceLimitedTimeRetryPolicy( + DocumentProcessorServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DocumentProcessorServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + DocumentProcessorServiceLimitedTimeRetryPolicy( + DocumentProcessorServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DocumentProcessorServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DocumentProcessorServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + documentai_v1_internal::DocumentProcessorServiceRetryTraits> + impl_; +}; /** * The `DocumentProcessorServiceConnection` object for diff --git a/google/cloud/domains/v1/domains_connection.h b/google/cloud/domains/v1/domains_connection.h index c25d9bb457b15..7d9b2b86d7ad8 100644 --- a/google/cloud/domains/v1/domains_connection.h +++ b/google/cloud/domains/v1/domains_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace domains_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DomainsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - domains_v1_internal::DomainsRetryTraits>; +/// The retry policy for `DomainsConnection`. +class DomainsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DomainsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DomainsLimitedErrorCountRetryPolicy : public DomainsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DomainsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DomainsLimitedErrorCountRetryPolicy( + DomainsLimitedErrorCountRetryPolicy&& rhs) noexcept + : DomainsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DomainsLimitedErrorCountRetryPolicy( + DomainsLimitedErrorCountRetryPolicy const& rhs) noexcept + : DomainsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DomainsRetryPolicy; -using DomainsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - domains_v1_internal::DomainsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + domains_v1_internal::DomainsRetryTraits> + impl_; +}; + +/** + * A retry policy for `DomainsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DomainsLimitedTimeRetryPolicy : public DomainsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DomainsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DomainsLimitedTimeRetryPolicy(DomainsLimitedTimeRetryPolicy&& rhs) noexcept + : DomainsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DomainsLimitedTimeRetryPolicy( + DomainsLimitedTimeRetryPolicy const& rhs) noexcept + : DomainsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DomainsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - domains_v1_internal::DomainsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DomainsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + domains_v1_internal::DomainsRetryTraits> + impl_; +}; /** * The `DomainsConnection` object for `DomainsClient`. diff --git a/google/cloud/edgecontainer/v1/edge_container_connection.h b/google/cloud/edgecontainer/v1/edge_container_connection.h index 7a46e5fee52a4..4cae3b950fb89 100644 --- a/google/cloud/edgecontainer/v1/edge_container_connection.h +++ b/google/cloud/edgecontainer/v1/edge_container_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace edgecontainer_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EdgeContainerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - edgecontainer_v1_internal::EdgeContainerRetryTraits>; +/// The retry policy for `EdgeContainerConnection`. +class EdgeContainerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `EdgeContainerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EdgeContainerLimitedErrorCountRetryPolicy + : public EdgeContainerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EdgeContainerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EdgeContainerLimitedErrorCountRetryPolicy( + EdgeContainerLimitedErrorCountRetryPolicy&& rhs) noexcept + : EdgeContainerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EdgeContainerLimitedErrorCountRetryPolicy( + EdgeContainerLimitedErrorCountRetryPolicy const& rhs) noexcept + : EdgeContainerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EdgeContainerRetryPolicy; -using EdgeContainerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - edgecontainer_v1_internal::EdgeContainerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + edgecontainer_v1_internal::EdgeContainerRetryTraits> + impl_; +}; + +/** + * A retry policy for `EdgeContainerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EdgeContainerLimitedTimeRetryPolicy : public EdgeContainerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EdgeContainerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EdgeContainerLimitedTimeRetryPolicy( + EdgeContainerLimitedTimeRetryPolicy&& rhs) noexcept + : EdgeContainerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EdgeContainerLimitedTimeRetryPolicy( + EdgeContainerLimitedTimeRetryPolicy const& rhs) noexcept + : EdgeContainerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using EdgeContainerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - edgecontainer_v1_internal::EdgeContainerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EdgeContainerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + edgecontainer_v1_internal::EdgeContainerRetryTraits> + impl_; +}; /** * The `EdgeContainerConnection` object for `EdgeContainerClient`. diff --git a/google/cloud/essentialcontacts/v1/essential_contacts_connection.h b/google/cloud/essentialcontacts/v1/essential_contacts_connection.h index f298308e97426..3ee8524a52e4a 100644 --- a/google/cloud/essentialcontacts/v1/essential_contacts_connection.h +++ b/google/cloud/essentialcontacts/v1/essential_contacts_connection.h @@ -35,17 +35,145 @@ namespace cloud { namespace essentialcontacts_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EssentialContactsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - essentialcontacts_v1_internal::EssentialContactsServiceRetryTraits>; +/// The retry policy for `EssentialContactsServiceConnection`. +class EssentialContactsServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `EssentialContactsServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EssentialContactsServiceLimitedErrorCountRetryPolicy + : public EssentialContactsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EssentialContactsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + EssentialContactsServiceLimitedErrorCountRetryPolicy( + EssentialContactsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : EssentialContactsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + EssentialContactsServiceLimitedErrorCountRetryPolicy( + EssentialContactsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : EssentialContactsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + EssentialContactsServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EssentialContactsServiceRetryPolicy; -using EssentialContactsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - essentialcontacts_v1_internal::EssentialContactsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + essentialcontacts_v1_internal::EssentialContactsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `EssentialContactsServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EssentialContactsServiceLimitedTimeRetryPolicy + : public EssentialContactsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EssentialContactsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EssentialContactsServiceLimitedTimeRetryPolicy( + EssentialContactsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : EssentialContactsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + EssentialContactsServiceLimitedTimeRetryPolicy( + EssentialContactsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : EssentialContactsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using EssentialContactsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - essentialcontacts_v1_internal::EssentialContactsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EssentialContactsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + essentialcontacts_v1_internal::EssentialContactsServiceRetryTraits> + impl_; +}; /** * The `EssentialContactsServiceConnection` object for diff --git a/google/cloud/eventarc/publishing/v1/publisher_connection.h b/google/cloud/eventarc/publishing/v1/publisher_connection.h index 51eb629e36e9e..ce8ca02922a15 100644 --- a/google/cloud/eventarc/publishing/v1/publisher_connection.h +++ b/google/cloud/eventarc/publishing/v1/publisher_connection.h @@ -34,16 +34,133 @@ namespace cloud { namespace eventarc_publishing_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PublisherRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - eventarc_publishing_v1_internal::PublisherRetryTraits>; +/// The retry policy for `PublisherConnection`. +class PublisherRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PublisherConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PublisherLimitedErrorCountRetryPolicy : public PublisherRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PublisherLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PublisherLimitedErrorCountRetryPolicy( + PublisherLimitedErrorCountRetryPolicy&& rhs) noexcept + : PublisherLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PublisherLimitedErrorCountRetryPolicy( + PublisherLimitedErrorCountRetryPolicy const& rhs) noexcept + : PublisherLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PublisherRetryPolicy; -using PublisherLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - eventarc_publishing_v1_internal::PublisherRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + eventarc_publishing_v1_internal::PublisherRetryTraits> + impl_; +}; + +/** + * A retry policy for `PublisherConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PublisherLimitedTimeRetryPolicy : public PublisherRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PublisherLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PublisherLimitedTimeRetryPolicy( + PublisherLimitedTimeRetryPolicy&& rhs) noexcept + : PublisherLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PublisherLimitedTimeRetryPolicy( + PublisherLimitedTimeRetryPolicy const& rhs) noexcept + : PublisherLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using PublisherLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - eventarc_publishing_v1_internal::PublisherRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PublisherRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + eventarc_publishing_v1_internal::PublisherRetryTraits> + impl_; +}; /** * The `PublisherConnection` object for `PublisherClient`. diff --git a/google/cloud/eventarc/v1/eventarc_connection.h b/google/cloud/eventarc/v1/eventarc_connection.h index f47250b4c8c08..c62bd68c1c902 100644 --- a/google/cloud/eventarc/v1/eventarc_connection.h +++ b/google/cloud/eventarc/v1/eventarc_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace eventarc_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EventarcRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - eventarc_v1_internal::EventarcRetryTraits>; +/// The retry policy for `EventarcConnection`. +class EventarcRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `EventarcConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class EventarcLimitedErrorCountRetryPolicy : public EventarcRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EventarcLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EventarcLimitedErrorCountRetryPolicy( + EventarcLimitedErrorCountRetryPolicy&& rhs) noexcept + : EventarcLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EventarcLimitedErrorCountRetryPolicy( + EventarcLimitedErrorCountRetryPolicy const& rhs) noexcept + : EventarcLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EventarcRetryPolicy; -using EventarcLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - eventarc_v1_internal::EventarcRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + eventarc_v1_internal::EventarcRetryTraits> + impl_; +}; + +/** + * A retry policy for `EventarcConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class EventarcLimitedTimeRetryPolicy : public EventarcRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EventarcLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EventarcLimitedTimeRetryPolicy(EventarcLimitedTimeRetryPolicy&& rhs) noexcept + : EventarcLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EventarcLimitedTimeRetryPolicy( + EventarcLimitedTimeRetryPolicy const& rhs) noexcept + : EventarcLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using EventarcLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - eventarc_v1_internal::EventarcRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EventarcRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + eventarc_v1_internal::EventarcRetryTraits> + impl_; +}; /** * The `EventarcConnection` object for `EventarcClient`. diff --git a/google/cloud/filestore/v1/cloud_filestore_manager_connection.h b/google/cloud/filestore/v1/cloud_filestore_manager_connection.h index ce5cfb387eee2..3c5a1f131e487 100644 --- a/google/cloud/filestore/v1/cloud_filestore_manager_connection.h +++ b/google/cloud/filestore/v1/cloud_filestore_manager_connection.h @@ -38,17 +38,139 @@ namespace cloud { namespace filestore_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudFilestoreManagerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - filestore_v1_internal::CloudFilestoreManagerRetryTraits>; +/// The retry policy for `CloudFilestoreManagerConnection`. +class CloudFilestoreManagerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CloudFilestoreManagerConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudFilestoreManagerLimitedErrorCountRetryPolicy + : public CloudFilestoreManagerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudFilestoreManagerLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + CloudFilestoreManagerLimitedErrorCountRetryPolicy( + CloudFilestoreManagerLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudFilestoreManagerLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + CloudFilestoreManagerLimitedErrorCountRetryPolicy( + CloudFilestoreManagerLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudFilestoreManagerLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudFilestoreManagerRetryPolicy; -using CloudFilestoreManagerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - filestore_v1_internal::CloudFilestoreManagerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + filestore_v1_internal::CloudFilestoreManagerRetryTraits> + impl_; +}; + +/** + * A retry policy for `CloudFilestoreManagerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudFilestoreManagerLimitedTimeRetryPolicy + : public CloudFilestoreManagerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudFilestoreManagerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudFilestoreManagerLimitedTimeRetryPolicy( + CloudFilestoreManagerLimitedTimeRetryPolicy&& rhs) noexcept + : CloudFilestoreManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudFilestoreManagerLimitedTimeRetryPolicy( + CloudFilestoreManagerLimitedTimeRetryPolicy const& rhs) noexcept + : CloudFilestoreManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CloudFilestoreManagerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - filestore_v1_internal::CloudFilestoreManagerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudFilestoreManagerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + filestore_v1_internal::CloudFilestoreManagerRetryTraits> + impl_; +}; /** * The `CloudFilestoreManagerConnection` object for diff --git a/google/cloud/functions/v1/cloud_functions_connection.h b/google/cloud/functions/v1/cloud_functions_connection.h index 875c8e3b054d4..c0730b22565f1 100644 --- a/google/cloud/functions/v1/cloud_functions_connection.h +++ b/google/cloud/functions/v1/cloud_functions_connection.h @@ -39,17 +39,139 @@ namespace cloud { namespace functions_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudFunctionsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - functions_v1_internal::CloudFunctionsServiceRetryTraits>; +/// The retry policy for `CloudFunctionsServiceConnection`. +class CloudFunctionsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CloudFunctionsServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudFunctionsServiceLimitedErrorCountRetryPolicy + : public CloudFunctionsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudFunctionsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + CloudFunctionsServiceLimitedErrorCountRetryPolicy( + CloudFunctionsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudFunctionsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + CloudFunctionsServiceLimitedErrorCountRetryPolicy( + CloudFunctionsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudFunctionsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudFunctionsServiceRetryPolicy; -using CloudFunctionsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - functions_v1_internal::CloudFunctionsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + functions_v1_internal::CloudFunctionsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `CloudFunctionsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudFunctionsServiceLimitedTimeRetryPolicy + : public CloudFunctionsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudFunctionsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudFunctionsServiceLimitedTimeRetryPolicy( + CloudFunctionsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CloudFunctionsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudFunctionsServiceLimitedTimeRetryPolicy( + CloudFunctionsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CloudFunctionsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CloudFunctionsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - functions_v1_internal::CloudFunctionsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudFunctionsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + functions_v1_internal::CloudFunctionsServiceRetryTraits> + impl_; +}; /** * The `CloudFunctionsServiceConnection` object for diff --git a/google/cloud/gkebackup/v1/backup_for_gke_connection.h b/google/cloud/gkebackup/v1/backup_for_gke_connection.h index 1c1334fec4dc2..6a7f789264ceb 100644 --- a/google/cloud/gkebackup/v1/backup_for_gke_connection.h +++ b/google/cloud/gkebackup/v1/backup_for_gke_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace gkebackup_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using BackupForGKERetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - gkebackup_v1_internal::BackupForGKERetryTraits>; +/// The retry policy for `BackupForGKEConnection`. +class BackupForGKERetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using BackupForGKELimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - gkebackup_v1_internal::BackupForGKERetryTraits>; +/** + * A retry policy for `BackupForGKEConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BackupForGKELimitedErrorCountRetryPolicy + : public BackupForGKERetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit BackupForGKELimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + BackupForGKELimitedErrorCountRetryPolicy( + BackupForGKELimitedErrorCountRetryPolicy&& rhs) noexcept + : BackupForGKELimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + BackupForGKELimitedErrorCountRetryPolicy( + BackupForGKELimitedErrorCountRetryPolicy const& rhs) noexcept + : BackupForGKELimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = BackupForGKERetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + gkebackup_v1_internal::BackupForGKERetryTraits> + impl_; +}; -using BackupForGKELimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - gkebackup_v1_internal::BackupForGKERetryTraits>; +/** + * A retry policy for `BackupForGKEConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class BackupForGKELimitedTimeRetryPolicy : public BackupForGKERetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit BackupForGKELimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + BackupForGKELimitedTimeRetryPolicy( + BackupForGKELimitedTimeRetryPolicy&& rhs) noexcept + : BackupForGKELimitedTimeRetryPolicy(rhs.maximum_duration()) {} + BackupForGKELimitedTimeRetryPolicy( + BackupForGKELimitedTimeRetryPolicy const& rhs) noexcept + : BackupForGKELimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = BackupForGKERetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + gkebackup_v1_internal::BackupForGKERetryTraits> + impl_; +}; /** * The `BackupForGKEConnection` object for `BackupForGKEClient`. diff --git a/google/cloud/gkehub/v1/gke_hub_connection.h b/google/cloud/gkehub/v1/gke_hub_connection.h index 89956c2cce954..29738885ca544 100644 --- a/google/cloud/gkehub/v1/gke_hub_connection.h +++ b/google/cloud/gkehub/v1/gke_hub_connection.h @@ -38,16 +38,130 @@ namespace cloud { namespace gkehub_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GkeHubRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - gkehub_v1_internal::GkeHubRetryTraits>; +/// The retry policy for `GkeHubConnection`. +class GkeHubRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using GkeHubLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - gkehub_v1_internal::GkeHubRetryTraits>; +/** + * A retry policy for `GkeHubConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GkeHubLimitedErrorCountRetryPolicy : public GkeHubRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GkeHubLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + GkeHubLimitedErrorCountRetryPolicy( + GkeHubLimitedErrorCountRetryPolicy&& rhs) noexcept + : GkeHubLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + GkeHubLimitedErrorCountRetryPolicy( + GkeHubLimitedErrorCountRetryPolicy const& rhs) noexcept + : GkeHubLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GkeHubRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + gkehub_v1_internal::GkeHubRetryTraits> + impl_; +}; -using GkeHubLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - gkehub_v1_internal::GkeHubRetryTraits>; +/** + * A retry policy for `GkeHubConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GkeHubLimitedTimeRetryPolicy : public GkeHubRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GkeHubLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GkeHubLimitedTimeRetryPolicy(GkeHubLimitedTimeRetryPolicy&& rhs) noexcept + : GkeHubLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + GkeHubLimitedTimeRetryPolicy(GkeHubLimitedTimeRetryPolicy const& rhs) noexcept + : GkeHubLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GkeHubRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + gkehub_v1_internal::GkeHubRetryTraits> + impl_; +}; /** * The `GkeHubConnection` object for `GkeHubClient`. diff --git a/google/cloud/gkemulticloud/v1/attached_clusters_connection.h b/google/cloud/gkemulticloud/v1/attached_clusters_connection.h index 66accb84fcfc8..f1c665b1b7cf7 100644 --- a/google/cloud/gkemulticloud/v1/attached_clusters_connection.h +++ b/google/cloud/gkemulticloud/v1/attached_clusters_connection.h @@ -39,17 +39,135 @@ namespace cloud { namespace gkemulticloud_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AttachedClustersRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - gkemulticloud_v1_internal::AttachedClustersRetryTraits>; +/// The retry policy for `AttachedClustersConnection`. +class AttachedClustersRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AttachedClustersConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AttachedClustersLimitedErrorCountRetryPolicy + : public AttachedClustersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AttachedClustersLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AttachedClustersLimitedErrorCountRetryPolicy( + AttachedClustersLimitedErrorCountRetryPolicy&& rhs) noexcept + : AttachedClustersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AttachedClustersLimitedErrorCountRetryPolicy( + AttachedClustersLimitedErrorCountRetryPolicy const& rhs) noexcept + : AttachedClustersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AttachedClustersRetryPolicy; -using AttachedClustersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - gkemulticloud_v1_internal::AttachedClustersRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + gkemulticloud_v1_internal::AttachedClustersRetryTraits> + impl_; +}; + +/** + * A retry policy for `AttachedClustersConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AttachedClustersLimitedTimeRetryPolicy + : public AttachedClustersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AttachedClustersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AttachedClustersLimitedTimeRetryPolicy( + AttachedClustersLimitedTimeRetryPolicy&& rhs) noexcept + : AttachedClustersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AttachedClustersLimitedTimeRetryPolicy( + AttachedClustersLimitedTimeRetryPolicy const& rhs) noexcept + : AttachedClustersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AttachedClustersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - gkemulticloud_v1_internal::AttachedClustersRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AttachedClustersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + gkemulticloud_v1_internal::AttachedClustersRetryTraits> + impl_; +}; /** * The `AttachedClustersConnection` object for `AttachedClustersClient`. diff --git a/google/cloud/gkemulticloud/v1/aws_clusters_connection.h b/google/cloud/gkemulticloud/v1/aws_clusters_connection.h index 3a4a8efbde0c9..bfa4d870ca009 100644 --- a/google/cloud/gkemulticloud/v1/aws_clusters_connection.h +++ b/google/cloud/gkemulticloud/v1/aws_clusters_connection.h @@ -39,16 +39,133 @@ namespace cloud { namespace gkemulticloud_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AwsClustersRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - gkemulticloud_v1_internal::AwsClustersRetryTraits>; +/// The retry policy for `AwsClustersConnection`. +class AwsClustersRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AwsClustersConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AwsClustersLimitedErrorCountRetryPolicy : public AwsClustersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AwsClustersLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AwsClustersLimitedErrorCountRetryPolicy( + AwsClustersLimitedErrorCountRetryPolicy&& rhs) noexcept + : AwsClustersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AwsClustersLimitedErrorCountRetryPolicy( + AwsClustersLimitedErrorCountRetryPolicy const& rhs) noexcept + : AwsClustersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AwsClustersRetryPolicy; -using AwsClustersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - gkemulticloud_v1_internal::AwsClustersRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + gkemulticloud_v1_internal::AwsClustersRetryTraits> + impl_; +}; + +/** + * A retry policy for `AwsClustersConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AwsClustersLimitedTimeRetryPolicy : public AwsClustersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AwsClustersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AwsClustersLimitedTimeRetryPolicy( + AwsClustersLimitedTimeRetryPolicy&& rhs) noexcept + : AwsClustersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AwsClustersLimitedTimeRetryPolicy( + AwsClustersLimitedTimeRetryPolicy const& rhs) noexcept + : AwsClustersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AwsClustersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - gkemulticloud_v1_internal::AwsClustersRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AwsClustersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + gkemulticloud_v1_internal::AwsClustersRetryTraits> + impl_; +}; /** * The `AwsClustersConnection` object for `AwsClustersClient`. diff --git a/google/cloud/gkemulticloud/v1/azure_clusters_connection.h b/google/cloud/gkemulticloud/v1/azure_clusters_connection.h index 4c627e47973b0..5656eae326502 100644 --- a/google/cloud/gkemulticloud/v1/azure_clusters_connection.h +++ b/google/cloud/gkemulticloud/v1/azure_clusters_connection.h @@ -39,17 +39,134 @@ namespace cloud { namespace gkemulticloud_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AzureClustersRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - gkemulticloud_v1_internal::AzureClustersRetryTraits>; +/// The retry policy for `AzureClustersConnection`. +class AzureClustersRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AzureClustersConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AzureClustersLimitedErrorCountRetryPolicy + : public AzureClustersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AzureClustersLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AzureClustersLimitedErrorCountRetryPolicy( + AzureClustersLimitedErrorCountRetryPolicy&& rhs) noexcept + : AzureClustersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AzureClustersLimitedErrorCountRetryPolicy( + AzureClustersLimitedErrorCountRetryPolicy const& rhs) noexcept + : AzureClustersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AzureClustersRetryPolicy; -using AzureClustersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - gkemulticloud_v1_internal::AzureClustersRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + gkemulticloud_v1_internal::AzureClustersRetryTraits> + impl_; +}; + +/** + * A retry policy for `AzureClustersConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AzureClustersLimitedTimeRetryPolicy : public AzureClustersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AzureClustersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AzureClustersLimitedTimeRetryPolicy( + AzureClustersLimitedTimeRetryPolicy&& rhs) noexcept + : AzureClustersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AzureClustersLimitedTimeRetryPolicy( + AzureClustersLimitedTimeRetryPolicy const& rhs) noexcept + : AzureClustersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AzureClustersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - gkemulticloud_v1_internal::AzureClustersRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AzureClustersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + gkemulticloud_v1_internal::AzureClustersRetryTraits> + impl_; +}; /** * The `AzureClustersConnection` object for `AzureClustersClient`. diff --git a/google/cloud/iam/admin/v1/iam_connection.h b/google/cloud/iam/admin/v1/iam_connection.h index 810fdc85e62cc..3873617ccde5a 100644 --- a/google/cloud/iam/admin/v1/iam_connection.h +++ b/google/cloud/iam/admin/v1/iam_connection.h @@ -35,16 +35,130 @@ namespace cloud { namespace iam_admin_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IAMRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - iam_admin_v1_internal::IAMRetryTraits>; +/// The retry policy for `IAMConnection`. +class IAMRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using IAMLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - iam_admin_v1_internal::IAMRetryTraits>; +/** + * A retry policy for `IAMConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IAMLimitedErrorCountRetryPolicy : public IAMRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IAMLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + IAMLimitedErrorCountRetryPolicy( + IAMLimitedErrorCountRetryPolicy&& rhs) noexcept + : IAMLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + IAMLimitedErrorCountRetryPolicy( + IAMLimitedErrorCountRetryPolicy const& rhs) noexcept + : IAMLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IAMRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + iam_admin_v1_internal::IAMRetryTraits> + impl_; +}; -using IAMLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - iam_admin_v1_internal::IAMRetryTraits>; +/** + * A retry policy for `IAMConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IAMLimitedTimeRetryPolicy : public IAMRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IAMLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IAMLimitedTimeRetryPolicy(IAMLimitedTimeRetryPolicy&& rhs) noexcept + : IAMLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IAMLimitedTimeRetryPolicy(IAMLimitedTimeRetryPolicy const& rhs) noexcept + : IAMLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IAMRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + iam_admin_v1_internal::IAMRetryTraits> + impl_; +}; /** * The `IAMConnection` object for `IAMClient`. diff --git a/google/cloud/iam/credentials/v1/iam_credentials_connection.h b/google/cloud/iam/credentials/v1/iam_credentials_connection.h index 5588d039df43e..130c86a4ba7eb 100644 --- a/google/cloud/iam/credentials/v1/iam_credentials_connection.h +++ b/google/cloud/iam/credentials/v1/iam_credentials_connection.h @@ -34,17 +34,134 @@ namespace cloud { namespace iam_credentials_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IAMCredentialsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - iam_credentials_v1_internal::IAMCredentialsRetryTraits>; +/// The retry policy for `IAMCredentialsConnection`. +class IAMCredentialsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using IAMCredentialsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - iam_credentials_v1_internal::IAMCredentialsRetryTraits>; +/** + * A retry policy for `IAMCredentialsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IAMCredentialsLimitedErrorCountRetryPolicy + : public IAMCredentialsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IAMCredentialsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + IAMCredentialsLimitedErrorCountRetryPolicy( + IAMCredentialsLimitedErrorCountRetryPolicy&& rhs) noexcept + : IAMCredentialsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + IAMCredentialsLimitedErrorCountRetryPolicy( + IAMCredentialsLimitedErrorCountRetryPolicy const& rhs) noexcept + : IAMCredentialsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IAMCredentialsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + iam_credentials_v1_internal::IAMCredentialsRetryTraits> + impl_; +}; -using IAMCredentialsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - iam_credentials_v1_internal::IAMCredentialsRetryTraits>; +/** + * A retry policy for `IAMCredentialsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IAMCredentialsLimitedTimeRetryPolicy : public IAMCredentialsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IAMCredentialsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IAMCredentialsLimitedTimeRetryPolicy( + IAMCredentialsLimitedTimeRetryPolicy&& rhs) noexcept + : IAMCredentialsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IAMCredentialsLimitedTimeRetryPolicy( + IAMCredentialsLimitedTimeRetryPolicy const& rhs) noexcept + : IAMCredentialsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IAMCredentialsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + iam_credentials_v1_internal::IAMCredentialsRetryTraits> + impl_; +}; /** * The `IAMCredentialsConnection` object for `IAMCredentialsClient`. diff --git a/google/cloud/iam/v1/iam_policy_connection.h b/google/cloud/iam/v1/iam_policy_connection.h index 692f96ef7d888..80a1fca3574c4 100644 --- a/google/cloud/iam/v1/iam_policy_connection.h +++ b/google/cloud/iam/v1/iam_policy_connection.h @@ -34,16 +34,133 @@ namespace cloud { namespace iam_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IAMPolicyRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - iam_v1_internal::IAMPolicyRetryTraits>; +/// The retry policy for `IAMPolicyConnection`. +class IAMPolicyRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `IAMPolicyConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IAMPolicyLimitedErrorCountRetryPolicy : public IAMPolicyRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IAMPolicyLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + IAMPolicyLimitedErrorCountRetryPolicy( + IAMPolicyLimitedErrorCountRetryPolicy&& rhs) noexcept + : IAMPolicyLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + IAMPolicyLimitedErrorCountRetryPolicy( + IAMPolicyLimitedErrorCountRetryPolicy const& rhs) noexcept + : IAMPolicyLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IAMPolicyRetryPolicy; -using IAMPolicyLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - iam_v1_internal::IAMPolicyRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + iam_v1_internal::IAMPolicyRetryTraits> + impl_; +}; + +/** + * A retry policy for `IAMPolicyConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IAMPolicyLimitedTimeRetryPolicy : public IAMPolicyRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IAMPolicyLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IAMPolicyLimitedTimeRetryPolicy( + IAMPolicyLimitedTimeRetryPolicy&& rhs) noexcept + : IAMPolicyLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IAMPolicyLimitedTimeRetryPolicy( + IAMPolicyLimitedTimeRetryPolicy const& rhs) noexcept + : IAMPolicyLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using IAMPolicyLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - iam_v1_internal::IAMPolicyRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IAMPolicyRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + iam_v1_internal::IAMPolicyRetryTraits> + impl_; +}; /** * The `IAMPolicyConnection` object for `IAMPolicyClient`. diff --git a/google/cloud/iam/v2/policies_connection.h b/google/cloud/iam/v2/policies_connection.h index 65a92d2b6f72e..8aaf76d147e9d 100644 --- a/google/cloud/iam/v2/policies_connection.h +++ b/google/cloud/iam/v2/policies_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace iam_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PoliciesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - iam_v2_internal::PoliciesRetryTraits>; +/// The retry policy for `PoliciesConnection`. +class PoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using PoliciesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - iam_v2_internal::PoliciesRetryTraits>; +/** + * A retry policy for `PoliciesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PoliciesLimitedErrorCountRetryPolicy : public PoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PoliciesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PoliciesLimitedErrorCountRetryPolicy( + PoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : PoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PoliciesLimitedErrorCountRetryPolicy( + PoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : PoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + iam_v2_internal::PoliciesRetryTraits> + impl_; +}; -using PoliciesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - iam_v2_internal::PoliciesRetryTraits>; +/** + * A retry policy for `PoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PoliciesLimitedTimeRetryPolicy : public PoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PoliciesLimitedTimeRetryPolicy(PoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : PoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PoliciesLimitedTimeRetryPolicy( + PoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : PoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + iam_v2_internal::PoliciesRetryTraits> + impl_; +}; /** * The `PoliciesConnection` object for `PoliciesClient`. diff --git a/google/cloud/iap/v1/identity_aware_proxy_admin_connection.h b/google/cloud/iap/v1/identity_aware_proxy_admin_connection.h index 0299796ca1c6a..9a9004f3061b6 100644 --- a/google/cloud/iap/v1/identity_aware_proxy_admin_connection.h +++ b/google/cloud/iap/v1/identity_aware_proxy_admin_connection.h @@ -35,17 +35,149 @@ namespace cloud { namespace iap_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IdentityAwareProxyAdminServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - iap_v1_internal::IdentityAwareProxyAdminServiceRetryTraits>; +/// The retry policy for `IdentityAwareProxyAdminServiceConnection`. +class IdentityAwareProxyAdminServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `IdentityAwareProxyAdminServiceConnection` based on + * counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy + : public IdentityAwareProxyAdminServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy( + IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy( + IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IdentityAwareProxyAdminServiceRetryPolicy; -using IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - iap_v1_internal::IdentityAwareProxyAdminServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + iap_v1_internal::IdentityAwareProxyAdminServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `IdentityAwareProxyAdminServiceConnection` based on + * elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy + : public IdentityAwareProxyAdminServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy( + IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy&& rhs) noexcept + : IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy( + IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy const& rhs) noexcept + : IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using IdentityAwareProxyAdminServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - iap_v1_internal::IdentityAwareProxyAdminServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + IdentityAwareProxyAdminServiceLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IdentityAwareProxyAdminServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + iap_v1_internal::IdentityAwareProxyAdminServiceRetryTraits> + impl_; +}; /** * The `IdentityAwareProxyAdminServiceConnection` object for diff --git a/google/cloud/iap/v1/identity_aware_proxy_o_auth_connection.h b/google/cloud/iap/v1/identity_aware_proxy_o_auth_connection.h index 43587405d082f..740202818b9f2 100644 --- a/google/cloud/iap/v1/identity_aware_proxy_o_auth_connection.h +++ b/google/cloud/iap/v1/identity_aware_proxy_o_auth_connection.h @@ -35,17 +35,149 @@ namespace cloud { namespace iap_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IdentityAwareProxyOAuthServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - iap_v1_internal::IdentityAwareProxyOAuthServiceRetryTraits>; +/// The retry policy for `IdentityAwareProxyOAuthServiceConnection`. +class IdentityAwareProxyOAuthServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `IdentityAwareProxyOAuthServiceConnection` based on + * counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy + : public IdentityAwareProxyOAuthServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy( + IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy( + IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IdentityAwareProxyOAuthServiceRetryPolicy; -using IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - iap_v1_internal::IdentityAwareProxyOAuthServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + iap_v1_internal::IdentityAwareProxyOAuthServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `IdentityAwareProxyOAuthServiceConnection` based on + * elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy + : public IdentityAwareProxyOAuthServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy( + IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy&& rhs) noexcept + : IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy( + IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy const& rhs) noexcept + : IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using IdentityAwareProxyOAuthServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - iap_v1_internal::IdentityAwareProxyOAuthServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + IdentityAwareProxyOAuthServiceLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IdentityAwareProxyOAuthServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + iap_v1_internal::IdentityAwareProxyOAuthServiceRetryTraits> + impl_; +}; /** * The `IdentityAwareProxyOAuthServiceConnection` object for diff --git a/google/cloud/ids/v1/ids_connection.h b/google/cloud/ids/v1/ids_connection.h index 501b70aab0f40..0f57adeb8ffa4 100644 --- a/google/cloud/ids/v1/ids_connection.h +++ b/google/cloud/ids/v1/ids_connection.h @@ -38,16 +38,130 @@ namespace cloud { namespace ids_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IDSRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - ids_v1_internal::IDSRetryTraits>; +/// The retry policy for `IDSConnection`. +class IDSRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using IDSLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - ids_v1_internal::IDSRetryTraits>; +/** + * A retry policy for `IDSConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IDSLimitedErrorCountRetryPolicy : public IDSRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IDSLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + IDSLimitedErrorCountRetryPolicy( + IDSLimitedErrorCountRetryPolicy&& rhs) noexcept + : IDSLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + IDSLimitedErrorCountRetryPolicy( + IDSLimitedErrorCountRetryPolicy const& rhs) noexcept + : IDSLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IDSRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + ids_v1_internal::IDSRetryTraits> + impl_; +}; -using IDSLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - ids_v1_internal::IDSRetryTraits>; +/** + * A retry policy for `IDSConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IDSLimitedTimeRetryPolicy : public IDSRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IDSLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IDSLimitedTimeRetryPolicy(IDSLimitedTimeRetryPolicy&& rhs) noexcept + : IDSLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IDSLimitedTimeRetryPolicy(IDSLimitedTimeRetryPolicy const& rhs) noexcept + : IDSLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IDSRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + ids_v1_internal::IDSRetryTraits> + impl_; +}; /** * The `IDSConnection` object for `IDSClient`. diff --git a/google/cloud/iot/v1/device_manager_connection.h b/google/cloud/iot/v1/device_manager_connection.h index 7cb745b330738..00db0d93bfd26 100644 --- a/google/cloud/iot/v1/device_manager_connection.h +++ b/google/cloud/iot/v1/device_manager_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace iot_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DeviceManagerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - iot_v1_internal::DeviceManagerRetryTraits>; +/// The retry policy for `DeviceManagerConnection`. +class DeviceManagerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DeviceManagerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DeviceManagerLimitedErrorCountRetryPolicy + : public DeviceManagerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DeviceManagerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DeviceManagerLimitedErrorCountRetryPolicy( + DeviceManagerLimitedErrorCountRetryPolicy&& rhs) noexcept + : DeviceManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DeviceManagerLimitedErrorCountRetryPolicy( + DeviceManagerLimitedErrorCountRetryPolicy const& rhs) noexcept + : DeviceManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DeviceManagerRetryPolicy; -using DeviceManagerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - iot_v1_internal::DeviceManagerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + iot_v1_internal::DeviceManagerRetryTraits> + impl_; +}; + +/** + * A retry policy for `DeviceManagerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DeviceManagerLimitedTimeRetryPolicy : public DeviceManagerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DeviceManagerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DeviceManagerLimitedTimeRetryPolicy( + DeviceManagerLimitedTimeRetryPolicy&& rhs) noexcept + : DeviceManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DeviceManagerLimitedTimeRetryPolicy( + DeviceManagerLimitedTimeRetryPolicy const& rhs) noexcept + : DeviceManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DeviceManagerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - iot_v1_internal::DeviceManagerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DeviceManagerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + iot_v1_internal::DeviceManagerRetryTraits> + impl_; +}; /** * The `DeviceManagerConnection` object for `DeviceManagerClient`. diff --git a/google/cloud/kms/inventory/v1/key_dashboard_connection.h b/google/cloud/kms/inventory/v1/key_dashboard_connection.h index 0a24c1828a10c..3c7f1f238cfc9 100644 --- a/google/cloud/kms/inventory/v1/key_dashboard_connection.h +++ b/google/cloud/kms/inventory/v1/key_dashboard_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace kms_inventory_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using KeyDashboardServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - kms_inventory_v1_internal::KeyDashboardServiceRetryTraits>; +/// The retry policy for `KeyDashboardServiceConnection`. +class KeyDashboardServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `KeyDashboardServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class KeyDashboardServiceLimitedErrorCountRetryPolicy + : public KeyDashboardServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit KeyDashboardServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + KeyDashboardServiceLimitedErrorCountRetryPolicy( + KeyDashboardServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : KeyDashboardServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + KeyDashboardServiceLimitedErrorCountRetryPolicy( + KeyDashboardServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : KeyDashboardServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = KeyDashboardServiceRetryPolicy; -using KeyDashboardServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - kms_inventory_v1_internal::KeyDashboardServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + kms_inventory_v1_internal::KeyDashboardServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `KeyDashboardServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class KeyDashboardServiceLimitedTimeRetryPolicy + : public KeyDashboardServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit KeyDashboardServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + KeyDashboardServiceLimitedTimeRetryPolicy( + KeyDashboardServiceLimitedTimeRetryPolicy&& rhs) noexcept + : KeyDashboardServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + KeyDashboardServiceLimitedTimeRetryPolicy( + KeyDashboardServiceLimitedTimeRetryPolicy const& rhs) noexcept + : KeyDashboardServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using KeyDashboardServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - kms_inventory_v1_internal::KeyDashboardServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = KeyDashboardServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + kms_inventory_v1_internal::KeyDashboardServiceRetryTraits> + impl_; +}; /** * The `KeyDashboardServiceConnection` object for `KeyDashboardServiceClient`. diff --git a/google/cloud/kms/inventory/v1/key_tracking_connection.h b/google/cloud/kms/inventory/v1/key_tracking_connection.h index 3de8352cfb50f..d0664312a00c3 100644 --- a/google/cloud/kms/inventory/v1/key_tracking_connection.h +++ b/google/cloud/kms/inventory/v1/key_tracking_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace kms_inventory_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using KeyTrackingServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - kms_inventory_v1_internal::KeyTrackingServiceRetryTraits>; +/// The retry policy for `KeyTrackingServiceConnection`. +class KeyTrackingServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `KeyTrackingServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class KeyTrackingServiceLimitedErrorCountRetryPolicy + : public KeyTrackingServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit KeyTrackingServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + KeyTrackingServiceLimitedErrorCountRetryPolicy( + KeyTrackingServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : KeyTrackingServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + KeyTrackingServiceLimitedErrorCountRetryPolicy( + KeyTrackingServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : KeyTrackingServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = KeyTrackingServiceRetryPolicy; -using KeyTrackingServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - kms_inventory_v1_internal::KeyTrackingServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + kms_inventory_v1_internal::KeyTrackingServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `KeyTrackingServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class KeyTrackingServiceLimitedTimeRetryPolicy + : public KeyTrackingServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit KeyTrackingServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + KeyTrackingServiceLimitedTimeRetryPolicy( + KeyTrackingServiceLimitedTimeRetryPolicy&& rhs) noexcept + : KeyTrackingServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + KeyTrackingServiceLimitedTimeRetryPolicy( + KeyTrackingServiceLimitedTimeRetryPolicy const& rhs) noexcept + : KeyTrackingServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using KeyTrackingServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - kms_inventory_v1_internal::KeyTrackingServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = KeyTrackingServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + kms_inventory_v1_internal::KeyTrackingServiceRetryTraits> + impl_; +}; /** * The `KeyTrackingServiceConnection` object for `KeyTrackingServiceClient`. diff --git a/google/cloud/kms/v1/ekm_connection.h b/google/cloud/kms/v1/ekm_connection.h index 52ca49847489a..6f9b1332f889a 100644 --- a/google/cloud/kms/v1/ekm_connection.h +++ b/google/cloud/kms/v1/ekm_connection.h @@ -35,16 +35,133 @@ namespace cloud { namespace kms_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EkmServiceRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - kms_v1_internal::EkmServiceRetryTraits>; +/// The retry policy for `EkmServiceConnection`. +class EkmServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using EkmServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - kms_v1_internal::EkmServiceRetryTraits>; +/** + * A retry policy for `EkmServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EkmServiceLimitedErrorCountRetryPolicy : public EkmServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EkmServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EkmServiceLimitedErrorCountRetryPolicy( + EkmServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : EkmServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EkmServiceLimitedErrorCountRetryPolicy( + EkmServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : EkmServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EkmServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + kms_v1_internal::EkmServiceRetryTraits> + impl_; +}; -using EkmServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - kms_v1_internal::EkmServiceRetryTraits>; +/** + * A retry policy for `EkmServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EkmServiceLimitedTimeRetryPolicy : public EkmServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EkmServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EkmServiceLimitedTimeRetryPolicy( + EkmServiceLimitedTimeRetryPolicy&& rhs) noexcept + : EkmServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EkmServiceLimitedTimeRetryPolicy( + EkmServiceLimitedTimeRetryPolicy const& rhs) noexcept + : EkmServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EkmServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + kms_v1_internal::EkmServiceRetryTraits> + impl_; +}; /** * The `EkmServiceConnection` object for `EkmServiceClient`. diff --git a/google/cloud/kms/v1/key_management_connection.h b/google/cloud/kms/v1/key_management_connection.h index f86642760d7a9..bdb454562f2ca 100644 --- a/google/cloud/kms/v1/key_management_connection.h +++ b/google/cloud/kms/v1/key_management_connection.h @@ -35,17 +35,138 @@ namespace cloud { namespace kms_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using KeyManagementServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - kms_v1_internal::KeyManagementServiceRetryTraits>; +/// The retry policy for `KeyManagementServiceConnection`. +class KeyManagementServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using KeyManagementServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - kms_v1_internal::KeyManagementServiceRetryTraits>; +/** + * A retry policy for `KeyManagementServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class KeyManagementServiceLimitedErrorCountRetryPolicy + : public KeyManagementServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit KeyManagementServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + KeyManagementServiceLimitedErrorCountRetryPolicy( + KeyManagementServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : KeyManagementServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + KeyManagementServiceLimitedErrorCountRetryPolicy( + KeyManagementServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : KeyManagementServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = KeyManagementServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + kms_v1_internal::KeyManagementServiceRetryTraits> + impl_; +}; -using KeyManagementServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - kms_v1_internal::KeyManagementServiceRetryTraits>; +/** + * A retry policy for `KeyManagementServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class KeyManagementServiceLimitedTimeRetryPolicy + : public KeyManagementServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit KeyManagementServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + KeyManagementServiceLimitedTimeRetryPolicy( + KeyManagementServiceLimitedTimeRetryPolicy&& rhs) noexcept + : KeyManagementServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + KeyManagementServiceLimitedTimeRetryPolicy( + KeyManagementServiceLimitedTimeRetryPolicy const& rhs) noexcept + : KeyManagementServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = KeyManagementServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + kms_v1_internal::KeyManagementServiceRetryTraits> + impl_; +}; /** * The `KeyManagementServiceConnection` object for `KeyManagementServiceClient`. diff --git a/google/cloud/language/v1/language_connection.h b/google/cloud/language/v1/language_connection.h index 7e29f184bbfe6..6fc6e325de570 100644 --- a/google/cloud/language/v1/language_connection.h +++ b/google/cloud/language/v1/language_connection.h @@ -34,17 +34,135 @@ namespace cloud { namespace language_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using LanguageServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - language_v1_internal::LanguageServiceRetryTraits>; +/// The retry policy for `LanguageServiceConnection`. +class LanguageServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using LanguageServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - language_v1_internal::LanguageServiceRetryTraits>; +/** + * A retry policy for `LanguageServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LanguageServiceLimitedErrorCountRetryPolicy + : public LanguageServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit LanguageServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + LanguageServiceLimitedErrorCountRetryPolicy( + LanguageServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : LanguageServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + LanguageServiceLimitedErrorCountRetryPolicy( + LanguageServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : LanguageServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = LanguageServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + language_v1_internal::LanguageServiceRetryTraits> + impl_; +}; -using LanguageServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - language_v1_internal::LanguageServiceRetryTraits>; +/** + * A retry policy for `LanguageServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LanguageServiceLimitedTimeRetryPolicy + : public LanguageServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit LanguageServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + LanguageServiceLimitedTimeRetryPolicy( + LanguageServiceLimitedTimeRetryPolicy&& rhs) noexcept + : LanguageServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + LanguageServiceLimitedTimeRetryPolicy( + LanguageServiceLimitedTimeRetryPolicy const& rhs) noexcept + : LanguageServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = LanguageServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + language_v1_internal::LanguageServiceRetryTraits> + impl_; +}; /** * The `LanguageServiceConnection` object for `LanguageServiceClient`. diff --git a/google/cloud/logging/v2/logging_service_v2_connection.h b/google/cloud/logging/v2/logging_service_v2_connection.h index cb38fec15ff69..3204b4821f69e 100644 --- a/google/cloud/logging/v2/logging_service_v2_connection.h +++ b/google/cloud/logging/v2/logging_service_v2_connection.h @@ -37,17 +37,137 @@ namespace cloud { namespace logging_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using LoggingServiceV2RetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - logging_v2_internal::LoggingServiceV2RetryTraits>; +/// The retry policy for `LoggingServiceV2Connection`. +class LoggingServiceV2RetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using LoggingServiceV2LimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - logging_v2_internal::LoggingServiceV2RetryTraits>; +/** + * A retry policy for `LoggingServiceV2Connection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kInternal`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LoggingServiceV2LimitedErrorCountRetryPolicy + : public LoggingServiceV2RetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit LoggingServiceV2LimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + LoggingServiceV2LimitedErrorCountRetryPolicy( + LoggingServiceV2LimitedErrorCountRetryPolicy&& rhs) noexcept + : LoggingServiceV2LimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + LoggingServiceV2LimitedErrorCountRetryPolicy( + LoggingServiceV2LimitedErrorCountRetryPolicy const& rhs) noexcept + : LoggingServiceV2LimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = LoggingServiceV2RetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + logging_v2_internal::LoggingServiceV2RetryTraits> + impl_; +}; -using LoggingServiceV2LimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - logging_v2_internal::LoggingServiceV2RetryTraits>; +/** + * A retry policy for `LoggingServiceV2Connection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kInternal`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LoggingServiceV2LimitedTimeRetryPolicy + : public LoggingServiceV2RetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit LoggingServiceV2LimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + LoggingServiceV2LimitedTimeRetryPolicy( + LoggingServiceV2LimitedTimeRetryPolicy&& rhs) noexcept + : LoggingServiceV2LimitedTimeRetryPolicy(rhs.maximum_duration()) {} + LoggingServiceV2LimitedTimeRetryPolicy( + LoggingServiceV2LimitedTimeRetryPolicy const& rhs) noexcept + : LoggingServiceV2LimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = LoggingServiceV2RetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + logging_v2_internal::LoggingServiceV2RetryTraits> + impl_; +}; /** * The `LoggingServiceV2Connection` object for `LoggingServiceV2Client`. diff --git a/google/cloud/managedidentities/v1/managed_identities_connection.h b/google/cloud/managedidentities/v1/managed_identities_connection.h index fa029047b9e00..b1c54cbb8b95c 100644 --- a/google/cloud/managedidentities/v1/managed_identities_connection.h +++ b/google/cloud/managedidentities/v1/managed_identities_connection.h @@ -38,17 +38,145 @@ namespace cloud { namespace managedidentities_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ManagedIdentitiesServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - managedidentities_v1_internal::ManagedIdentitiesServiceRetryTraits>; +/// The retry policy for `ManagedIdentitiesServiceConnection`. +class ManagedIdentitiesServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `ManagedIdentitiesServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ManagedIdentitiesServiceLimitedErrorCountRetryPolicy + : public ManagedIdentitiesServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ManagedIdentitiesServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ManagedIdentitiesServiceLimitedErrorCountRetryPolicy( + ManagedIdentitiesServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ManagedIdentitiesServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ManagedIdentitiesServiceLimitedErrorCountRetryPolicy( + ManagedIdentitiesServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ManagedIdentitiesServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + ManagedIdentitiesServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ManagedIdentitiesServiceRetryPolicy; -using ManagedIdentitiesServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - managedidentities_v1_internal::ManagedIdentitiesServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + managedidentities_v1_internal::ManagedIdentitiesServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ManagedIdentitiesServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ManagedIdentitiesServiceLimitedTimeRetryPolicy + : public ManagedIdentitiesServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ManagedIdentitiesServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ManagedIdentitiesServiceLimitedTimeRetryPolicy( + ManagedIdentitiesServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ManagedIdentitiesServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + ManagedIdentitiesServiceLimitedTimeRetryPolicy( + ManagedIdentitiesServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ManagedIdentitiesServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ManagedIdentitiesServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - managedidentities_v1_internal::ManagedIdentitiesServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ManagedIdentitiesServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + managedidentities_v1_internal::ManagedIdentitiesServiceRetryTraits> + impl_; +}; /** * The `ManagedIdentitiesServiceConnection` object for diff --git a/google/cloud/memcache/v1/cloud_memcache_connection.h b/google/cloud/memcache/v1/cloud_memcache_connection.h index 0df9b3221c02d..28b36baf554f5 100644 --- a/google/cloud/memcache/v1/cloud_memcache_connection.h +++ b/google/cloud/memcache/v1/cloud_memcache_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace memcache_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudMemcacheRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - memcache_v1_internal::CloudMemcacheRetryTraits>; +/// The retry policy for `CloudMemcacheConnection`. +class CloudMemcacheRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CloudMemcacheLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - memcache_v1_internal::CloudMemcacheRetryTraits>; +/** + * A retry policy for `CloudMemcacheConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudMemcacheLimitedErrorCountRetryPolicy + : public CloudMemcacheRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudMemcacheLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudMemcacheLimitedErrorCountRetryPolicy( + CloudMemcacheLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudMemcacheLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudMemcacheLimitedErrorCountRetryPolicy( + CloudMemcacheLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudMemcacheLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudMemcacheRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + memcache_v1_internal::CloudMemcacheRetryTraits> + impl_; +}; -using CloudMemcacheLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - memcache_v1_internal::CloudMemcacheRetryTraits>; +/** + * A retry policy for `CloudMemcacheConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudMemcacheLimitedTimeRetryPolicy : public CloudMemcacheRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudMemcacheLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudMemcacheLimitedTimeRetryPolicy( + CloudMemcacheLimitedTimeRetryPolicy&& rhs) noexcept + : CloudMemcacheLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudMemcacheLimitedTimeRetryPolicy( + CloudMemcacheLimitedTimeRetryPolicy const& rhs) noexcept + : CloudMemcacheLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudMemcacheRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + memcache_v1_internal::CloudMemcacheRetryTraits> + impl_; +}; /** * The `CloudMemcacheConnection` object for `CloudMemcacheClient`. diff --git a/google/cloud/metastore/v1/dataproc_metastore_connection.h b/google/cloud/metastore/v1/dataproc_metastore_connection.h index b952d43213e43..3a856e2d487fe 100644 --- a/google/cloud/metastore/v1/dataproc_metastore_connection.h +++ b/google/cloud/metastore/v1/dataproc_metastore_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace metastore_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DataprocMetastoreRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - metastore_v1_internal::DataprocMetastoreRetryTraits>; +/// The retry policy for `DataprocMetastoreConnection`. +class DataprocMetastoreRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DataprocMetastoreConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataprocMetastoreLimitedErrorCountRetryPolicy + : public DataprocMetastoreRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DataprocMetastoreLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DataprocMetastoreLimitedErrorCountRetryPolicy( + DataprocMetastoreLimitedErrorCountRetryPolicy&& rhs) noexcept + : DataprocMetastoreLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DataprocMetastoreLimitedErrorCountRetryPolicy( + DataprocMetastoreLimitedErrorCountRetryPolicy const& rhs) noexcept + : DataprocMetastoreLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataprocMetastoreRetryPolicy; -using DataprocMetastoreLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - metastore_v1_internal::DataprocMetastoreRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + metastore_v1_internal::DataprocMetastoreRetryTraits> + impl_; +}; + +/** + * A retry policy for `DataprocMetastoreConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataprocMetastoreLimitedTimeRetryPolicy + : public DataprocMetastoreRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DataprocMetastoreLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DataprocMetastoreLimitedTimeRetryPolicy( + DataprocMetastoreLimitedTimeRetryPolicy&& rhs) noexcept + : DataprocMetastoreLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DataprocMetastoreLimitedTimeRetryPolicy( + DataprocMetastoreLimitedTimeRetryPolicy const& rhs) noexcept + : DataprocMetastoreLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using DataprocMetastoreLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - metastore_v1_internal::DataprocMetastoreRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataprocMetastoreRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + metastore_v1_internal::DataprocMetastoreRetryTraits> + impl_; +}; /** * The `DataprocMetastoreConnection` object for `DataprocMetastoreClient`. diff --git a/google/cloud/metastore/v1/dataproc_metastore_federation_connection.h b/google/cloud/metastore/v1/dataproc_metastore_federation_connection.h index e702b9c4c2d1a..c265628b09f24 100644 --- a/google/cloud/metastore/v1/dataproc_metastore_federation_connection.h +++ b/google/cloud/metastore/v1/dataproc_metastore_federation_connection.h @@ -38,17 +38,148 @@ namespace cloud { namespace metastore_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DataprocMetastoreFederationRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - metastore_v1_internal::DataprocMetastoreFederationRetryTraits>; +/// The retry policy for `DataprocMetastoreFederationConnection`. +class DataprocMetastoreFederationRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; -using DataprocMetastoreFederationLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - metastore_v1_internal::DataprocMetastoreFederationRetryTraits>; +/** + * A retry policy for `DataprocMetastoreFederationConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataprocMetastoreFederationLimitedErrorCountRetryPolicy + : public DataprocMetastoreFederationRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DataprocMetastoreFederationLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + DataprocMetastoreFederationLimitedErrorCountRetryPolicy( + DataprocMetastoreFederationLimitedErrorCountRetryPolicy&& rhs) noexcept + : DataprocMetastoreFederationLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + DataprocMetastoreFederationLimitedErrorCountRetryPolicy( + DataprocMetastoreFederationLimitedErrorCountRetryPolicy const& + rhs) noexcept + : DataprocMetastoreFederationLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + DataprocMetastoreFederationLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataprocMetastoreFederationRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + metastore_v1_internal::DataprocMetastoreFederationRetryTraits> + impl_; +}; -using DataprocMetastoreFederationLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - metastore_v1_internal::DataprocMetastoreFederationRetryTraits>; +/** + * A retry policy for `DataprocMetastoreFederationConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DataprocMetastoreFederationLimitedTimeRetryPolicy + : public DataprocMetastoreFederationRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DataprocMetastoreFederationLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DataprocMetastoreFederationLimitedTimeRetryPolicy( + DataprocMetastoreFederationLimitedTimeRetryPolicy&& rhs) noexcept + : DataprocMetastoreFederationLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + DataprocMetastoreFederationLimitedTimeRetryPolicy( + DataprocMetastoreFederationLimitedTimeRetryPolicy const& rhs) noexcept + : DataprocMetastoreFederationLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DataprocMetastoreFederationRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + metastore_v1_internal::DataprocMetastoreFederationRetryTraits> + impl_; +}; /** * The `DataprocMetastoreFederationConnection` object for diff --git a/google/cloud/migrationcenter/v1/migration_center_connection.h b/google/cloud/migrationcenter/v1/migration_center_connection.h index b458af24cd6c9..0ade5d8901997 100644 --- a/google/cloud/migrationcenter/v1/migration_center_connection.h +++ b/google/cloud/migrationcenter/v1/migration_center_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace migrationcenter_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MigrationCenterRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - migrationcenter_v1_internal::MigrationCenterRetryTraits>; +/// The retry policy for `MigrationCenterConnection`. +class MigrationCenterRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using MigrationCenterLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - migrationcenter_v1_internal::MigrationCenterRetryTraits>; +/** + * A retry policy for `MigrationCenterConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MigrationCenterLimitedErrorCountRetryPolicy + : public MigrationCenterRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MigrationCenterLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MigrationCenterLimitedErrorCountRetryPolicy( + MigrationCenterLimitedErrorCountRetryPolicy&& rhs) noexcept + : MigrationCenterLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MigrationCenterLimitedErrorCountRetryPolicy( + MigrationCenterLimitedErrorCountRetryPolicy const& rhs) noexcept + : MigrationCenterLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MigrationCenterRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + migrationcenter_v1_internal::MigrationCenterRetryTraits> + impl_; +}; -using MigrationCenterLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - migrationcenter_v1_internal::MigrationCenterRetryTraits>; +/** + * A retry policy for `MigrationCenterConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MigrationCenterLimitedTimeRetryPolicy + : public MigrationCenterRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MigrationCenterLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MigrationCenterLimitedTimeRetryPolicy( + MigrationCenterLimitedTimeRetryPolicy&& rhs) noexcept + : MigrationCenterLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MigrationCenterLimitedTimeRetryPolicy( + MigrationCenterLimitedTimeRetryPolicy const& rhs) noexcept + : MigrationCenterLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MigrationCenterRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + migrationcenter_v1_internal::MigrationCenterRetryTraits> + impl_; +}; /** * The `MigrationCenterConnection` object for `MigrationCenterClient`. diff --git a/google/cloud/monitoring/dashboard/v1/dashboards_connection.h b/google/cloud/monitoring/dashboard/v1/dashboards_connection.h index 687cfdaecb67b..1ab7a10561569 100644 --- a/google/cloud/monitoring/dashboard/v1/dashboards_connection.h +++ b/google/cloud/monitoring/dashboard/v1/dashboards_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace monitoring_dashboard_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DashboardsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_dashboard_v1_internal::DashboardsServiceRetryTraits>; +/// The retry policy for `DashboardsServiceConnection`. +class DashboardsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DashboardsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_dashboard_v1_internal::DashboardsServiceRetryTraits>; +/** + * A retry policy for `DashboardsServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DashboardsServiceLimitedErrorCountRetryPolicy + : public DashboardsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DashboardsServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DashboardsServiceLimitedErrorCountRetryPolicy( + DashboardsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DashboardsServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DashboardsServiceLimitedErrorCountRetryPolicy( + DashboardsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DashboardsServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DashboardsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_dashboard_v1_internal::DashboardsServiceRetryTraits> + impl_; +}; -using DashboardsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_dashboard_v1_internal::DashboardsServiceRetryTraits>; +/** + * A retry policy for `DashboardsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DashboardsServiceLimitedTimeRetryPolicy + : public DashboardsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DashboardsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DashboardsServiceLimitedTimeRetryPolicy( + DashboardsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DashboardsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DashboardsServiceLimitedTimeRetryPolicy( + DashboardsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DashboardsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DashboardsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_dashboard_v1_internal::DashboardsServiceRetryTraits> + impl_; +}; /** * The `DashboardsServiceConnection` object for `DashboardsServiceClient`. diff --git a/google/cloud/monitoring/metricsscope/v1/metrics_scopes_connection.h b/google/cloud/monitoring/metricsscope/v1/metrics_scopes_connection.h index 30bea6c7f7094..9b331f9e464ee 100644 --- a/google/cloud/monitoring/metricsscope/v1/metrics_scopes_connection.h +++ b/google/cloud/monitoring/metricsscope/v1/metrics_scopes_connection.h @@ -37,17 +37,134 @@ namespace cloud { namespace monitoring_metricsscope_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MetricsScopesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_metricsscope_v1_internal::MetricsScopesRetryTraits>; +/// The retry policy for `MetricsScopesConnection`. +class MetricsScopesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using MetricsScopesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_metricsscope_v1_internal::MetricsScopesRetryTraits>; +/** + * A retry policy for `MetricsScopesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetricsScopesLimitedErrorCountRetryPolicy + : public MetricsScopesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MetricsScopesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MetricsScopesLimitedErrorCountRetryPolicy( + MetricsScopesLimitedErrorCountRetryPolicy&& rhs) noexcept + : MetricsScopesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MetricsScopesLimitedErrorCountRetryPolicy( + MetricsScopesLimitedErrorCountRetryPolicy const& rhs) noexcept + : MetricsScopesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetricsScopesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_metricsscope_v1_internal::MetricsScopesRetryTraits> + impl_; +}; -using MetricsScopesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_metricsscope_v1_internal::MetricsScopesRetryTraits>; +/** + * A retry policy for `MetricsScopesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetricsScopesLimitedTimeRetryPolicy : public MetricsScopesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MetricsScopesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MetricsScopesLimitedTimeRetryPolicy( + MetricsScopesLimitedTimeRetryPolicy&& rhs) noexcept + : MetricsScopesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MetricsScopesLimitedTimeRetryPolicy( + MetricsScopesLimitedTimeRetryPolicy const& rhs) noexcept + : MetricsScopesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetricsScopesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_metricsscope_v1_internal::MetricsScopesRetryTraits> + impl_; +}; /** * The `MetricsScopesConnection` object for `MetricsScopesClient`. diff --git a/google/cloud/monitoring/v3/alert_policy_connection.h b/google/cloud/monitoring/v3/alert_policy_connection.h index 60dc38c9727f9..ba46c0c9557fc 100644 --- a/google/cloud/monitoring/v3/alert_policy_connection.h +++ b/google/cloud/monitoring/v3/alert_policy_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace monitoring_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AlertPolicyServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_v3_internal::AlertPolicyServiceRetryTraits>; +/// The retry policy for `AlertPolicyServiceConnection`. +class AlertPolicyServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AlertPolicyServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_v3_internal::AlertPolicyServiceRetryTraits>; +/** + * A retry policy for `AlertPolicyServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AlertPolicyServiceLimitedErrorCountRetryPolicy + : public AlertPolicyServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AlertPolicyServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AlertPolicyServiceLimitedErrorCountRetryPolicy( + AlertPolicyServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AlertPolicyServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + AlertPolicyServiceLimitedErrorCountRetryPolicy( + AlertPolicyServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AlertPolicyServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AlertPolicyServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_v3_internal::AlertPolicyServiceRetryTraits> + impl_; +}; -using AlertPolicyServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_v3_internal::AlertPolicyServiceRetryTraits>; +/** + * A retry policy for `AlertPolicyServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AlertPolicyServiceLimitedTimeRetryPolicy + : public AlertPolicyServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AlertPolicyServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AlertPolicyServiceLimitedTimeRetryPolicy( + AlertPolicyServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AlertPolicyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AlertPolicyServiceLimitedTimeRetryPolicy( + AlertPolicyServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AlertPolicyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AlertPolicyServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_v3_internal::AlertPolicyServiceRetryTraits> + impl_; +}; /** * The `AlertPolicyServiceConnection` object for `AlertPolicyServiceClient`. diff --git a/google/cloud/monitoring/v3/group_connection.h b/google/cloud/monitoring/v3/group_connection.h index 2eb25aa0ffd3c..970c92b73daea 100644 --- a/google/cloud/monitoring/v3/group_connection.h +++ b/google/cloud/monitoring/v3/group_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace monitoring_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using GroupServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_v3_internal::GroupServiceRetryTraits>; +/// The retry policy for `GroupServiceConnection`. +class GroupServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using GroupServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_v3_internal::GroupServiceRetryTraits>; +/** + * A retry policy for `GroupServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GroupServiceLimitedErrorCountRetryPolicy + : public GroupServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit GroupServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + GroupServiceLimitedErrorCountRetryPolicy( + GroupServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : GroupServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + GroupServiceLimitedErrorCountRetryPolicy( + GroupServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : GroupServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = GroupServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_v3_internal::GroupServiceRetryTraits> + impl_; +}; -using GroupServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_v3_internal::GroupServiceRetryTraits>; +/** + * A retry policy for `GroupServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class GroupServiceLimitedTimeRetryPolicy : public GroupServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit GroupServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + GroupServiceLimitedTimeRetryPolicy( + GroupServiceLimitedTimeRetryPolicy&& rhs) noexcept + : GroupServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + GroupServiceLimitedTimeRetryPolicy( + GroupServiceLimitedTimeRetryPolicy const& rhs) noexcept + : GroupServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = GroupServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_v3_internal::GroupServiceRetryTraits> + impl_; +}; /** * The `GroupServiceConnection` object for `GroupServiceClient`. diff --git a/google/cloud/monitoring/v3/metric_connection.h b/google/cloud/monitoring/v3/metric_connection.h index de5d2bca525a3..8842e0a37abf7 100644 --- a/google/cloud/monitoring/v3/metric_connection.h +++ b/google/cloud/monitoring/v3/metric_connection.h @@ -36,17 +36,134 @@ namespace cloud { namespace monitoring_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using MetricServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_v3_internal::MetricServiceRetryTraits>; +/// The retry policy for `MetricServiceConnection`. +class MetricServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using MetricServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_v3_internal::MetricServiceRetryTraits>; +/** + * A retry policy for `MetricServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetricServiceLimitedErrorCountRetryPolicy + : public MetricServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit MetricServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + MetricServiceLimitedErrorCountRetryPolicy( + MetricServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : MetricServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + MetricServiceLimitedErrorCountRetryPolicy( + MetricServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : MetricServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetricServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_v3_internal::MetricServiceRetryTraits> + impl_; +}; -using MetricServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_v3_internal::MetricServiceRetryTraits>; +/** + * A retry policy for `MetricServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class MetricServiceLimitedTimeRetryPolicy : public MetricServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit MetricServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + MetricServiceLimitedTimeRetryPolicy( + MetricServiceLimitedTimeRetryPolicy&& rhs) noexcept + : MetricServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + MetricServiceLimitedTimeRetryPolicy( + MetricServiceLimitedTimeRetryPolicy const& rhs) noexcept + : MetricServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = MetricServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_v3_internal::MetricServiceRetryTraits> + impl_; +}; /** * The `MetricServiceConnection` object for `MetricServiceClient`. diff --git a/google/cloud/monitoring/v3/notification_channel_connection.h b/google/cloud/monitoring/v3/notification_channel_connection.h index a6bfd955dde21..121d40016f60c 100644 --- a/google/cloud/monitoring/v3/notification_channel_connection.h +++ b/google/cloud/monitoring/v3/notification_channel_connection.h @@ -35,17 +35,148 @@ namespace cloud { namespace monitoring_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NotificationChannelServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_v3_internal::NotificationChannelServiceRetryTraits>; +/// The retry policy for `NotificationChannelServiceConnection`. +class NotificationChannelServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `NotificationChannelServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NotificationChannelServiceLimitedErrorCountRetryPolicy + : public NotificationChannelServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NotificationChannelServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + NotificationChannelServiceLimitedErrorCountRetryPolicy( + NotificationChannelServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : NotificationChannelServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + NotificationChannelServiceLimitedErrorCountRetryPolicy( + NotificationChannelServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : NotificationChannelServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + NotificationChannelServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NotificationChannelServiceRetryPolicy; -using NotificationChannelServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_v3_internal::NotificationChannelServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_v3_internal::NotificationChannelServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `NotificationChannelServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NotificationChannelServiceLimitedTimeRetryPolicy + : public NotificationChannelServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NotificationChannelServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NotificationChannelServiceLimitedTimeRetryPolicy( + NotificationChannelServiceLimitedTimeRetryPolicy&& rhs) noexcept + : NotificationChannelServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + NotificationChannelServiceLimitedTimeRetryPolicy( + NotificationChannelServiceLimitedTimeRetryPolicy const& rhs) noexcept + : NotificationChannelServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using NotificationChannelServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_v3_internal::NotificationChannelServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NotificationChannelServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_v3_internal::NotificationChannelServiceRetryTraits> + impl_; +}; /** * The `NotificationChannelServiceConnection` object for diff --git a/google/cloud/monitoring/v3/query_connection.h b/google/cloud/monitoring/v3/query_connection.h index 83f3ddce4f1d9..104d50b77b132 100644 --- a/google/cloud/monitoring/v3/query_connection.h +++ b/google/cloud/monitoring/v3/query_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace monitoring_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using QueryServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_v3_internal::QueryServiceRetryTraits>; +/// The retry policy for `QueryServiceConnection`. +class QueryServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `QueryServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class QueryServiceLimitedErrorCountRetryPolicy + : public QueryServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit QueryServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + QueryServiceLimitedErrorCountRetryPolicy( + QueryServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : QueryServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + QueryServiceLimitedErrorCountRetryPolicy( + QueryServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : QueryServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = QueryServiceRetryPolicy; -using QueryServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_v3_internal::QueryServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_v3_internal::QueryServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `QueryServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class QueryServiceLimitedTimeRetryPolicy : public QueryServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit QueryServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + QueryServiceLimitedTimeRetryPolicy( + QueryServiceLimitedTimeRetryPolicy&& rhs) noexcept + : QueryServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + QueryServiceLimitedTimeRetryPolicy( + QueryServiceLimitedTimeRetryPolicy const& rhs) noexcept + : QueryServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using QueryServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_v3_internal::QueryServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = QueryServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_v3_internal::QueryServiceRetryTraits> + impl_; +}; /** * The `QueryServiceConnection` object for `QueryServiceClient`. diff --git a/google/cloud/monitoring/v3/service_monitoring_connection.h b/google/cloud/monitoring/v3/service_monitoring_connection.h index fe8184b0ef01c..e35d14c50e859 100644 --- a/google/cloud/monitoring/v3/service_monitoring_connection.h +++ b/google/cloud/monitoring/v3/service_monitoring_connection.h @@ -35,17 +35,145 @@ namespace cloud { namespace monitoring_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ServiceMonitoringServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_v3_internal::ServiceMonitoringServiceRetryTraits>; +/// The retry policy for `ServiceMonitoringServiceConnection`. +class ServiceMonitoringServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `ServiceMonitoringServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceMonitoringServiceLimitedErrorCountRetryPolicy + : public ServiceMonitoringServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ServiceMonitoringServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ServiceMonitoringServiceLimitedErrorCountRetryPolicy( + ServiceMonitoringServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ServiceMonitoringServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ServiceMonitoringServiceLimitedErrorCountRetryPolicy( + ServiceMonitoringServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ServiceMonitoringServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + ServiceMonitoringServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceMonitoringServiceRetryPolicy; -using ServiceMonitoringServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_v3_internal::ServiceMonitoringServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_v3_internal::ServiceMonitoringServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ServiceMonitoringServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceMonitoringServiceLimitedTimeRetryPolicy + : public ServiceMonitoringServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ServiceMonitoringServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ServiceMonitoringServiceLimitedTimeRetryPolicy( + ServiceMonitoringServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ServiceMonitoringServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + ServiceMonitoringServiceLimitedTimeRetryPolicy( + ServiceMonitoringServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ServiceMonitoringServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ServiceMonitoringServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_v3_internal::ServiceMonitoringServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceMonitoringServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_v3_internal::ServiceMonitoringServiceRetryTraits> + impl_; +}; /** * The `ServiceMonitoringServiceConnection` object for diff --git a/google/cloud/monitoring/v3/uptime_check_connection.h b/google/cloud/monitoring/v3/uptime_check_connection.h index e6272df14b57c..e423daa52ab6c 100644 --- a/google/cloud/monitoring/v3/uptime_check_connection.h +++ b/google/cloud/monitoring/v3/uptime_check_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace monitoring_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using UptimeCheckServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - monitoring_v3_internal::UptimeCheckServiceRetryTraits>; +/// The retry policy for `UptimeCheckServiceConnection`. +class UptimeCheckServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using UptimeCheckServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - monitoring_v3_internal::UptimeCheckServiceRetryTraits>; +/** + * A retry policy for `UptimeCheckServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class UptimeCheckServiceLimitedErrorCountRetryPolicy + : public UptimeCheckServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit UptimeCheckServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + UptimeCheckServiceLimitedErrorCountRetryPolicy( + UptimeCheckServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : UptimeCheckServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + UptimeCheckServiceLimitedErrorCountRetryPolicy( + UptimeCheckServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : UptimeCheckServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = UptimeCheckServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + monitoring_v3_internal::UptimeCheckServiceRetryTraits> + impl_; +}; -using UptimeCheckServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - monitoring_v3_internal::UptimeCheckServiceRetryTraits>; +/** + * A retry policy for `UptimeCheckServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class UptimeCheckServiceLimitedTimeRetryPolicy + : public UptimeCheckServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit UptimeCheckServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + UptimeCheckServiceLimitedTimeRetryPolicy( + UptimeCheckServiceLimitedTimeRetryPolicy&& rhs) noexcept + : UptimeCheckServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + UptimeCheckServiceLimitedTimeRetryPolicy( + UptimeCheckServiceLimitedTimeRetryPolicy const& rhs) noexcept + : UptimeCheckServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = UptimeCheckServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + monitoring_v3_internal::UptimeCheckServiceRetryTraits> + impl_; +}; /** * The `UptimeCheckServiceConnection` object for `UptimeCheckServiceClient`. diff --git a/google/cloud/networkconnectivity/v1/hub_connection.h b/google/cloud/networkconnectivity/v1/hub_connection.h index c5cedc8274f17..c5628dfde92c5 100644 --- a/google/cloud/networkconnectivity/v1/hub_connection.h +++ b/google/cloud/networkconnectivity/v1/hub_connection.h @@ -39,16 +39,133 @@ namespace cloud { namespace networkconnectivity_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using HubServiceRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - networkconnectivity_v1_internal::HubServiceRetryTraits>; +/// The retry policy for `HubServiceConnection`. +class HubServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `HubServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class HubServiceLimitedErrorCountRetryPolicy : public HubServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit HubServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + HubServiceLimitedErrorCountRetryPolicy( + HubServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : HubServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + HubServiceLimitedErrorCountRetryPolicy( + HubServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : HubServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = HubServiceRetryPolicy; -using HubServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - networkconnectivity_v1_internal::HubServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + networkconnectivity_v1_internal::HubServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `HubServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class HubServiceLimitedTimeRetryPolicy : public HubServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit HubServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + HubServiceLimitedTimeRetryPolicy( + HubServiceLimitedTimeRetryPolicy&& rhs) noexcept + : HubServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + HubServiceLimitedTimeRetryPolicy( + HubServiceLimitedTimeRetryPolicy const& rhs) noexcept + : HubServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using HubServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - networkconnectivity_v1_internal::HubServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = HubServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + networkconnectivity_v1_internal::HubServiceRetryTraits> + impl_; +}; /** * The `HubServiceConnection` object for `HubServiceClient`. diff --git a/google/cloud/networkmanagement/v1/reachability_connection.h b/google/cloud/networkmanagement/v1/reachability_connection.h index dd5b08ceac2f1..5abdcb6745151 100644 --- a/google/cloud/networkmanagement/v1/reachability_connection.h +++ b/google/cloud/networkmanagement/v1/reachability_connection.h @@ -38,17 +38,137 @@ namespace cloud { namespace networkmanagement_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ReachabilityServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - networkmanagement_v1_internal::ReachabilityServiceRetryTraits>; +/// The retry policy for `ReachabilityServiceConnection`. +class ReachabilityServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ReachabilityServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ReachabilityServiceLimitedErrorCountRetryPolicy + : public ReachabilityServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ReachabilityServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ReachabilityServiceLimitedErrorCountRetryPolicy( + ReachabilityServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ReachabilityServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ReachabilityServiceLimitedErrorCountRetryPolicy( + ReachabilityServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ReachabilityServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ReachabilityServiceRetryPolicy; -using ReachabilityServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - networkmanagement_v1_internal::ReachabilityServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + networkmanagement_v1_internal::ReachabilityServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ReachabilityServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ReachabilityServiceLimitedTimeRetryPolicy + : public ReachabilityServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ReachabilityServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ReachabilityServiceLimitedTimeRetryPolicy( + ReachabilityServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ReachabilityServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ReachabilityServiceLimitedTimeRetryPolicy( + ReachabilityServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ReachabilityServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ReachabilityServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - networkmanagement_v1_internal::ReachabilityServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ReachabilityServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + networkmanagement_v1_internal::ReachabilityServiceRetryTraits> + impl_; +}; /** * The `ReachabilityServiceConnection` object for `ReachabilityServiceClient`. diff --git a/google/cloud/networksecurity/v1/network_security_connection.h b/google/cloud/networksecurity/v1/network_security_connection.h index 87db0676ad507..cb42d0ffdd2d8 100644 --- a/google/cloud/networksecurity/v1/network_security_connection.h +++ b/google/cloud/networksecurity/v1/network_security_connection.h @@ -39,17 +39,135 @@ namespace cloud { namespace networksecurity_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NetworkSecurityRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - networksecurity_v1_internal::NetworkSecurityRetryTraits>; +/// The retry policy for `NetworkSecurityConnection`. +class NetworkSecurityRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `NetworkSecurityConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkSecurityLimitedErrorCountRetryPolicy + : public NetworkSecurityRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NetworkSecurityLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + NetworkSecurityLimitedErrorCountRetryPolicy( + NetworkSecurityLimitedErrorCountRetryPolicy&& rhs) noexcept + : NetworkSecurityLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + NetworkSecurityLimitedErrorCountRetryPolicy( + NetworkSecurityLimitedErrorCountRetryPolicy const& rhs) noexcept + : NetworkSecurityLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkSecurityRetryPolicy; -using NetworkSecurityLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - networksecurity_v1_internal::NetworkSecurityRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + networksecurity_v1_internal::NetworkSecurityRetryTraits> + impl_; +}; + +/** + * A retry policy for `NetworkSecurityConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkSecurityLimitedTimeRetryPolicy + : public NetworkSecurityRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NetworkSecurityLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NetworkSecurityLimitedTimeRetryPolicy( + NetworkSecurityLimitedTimeRetryPolicy&& rhs) noexcept + : NetworkSecurityLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NetworkSecurityLimitedTimeRetryPolicy( + NetworkSecurityLimitedTimeRetryPolicy const& rhs) noexcept + : NetworkSecurityLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using NetworkSecurityLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - networksecurity_v1_internal::NetworkSecurityRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkSecurityRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + networksecurity_v1_internal::NetworkSecurityRetryTraits> + impl_; +}; /** * The `NetworkSecurityConnection` object for `NetworkSecurityClient`. diff --git a/google/cloud/networkservices/v1/network_services_connection.h b/google/cloud/networkservices/v1/network_services_connection.h index 7e2e297dfcc4a..ed9f5df91fcec 100644 --- a/google/cloud/networkservices/v1/network_services_connection.h +++ b/google/cloud/networkservices/v1/network_services_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace networkservices_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NetworkServicesRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - networkservices_v1_internal::NetworkServicesRetryTraits>; +/// The retry policy for `NetworkServicesConnection`. +class NetworkServicesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using NetworkServicesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - networkservices_v1_internal::NetworkServicesRetryTraits>; +/** + * A retry policy for `NetworkServicesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkServicesLimitedErrorCountRetryPolicy + : public NetworkServicesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NetworkServicesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + NetworkServicesLimitedErrorCountRetryPolicy( + NetworkServicesLimitedErrorCountRetryPolicy&& rhs) noexcept + : NetworkServicesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + NetworkServicesLimitedErrorCountRetryPolicy( + NetworkServicesLimitedErrorCountRetryPolicy const& rhs) noexcept + : NetworkServicesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkServicesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + networkservices_v1_internal::NetworkServicesRetryTraits> + impl_; +}; -using NetworkServicesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - networkservices_v1_internal::NetworkServicesRetryTraits>; +/** + * A retry policy for `NetworkServicesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NetworkServicesLimitedTimeRetryPolicy + : public NetworkServicesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NetworkServicesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NetworkServicesLimitedTimeRetryPolicy( + NetworkServicesLimitedTimeRetryPolicy&& rhs) noexcept + : NetworkServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NetworkServicesLimitedTimeRetryPolicy( + NetworkServicesLimitedTimeRetryPolicy const& rhs) noexcept + : NetworkServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NetworkServicesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + networkservices_v1_internal::NetworkServicesRetryTraits> + impl_; +}; /** * The `NetworkServicesConnection` object for `NetworkServicesClient`. diff --git a/google/cloud/notebooks/v1/managed_notebook_connection.h b/google/cloud/notebooks/v1/managed_notebook_connection.h index f58f10b8556b0..c677319d38020 100644 --- a/google/cloud/notebooks/v1/managed_notebook_connection.h +++ b/google/cloud/notebooks/v1/managed_notebook_connection.h @@ -39,17 +39,139 @@ namespace cloud { namespace notebooks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ManagedNotebookServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - notebooks_v1_internal::ManagedNotebookServiceRetryTraits>; +/// The retry policy for `ManagedNotebookServiceConnection`. +class ManagedNotebookServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ManagedNotebookServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ManagedNotebookServiceLimitedErrorCountRetryPolicy + : public ManagedNotebookServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ManagedNotebookServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ManagedNotebookServiceLimitedErrorCountRetryPolicy( + ManagedNotebookServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ManagedNotebookServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ManagedNotebookServiceLimitedErrorCountRetryPolicy( + ManagedNotebookServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ManagedNotebookServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ManagedNotebookServiceRetryPolicy; -using ManagedNotebookServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - notebooks_v1_internal::ManagedNotebookServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + notebooks_v1_internal::ManagedNotebookServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ManagedNotebookServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ManagedNotebookServiceLimitedTimeRetryPolicy + : public ManagedNotebookServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ManagedNotebookServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ManagedNotebookServiceLimitedTimeRetryPolicy( + ManagedNotebookServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ManagedNotebookServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ManagedNotebookServiceLimitedTimeRetryPolicy( + ManagedNotebookServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ManagedNotebookServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ManagedNotebookServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - notebooks_v1_internal::ManagedNotebookServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ManagedNotebookServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + notebooks_v1_internal::ManagedNotebookServiceRetryTraits> + impl_; +}; /** * The `ManagedNotebookServiceConnection` object for diff --git a/google/cloud/notebooks/v1/notebook_connection.h b/google/cloud/notebooks/v1/notebook_connection.h index b07fcad81a06a..ffa421bb7fc63 100644 --- a/google/cloud/notebooks/v1/notebook_connection.h +++ b/google/cloud/notebooks/v1/notebook_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace notebooks_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using NotebookServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - notebooks_v1_internal::NotebookServiceRetryTraits>; +/// The retry policy for `NotebookServiceConnection`. +class NotebookServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using NotebookServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - notebooks_v1_internal::NotebookServiceRetryTraits>; +/** + * A retry policy for `NotebookServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NotebookServiceLimitedErrorCountRetryPolicy + : public NotebookServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit NotebookServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + NotebookServiceLimitedErrorCountRetryPolicy( + NotebookServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : NotebookServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + NotebookServiceLimitedErrorCountRetryPolicy( + NotebookServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : NotebookServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = NotebookServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + notebooks_v1_internal::NotebookServiceRetryTraits> + impl_; +}; -using NotebookServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - notebooks_v1_internal::NotebookServiceRetryTraits>; +/** + * A retry policy for `NotebookServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class NotebookServiceLimitedTimeRetryPolicy + : public NotebookServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit NotebookServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + NotebookServiceLimitedTimeRetryPolicy( + NotebookServiceLimitedTimeRetryPolicy&& rhs) noexcept + : NotebookServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + NotebookServiceLimitedTimeRetryPolicy( + NotebookServiceLimitedTimeRetryPolicy const& rhs) noexcept + : NotebookServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = NotebookServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + notebooks_v1_internal::NotebookServiceRetryTraits> + impl_; +}; /** * The `NotebookServiceConnection` object for `NotebookServiceClient`. diff --git a/google/cloud/optimization/v1/fleet_routing_connection.h b/google/cloud/optimization/v1/fleet_routing_connection.h index 84129b834c4ab..6c00485e58534 100644 --- a/google/cloud/optimization/v1/fleet_routing_connection.h +++ b/google/cloud/optimization/v1/fleet_routing_connection.h @@ -37,17 +37,134 @@ namespace cloud { namespace optimization_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FleetRoutingRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - optimization_v1_internal::FleetRoutingRetryTraits>; +/// The retry policy for `FleetRoutingConnection`. +class FleetRoutingRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `FleetRoutingConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FleetRoutingLimitedErrorCountRetryPolicy + : public FleetRoutingRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FleetRoutingLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + FleetRoutingLimitedErrorCountRetryPolicy( + FleetRoutingLimitedErrorCountRetryPolicy&& rhs) noexcept + : FleetRoutingLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + FleetRoutingLimitedErrorCountRetryPolicy( + FleetRoutingLimitedErrorCountRetryPolicy const& rhs) noexcept + : FleetRoutingLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FleetRoutingRetryPolicy; -using FleetRoutingLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - optimization_v1_internal::FleetRoutingRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + optimization_v1_internal::FleetRoutingRetryTraits> + impl_; +}; + +/** + * A retry policy for `FleetRoutingConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FleetRoutingLimitedTimeRetryPolicy : public FleetRoutingRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FleetRoutingLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FleetRoutingLimitedTimeRetryPolicy( + FleetRoutingLimitedTimeRetryPolicy&& rhs) noexcept + : FleetRoutingLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + FleetRoutingLimitedTimeRetryPolicy( + FleetRoutingLimitedTimeRetryPolicy const& rhs) noexcept + : FleetRoutingLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using FleetRoutingLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - optimization_v1_internal::FleetRoutingRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FleetRoutingRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + optimization_v1_internal::FleetRoutingRetryTraits> + impl_; +}; /** * The `FleetRoutingConnection` object for `FleetRoutingClient`. diff --git a/google/cloud/orgpolicy/v2/org_policy_connection.h b/google/cloud/orgpolicy/v2/org_policy_connection.h index 073a26c0fe1ae..5f12f616108e3 100644 --- a/google/cloud/orgpolicy/v2/org_policy_connection.h +++ b/google/cloud/orgpolicy/v2/org_policy_connection.h @@ -35,16 +35,133 @@ namespace cloud { namespace orgpolicy_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using OrgPolicyRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - orgpolicy_v2_internal::OrgPolicyRetryTraits>; +/// The retry policy for `OrgPolicyConnection`. +class OrgPolicyRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using OrgPolicyLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - orgpolicy_v2_internal::OrgPolicyRetryTraits>; +/** + * A retry policy for `OrgPolicyConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class OrgPolicyLimitedErrorCountRetryPolicy : public OrgPolicyRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit OrgPolicyLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + OrgPolicyLimitedErrorCountRetryPolicy( + OrgPolicyLimitedErrorCountRetryPolicy&& rhs) noexcept + : OrgPolicyLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + OrgPolicyLimitedErrorCountRetryPolicy( + OrgPolicyLimitedErrorCountRetryPolicy const& rhs) noexcept + : OrgPolicyLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = OrgPolicyRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + orgpolicy_v2_internal::OrgPolicyRetryTraits> + impl_; +}; -using OrgPolicyLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - orgpolicy_v2_internal::OrgPolicyRetryTraits>; +/** + * A retry policy for `OrgPolicyConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class OrgPolicyLimitedTimeRetryPolicy : public OrgPolicyRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit OrgPolicyLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + OrgPolicyLimitedTimeRetryPolicy( + OrgPolicyLimitedTimeRetryPolicy&& rhs) noexcept + : OrgPolicyLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + OrgPolicyLimitedTimeRetryPolicy( + OrgPolicyLimitedTimeRetryPolicy const& rhs) noexcept + : OrgPolicyLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = OrgPolicyRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + orgpolicy_v2_internal::OrgPolicyRetryTraits> + impl_; +}; /** * The `OrgPolicyConnection` object for `OrgPolicyClient`. diff --git a/google/cloud/osconfig/agentendpoint/v1/agent_endpoint_connection.h b/google/cloud/osconfig/agentendpoint/v1/agent_endpoint_connection.h index fec6bfcc1e721..4089c9bf02e76 100644 --- a/google/cloud/osconfig/agentendpoint/v1/agent_endpoint_connection.h +++ b/google/cloud/osconfig/agentendpoint/v1/agent_endpoint_connection.h @@ -35,17 +35,138 @@ namespace cloud { namespace osconfig_agentendpoint_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AgentEndpointServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - osconfig_agentendpoint_v1_internal::AgentEndpointServiceRetryTraits>; +/// The retry policy for `AgentEndpointServiceConnection`. +class AgentEndpointServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `AgentEndpointServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AgentEndpointServiceLimitedErrorCountRetryPolicy + : public AgentEndpointServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AgentEndpointServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + AgentEndpointServiceLimitedErrorCountRetryPolicy( + AgentEndpointServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AgentEndpointServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + AgentEndpointServiceLimitedErrorCountRetryPolicy( + AgentEndpointServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AgentEndpointServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AgentEndpointServiceRetryPolicy; -using AgentEndpointServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - osconfig_agentendpoint_v1_internal::AgentEndpointServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + osconfig_agentendpoint_v1_internal::AgentEndpointServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `AgentEndpointServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AgentEndpointServiceLimitedTimeRetryPolicy + : public AgentEndpointServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AgentEndpointServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AgentEndpointServiceLimitedTimeRetryPolicy( + AgentEndpointServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AgentEndpointServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AgentEndpointServiceLimitedTimeRetryPolicy( + AgentEndpointServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AgentEndpointServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using AgentEndpointServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - osconfig_agentendpoint_v1_internal::AgentEndpointServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AgentEndpointServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + osconfig_agentendpoint_v1_internal::AgentEndpointServiceRetryTraits> + impl_; +}; /** * The `AgentEndpointServiceConnection` object for `AgentEndpointServiceClient`. diff --git a/google/cloud/osconfig/v1/os_config_connection.h b/google/cloud/osconfig/v1/os_config_connection.h index 913648697e026..ad2751fbed287 100644 --- a/google/cloud/osconfig/v1/os_config_connection.h +++ b/google/cloud/osconfig/v1/os_config_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace osconfig_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using OsConfigServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - osconfig_v1_internal::OsConfigServiceRetryTraits>; +/// The retry policy for `OsConfigServiceConnection`. +class OsConfigServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `OsConfigServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class OsConfigServiceLimitedErrorCountRetryPolicy + : public OsConfigServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit OsConfigServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + OsConfigServiceLimitedErrorCountRetryPolicy( + OsConfigServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : OsConfigServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + OsConfigServiceLimitedErrorCountRetryPolicy( + OsConfigServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : OsConfigServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = OsConfigServiceRetryPolicy; -using OsConfigServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - osconfig_v1_internal::OsConfigServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + osconfig_v1_internal::OsConfigServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `OsConfigServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class OsConfigServiceLimitedTimeRetryPolicy + : public OsConfigServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit OsConfigServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + OsConfigServiceLimitedTimeRetryPolicy( + OsConfigServiceLimitedTimeRetryPolicy&& rhs) noexcept + : OsConfigServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + OsConfigServiceLimitedTimeRetryPolicy( + OsConfigServiceLimitedTimeRetryPolicy const& rhs) noexcept + : OsConfigServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using OsConfigServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - osconfig_v1_internal::OsConfigServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = OsConfigServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + osconfig_v1_internal::OsConfigServiceRetryTraits> + impl_; +}; /** * The `OsConfigServiceConnection` object for `OsConfigServiceClient`. diff --git a/google/cloud/oslogin/v1/os_login_connection.h b/google/cloud/oslogin/v1/os_login_connection.h index 96256e5b32530..daa53d7d945a3 100644 --- a/google/cloud/oslogin/v1/os_login_connection.h +++ b/google/cloud/oslogin/v1/os_login_connection.h @@ -34,17 +34,134 @@ namespace cloud { namespace oslogin_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using OsLoginServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - oslogin_v1_internal::OsLoginServiceRetryTraits>; +/// The retry policy for `OsLoginServiceConnection`. +class OsLoginServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using OsLoginServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - oslogin_v1_internal::OsLoginServiceRetryTraits>; +/** + * A retry policy for `OsLoginServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class OsLoginServiceLimitedErrorCountRetryPolicy + : public OsLoginServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit OsLoginServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + OsLoginServiceLimitedErrorCountRetryPolicy( + OsLoginServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : OsLoginServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + OsLoginServiceLimitedErrorCountRetryPolicy( + OsLoginServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : OsLoginServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = OsLoginServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + oslogin_v1_internal::OsLoginServiceRetryTraits> + impl_; +}; -using OsLoginServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - oslogin_v1_internal::OsLoginServiceRetryTraits>; +/** + * A retry policy for `OsLoginServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class OsLoginServiceLimitedTimeRetryPolicy : public OsLoginServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit OsLoginServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + OsLoginServiceLimitedTimeRetryPolicy( + OsLoginServiceLimitedTimeRetryPolicy&& rhs) noexcept + : OsLoginServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + OsLoginServiceLimitedTimeRetryPolicy( + OsLoginServiceLimitedTimeRetryPolicy const& rhs) noexcept + : OsLoginServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = OsLoginServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + oslogin_v1_internal::OsLoginServiceRetryTraits> + impl_; +}; /** * The `OsLoginServiceConnection` object for `OsLoginServiceClient`. diff --git a/google/cloud/policytroubleshooter/v1/iam_checker_connection.h b/google/cloud/policytroubleshooter/v1/iam_checker_connection.h index b03d0b5fe98be..f51ebef4c44cd 100644 --- a/google/cloud/policytroubleshooter/v1/iam_checker_connection.h +++ b/google/cloud/policytroubleshooter/v1/iam_checker_connection.h @@ -34,16 +34,133 @@ namespace cloud { namespace policytroubleshooter_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using IamCheckerRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - policytroubleshooter_v1_internal::IamCheckerRetryTraits>; +/// The retry policy for `IamCheckerConnection`. +class IamCheckerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `IamCheckerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IamCheckerLimitedErrorCountRetryPolicy : public IamCheckerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit IamCheckerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + IamCheckerLimitedErrorCountRetryPolicy( + IamCheckerLimitedErrorCountRetryPolicy&& rhs) noexcept + : IamCheckerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + IamCheckerLimitedErrorCountRetryPolicy( + IamCheckerLimitedErrorCountRetryPolicy const& rhs) noexcept + : IamCheckerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = IamCheckerRetryPolicy; -using IamCheckerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - policytroubleshooter_v1_internal::IamCheckerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + policytroubleshooter_v1_internal::IamCheckerRetryTraits> + impl_; +}; + +/** + * A retry policy for `IamCheckerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class IamCheckerLimitedTimeRetryPolicy : public IamCheckerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit IamCheckerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + IamCheckerLimitedTimeRetryPolicy( + IamCheckerLimitedTimeRetryPolicy&& rhs) noexcept + : IamCheckerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + IamCheckerLimitedTimeRetryPolicy( + IamCheckerLimitedTimeRetryPolicy const& rhs) noexcept + : IamCheckerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using IamCheckerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - policytroubleshooter_v1_internal::IamCheckerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = IamCheckerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + policytroubleshooter_v1_internal::IamCheckerRetryTraits> + impl_; +}; /** * The `IamCheckerConnection` object for `IamCheckerClient`. diff --git a/google/cloud/privateca/v1/certificate_authority_connection.h b/google/cloud/privateca/v1/certificate_authority_connection.h index d984480b69c32..ef8d487458b68 100644 --- a/google/cloud/privateca/v1/certificate_authority_connection.h +++ b/google/cloud/privateca/v1/certificate_authority_connection.h @@ -38,17 +38,150 @@ namespace cloud { namespace privateca_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CertificateAuthorityServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - privateca_v1_internal::CertificateAuthorityServiceRetryTraits>; +/// The retry policy for `CertificateAuthorityServiceConnection`. +class CertificateAuthorityServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; -using CertificateAuthorityServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - privateca_v1_internal::CertificateAuthorityServiceRetryTraits>; +/** + * A retry policy for `CertificateAuthorityServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class CertificateAuthorityServiceLimitedErrorCountRetryPolicy + : public CertificateAuthorityServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CertificateAuthorityServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + CertificateAuthorityServiceLimitedErrorCountRetryPolicy( + CertificateAuthorityServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CertificateAuthorityServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + CertificateAuthorityServiceLimitedErrorCountRetryPolicy( + CertificateAuthorityServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : CertificateAuthorityServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + CertificateAuthorityServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CertificateAuthorityServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + privateca_v1_internal::CertificateAuthorityServiceRetryTraits> + impl_; +}; -using CertificateAuthorityServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - privateca_v1_internal::CertificateAuthorityServiceRetryTraits>; +/** + * A retry policy for `CertificateAuthorityServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class CertificateAuthorityServiceLimitedTimeRetryPolicy + : public CertificateAuthorityServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CertificateAuthorityServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CertificateAuthorityServiceLimitedTimeRetryPolicy( + CertificateAuthorityServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CertificateAuthorityServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + CertificateAuthorityServiceLimitedTimeRetryPolicy( + CertificateAuthorityServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CertificateAuthorityServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CertificateAuthorityServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + privateca_v1_internal::CertificateAuthorityServiceRetryTraits> + impl_; +}; /** * The `CertificateAuthorityServiceConnection` object for diff --git a/google/cloud/profiler/v2/profiler_connection.h b/google/cloud/profiler/v2/profiler_connection.h index db4669f48e2ad..9b4402c3a95c4 100644 --- a/google/cloud/profiler/v2/profiler_connection.h +++ b/google/cloud/profiler/v2/profiler_connection.h @@ -34,17 +34,135 @@ namespace cloud { namespace profiler_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ProfilerServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - profiler_v2_internal::ProfilerServiceRetryTraits>; +/// The retry policy for `ProfilerServiceConnection`. +class ProfilerServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ProfilerServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProfilerServiceLimitedErrorCountRetryPolicy + : public ProfilerServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ProfilerServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ProfilerServiceLimitedErrorCountRetryPolicy( + ProfilerServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ProfilerServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ProfilerServiceLimitedErrorCountRetryPolicy( + ProfilerServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ProfilerServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProfilerServiceRetryPolicy; -using ProfilerServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - profiler_v2_internal::ProfilerServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + profiler_v2_internal::ProfilerServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ProfilerServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProfilerServiceLimitedTimeRetryPolicy + : public ProfilerServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ProfilerServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ProfilerServiceLimitedTimeRetryPolicy( + ProfilerServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ProfilerServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ProfilerServiceLimitedTimeRetryPolicy( + ProfilerServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ProfilerServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ProfilerServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - profiler_v2_internal::ProfilerServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProfilerServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + profiler_v2_internal::ProfilerServiceRetryTraits> + impl_; +}; /** * The `ProfilerServiceConnection` object for `ProfilerServiceClient`. diff --git a/google/cloud/pubsub/schema_connection.h b/google/cloud/pubsub/schema_connection.h index ae1ebc532ff7c..8dae5f0d4765e 100644 --- a/google/cloud/pubsub/schema_connection.h +++ b/google/cloud/pubsub/schema_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace pubsub { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SchemaServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - pubsub_internal::SchemaServiceRetryTraits>; +/// The retry policy for `SchemaServiceConnection`. +class SchemaServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SchemaServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - pubsub_internal::SchemaServiceRetryTraits>; +/** + * A retry policy for `SchemaServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SchemaServiceLimitedErrorCountRetryPolicy + : public SchemaServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SchemaServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SchemaServiceLimitedErrorCountRetryPolicy( + SchemaServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SchemaServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SchemaServiceLimitedErrorCountRetryPolicy( + SchemaServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SchemaServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SchemaServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + pubsub_internal::SchemaServiceRetryTraits> + impl_; +}; -using SchemaServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - pubsub_internal::SchemaServiceRetryTraits>; +/** + * A retry policy for `SchemaServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SchemaServiceLimitedTimeRetryPolicy : public SchemaServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SchemaServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SchemaServiceLimitedTimeRetryPolicy( + SchemaServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SchemaServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SchemaServiceLimitedTimeRetryPolicy( + SchemaServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SchemaServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SchemaServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + pubsub_internal::SchemaServiceRetryTraits> + impl_; +}; /** * The `SchemaServiceConnection` object for `SchemaServiceClient`. diff --git a/google/cloud/pubsublite/admin_connection.h b/google/cloud/pubsublite/admin_connection.h index b36ff7da972ae..ce7b079cf7a24 100644 --- a/google/cloud/pubsublite/admin_connection.h +++ b/google/cloud/pubsublite/admin_connection.h @@ -38,17 +38,136 @@ namespace cloud { namespace pubsublite { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using AdminServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - pubsublite_internal::AdminServiceRetryTraits>; +/// The retry policy for `AdminServiceConnection`. +class AdminServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using AdminServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - pubsublite_internal::AdminServiceRetryTraits>; +/** + * A retry policy for `AdminServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kInternal`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AdminServiceLimitedErrorCountRetryPolicy + : public AdminServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit AdminServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + AdminServiceLimitedErrorCountRetryPolicy( + AdminServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : AdminServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + AdminServiceLimitedErrorCountRetryPolicy( + AdminServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : AdminServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = AdminServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + pubsublite_internal::AdminServiceRetryTraits> + impl_; +}; -using AdminServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - pubsublite_internal::AdminServiceRetryTraits>; +/** + * A retry policy for `AdminServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kInternal`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class AdminServiceLimitedTimeRetryPolicy : public AdminServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit AdminServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + AdminServiceLimitedTimeRetryPolicy( + AdminServiceLimitedTimeRetryPolicy&& rhs) noexcept + : AdminServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + AdminServiceLimitedTimeRetryPolicy( + AdminServiceLimitedTimeRetryPolicy const& rhs) noexcept + : AdminServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = AdminServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + pubsublite_internal::AdminServiceRetryTraits> + impl_; +}; /** * The `AdminServiceConnection` object for `AdminServiceClient`. diff --git a/google/cloud/pubsublite/topic_stats_connection.h b/google/cloud/pubsublite/topic_stats_connection.h index 5f3f4ea01e57a..afb2959507d94 100644 --- a/google/cloud/pubsublite/topic_stats_connection.h +++ b/google/cloud/pubsublite/topic_stats_connection.h @@ -34,17 +34,137 @@ namespace cloud { namespace pubsublite { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TopicStatsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - pubsublite_internal::TopicStatsServiceRetryTraits>; +/// The retry policy for `TopicStatsServiceConnection`. +class TopicStatsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TopicStatsServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kInternal`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TopicStatsServiceLimitedErrorCountRetryPolicy + : public TopicStatsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TopicStatsServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TopicStatsServiceLimitedErrorCountRetryPolicy( + TopicStatsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : TopicStatsServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TopicStatsServiceLimitedErrorCountRetryPolicy( + TopicStatsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : TopicStatsServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TopicStatsServiceRetryPolicy; -using TopicStatsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - pubsublite_internal::TopicStatsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + pubsublite_internal::TopicStatsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `TopicStatsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kInternal`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TopicStatsServiceLimitedTimeRetryPolicy + : public TopicStatsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TopicStatsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TopicStatsServiceLimitedTimeRetryPolicy( + TopicStatsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : TopicStatsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TopicStatsServiceLimitedTimeRetryPolicy( + TopicStatsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : TopicStatsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using TopicStatsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - pubsublite_internal::TopicStatsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TopicStatsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + pubsublite_internal::TopicStatsServiceRetryTraits> + impl_; +}; /** * The `TopicStatsServiceConnection` object for `TopicStatsServiceClient`. diff --git a/google/cloud/rapidmigrationassessment/v1/rapid_migration_assessment_connection.h b/google/cloud/rapidmigrationassessment/v1/rapid_migration_assessment_connection.h index cd6389a021473..2e0bc5f172813 100644 --- a/google/cloud/rapidmigrationassessment/v1/rapid_migration_assessment_connection.h +++ b/google/cloud/rapidmigrationassessment/v1/rapid_migration_assessment_connection.h @@ -39,20 +39,145 @@ namespace cloud { namespace rapidmigrationassessment_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RapidMigrationAssessmentRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - rapidmigrationassessment_v1_internal:: - RapidMigrationAssessmentRetryTraits>; - -using RapidMigrationAssessmentLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - rapidmigrationassessment_v1_internal:: - RapidMigrationAssessmentRetryTraits>; - -using RapidMigrationAssessmentLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - rapidmigrationassessment_v1_internal:: - RapidMigrationAssessmentRetryTraits>; +/// The retry policy for `RapidMigrationAssessmentConnection`. +class RapidMigrationAssessmentRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `RapidMigrationAssessmentConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RapidMigrationAssessmentLimitedErrorCountRetryPolicy + : public RapidMigrationAssessmentRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RapidMigrationAssessmentLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RapidMigrationAssessmentLimitedErrorCountRetryPolicy( + RapidMigrationAssessmentLimitedErrorCountRetryPolicy&& rhs) noexcept + : RapidMigrationAssessmentLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RapidMigrationAssessmentLimitedErrorCountRetryPolicy( + RapidMigrationAssessmentLimitedErrorCountRetryPolicy const& rhs) noexcept + : RapidMigrationAssessmentLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + RapidMigrationAssessmentLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RapidMigrationAssessmentRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + rapidmigrationassessment_v1_internal::RapidMigrationAssessmentRetryTraits> + impl_; +}; + +/** + * A retry policy for `RapidMigrationAssessmentConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RapidMigrationAssessmentLimitedTimeRetryPolicy + : public RapidMigrationAssessmentRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RapidMigrationAssessmentLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RapidMigrationAssessmentLimitedTimeRetryPolicy( + RapidMigrationAssessmentLimitedTimeRetryPolicy&& rhs) noexcept + : RapidMigrationAssessmentLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + RapidMigrationAssessmentLimitedTimeRetryPolicy( + RapidMigrationAssessmentLimitedTimeRetryPolicy const& rhs) noexcept + : RapidMigrationAssessmentLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RapidMigrationAssessmentRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + rapidmigrationassessment_v1_internal::RapidMigrationAssessmentRetryTraits> + impl_; +}; /** * The `RapidMigrationAssessmentConnection` object for diff --git a/google/cloud/recaptchaenterprise/v1/recaptcha_enterprise_connection.h b/google/cloud/recaptchaenterprise/v1/recaptcha_enterprise_connection.h index 4191b05a5839c..66c14a2a640ac 100644 --- a/google/cloud/recaptchaenterprise/v1/recaptcha_enterprise_connection.h +++ b/google/cloud/recaptchaenterprise/v1/recaptcha_enterprise_connection.h @@ -35,17 +35,148 @@ namespace cloud { namespace recaptchaenterprise_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RecaptchaEnterpriseServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - recaptchaenterprise_v1_internal::RecaptchaEnterpriseServiceRetryTraits>; +/// The retry policy for `RecaptchaEnterpriseServiceConnection`. +class RecaptchaEnterpriseServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `RecaptchaEnterpriseServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy + : public RecaptchaEnterpriseServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy( + RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy( + RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RecaptchaEnterpriseServiceRetryPolicy; -using RecaptchaEnterpriseServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - recaptchaenterprise_v1_internal::RecaptchaEnterpriseServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + recaptchaenterprise_v1_internal::RecaptchaEnterpriseServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `RecaptchaEnterpriseServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RecaptchaEnterpriseServiceLimitedTimeRetryPolicy + : public RecaptchaEnterpriseServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RecaptchaEnterpriseServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RecaptchaEnterpriseServiceLimitedTimeRetryPolicy( + RecaptchaEnterpriseServiceLimitedTimeRetryPolicy&& rhs) noexcept + : RecaptchaEnterpriseServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + RecaptchaEnterpriseServiceLimitedTimeRetryPolicy( + RecaptchaEnterpriseServiceLimitedTimeRetryPolicy const& rhs) noexcept + : RecaptchaEnterpriseServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RecaptchaEnterpriseServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - recaptchaenterprise_v1_internal::RecaptchaEnterpriseServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RecaptchaEnterpriseServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + recaptchaenterprise_v1_internal::RecaptchaEnterpriseServiceRetryTraits> + impl_; +}; /** * The `RecaptchaEnterpriseServiceConnection` object for diff --git a/google/cloud/recommender/v1/recommender_connection.h b/google/cloud/recommender/v1/recommender_connection.h index 8e969c57921d4..79659d336d31a 100644 --- a/google/cloud/recommender/v1/recommender_connection.h +++ b/google/cloud/recommender/v1/recommender_connection.h @@ -35,16 +35,133 @@ namespace cloud { namespace recommender_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RecommenderRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - recommender_v1_internal::RecommenderRetryTraits>; +/// The retry policy for `RecommenderConnection`. +class RecommenderRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RecommenderConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RecommenderLimitedErrorCountRetryPolicy : public RecommenderRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RecommenderLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RecommenderLimitedErrorCountRetryPolicy( + RecommenderLimitedErrorCountRetryPolicy&& rhs) noexcept + : RecommenderLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RecommenderLimitedErrorCountRetryPolicy( + RecommenderLimitedErrorCountRetryPolicy const& rhs) noexcept + : RecommenderLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RecommenderRetryPolicy; -using RecommenderLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - recommender_v1_internal::RecommenderRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + recommender_v1_internal::RecommenderRetryTraits> + impl_; +}; + +/** + * A retry policy for `RecommenderConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RecommenderLimitedTimeRetryPolicy : public RecommenderRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RecommenderLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RecommenderLimitedTimeRetryPolicy( + RecommenderLimitedTimeRetryPolicy&& rhs) noexcept + : RecommenderLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RecommenderLimitedTimeRetryPolicy( + RecommenderLimitedTimeRetryPolicy const& rhs) noexcept + : RecommenderLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RecommenderLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - recommender_v1_internal::RecommenderRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RecommenderRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + recommender_v1_internal::RecommenderRetryTraits> + impl_; +}; /** * The `RecommenderConnection` object for `RecommenderClient`. diff --git a/google/cloud/redis/v1/cloud_redis_connection.h b/google/cloud/redis/v1/cloud_redis_connection.h index b5e4d6c97619b..6298234317a56 100644 --- a/google/cloud/redis/v1/cloud_redis_connection.h +++ b/google/cloud/redis/v1/cloud_redis_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace redis_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudRedisRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - redis_v1_internal::CloudRedisRetryTraits>; +/// The retry policy for `CloudRedisConnection`. +class CloudRedisRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CloudRedisLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - redis_v1_internal::CloudRedisRetryTraits>; +/** + * A retry policy for `CloudRedisConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudRedisLimitedErrorCountRetryPolicy : public CloudRedisRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudRedisLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudRedisLimitedErrorCountRetryPolicy( + CloudRedisLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudRedisLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudRedisLimitedErrorCountRetryPolicy( + CloudRedisLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudRedisLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudRedisRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + redis_v1_internal::CloudRedisRetryTraits> + impl_; +}; -using CloudRedisLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - redis_v1_internal::CloudRedisRetryTraits>; +/** + * A retry policy for `CloudRedisConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudRedisLimitedTimeRetryPolicy : public CloudRedisRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudRedisLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudRedisLimitedTimeRetryPolicy( + CloudRedisLimitedTimeRetryPolicy&& rhs) noexcept + : CloudRedisLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudRedisLimitedTimeRetryPolicy( + CloudRedisLimitedTimeRetryPolicy const& rhs) noexcept + : CloudRedisLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudRedisRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + redis_v1_internal::CloudRedisRetryTraits> + impl_; +}; /** * The `CloudRedisConnection` object for `CloudRedisClient`. diff --git a/google/cloud/resourcemanager/v3/folders_connection.h b/google/cloud/resourcemanager/v3/folders_connection.h index 7fb8570ab358c..f03bbbf0e0ad0 100644 --- a/google/cloud/resourcemanager/v3/folders_connection.h +++ b/google/cloud/resourcemanager/v3/folders_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace resourcemanager_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using FoldersRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - resourcemanager_v3_internal::FoldersRetryTraits>; +/// The retry policy for `FoldersConnection`. +class FoldersRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using FoldersLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - resourcemanager_v3_internal::FoldersRetryTraits>; +/** + * A retry policy for `FoldersConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FoldersLimitedErrorCountRetryPolicy : public FoldersRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit FoldersLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + FoldersLimitedErrorCountRetryPolicy( + FoldersLimitedErrorCountRetryPolicy&& rhs) noexcept + : FoldersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + FoldersLimitedErrorCountRetryPolicy( + FoldersLimitedErrorCountRetryPolicy const& rhs) noexcept + : FoldersLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = FoldersRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + resourcemanager_v3_internal::FoldersRetryTraits> + impl_; +}; -using FoldersLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - resourcemanager_v3_internal::FoldersRetryTraits>; +/** + * A retry policy for `FoldersConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class FoldersLimitedTimeRetryPolicy : public FoldersRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit FoldersLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + FoldersLimitedTimeRetryPolicy(FoldersLimitedTimeRetryPolicy&& rhs) noexcept + : FoldersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + FoldersLimitedTimeRetryPolicy( + FoldersLimitedTimeRetryPolicy const& rhs) noexcept + : FoldersLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = FoldersRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + resourcemanager_v3_internal::FoldersRetryTraits> + impl_; +}; /** * The `FoldersConnection` object for `FoldersClient`. diff --git a/google/cloud/resourcemanager/v3/organizations_connection.h b/google/cloud/resourcemanager/v3/organizations_connection.h index ee0f230d73dc5..a14585c370614 100644 --- a/google/cloud/resourcemanager/v3/organizations_connection.h +++ b/google/cloud/resourcemanager/v3/organizations_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace resourcemanager_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using OrganizationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - resourcemanager_v3_internal::OrganizationsRetryTraits>; +/// The retry policy for `OrganizationsConnection`. +class OrganizationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using OrganizationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - resourcemanager_v3_internal::OrganizationsRetryTraits>; +/** + * A retry policy for `OrganizationsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class OrganizationsLimitedErrorCountRetryPolicy + : public OrganizationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit OrganizationsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + OrganizationsLimitedErrorCountRetryPolicy( + OrganizationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : OrganizationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + OrganizationsLimitedErrorCountRetryPolicy( + OrganizationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : OrganizationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = OrganizationsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + resourcemanager_v3_internal::OrganizationsRetryTraits> + impl_; +}; -using OrganizationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - resourcemanager_v3_internal::OrganizationsRetryTraits>; +/** + * A retry policy for `OrganizationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class OrganizationsLimitedTimeRetryPolicy : public OrganizationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit OrganizationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + OrganizationsLimitedTimeRetryPolicy( + OrganizationsLimitedTimeRetryPolicy&& rhs) noexcept + : OrganizationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + OrganizationsLimitedTimeRetryPolicy( + OrganizationsLimitedTimeRetryPolicy const& rhs) noexcept + : OrganizationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = OrganizationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + resourcemanager_v3_internal::OrganizationsRetryTraits> + impl_; +}; /** * The `OrganizationsConnection` object for `OrganizationsClient`. diff --git a/google/cloud/resourcemanager/v3/projects_connection.h b/google/cloud/resourcemanager/v3/projects_connection.h index 973fcca5780ac..2612813867574 100644 --- a/google/cloud/resourcemanager/v3/projects_connection.h +++ b/google/cloud/resourcemanager/v3/projects_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace resourcemanager_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ProjectsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - resourcemanager_v3_internal::ProjectsRetryTraits>; +/// The retry policy for `ProjectsConnection`. +class ProjectsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ProjectsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - resourcemanager_v3_internal::ProjectsRetryTraits>; +/** + * A retry policy for `ProjectsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProjectsLimitedErrorCountRetryPolicy : public ProjectsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ProjectsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ProjectsLimitedErrorCountRetryPolicy( + ProjectsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ProjectsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ProjectsLimitedErrorCountRetryPolicy( + ProjectsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ProjectsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProjectsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + resourcemanager_v3_internal::ProjectsRetryTraits> + impl_; +}; -using ProjectsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - resourcemanager_v3_internal::ProjectsRetryTraits>; +/** + * A retry policy for `ProjectsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProjectsLimitedTimeRetryPolicy : public ProjectsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ProjectsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ProjectsLimitedTimeRetryPolicy(ProjectsLimitedTimeRetryPolicy&& rhs) noexcept + : ProjectsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ProjectsLimitedTimeRetryPolicy( + ProjectsLimitedTimeRetryPolicy const& rhs) noexcept + : ProjectsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProjectsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + resourcemanager_v3_internal::ProjectsRetryTraits> + impl_; +}; /** * The `ProjectsConnection` object for `ProjectsClient`. diff --git a/google/cloud/resourcesettings/v1/resource_settings_connection.h b/google/cloud/resourcesettings/v1/resource_settings_connection.h index fe3de85a46b95..56027ef817795 100644 --- a/google/cloud/resourcesettings/v1/resource_settings_connection.h +++ b/google/cloud/resourcesettings/v1/resource_settings_connection.h @@ -35,17 +35,140 @@ namespace cloud { namespace resourcesettings_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ResourceSettingsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - resourcesettings_v1_internal::ResourceSettingsServiceRetryTraits>; +/// The retry policy for `ResourceSettingsServiceConnection`. +class ResourceSettingsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ResourceSettingsServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ResourceSettingsServiceLimitedErrorCountRetryPolicy + : public ResourceSettingsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ResourceSettingsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + ResourceSettingsServiceLimitedErrorCountRetryPolicy( + ResourceSettingsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ResourceSettingsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + ResourceSettingsServiceLimitedErrorCountRetryPolicy( + ResourceSettingsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ResourceSettingsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + ResourceSettingsServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ResourceSettingsServiceRetryPolicy; -using ResourceSettingsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - resourcesettings_v1_internal::ResourceSettingsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + resourcesettings_v1_internal::ResourceSettingsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ResourceSettingsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ResourceSettingsServiceLimitedTimeRetryPolicy + : public ResourceSettingsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ResourceSettingsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ResourceSettingsServiceLimitedTimeRetryPolicy( + ResourceSettingsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ResourceSettingsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ResourceSettingsServiceLimitedTimeRetryPolicy( + ResourceSettingsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ResourceSettingsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ResourceSettingsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - resourcesettings_v1_internal::ResourceSettingsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ResourceSettingsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + resourcesettings_v1_internal::ResourceSettingsServiceRetryTraits> + impl_; +}; /** * The `ResourceSettingsServiceConnection` object for diff --git a/google/cloud/retail/v2/catalog_connection.h b/google/cloud/retail/v2/catalog_connection.h index e4911ae17a5ef..e3cd7cea13719 100644 --- a/google/cloud/retail/v2/catalog_connection.h +++ b/google/cloud/retail/v2/catalog_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace retail_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CatalogServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - retail_v2_internal::CatalogServiceRetryTraits>; +/// The retry policy for `CatalogServiceConnection`. +class CatalogServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CatalogServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CatalogServiceLimitedErrorCountRetryPolicy + : public CatalogServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CatalogServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CatalogServiceLimitedErrorCountRetryPolicy( + CatalogServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CatalogServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CatalogServiceLimitedErrorCountRetryPolicy( + CatalogServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CatalogServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CatalogServiceRetryPolicy; -using CatalogServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - retail_v2_internal::CatalogServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + retail_v2_internal::CatalogServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `CatalogServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CatalogServiceLimitedTimeRetryPolicy : public CatalogServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CatalogServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CatalogServiceLimitedTimeRetryPolicy( + CatalogServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CatalogServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CatalogServiceLimitedTimeRetryPolicy( + CatalogServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CatalogServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CatalogServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - retail_v2_internal::CatalogServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CatalogServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + retail_v2_internal::CatalogServiceRetryTraits> + impl_; +}; /** * The `CatalogServiceConnection` object for `CatalogServiceClient`. diff --git a/google/cloud/retail/v2/completion_connection.h b/google/cloud/retail/v2/completion_connection.h index 85860aed037cb..a6adc6456dee3 100644 --- a/google/cloud/retail/v2/completion_connection.h +++ b/google/cloud/retail/v2/completion_connection.h @@ -37,17 +37,135 @@ namespace cloud { namespace retail_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CompletionServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - retail_v2_internal::CompletionServiceRetryTraits>; +/// The retry policy for `CompletionServiceConnection`. +class CompletionServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CompletionServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CompletionServiceLimitedErrorCountRetryPolicy + : public CompletionServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CompletionServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CompletionServiceLimitedErrorCountRetryPolicy( + CompletionServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CompletionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CompletionServiceLimitedErrorCountRetryPolicy( + CompletionServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CompletionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CompletionServiceRetryPolicy; -using CompletionServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - retail_v2_internal::CompletionServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + retail_v2_internal::CompletionServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `CompletionServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CompletionServiceLimitedTimeRetryPolicy + : public CompletionServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CompletionServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CompletionServiceLimitedTimeRetryPolicy( + CompletionServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CompletionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CompletionServiceLimitedTimeRetryPolicy( + CompletionServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CompletionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CompletionServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - retail_v2_internal::CompletionServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CompletionServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + retail_v2_internal::CompletionServiceRetryTraits> + impl_; +}; /** * The `CompletionServiceConnection` object for `CompletionServiceClient`. diff --git a/google/cloud/retail/v2/prediction_connection.h b/google/cloud/retail/v2/prediction_connection.h index 2383795a9078e..9289fc79a05b4 100644 --- a/google/cloud/retail/v2/prediction_connection.h +++ b/google/cloud/retail/v2/prediction_connection.h @@ -34,17 +34,135 @@ namespace cloud { namespace retail_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using PredictionServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - retail_v2_internal::PredictionServiceRetryTraits>; +/// The retry policy for `PredictionServiceConnection`. +class PredictionServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PredictionServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PredictionServiceLimitedErrorCountRetryPolicy + : public PredictionServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PredictionServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PredictionServiceLimitedErrorCountRetryPolicy( + PredictionServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : PredictionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PredictionServiceLimitedErrorCountRetryPolicy( + PredictionServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : PredictionServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PredictionServiceRetryPolicy; -using PredictionServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - retail_v2_internal::PredictionServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + retail_v2_internal::PredictionServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `PredictionServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PredictionServiceLimitedTimeRetryPolicy + : public PredictionServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PredictionServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PredictionServiceLimitedTimeRetryPolicy( + PredictionServiceLimitedTimeRetryPolicy&& rhs) noexcept + : PredictionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PredictionServiceLimitedTimeRetryPolicy( + PredictionServiceLimitedTimeRetryPolicy const& rhs) noexcept + : PredictionServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using PredictionServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - retail_v2_internal::PredictionServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PredictionServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + retail_v2_internal::PredictionServiceRetryTraits> + impl_; +}; /** * The `PredictionServiceConnection` object for `PredictionServiceClient`. diff --git a/google/cloud/retail/v2/product_connection.h b/google/cloud/retail/v2/product_connection.h index 27a4c11c4b89e..3bad6e283d280 100644 --- a/google/cloud/retail/v2/product_connection.h +++ b/google/cloud/retail/v2/product_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace retail_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ProductServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - retail_v2_internal::ProductServiceRetryTraits>; +/// The retry policy for `ProductServiceConnection`. +class ProductServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ProductServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProductServiceLimitedErrorCountRetryPolicy + : public ProductServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ProductServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ProductServiceLimitedErrorCountRetryPolicy( + ProductServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ProductServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ProductServiceLimitedErrorCountRetryPolicy( + ProductServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ProductServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProductServiceRetryPolicy; -using ProductServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - retail_v2_internal::ProductServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + retail_v2_internal::ProductServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ProductServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProductServiceLimitedTimeRetryPolicy : public ProductServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ProductServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ProductServiceLimitedTimeRetryPolicy( + ProductServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ProductServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ProductServiceLimitedTimeRetryPolicy( + ProductServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ProductServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ProductServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - retail_v2_internal::ProductServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProductServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + retail_v2_internal::ProductServiceRetryTraits> + impl_; +}; /** * The `ProductServiceConnection` object for `ProductServiceClient`. diff --git a/google/cloud/retail/v2/search_connection.h b/google/cloud/retail/v2/search_connection.h index 60d2367f53910..18a5d2ee8ba74 100644 --- a/google/cloud/retail/v2/search_connection.h +++ b/google/cloud/retail/v2/search_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace retail_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SearchServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - retail_v2_internal::SearchServiceRetryTraits>; +/// The retry policy for `SearchServiceConnection`. +class SearchServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SearchServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SearchServiceLimitedErrorCountRetryPolicy + : public SearchServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SearchServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SearchServiceLimitedErrorCountRetryPolicy( + SearchServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SearchServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SearchServiceLimitedErrorCountRetryPolicy( + SearchServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SearchServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SearchServiceRetryPolicy; -using SearchServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - retail_v2_internal::SearchServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + retail_v2_internal::SearchServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SearchServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SearchServiceLimitedTimeRetryPolicy : public SearchServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SearchServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SearchServiceLimitedTimeRetryPolicy( + SearchServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SearchServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SearchServiceLimitedTimeRetryPolicy( + SearchServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SearchServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SearchServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - retail_v2_internal::SearchServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SearchServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + retail_v2_internal::SearchServiceRetryTraits> + impl_; +}; /** * The `SearchServiceConnection` object for `SearchServiceClient`. diff --git a/google/cloud/retail/v2/user_event_connection.h b/google/cloud/retail/v2/user_event_connection.h index 94fcfa8a7c71e..f4eeb6e7d9c33 100644 --- a/google/cloud/retail/v2/user_event_connection.h +++ b/google/cloud/retail/v2/user_event_connection.h @@ -37,17 +37,135 @@ namespace cloud { namespace retail_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using UserEventServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - retail_v2_internal::UserEventServiceRetryTraits>; +/// The retry policy for `UserEventServiceConnection`. +class UserEventServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using UserEventServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - retail_v2_internal::UserEventServiceRetryTraits>; +/** + * A retry policy for `UserEventServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class UserEventServiceLimitedErrorCountRetryPolicy + : public UserEventServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit UserEventServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + UserEventServiceLimitedErrorCountRetryPolicy( + UserEventServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : UserEventServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + UserEventServiceLimitedErrorCountRetryPolicy( + UserEventServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : UserEventServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = UserEventServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + retail_v2_internal::UserEventServiceRetryTraits> + impl_; +}; -using UserEventServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - retail_v2_internal::UserEventServiceRetryTraits>; +/** + * A retry policy for `UserEventServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class UserEventServiceLimitedTimeRetryPolicy + : public UserEventServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit UserEventServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + UserEventServiceLimitedTimeRetryPolicy( + UserEventServiceLimitedTimeRetryPolicy&& rhs) noexcept + : UserEventServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + UserEventServiceLimitedTimeRetryPolicy( + UserEventServiceLimitedTimeRetryPolicy const& rhs) noexcept + : UserEventServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = UserEventServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + retail_v2_internal::UserEventServiceRetryTraits> + impl_; +}; /** * The `UserEventServiceConnection` object for `UserEventServiceClient`. diff --git a/google/cloud/run/v2/revisions_connection.h b/google/cloud/run/v2/revisions_connection.h index b0b2bdf47b173..7d8cc8a3783c6 100644 --- a/google/cloud/run/v2/revisions_connection.h +++ b/google/cloud/run/v2/revisions_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace run_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RevisionsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - run_v2_internal::RevisionsRetryTraits>; +/// The retry policy for `RevisionsConnection`. +class RevisionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RevisionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RevisionsLimitedErrorCountRetryPolicy : public RevisionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RevisionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RevisionsLimitedErrorCountRetryPolicy( + RevisionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : RevisionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RevisionsLimitedErrorCountRetryPolicy( + RevisionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : RevisionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RevisionsRetryPolicy; -using RevisionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - run_v2_internal::RevisionsRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + run_v2_internal::RevisionsRetryTraits> + impl_; +}; + +/** + * A retry policy for `RevisionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RevisionsLimitedTimeRetryPolicy : public RevisionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RevisionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RevisionsLimitedTimeRetryPolicy( + RevisionsLimitedTimeRetryPolicy&& rhs) noexcept + : RevisionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RevisionsLimitedTimeRetryPolicy( + RevisionsLimitedTimeRetryPolicy const& rhs) noexcept + : RevisionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RevisionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - run_v2_internal::RevisionsRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RevisionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + run_v2_internal::RevisionsRetryTraits> + impl_; +}; /** * The `RevisionsConnection` object for `RevisionsClient`. diff --git a/google/cloud/run/v2/services_connection.h b/google/cloud/run/v2/services_connection.h index 3df595e95759a..a169c444737ff 100644 --- a/google/cloud/run/v2/services_connection.h +++ b/google/cloud/run/v2/services_connection.h @@ -38,16 +38,131 @@ namespace cloud { namespace run_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ServicesRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - run_v2_internal::ServicesRetryTraits>; +/// The retry policy for `ServicesConnection`. +class ServicesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ServicesLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - run_v2_internal::ServicesRetryTraits>; +/** + * A retry policy for `ServicesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServicesLimitedErrorCountRetryPolicy : public ServicesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ServicesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ServicesLimitedErrorCountRetryPolicy( + ServicesLimitedErrorCountRetryPolicy&& rhs) noexcept + : ServicesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ServicesLimitedErrorCountRetryPolicy( + ServicesLimitedErrorCountRetryPolicy const& rhs) noexcept + : ServicesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServicesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + run_v2_internal::ServicesRetryTraits> + impl_; +}; -using ServicesLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - run_v2_internal::ServicesRetryTraits>; +/** + * A retry policy for `ServicesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServicesLimitedTimeRetryPolicy : public ServicesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ServicesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ServicesLimitedTimeRetryPolicy(ServicesLimitedTimeRetryPolicy&& rhs) noexcept + : ServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ServicesLimitedTimeRetryPolicy( + ServicesLimitedTimeRetryPolicy const& rhs) noexcept + : ServicesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServicesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + run_v2_internal::ServicesRetryTraits> + impl_; +}; /** * The `ServicesConnection` object for `ServicesClient`. diff --git a/google/cloud/scheduler/v1/cloud_scheduler_connection.h b/google/cloud/scheduler/v1/cloud_scheduler_connection.h index 23443b19a20be..5b470ec5a2f2d 100644 --- a/google/cloud/scheduler/v1/cloud_scheduler_connection.h +++ b/google/cloud/scheduler/v1/cloud_scheduler_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace scheduler_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudSchedulerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - scheduler_v1_internal::CloudSchedulerRetryTraits>; +/// The retry policy for `CloudSchedulerConnection`. +class CloudSchedulerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CloudSchedulerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - scheduler_v1_internal::CloudSchedulerRetryTraits>; +/** + * A retry policy for `CloudSchedulerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudSchedulerLimitedErrorCountRetryPolicy + : public CloudSchedulerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudSchedulerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudSchedulerLimitedErrorCountRetryPolicy( + CloudSchedulerLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudSchedulerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudSchedulerLimitedErrorCountRetryPolicy( + CloudSchedulerLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudSchedulerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudSchedulerRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + scheduler_v1_internal::CloudSchedulerRetryTraits> + impl_; +}; -using CloudSchedulerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - scheduler_v1_internal::CloudSchedulerRetryTraits>; +/** + * A retry policy for `CloudSchedulerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudSchedulerLimitedTimeRetryPolicy : public CloudSchedulerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudSchedulerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudSchedulerLimitedTimeRetryPolicy( + CloudSchedulerLimitedTimeRetryPolicy&& rhs) noexcept + : CloudSchedulerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudSchedulerLimitedTimeRetryPolicy( + CloudSchedulerLimitedTimeRetryPolicy const& rhs) noexcept + : CloudSchedulerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudSchedulerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + scheduler_v1_internal::CloudSchedulerRetryTraits> + impl_; +}; /** * The `CloudSchedulerConnection` object for `CloudSchedulerClient`. diff --git a/google/cloud/secretmanager/v1/secret_manager_connection.h b/google/cloud/secretmanager/v1/secret_manager_connection.h index 411681818f7b4..12245c6cdb2a0 100644 --- a/google/cloud/secretmanager/v1/secret_manager_connection.h +++ b/google/cloud/secretmanager/v1/secret_manager_connection.h @@ -35,17 +35,138 @@ namespace cloud { namespace secretmanager_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SecretManagerServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - secretmanager_v1_internal::SecretManagerServiceRetryTraits>; +/// The retry policy for `SecretManagerServiceConnection`. +class SecretManagerServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SecretManagerServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SecretManagerServiceLimitedErrorCountRetryPolicy + : public SecretManagerServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SecretManagerServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + SecretManagerServiceLimitedErrorCountRetryPolicy( + SecretManagerServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SecretManagerServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + SecretManagerServiceLimitedErrorCountRetryPolicy( + SecretManagerServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SecretManagerServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SecretManagerServiceRetryPolicy; -using SecretManagerServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - secretmanager_v1_internal::SecretManagerServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + secretmanager_v1_internal::SecretManagerServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SecretManagerServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SecretManagerServiceLimitedTimeRetryPolicy + : public SecretManagerServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SecretManagerServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SecretManagerServiceLimitedTimeRetryPolicy( + SecretManagerServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SecretManagerServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SecretManagerServiceLimitedTimeRetryPolicy( + SecretManagerServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SecretManagerServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SecretManagerServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - secretmanager_v1_internal::SecretManagerServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SecretManagerServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + secretmanager_v1_internal::SecretManagerServiceRetryTraits> + impl_; +}; /** * The `SecretManagerServiceConnection` object for `SecretManagerServiceClient`. diff --git a/google/cloud/securitycenter/v1/security_center_connection.h b/google/cloud/securitycenter/v1/security_center_connection.h index 166a4767f659b..18ad7ed92157a 100644 --- a/google/cloud/securitycenter/v1/security_center_connection.h +++ b/google/cloud/securitycenter/v1/security_center_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace securitycenter_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SecurityCenterRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - securitycenter_v1_internal::SecurityCenterRetryTraits>; +/// The retry policy for `SecurityCenterConnection`. +class SecurityCenterRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SecurityCenterLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - securitycenter_v1_internal::SecurityCenterRetryTraits>; +/** + * A retry policy for `SecurityCenterConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SecurityCenterLimitedErrorCountRetryPolicy + : public SecurityCenterRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SecurityCenterLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SecurityCenterLimitedErrorCountRetryPolicy( + SecurityCenterLimitedErrorCountRetryPolicy&& rhs) noexcept + : SecurityCenterLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SecurityCenterLimitedErrorCountRetryPolicy( + SecurityCenterLimitedErrorCountRetryPolicy const& rhs) noexcept + : SecurityCenterLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SecurityCenterRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + securitycenter_v1_internal::SecurityCenterRetryTraits> + impl_; +}; -using SecurityCenterLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - securitycenter_v1_internal::SecurityCenterRetryTraits>; +/** + * A retry policy for `SecurityCenterConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SecurityCenterLimitedTimeRetryPolicy : public SecurityCenterRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SecurityCenterLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SecurityCenterLimitedTimeRetryPolicy( + SecurityCenterLimitedTimeRetryPolicy&& rhs) noexcept + : SecurityCenterLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SecurityCenterLimitedTimeRetryPolicy( + SecurityCenterLimitedTimeRetryPolicy const& rhs) noexcept + : SecurityCenterLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SecurityCenterRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + securitycenter_v1_internal::SecurityCenterRetryTraits> + impl_; +}; /** * The `SecurityCenterConnection` object for `SecurityCenterClient`. diff --git a/google/cloud/servicecontrol/v1/quota_controller_connection.h b/google/cloud/servicecontrol/v1/quota_controller_connection.h index 54964834439a1..9e8f65c30f43d 100644 --- a/google/cloud/servicecontrol/v1/quota_controller_connection.h +++ b/google/cloud/servicecontrol/v1/quota_controller_connection.h @@ -34,17 +34,135 @@ namespace cloud { namespace servicecontrol_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using QuotaControllerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - servicecontrol_v1_internal::QuotaControllerRetryTraits>; +/// The retry policy for `QuotaControllerConnection`. +class QuotaControllerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `QuotaControllerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class QuotaControllerLimitedErrorCountRetryPolicy + : public QuotaControllerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit QuotaControllerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + QuotaControllerLimitedErrorCountRetryPolicy( + QuotaControllerLimitedErrorCountRetryPolicy&& rhs) noexcept + : QuotaControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + QuotaControllerLimitedErrorCountRetryPolicy( + QuotaControllerLimitedErrorCountRetryPolicy const& rhs) noexcept + : QuotaControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = QuotaControllerRetryPolicy; -using QuotaControllerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - servicecontrol_v1_internal::QuotaControllerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + servicecontrol_v1_internal::QuotaControllerRetryTraits> + impl_; +}; + +/** + * A retry policy for `QuotaControllerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class QuotaControllerLimitedTimeRetryPolicy + : public QuotaControllerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit QuotaControllerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + QuotaControllerLimitedTimeRetryPolicy( + QuotaControllerLimitedTimeRetryPolicy&& rhs) noexcept + : QuotaControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + QuotaControllerLimitedTimeRetryPolicy( + QuotaControllerLimitedTimeRetryPolicy const& rhs) noexcept + : QuotaControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using QuotaControllerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - servicecontrol_v1_internal::QuotaControllerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = QuotaControllerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + servicecontrol_v1_internal::QuotaControllerRetryTraits> + impl_; +}; /** * The `QuotaControllerConnection` object for `QuotaControllerClient`. diff --git a/google/cloud/servicecontrol/v1/service_controller_connection.h b/google/cloud/servicecontrol/v1/service_controller_connection.h index ca8b718e85790..5475e099a3396 100644 --- a/google/cloud/servicecontrol/v1/service_controller_connection.h +++ b/google/cloud/servicecontrol/v1/service_controller_connection.h @@ -34,17 +34,135 @@ namespace cloud { namespace servicecontrol_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ServiceControllerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - servicecontrol_v1_internal::ServiceControllerRetryTraits>; +/// The retry policy for `ServiceControllerConnection`. +class ServiceControllerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ServiceControllerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceControllerLimitedErrorCountRetryPolicy + : public ServiceControllerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ServiceControllerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ServiceControllerLimitedErrorCountRetryPolicy( + ServiceControllerLimitedErrorCountRetryPolicy&& rhs) noexcept + : ServiceControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ServiceControllerLimitedErrorCountRetryPolicy( + ServiceControllerLimitedErrorCountRetryPolicy const& rhs) noexcept + : ServiceControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceControllerRetryPolicy; -using ServiceControllerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - servicecontrol_v1_internal::ServiceControllerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + servicecontrol_v1_internal::ServiceControllerRetryTraits> + impl_; +}; + +/** + * A retry policy for `ServiceControllerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceControllerLimitedTimeRetryPolicy + : public ServiceControllerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ServiceControllerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ServiceControllerLimitedTimeRetryPolicy( + ServiceControllerLimitedTimeRetryPolicy&& rhs) noexcept + : ServiceControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ServiceControllerLimitedTimeRetryPolicy( + ServiceControllerLimitedTimeRetryPolicy const& rhs) noexcept + : ServiceControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ServiceControllerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - servicecontrol_v1_internal::ServiceControllerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceControllerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + servicecontrol_v1_internal::ServiceControllerRetryTraits> + impl_; +}; /** * The `ServiceControllerConnection` object for `ServiceControllerClient`. diff --git a/google/cloud/servicecontrol/v2/service_controller_connection.h b/google/cloud/servicecontrol/v2/service_controller_connection.h index be86a79a480c4..1cfbdfd836578 100644 --- a/google/cloud/servicecontrol/v2/service_controller_connection.h +++ b/google/cloud/servicecontrol/v2/service_controller_connection.h @@ -34,17 +34,135 @@ namespace cloud { namespace servicecontrol_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ServiceControllerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - servicecontrol_v2_internal::ServiceControllerRetryTraits>; +/// The retry policy for `ServiceControllerConnection`. +class ServiceControllerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ServiceControllerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceControllerLimitedErrorCountRetryPolicy + : public ServiceControllerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ServiceControllerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ServiceControllerLimitedErrorCountRetryPolicy( + ServiceControllerLimitedErrorCountRetryPolicy&& rhs) noexcept + : ServiceControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ServiceControllerLimitedErrorCountRetryPolicy( + ServiceControllerLimitedErrorCountRetryPolicy const& rhs) noexcept + : ServiceControllerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceControllerRetryPolicy; -using ServiceControllerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - servicecontrol_v2_internal::ServiceControllerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + servicecontrol_v2_internal::ServiceControllerRetryTraits> + impl_; +}; + +/** + * A retry policy for `ServiceControllerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceControllerLimitedTimeRetryPolicy + : public ServiceControllerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ServiceControllerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ServiceControllerLimitedTimeRetryPolicy( + ServiceControllerLimitedTimeRetryPolicy&& rhs) noexcept + : ServiceControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ServiceControllerLimitedTimeRetryPolicy( + ServiceControllerLimitedTimeRetryPolicy const& rhs) noexcept + : ServiceControllerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ServiceControllerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - servicecontrol_v2_internal::ServiceControllerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceControllerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + servicecontrol_v2_internal::ServiceControllerRetryTraits> + impl_; +}; /** * The `ServiceControllerConnection` object for `ServiceControllerClient`. diff --git a/google/cloud/servicedirectory/v1/lookup_connection.h b/google/cloud/servicedirectory/v1/lookup_connection.h index 2b8deb0e3d16e..4370b41e76d49 100644 --- a/google/cloud/servicedirectory/v1/lookup_connection.h +++ b/google/cloud/servicedirectory/v1/lookup_connection.h @@ -34,17 +34,136 @@ namespace cloud { namespace servicedirectory_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using LookupServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - servicedirectory_v1_internal::LookupServiceRetryTraits>; +/// The retry policy for `LookupServiceConnection`. +class LookupServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `LookupServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class LookupServiceLimitedErrorCountRetryPolicy + : public LookupServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit LookupServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + LookupServiceLimitedErrorCountRetryPolicy( + LookupServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : LookupServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + LookupServiceLimitedErrorCountRetryPolicy( + LookupServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : LookupServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = LookupServiceRetryPolicy; -using LookupServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - servicedirectory_v1_internal::LookupServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + servicedirectory_v1_internal::LookupServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `LookupServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class LookupServiceLimitedTimeRetryPolicy : public LookupServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit LookupServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + LookupServiceLimitedTimeRetryPolicy( + LookupServiceLimitedTimeRetryPolicy&& rhs) noexcept + : LookupServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + LookupServiceLimitedTimeRetryPolicy( + LookupServiceLimitedTimeRetryPolicy const& rhs) noexcept + : LookupServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using LookupServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - servicedirectory_v1_internal::LookupServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = LookupServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + servicedirectory_v1_internal::LookupServiceRetryTraits> + impl_; +}; /** * The `LookupServiceConnection` object for `LookupServiceClient`. diff --git a/google/cloud/servicedirectory/v1/registration_connection.h b/google/cloud/servicedirectory/v1/registration_connection.h index e0cb157f363e1..de5c856664ca8 100644 --- a/google/cloud/servicedirectory/v1/registration_connection.h +++ b/google/cloud/servicedirectory/v1/registration_connection.h @@ -35,17 +35,139 @@ namespace cloud { namespace servicedirectory_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using RegistrationServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - servicedirectory_v1_internal::RegistrationServiceRetryTraits>; +/// The retry policy for `RegistrationServiceConnection`. +class RegistrationServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RegistrationServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class RegistrationServiceLimitedErrorCountRetryPolicy + : public RegistrationServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RegistrationServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RegistrationServiceLimitedErrorCountRetryPolicy( + RegistrationServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : RegistrationServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RegistrationServiceLimitedErrorCountRetryPolicy( + RegistrationServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : RegistrationServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegistrationServiceRetryPolicy; -using RegistrationServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - servicedirectory_v1_internal::RegistrationServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + servicedirectory_v1_internal::RegistrationServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `RegistrationServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class RegistrationServiceLimitedTimeRetryPolicy + : public RegistrationServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RegistrationServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RegistrationServiceLimitedTimeRetryPolicy( + RegistrationServiceLimitedTimeRetryPolicy&& rhs) noexcept + : RegistrationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RegistrationServiceLimitedTimeRetryPolicy( + RegistrationServiceLimitedTimeRetryPolicy const& rhs) noexcept + : RegistrationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using RegistrationServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - servicedirectory_v1_internal::RegistrationServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RegistrationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + servicedirectory_v1_internal::RegistrationServiceRetryTraits> + impl_; +}; /** * The `RegistrationServiceConnection` object for `RegistrationServiceClient`. diff --git a/google/cloud/servicemanagement/v1/service_manager_connection.h b/google/cloud/servicemanagement/v1/service_manager_connection.h index e33f949a86334..e679bf9aa8508 100644 --- a/google/cloud/servicemanagement/v1/service_manager_connection.h +++ b/google/cloud/servicemanagement/v1/service_manager_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace servicemanagement_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ServiceManagerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - servicemanagement_v1_internal::ServiceManagerRetryTraits>; +/// The retry policy for `ServiceManagerConnection`. +class ServiceManagerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ServiceManagerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceManagerLimitedErrorCountRetryPolicy + : public ServiceManagerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ServiceManagerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ServiceManagerLimitedErrorCountRetryPolicy( + ServiceManagerLimitedErrorCountRetryPolicy&& rhs) noexcept + : ServiceManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ServiceManagerLimitedErrorCountRetryPolicy( + ServiceManagerLimitedErrorCountRetryPolicy const& rhs) noexcept + : ServiceManagerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceManagerRetryPolicy; -using ServiceManagerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - servicemanagement_v1_internal::ServiceManagerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + servicemanagement_v1_internal::ServiceManagerRetryTraits> + impl_; +}; + +/** + * A retry policy for `ServiceManagerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceManagerLimitedTimeRetryPolicy : public ServiceManagerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ServiceManagerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ServiceManagerLimitedTimeRetryPolicy( + ServiceManagerLimitedTimeRetryPolicy&& rhs) noexcept + : ServiceManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ServiceManagerLimitedTimeRetryPolicy( + ServiceManagerLimitedTimeRetryPolicy const& rhs) noexcept + : ServiceManagerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ServiceManagerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - servicemanagement_v1_internal::ServiceManagerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceManagerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + servicemanagement_v1_internal::ServiceManagerRetryTraits> + impl_; +}; /** * The `ServiceManagerConnection` object for `ServiceManagerClient`. diff --git a/google/cloud/serviceusage/v1/service_usage_connection.h b/google/cloud/serviceusage/v1/service_usage_connection.h index 01092b4217e6e..626d343846a1a 100644 --- a/google/cloud/serviceusage/v1/service_usage_connection.h +++ b/google/cloud/serviceusage/v1/service_usage_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace serviceusage_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ServiceUsageRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - serviceusage_v1_internal::ServiceUsageRetryTraits>; +/// The retry policy for `ServiceUsageConnection`. +class ServiceUsageRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ServiceUsageLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - serviceusage_v1_internal::ServiceUsageRetryTraits>; +/** + * A retry policy for `ServiceUsageConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceUsageLimitedErrorCountRetryPolicy + : public ServiceUsageRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ServiceUsageLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ServiceUsageLimitedErrorCountRetryPolicy( + ServiceUsageLimitedErrorCountRetryPolicy&& rhs) noexcept + : ServiceUsageLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ServiceUsageLimitedErrorCountRetryPolicy( + ServiceUsageLimitedErrorCountRetryPolicy const& rhs) noexcept + : ServiceUsageLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceUsageRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + serviceusage_v1_internal::ServiceUsageRetryTraits> + impl_; +}; -using ServiceUsageLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - serviceusage_v1_internal::ServiceUsageRetryTraits>; +/** + * A retry policy for `ServiceUsageConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ServiceUsageLimitedTimeRetryPolicy : public ServiceUsageRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ServiceUsageLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ServiceUsageLimitedTimeRetryPolicy( + ServiceUsageLimitedTimeRetryPolicy&& rhs) noexcept + : ServiceUsageLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ServiceUsageLimitedTimeRetryPolicy( + ServiceUsageLimitedTimeRetryPolicy const& rhs) noexcept + : ServiceUsageLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ServiceUsageRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + serviceusage_v1_internal::ServiceUsageRetryTraits> + impl_; +}; /** * The `ServiceUsageConnection` object for `ServiceUsageClient`. diff --git a/google/cloud/shell/v1/cloud_shell_connection.h b/google/cloud/shell/v1/cloud_shell_connection.h index 176e26c495bda..fd21d3b8696ae 100644 --- a/google/cloud/shell/v1/cloud_shell_connection.h +++ b/google/cloud/shell/v1/cloud_shell_connection.h @@ -37,17 +37,137 @@ namespace cloud { namespace shell_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudShellServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - shell_v1_internal::CloudShellServiceRetryTraits>; +/// The retry policy for `CloudShellServiceConnection`. +class CloudShellServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CloudShellServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - shell_v1_internal::CloudShellServiceRetryTraits>; +/** + * A retry policy for `CloudShellServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class CloudShellServiceLimitedErrorCountRetryPolicy + : public CloudShellServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudShellServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudShellServiceLimitedErrorCountRetryPolicy( + CloudShellServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudShellServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudShellServiceLimitedErrorCountRetryPolicy( + CloudShellServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudShellServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudShellServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + shell_v1_internal::CloudShellServiceRetryTraits> + impl_; +}; -using CloudShellServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - shell_v1_internal::CloudShellServiceRetryTraits>; +/** + * A retry policy for `CloudShellServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class CloudShellServiceLimitedTimeRetryPolicy + : public CloudShellServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudShellServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudShellServiceLimitedTimeRetryPolicy( + CloudShellServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CloudShellServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudShellServiceLimitedTimeRetryPolicy( + CloudShellServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CloudShellServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudShellServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + shell_v1_internal::CloudShellServiceRetryTraits> + impl_; +}; /** * The `CloudShellServiceConnection` object for `CloudShellServiceClient`. diff --git a/google/cloud/spanner/admin/database_admin_connection.h b/google/cloud/spanner/admin/database_admin_connection.h index 5458551f1cddf..d50e980dc3492 100644 --- a/google/cloud/spanner/admin/database_admin_connection.h +++ b/google/cloud/spanner/admin/database_admin_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace spanner_admin { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using DatabaseAdminRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - spanner_admin_internal::DatabaseAdminRetryTraits>; +/// The retry policy for `DatabaseAdminConnection`. +class DatabaseAdminRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using DatabaseAdminLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - spanner_admin_internal::DatabaseAdminRetryTraits>; +/** + * A retry policy for `DatabaseAdminConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DatabaseAdminLimitedErrorCountRetryPolicy + : public DatabaseAdminRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DatabaseAdminLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DatabaseAdminLimitedErrorCountRetryPolicy( + DatabaseAdminLimitedErrorCountRetryPolicy&& rhs) noexcept + : DatabaseAdminLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DatabaseAdminLimitedErrorCountRetryPolicy( + DatabaseAdminLimitedErrorCountRetryPolicy const& rhs) noexcept + : DatabaseAdminLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DatabaseAdminRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + spanner_admin_internal::DatabaseAdminRetryTraits> + impl_; +}; -using DatabaseAdminLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - spanner_admin_internal::DatabaseAdminRetryTraits>; +/** + * A retry policy for `DatabaseAdminConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DatabaseAdminLimitedTimeRetryPolicy : public DatabaseAdminRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DatabaseAdminLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DatabaseAdminLimitedTimeRetryPolicy( + DatabaseAdminLimitedTimeRetryPolicy&& rhs) noexcept + : DatabaseAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DatabaseAdminLimitedTimeRetryPolicy( + DatabaseAdminLimitedTimeRetryPolicy const& rhs) noexcept + : DatabaseAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DatabaseAdminRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + spanner_admin_internal::DatabaseAdminRetryTraits> + impl_; +}; /** * The `DatabaseAdminConnection` object for `DatabaseAdminClient`. diff --git a/google/cloud/spanner/admin/instance_admin_connection.h b/google/cloud/spanner/admin/instance_admin_connection.h index 3c9fffad3c5a8..45b5ee8391aa9 100644 --- a/google/cloud/spanner/admin/instance_admin_connection.h +++ b/google/cloud/spanner/admin/instance_admin_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace spanner_admin { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using InstanceAdminRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - spanner_admin_internal::InstanceAdminRetryTraits>; +/// The retry policy for `InstanceAdminConnection`. +class InstanceAdminRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `InstanceAdminConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstanceAdminLimitedErrorCountRetryPolicy + : public InstanceAdminRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit InstanceAdminLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + InstanceAdminLimitedErrorCountRetryPolicy( + InstanceAdminLimitedErrorCountRetryPolicy&& rhs) noexcept + : InstanceAdminLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + InstanceAdminLimitedErrorCountRetryPolicy( + InstanceAdminLimitedErrorCountRetryPolicy const& rhs) noexcept + : InstanceAdminLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstanceAdminRetryPolicy; -using InstanceAdminLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - spanner_admin_internal::InstanceAdminRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + spanner_admin_internal::InstanceAdminRetryTraits> + impl_; +}; + +/** + * A retry policy for `InstanceAdminConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class InstanceAdminLimitedTimeRetryPolicy : public InstanceAdminRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit InstanceAdminLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + InstanceAdminLimitedTimeRetryPolicy( + InstanceAdminLimitedTimeRetryPolicy&& rhs) noexcept + : InstanceAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + InstanceAdminLimitedTimeRetryPolicy( + InstanceAdminLimitedTimeRetryPolicy const& rhs) noexcept + : InstanceAdminLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using InstanceAdminLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - spanner_admin_internal::InstanceAdminRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = InstanceAdminRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + spanner_admin_internal::InstanceAdminRetryTraits> + impl_; +}; /** * The `InstanceAdminConnection` object for `InstanceAdminClient`. diff --git a/google/cloud/speech/v1/speech_connection.h b/google/cloud/speech/v1/speech_connection.h index 2e784b418192a..24b5a0150de4e 100644 --- a/google/cloud/speech/v1/speech_connection.h +++ b/google/cloud/speech/v1/speech_connection.h @@ -38,16 +38,130 @@ namespace cloud { namespace speech_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SpeechRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - speech_v1_internal::SpeechRetryTraits>; +/// The retry policy for `SpeechConnection`. +class SpeechRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SpeechConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SpeechLimitedErrorCountRetryPolicy : public SpeechRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SpeechLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SpeechLimitedErrorCountRetryPolicy( + SpeechLimitedErrorCountRetryPolicy&& rhs) noexcept + : SpeechLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SpeechLimitedErrorCountRetryPolicy( + SpeechLimitedErrorCountRetryPolicy const& rhs) noexcept + : SpeechLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SpeechRetryPolicy; -using SpeechLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - speech_v1_internal::SpeechRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + speech_v1_internal::SpeechRetryTraits> + impl_; +}; + +/** + * A retry policy for `SpeechConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SpeechLimitedTimeRetryPolicy : public SpeechRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SpeechLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SpeechLimitedTimeRetryPolicy(SpeechLimitedTimeRetryPolicy&& rhs) noexcept + : SpeechLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SpeechLimitedTimeRetryPolicy(SpeechLimitedTimeRetryPolicy const& rhs) noexcept + : SpeechLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SpeechLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - speech_v1_internal::SpeechRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SpeechRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + speech_v1_internal::SpeechRetryTraits> + impl_; +}; /** * The `SpeechConnection` object for `SpeechClient`. diff --git a/google/cloud/speech/v2/speech_connection.h b/google/cloud/speech/v2/speech_connection.h index 0eab5147cf2a2..dacc566924d43 100644 --- a/google/cloud/speech/v2/speech_connection.h +++ b/google/cloud/speech/v2/speech_connection.h @@ -40,16 +40,130 @@ namespace cloud { namespace speech_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SpeechRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - speech_v2_internal::SpeechRetryTraits>; +/// The retry policy for `SpeechConnection`. +class SpeechRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SpeechLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - speech_v2_internal::SpeechRetryTraits>; +/** + * A retry policy for `SpeechConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SpeechLimitedErrorCountRetryPolicy : public SpeechRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SpeechLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SpeechLimitedErrorCountRetryPolicy( + SpeechLimitedErrorCountRetryPolicy&& rhs) noexcept + : SpeechLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SpeechLimitedErrorCountRetryPolicy( + SpeechLimitedErrorCountRetryPolicy const& rhs) noexcept + : SpeechLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SpeechRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + speech_v2_internal::SpeechRetryTraits> + impl_; +}; -using SpeechLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - speech_v2_internal::SpeechRetryTraits>; +/** + * A retry policy for `SpeechConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SpeechLimitedTimeRetryPolicy : public SpeechRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SpeechLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SpeechLimitedTimeRetryPolicy(SpeechLimitedTimeRetryPolicy&& rhs) noexcept + : SpeechLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SpeechLimitedTimeRetryPolicy(SpeechLimitedTimeRetryPolicy const& rhs) noexcept + : SpeechLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SpeechRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + speech_v2_internal::SpeechRetryTraits> + impl_; +}; /** * The `SpeechConnection` object for `SpeechClient`. diff --git a/google/cloud/sql/v1/sql_backup_runs_connection.h b/google/cloud/sql/v1/sql_backup_runs_connection.h index 30d412f064359..c9300a96f5711 100644 --- a/google/cloud/sql/v1/sql_backup_runs_connection.h +++ b/google/cloud/sql/v1/sql_backup_runs_connection.h @@ -35,17 +35,138 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlBackupRunsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlBackupRunsServiceRetryTraits>; +/// The retry policy for `SqlBackupRunsServiceConnection`. +class SqlBackupRunsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SqlBackupRunsServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlBackupRunsServiceLimitedErrorCountRetryPolicy + : public SqlBackupRunsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlBackupRunsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + SqlBackupRunsServiceLimitedErrorCountRetryPolicy( + SqlBackupRunsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlBackupRunsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + SqlBackupRunsServiceLimitedErrorCountRetryPolicy( + SqlBackupRunsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlBackupRunsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlBackupRunsServiceRetryPolicy; -using SqlBackupRunsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlBackupRunsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlBackupRunsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SqlBackupRunsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlBackupRunsServiceLimitedTimeRetryPolicy + : public SqlBackupRunsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlBackupRunsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlBackupRunsServiceLimitedTimeRetryPolicy( + SqlBackupRunsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlBackupRunsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlBackupRunsServiceLimitedTimeRetryPolicy( + SqlBackupRunsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlBackupRunsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SqlBackupRunsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlBackupRunsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlBackupRunsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlBackupRunsServiceRetryTraits> + impl_; +}; /** * The `SqlBackupRunsServiceConnection` object for `SqlBackupRunsServiceClient`. diff --git a/google/cloud/sql/v1/sql_connect_connection.h b/google/cloud/sql/v1/sql_connect_connection.h index 3782e2a991848..7250621410741 100644 --- a/google/cloud/sql/v1/sql_connect_connection.h +++ b/google/cloud/sql/v1/sql_connect_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlConnectServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlConnectServiceRetryTraits>; +/// The retry policy for `SqlConnectServiceConnection`. +class SqlConnectServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SqlConnectServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlConnectServiceLimitedErrorCountRetryPolicy + : public SqlConnectServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlConnectServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SqlConnectServiceLimitedErrorCountRetryPolicy( + SqlConnectServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlConnectServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SqlConnectServiceLimitedErrorCountRetryPolicy( + SqlConnectServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlConnectServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlConnectServiceRetryPolicy; -using SqlConnectServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlConnectServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlConnectServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SqlConnectServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlConnectServiceLimitedTimeRetryPolicy + : public SqlConnectServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlConnectServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlConnectServiceLimitedTimeRetryPolicy( + SqlConnectServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlConnectServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlConnectServiceLimitedTimeRetryPolicy( + SqlConnectServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlConnectServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SqlConnectServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlConnectServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlConnectServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlConnectServiceRetryTraits> + impl_; +}; /** * The `SqlConnectServiceConnection` object for `SqlConnectServiceClient`. diff --git a/google/cloud/sql/v1/sql_databases_connection.h b/google/cloud/sql/v1/sql_databases_connection.h index 58962ba0846de..1c275ccb30d76 100644 --- a/google/cloud/sql/v1/sql_databases_connection.h +++ b/google/cloud/sql/v1/sql_databases_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlDatabasesServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlDatabasesServiceRetryTraits>; +/// The retry policy for `SqlDatabasesServiceConnection`. +class SqlDatabasesServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SqlDatabasesServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlDatabasesServiceRetryTraits>; +/** + * A retry policy for `SqlDatabasesServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlDatabasesServiceLimitedErrorCountRetryPolicy + : public SqlDatabasesServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlDatabasesServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SqlDatabasesServiceLimitedErrorCountRetryPolicy( + SqlDatabasesServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlDatabasesServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + SqlDatabasesServiceLimitedErrorCountRetryPolicy( + SqlDatabasesServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlDatabasesServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlDatabasesServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlDatabasesServiceRetryTraits> + impl_; +}; -using SqlDatabasesServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlDatabasesServiceRetryTraits>; +/** + * A retry policy for `SqlDatabasesServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlDatabasesServiceLimitedTimeRetryPolicy + : public SqlDatabasesServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlDatabasesServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlDatabasesServiceLimitedTimeRetryPolicy( + SqlDatabasesServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlDatabasesServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlDatabasesServiceLimitedTimeRetryPolicy( + SqlDatabasesServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlDatabasesServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlDatabasesServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlDatabasesServiceRetryTraits> + impl_; +}; /** * The `SqlDatabasesServiceConnection` object for `SqlDatabasesServiceClient`. diff --git a/google/cloud/sql/v1/sql_flags_connection.h b/google/cloud/sql/v1/sql_flags_connection.h index bb41411b008bb..c1248577d062a 100644 --- a/google/cloud/sql/v1/sql_flags_connection.h +++ b/google/cloud/sql/v1/sql_flags_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlFlagsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlFlagsServiceRetryTraits>; +/// The retry policy for `SqlFlagsServiceConnection`. +class SqlFlagsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SqlFlagsServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlFlagsServiceLimitedErrorCountRetryPolicy + : public SqlFlagsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlFlagsServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SqlFlagsServiceLimitedErrorCountRetryPolicy( + SqlFlagsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlFlagsServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SqlFlagsServiceLimitedErrorCountRetryPolicy( + SqlFlagsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlFlagsServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlFlagsServiceRetryPolicy; -using SqlFlagsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlFlagsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlFlagsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SqlFlagsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlFlagsServiceLimitedTimeRetryPolicy + : public SqlFlagsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlFlagsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlFlagsServiceLimitedTimeRetryPolicy( + SqlFlagsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlFlagsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlFlagsServiceLimitedTimeRetryPolicy( + SqlFlagsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlFlagsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SqlFlagsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlFlagsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlFlagsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlFlagsServiceRetryTraits> + impl_; +}; /** * The `SqlFlagsServiceConnection` object for `SqlFlagsServiceClient`. diff --git a/google/cloud/sql/v1/sql_instances_connection.h b/google/cloud/sql/v1/sql_instances_connection.h index a8713a3c6207f..91c550fc73343 100644 --- a/google/cloud/sql/v1/sql_instances_connection.h +++ b/google/cloud/sql/v1/sql_instances_connection.h @@ -36,17 +36,137 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlInstancesServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlInstancesServiceRetryTraits>; +/// The retry policy for `SqlInstancesServiceConnection`. +class SqlInstancesServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using SqlInstancesServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlInstancesServiceRetryTraits>; +/** + * A retry policy for `SqlInstancesServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlInstancesServiceLimitedErrorCountRetryPolicy + : public SqlInstancesServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlInstancesServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SqlInstancesServiceLimitedErrorCountRetryPolicy( + SqlInstancesServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlInstancesServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + SqlInstancesServiceLimitedErrorCountRetryPolicy( + SqlInstancesServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlInstancesServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlInstancesServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlInstancesServiceRetryTraits> + impl_; +}; -using SqlInstancesServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlInstancesServiceRetryTraits>; +/** + * A retry policy for `SqlInstancesServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlInstancesServiceLimitedTimeRetryPolicy + : public SqlInstancesServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlInstancesServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlInstancesServiceLimitedTimeRetryPolicy( + SqlInstancesServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlInstancesServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlInstancesServiceLimitedTimeRetryPolicy( + SqlInstancesServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlInstancesServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlInstancesServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlInstancesServiceRetryTraits> + impl_; +}; /** * The `SqlInstancesServiceConnection` object for `SqlInstancesServiceClient`. diff --git a/google/cloud/sql/v1/sql_operations_connection.h b/google/cloud/sql/v1/sql_operations_connection.h index 101735fa2f182..68c1d3d49b26b 100644 --- a/google/cloud/sql/v1/sql_operations_connection.h +++ b/google/cloud/sql/v1/sql_operations_connection.h @@ -36,17 +36,138 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlOperationsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlOperationsServiceRetryTraits>; +/// The retry policy for `SqlOperationsServiceConnection`. +class SqlOperationsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SqlOperationsServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlOperationsServiceLimitedErrorCountRetryPolicy + : public SqlOperationsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlOperationsServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + SqlOperationsServiceLimitedErrorCountRetryPolicy( + SqlOperationsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlOperationsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + SqlOperationsServiceLimitedErrorCountRetryPolicy( + SqlOperationsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlOperationsServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlOperationsServiceRetryPolicy; -using SqlOperationsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlOperationsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlOperationsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SqlOperationsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlOperationsServiceLimitedTimeRetryPolicy + : public SqlOperationsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlOperationsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlOperationsServiceLimitedTimeRetryPolicy( + SqlOperationsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlOperationsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlOperationsServiceLimitedTimeRetryPolicy( + SqlOperationsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlOperationsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SqlOperationsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlOperationsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlOperationsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlOperationsServiceRetryTraits> + impl_; +}; /** * The `SqlOperationsServiceConnection` object for `SqlOperationsServiceClient`. diff --git a/google/cloud/sql/v1/sql_ssl_certs_connection.h b/google/cloud/sql/v1/sql_ssl_certs_connection.h index 676402a516ec3..ab5bbb20636fc 100644 --- a/google/cloud/sql/v1/sql_ssl_certs_connection.h +++ b/google/cloud/sql/v1/sql_ssl_certs_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlSslCertsServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlSslCertsServiceRetryTraits>; +/// The retry policy for `SqlSslCertsServiceConnection`. +class SqlSslCertsServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SqlSslCertsServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlSslCertsServiceLimitedErrorCountRetryPolicy + : public SqlSslCertsServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlSslCertsServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SqlSslCertsServiceLimitedErrorCountRetryPolicy( + SqlSslCertsServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlSslCertsServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + SqlSslCertsServiceLimitedErrorCountRetryPolicy( + SqlSslCertsServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlSslCertsServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlSslCertsServiceRetryPolicy; -using SqlSslCertsServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlSslCertsServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlSslCertsServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SqlSslCertsServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlSslCertsServiceLimitedTimeRetryPolicy + : public SqlSslCertsServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlSslCertsServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlSslCertsServiceLimitedTimeRetryPolicy( + SqlSslCertsServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlSslCertsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlSslCertsServiceLimitedTimeRetryPolicy( + SqlSslCertsServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlSslCertsServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SqlSslCertsServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlSslCertsServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlSslCertsServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlSslCertsServiceRetryTraits> + impl_; +}; /** * The `SqlSslCertsServiceConnection` object for `SqlSslCertsServiceClient`. diff --git a/google/cloud/sql/v1/sql_tiers_connection.h b/google/cloud/sql/v1/sql_tiers_connection.h index d2d40bc76319c..158b3e99249a9 100644 --- a/google/cloud/sql/v1/sql_tiers_connection.h +++ b/google/cloud/sql/v1/sql_tiers_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlTiersServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlTiersServiceRetryTraits>; +/// The retry policy for `SqlTiersServiceConnection`. +class SqlTiersServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SqlTiersServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlTiersServiceLimitedErrorCountRetryPolicy + : public SqlTiersServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlTiersServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SqlTiersServiceLimitedErrorCountRetryPolicy( + SqlTiersServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlTiersServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SqlTiersServiceLimitedErrorCountRetryPolicy( + SqlTiersServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlTiersServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlTiersServiceRetryPolicy; -using SqlTiersServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlTiersServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlTiersServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SqlTiersServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlTiersServiceLimitedTimeRetryPolicy + : public SqlTiersServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlTiersServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlTiersServiceLimitedTimeRetryPolicy( + SqlTiersServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlTiersServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlTiersServiceLimitedTimeRetryPolicy( + SqlTiersServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlTiersServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SqlTiersServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlTiersServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlTiersServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlTiersServiceRetryTraits> + impl_; +}; /** * The `SqlTiersServiceConnection` object for `SqlTiersServiceClient`. diff --git a/google/cloud/sql/v1/sql_users_connection.h b/google/cloud/sql/v1/sql_users_connection.h index a6781577fa92d..c0c5882504e10 100644 --- a/google/cloud/sql/v1/sql_users_connection.h +++ b/google/cloud/sql/v1/sql_users_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace sql_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using SqlUsersServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - sql_v1_internal::SqlUsersServiceRetryTraits>; +/// The retry policy for `SqlUsersServiceConnection`. +class SqlUsersServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `SqlUsersServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlUsersServiceLimitedErrorCountRetryPolicy + : public SqlUsersServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit SqlUsersServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + SqlUsersServiceLimitedErrorCountRetryPolicy( + SqlUsersServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : SqlUsersServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + SqlUsersServiceLimitedErrorCountRetryPolicy( + SqlUsersServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : SqlUsersServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlUsersServiceRetryPolicy; -using SqlUsersServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - sql_v1_internal::SqlUsersServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + sql_v1_internal::SqlUsersServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `SqlUsersServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class SqlUsersServiceLimitedTimeRetryPolicy + : public SqlUsersServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit SqlUsersServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + SqlUsersServiceLimitedTimeRetryPolicy( + SqlUsersServiceLimitedTimeRetryPolicy&& rhs) noexcept + : SqlUsersServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + SqlUsersServiceLimitedTimeRetryPolicy( + SqlUsersServiceLimitedTimeRetryPolicy const& rhs) noexcept + : SqlUsersServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using SqlUsersServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - sql_v1_internal::SqlUsersServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = SqlUsersServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + sql_v1_internal::SqlUsersServiceRetryTraits> + impl_; +}; /** * The `SqlUsersServiceConnection` object for `SqlUsersServiceClient`. diff --git a/google/cloud/storageinsights/v1/storage_insights_connection.h b/google/cloud/storageinsights/v1/storage_insights_connection.h index 85a100d52499a..c788c33c0579e 100644 --- a/google/cloud/storageinsights/v1/storage_insights_connection.h +++ b/google/cloud/storageinsights/v1/storage_insights_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace storageinsights_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using StorageInsightsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - storageinsights_v1_internal::StorageInsightsRetryTraits>; +/// The retry policy for `StorageInsightsConnection`. +class StorageInsightsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using StorageInsightsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - storageinsights_v1_internal::StorageInsightsRetryTraits>; +/** + * A retry policy for `StorageInsightsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class StorageInsightsLimitedErrorCountRetryPolicy + : public StorageInsightsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit StorageInsightsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + StorageInsightsLimitedErrorCountRetryPolicy( + StorageInsightsLimitedErrorCountRetryPolicy&& rhs) noexcept + : StorageInsightsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + StorageInsightsLimitedErrorCountRetryPolicy( + StorageInsightsLimitedErrorCountRetryPolicy const& rhs) noexcept + : StorageInsightsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = StorageInsightsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + storageinsights_v1_internal::StorageInsightsRetryTraits> + impl_; +}; -using StorageInsightsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - storageinsights_v1_internal::StorageInsightsRetryTraits>; +/** + * A retry policy for `StorageInsightsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class StorageInsightsLimitedTimeRetryPolicy + : public StorageInsightsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit StorageInsightsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + StorageInsightsLimitedTimeRetryPolicy( + StorageInsightsLimitedTimeRetryPolicy&& rhs) noexcept + : StorageInsightsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + StorageInsightsLimitedTimeRetryPolicy( + StorageInsightsLimitedTimeRetryPolicy const& rhs) noexcept + : StorageInsightsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = StorageInsightsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + storageinsights_v1_internal::StorageInsightsRetryTraits> + impl_; +}; /** * The `StorageInsightsConnection` object for `StorageInsightsClient`. diff --git a/google/cloud/storagetransfer/v1/storage_transfer_connection.h b/google/cloud/storagetransfer/v1/storage_transfer_connection.h index b4bc10b587a37..92aa6890ef16f 100644 --- a/google/cloud/storagetransfer/v1/storage_transfer_connection.h +++ b/google/cloud/storagetransfer/v1/storage_transfer_connection.h @@ -38,17 +38,139 @@ namespace cloud { namespace storagetransfer_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using StorageTransferServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - storagetransfer_v1_internal::StorageTransferServiceRetryTraits>; +/// The retry policy for `StorageTransferServiceConnection`. +class StorageTransferServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `StorageTransferServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class StorageTransferServiceLimitedErrorCountRetryPolicy + : public StorageTransferServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit StorageTransferServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + StorageTransferServiceLimitedErrorCountRetryPolicy( + StorageTransferServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : StorageTransferServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + StorageTransferServiceLimitedErrorCountRetryPolicy( + StorageTransferServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : StorageTransferServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = StorageTransferServiceRetryPolicy; -using StorageTransferServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - storagetransfer_v1_internal::StorageTransferServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + storagetransfer_v1_internal::StorageTransferServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `StorageTransferServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class StorageTransferServiceLimitedTimeRetryPolicy + : public StorageTransferServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit StorageTransferServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + StorageTransferServiceLimitedTimeRetryPolicy( + StorageTransferServiceLimitedTimeRetryPolicy&& rhs) noexcept + : StorageTransferServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + StorageTransferServiceLimitedTimeRetryPolicy( + StorageTransferServiceLimitedTimeRetryPolicy const& rhs) noexcept + : StorageTransferServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using StorageTransferServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - storagetransfer_v1_internal::StorageTransferServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = StorageTransferServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + storagetransfer_v1_internal::StorageTransferServiceRetryTraits> + impl_; +}; /** * The `StorageTransferServiceConnection` object for diff --git a/google/cloud/support/v2/case_attachment_connection.h b/google/cloud/support/v2/case_attachment_connection.h index 0dd64a4e613d8..cbb912a173e51 100644 --- a/google/cloud/support/v2/case_attachment_connection.h +++ b/google/cloud/support/v2/case_attachment_connection.h @@ -35,17 +35,139 @@ namespace cloud { namespace support_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CaseAttachmentServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - support_v2_internal::CaseAttachmentServiceRetryTraits>; +/// The retry policy for `CaseAttachmentServiceConnection`. +class CaseAttachmentServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CaseAttachmentServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CaseAttachmentServiceLimitedErrorCountRetryPolicy + : public CaseAttachmentServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CaseAttachmentServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + CaseAttachmentServiceLimitedErrorCountRetryPolicy( + CaseAttachmentServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CaseAttachmentServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + CaseAttachmentServiceLimitedErrorCountRetryPolicy( + CaseAttachmentServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CaseAttachmentServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CaseAttachmentServiceRetryPolicy; -using CaseAttachmentServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - support_v2_internal::CaseAttachmentServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + support_v2_internal::CaseAttachmentServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `CaseAttachmentServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CaseAttachmentServiceLimitedTimeRetryPolicy + : public CaseAttachmentServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CaseAttachmentServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CaseAttachmentServiceLimitedTimeRetryPolicy( + CaseAttachmentServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CaseAttachmentServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CaseAttachmentServiceLimitedTimeRetryPolicy( + CaseAttachmentServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CaseAttachmentServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CaseAttachmentServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - support_v2_internal::CaseAttachmentServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CaseAttachmentServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + support_v2_internal::CaseAttachmentServiceRetryTraits> + impl_; +}; /** * The `CaseAttachmentServiceConnection` object for diff --git a/google/cloud/support/v2/case_connection.h b/google/cloud/support/v2/case_connection.h index 5215fc520a7e4..d3f8a93246066 100644 --- a/google/cloud/support/v2/case_connection.h +++ b/google/cloud/support/v2/case_connection.h @@ -35,16 +35,133 @@ namespace cloud { namespace support_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CaseServiceRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - support_v2_internal::CaseServiceRetryTraits>; +/// The retry policy for `CaseServiceConnection`. +class CaseServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CaseServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - support_v2_internal::CaseServiceRetryTraits>; +/** + * A retry policy for `CaseServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CaseServiceLimitedErrorCountRetryPolicy : public CaseServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CaseServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CaseServiceLimitedErrorCountRetryPolicy( + CaseServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CaseServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CaseServiceLimitedErrorCountRetryPolicy( + CaseServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CaseServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CaseServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + support_v2_internal::CaseServiceRetryTraits> + impl_; +}; -using CaseServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - support_v2_internal::CaseServiceRetryTraits>; +/** + * A retry policy for `CaseServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CaseServiceLimitedTimeRetryPolicy : public CaseServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CaseServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CaseServiceLimitedTimeRetryPolicy( + CaseServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CaseServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CaseServiceLimitedTimeRetryPolicy( + CaseServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CaseServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CaseServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + support_v2_internal::CaseServiceRetryTraits> + impl_; +}; /** * The `CaseServiceConnection` object for `CaseServiceClient`. diff --git a/google/cloud/support/v2/comment_connection.h b/google/cloud/support/v2/comment_connection.h index 75d29ec8c967f..05673b43ea1aa 100644 --- a/google/cloud/support/v2/comment_connection.h +++ b/google/cloud/support/v2/comment_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace support_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CommentServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - support_v2_internal::CommentServiceRetryTraits>; +/// The retry policy for `CommentServiceConnection`. +class CommentServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CommentServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CommentServiceLimitedErrorCountRetryPolicy + : public CommentServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CommentServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CommentServiceLimitedErrorCountRetryPolicy( + CommentServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CommentServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CommentServiceLimitedErrorCountRetryPolicy( + CommentServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CommentServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CommentServiceRetryPolicy; -using CommentServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - support_v2_internal::CommentServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + support_v2_internal::CommentServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `CommentServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CommentServiceLimitedTimeRetryPolicy : public CommentServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CommentServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CommentServiceLimitedTimeRetryPolicy( + CommentServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CommentServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CommentServiceLimitedTimeRetryPolicy( + CommentServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CommentServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CommentServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - support_v2_internal::CommentServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CommentServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + support_v2_internal::CommentServiceRetryTraits> + impl_; +}; /** * The `CommentServiceConnection` object for `CommentServiceClient`. diff --git a/google/cloud/talent/v4/company_connection.h b/google/cloud/talent/v4/company_connection.h index d16640048c8e3..a107ff041fe03 100644 --- a/google/cloud/talent/v4/company_connection.h +++ b/google/cloud/talent/v4/company_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace talent_v4 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CompanyServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - talent_v4_internal::CompanyServiceRetryTraits>; +/// The retry policy for `CompanyServiceConnection`. +class CompanyServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using CompanyServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - talent_v4_internal::CompanyServiceRetryTraits>; +/** + * A retry policy for `CompanyServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CompanyServiceLimitedErrorCountRetryPolicy + : public CompanyServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CompanyServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CompanyServiceLimitedErrorCountRetryPolicy( + CompanyServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : CompanyServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CompanyServiceLimitedErrorCountRetryPolicy( + CompanyServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : CompanyServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CompanyServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + talent_v4_internal::CompanyServiceRetryTraits> + impl_; +}; -using CompanyServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - talent_v4_internal::CompanyServiceRetryTraits>; +/** + * A retry policy for `CompanyServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CompanyServiceLimitedTimeRetryPolicy : public CompanyServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CompanyServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CompanyServiceLimitedTimeRetryPolicy( + CompanyServiceLimitedTimeRetryPolicy&& rhs) noexcept + : CompanyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CompanyServiceLimitedTimeRetryPolicy( + CompanyServiceLimitedTimeRetryPolicy const& rhs) noexcept + : CompanyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CompanyServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + talent_v4_internal::CompanyServiceRetryTraits> + impl_; +}; /** * The `CompanyServiceConnection` object for `CompanyServiceClient`. diff --git a/google/cloud/talent/v4/completion_connection.h b/google/cloud/talent/v4/completion_connection.h index e5229bc6858b9..c17847cc053dd 100644 --- a/google/cloud/talent/v4/completion_connection.h +++ b/google/cloud/talent/v4/completion_connection.h @@ -34,16 +34,133 @@ namespace cloud { namespace talent_v4 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CompletionRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - talent_v4_internal::CompletionRetryTraits>; +/// The retry policy for `CompletionConnection`. +class CompletionRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CompletionConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CompletionLimitedErrorCountRetryPolicy : public CompletionRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CompletionLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CompletionLimitedErrorCountRetryPolicy( + CompletionLimitedErrorCountRetryPolicy&& rhs) noexcept + : CompletionLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CompletionLimitedErrorCountRetryPolicy( + CompletionLimitedErrorCountRetryPolicy const& rhs) noexcept + : CompletionLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CompletionRetryPolicy; -using CompletionLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - talent_v4_internal::CompletionRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + talent_v4_internal::CompletionRetryTraits> + impl_; +}; + +/** + * A retry policy for `CompletionConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CompletionLimitedTimeRetryPolicy : public CompletionRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CompletionLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CompletionLimitedTimeRetryPolicy( + CompletionLimitedTimeRetryPolicy&& rhs) noexcept + : CompletionLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CompletionLimitedTimeRetryPolicy( + CompletionLimitedTimeRetryPolicy const& rhs) noexcept + : CompletionLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CompletionLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - talent_v4_internal::CompletionRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CompletionRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + talent_v4_internal::CompletionRetryTraits> + impl_; +}; /** * The `CompletionConnection` object for `CompletionClient`. diff --git a/google/cloud/talent/v4/event_connection.h b/google/cloud/talent/v4/event_connection.h index 3feb96dd87062..9d95989d6cd34 100644 --- a/google/cloud/talent/v4/event_connection.h +++ b/google/cloud/talent/v4/event_connection.h @@ -34,17 +34,134 @@ namespace cloud { namespace talent_v4 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using EventServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - talent_v4_internal::EventServiceRetryTraits>; +/// The retry policy for `EventServiceConnection`. +class EventServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `EventServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EventServiceLimitedErrorCountRetryPolicy + : public EventServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit EventServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + EventServiceLimitedErrorCountRetryPolicy( + EventServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : EventServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + EventServiceLimitedErrorCountRetryPolicy( + EventServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : EventServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = EventServiceRetryPolicy; -using EventServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - talent_v4_internal::EventServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + talent_v4_internal::EventServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `EventServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class EventServiceLimitedTimeRetryPolicy : public EventServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit EventServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + EventServiceLimitedTimeRetryPolicy( + EventServiceLimitedTimeRetryPolicy&& rhs) noexcept + : EventServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + EventServiceLimitedTimeRetryPolicy( + EventServiceLimitedTimeRetryPolicy const& rhs) noexcept + : EventServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using EventServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - talent_v4_internal::EventServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = EventServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + talent_v4_internal::EventServiceRetryTraits> + impl_; +}; /** * The `EventServiceConnection` object for `EventServiceClient`. diff --git a/google/cloud/talent/v4/job_connection.h b/google/cloud/talent/v4/job_connection.h index d69bcd3b6cb13..7bb8e3ea7a50a 100644 --- a/google/cloud/talent/v4/job_connection.h +++ b/google/cloud/talent/v4/job_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace talent_v4 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using JobServiceRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - talent_v4_internal::JobServiceRetryTraits>; +/// The retry policy for `JobServiceConnection`. +class JobServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using JobServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - talent_v4_internal::JobServiceRetryTraits>; +/** + * A retry policy for `JobServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class JobServiceLimitedErrorCountRetryPolicy : public JobServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit JobServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + JobServiceLimitedErrorCountRetryPolicy( + JobServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : JobServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + JobServiceLimitedErrorCountRetryPolicy( + JobServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : JobServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = JobServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + talent_v4_internal::JobServiceRetryTraits> + impl_; +}; -using JobServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - talent_v4_internal::JobServiceRetryTraits>; +/** + * A retry policy for `JobServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class JobServiceLimitedTimeRetryPolicy : public JobServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit JobServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + JobServiceLimitedTimeRetryPolicy( + JobServiceLimitedTimeRetryPolicy&& rhs) noexcept + : JobServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + JobServiceLimitedTimeRetryPolicy( + JobServiceLimitedTimeRetryPolicy const& rhs) noexcept + : JobServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = JobServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + talent_v4_internal::JobServiceRetryTraits> + impl_; +}; /** * The `JobServiceConnection` object for `JobServiceClient`. diff --git a/google/cloud/talent/v4/tenant_connection.h b/google/cloud/talent/v4/tenant_connection.h index c4dd5cd16df4d..662b7320de467 100644 --- a/google/cloud/talent/v4/tenant_connection.h +++ b/google/cloud/talent/v4/tenant_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace talent_v4 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TenantServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - talent_v4_internal::TenantServiceRetryTraits>; +/// The retry policy for `TenantServiceConnection`. +class TenantServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TenantServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - talent_v4_internal::TenantServiceRetryTraits>; +/** + * A retry policy for `TenantServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TenantServiceLimitedErrorCountRetryPolicy + : public TenantServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TenantServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TenantServiceLimitedErrorCountRetryPolicy( + TenantServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : TenantServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TenantServiceLimitedErrorCountRetryPolicy( + TenantServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : TenantServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TenantServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + talent_v4_internal::TenantServiceRetryTraits> + impl_; +}; -using TenantServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - talent_v4_internal::TenantServiceRetryTraits>; +/** + * A retry policy for `TenantServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TenantServiceLimitedTimeRetryPolicy : public TenantServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TenantServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TenantServiceLimitedTimeRetryPolicy( + TenantServiceLimitedTimeRetryPolicy&& rhs) noexcept + : TenantServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TenantServiceLimitedTimeRetryPolicy( + TenantServiceLimitedTimeRetryPolicy const& rhs) noexcept + : TenantServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TenantServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + talent_v4_internal::TenantServiceRetryTraits> + impl_; +}; /** * The `TenantServiceConnection` object for `TenantServiceClient`. diff --git a/google/cloud/tasks/v2/cloud_tasks_connection.h b/google/cloud/tasks/v2/cloud_tasks_connection.h index 59ca3cd5e14db..7a62b8e510020 100644 --- a/google/cloud/tasks/v2/cloud_tasks_connection.h +++ b/google/cloud/tasks/v2/cloud_tasks_connection.h @@ -35,16 +35,135 @@ namespace cloud { namespace tasks_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using CloudTasksRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - tasks_v2_internal::CloudTasksRetryTraits>; +/// The retry policy for `CloudTasksConnection`. +class CloudTasksRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `CloudTasksConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kInternal`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudTasksLimitedErrorCountRetryPolicy : public CloudTasksRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit CloudTasksLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + CloudTasksLimitedErrorCountRetryPolicy( + CloudTasksLimitedErrorCountRetryPolicy&& rhs) noexcept + : CloudTasksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + CloudTasksLimitedErrorCountRetryPolicy( + CloudTasksLimitedErrorCountRetryPolicy const& rhs) noexcept + : CloudTasksLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudTasksRetryPolicy; -using CloudTasksLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - tasks_v2_internal::CloudTasksRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + tasks_v2_internal::CloudTasksRetryTraits> + impl_; +}; + +/** + * A retry policy for `CloudTasksConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kInternal`](@ref google::cloud::StatusCode) + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class CloudTasksLimitedTimeRetryPolicy : public CloudTasksRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit CloudTasksLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + CloudTasksLimitedTimeRetryPolicy( + CloudTasksLimitedTimeRetryPolicy&& rhs) noexcept + : CloudTasksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + CloudTasksLimitedTimeRetryPolicy( + CloudTasksLimitedTimeRetryPolicy const& rhs) noexcept + : CloudTasksLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using CloudTasksLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - tasks_v2_internal::CloudTasksRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = CloudTasksRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + tasks_v2_internal::CloudTasksRetryTraits> + impl_; +}; /** * The `CloudTasksConnection` object for `CloudTasksClient`. diff --git a/google/cloud/texttospeech/v1/text_to_speech_connection.h b/google/cloud/texttospeech/v1/text_to_speech_connection.h index 3f3df5a99d49b..2ab1c8df7fc24 100644 --- a/google/cloud/texttospeech/v1/text_to_speech_connection.h +++ b/google/cloud/texttospeech/v1/text_to_speech_connection.h @@ -34,17 +34,134 @@ namespace cloud { namespace texttospeech_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TextToSpeechRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - texttospeech_v1_internal::TextToSpeechRetryTraits>; +/// The retry policy for `TextToSpeechConnection`. +class TextToSpeechRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TextToSpeechConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TextToSpeechLimitedErrorCountRetryPolicy + : public TextToSpeechRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TextToSpeechLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TextToSpeechLimitedErrorCountRetryPolicy( + TextToSpeechLimitedErrorCountRetryPolicy&& rhs) noexcept + : TextToSpeechLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TextToSpeechLimitedErrorCountRetryPolicy( + TextToSpeechLimitedErrorCountRetryPolicy const& rhs) noexcept + : TextToSpeechLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TextToSpeechRetryPolicy; -using TextToSpeechLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - texttospeech_v1_internal::TextToSpeechRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + texttospeech_v1_internal::TextToSpeechRetryTraits> + impl_; +}; + +/** + * A retry policy for `TextToSpeechConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TextToSpeechLimitedTimeRetryPolicy : public TextToSpeechRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TextToSpeechLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TextToSpeechLimitedTimeRetryPolicy( + TextToSpeechLimitedTimeRetryPolicy&& rhs) noexcept + : TextToSpeechLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TextToSpeechLimitedTimeRetryPolicy( + TextToSpeechLimitedTimeRetryPolicy const& rhs) noexcept + : TextToSpeechLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using TextToSpeechLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - texttospeech_v1_internal::TextToSpeechRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TextToSpeechRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + texttospeech_v1_internal::TextToSpeechRetryTraits> + impl_; +}; /** * The `TextToSpeechConnection` object for `TextToSpeechClient`. diff --git a/google/cloud/timeseriesinsights/v1/timeseries_insights_controller_connection.h b/google/cloud/timeseriesinsights/v1/timeseries_insights_controller_connection.h index 3ffd3910f3f86..69fd5b335f1b0 100644 --- a/google/cloud/timeseriesinsights/v1/timeseries_insights_controller_connection.h +++ b/google/cloud/timeseriesinsights/v1/timeseries_insights_controller_connection.h @@ -35,20 +35,148 @@ namespace cloud { namespace timeseriesinsights_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TimeseriesInsightsControllerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - timeseriesinsights_v1_internal:: - TimeseriesInsightsControllerRetryTraits>; - -using TimeseriesInsightsControllerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - timeseriesinsights_v1_internal:: - TimeseriesInsightsControllerRetryTraits>; - -using TimeseriesInsightsControllerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - timeseriesinsights_v1_internal:: - TimeseriesInsightsControllerRetryTraits>; +/// The retry policy for `TimeseriesInsightsControllerConnection`. +class TimeseriesInsightsControllerRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `TimeseriesInsightsControllerConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TimeseriesInsightsControllerLimitedErrorCountRetryPolicy + : public TimeseriesInsightsControllerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TimeseriesInsightsControllerLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + TimeseriesInsightsControllerLimitedErrorCountRetryPolicy( + TimeseriesInsightsControllerLimitedErrorCountRetryPolicy&& rhs) noexcept + : TimeseriesInsightsControllerLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + TimeseriesInsightsControllerLimitedErrorCountRetryPolicy( + TimeseriesInsightsControllerLimitedErrorCountRetryPolicy const& + rhs) noexcept + : TimeseriesInsightsControllerLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique< + TimeseriesInsightsControllerLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TimeseriesInsightsControllerRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + timeseriesinsights_v1_internal::TimeseriesInsightsControllerRetryTraits> + impl_; +}; + +/** + * A retry policy for `TimeseriesInsightsControllerConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TimeseriesInsightsControllerLimitedTimeRetryPolicy + : public TimeseriesInsightsControllerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TimeseriesInsightsControllerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TimeseriesInsightsControllerLimitedTimeRetryPolicy( + TimeseriesInsightsControllerLimitedTimeRetryPolicy&& rhs) noexcept + : TimeseriesInsightsControllerLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + TimeseriesInsightsControllerLimitedTimeRetryPolicy( + TimeseriesInsightsControllerLimitedTimeRetryPolicy const& rhs) noexcept + : TimeseriesInsightsControllerLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() + const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TimeseriesInsightsControllerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + timeseriesinsights_v1_internal::TimeseriesInsightsControllerRetryTraits> + impl_; +}; /** * The `TimeseriesInsightsControllerConnection` object for diff --git a/google/cloud/tpu/v1/tpu_connection.h b/google/cloud/tpu/v1/tpu_connection.h index 87d48f5dee0eb..2f47dcba6c57d 100644 --- a/google/cloud/tpu/v1/tpu_connection.h +++ b/google/cloud/tpu/v1/tpu_connection.h @@ -38,16 +38,130 @@ namespace cloud { namespace tpu_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TpuRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - tpu_v1_internal::TpuRetryTraits>; +/// The retry policy for `TpuConnection`. +class TpuRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TpuLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - tpu_v1_internal::TpuRetryTraits>; +/** + * A retry policy for `TpuConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TpuLimitedErrorCountRetryPolicy : public TpuRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TpuLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TpuLimitedErrorCountRetryPolicy( + TpuLimitedErrorCountRetryPolicy&& rhs) noexcept + : TpuLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TpuLimitedErrorCountRetryPolicy( + TpuLimitedErrorCountRetryPolicy const& rhs) noexcept + : TpuLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TpuRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + tpu_v1_internal::TpuRetryTraits> + impl_; +}; -using TpuLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - tpu_v1_internal::TpuRetryTraits>; +/** + * A retry policy for `TpuConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TpuLimitedTimeRetryPolicy : public TpuRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TpuLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TpuLimitedTimeRetryPolicy(TpuLimitedTimeRetryPolicy&& rhs) noexcept + : TpuLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TpuLimitedTimeRetryPolicy(TpuLimitedTimeRetryPolicy const& rhs) noexcept + : TpuLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TpuRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + tpu_v1_internal::TpuRetryTraits> + impl_; +}; /** * The `TpuConnection` object for `TpuClient`. diff --git a/google/cloud/tpu/v2/tpu_connection.h b/google/cloud/tpu/v2/tpu_connection.h index 12329ed3aa052..53df4a70e32a0 100644 --- a/google/cloud/tpu/v2/tpu_connection.h +++ b/google/cloud/tpu/v2/tpu_connection.h @@ -38,16 +38,130 @@ namespace cloud { namespace tpu_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TpuRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - tpu_v2_internal::TpuRetryTraits>; +/// The retry policy for `TpuConnection`. +class TpuRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TpuConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TpuLimitedErrorCountRetryPolicy : public TpuRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TpuLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TpuLimitedErrorCountRetryPolicy( + TpuLimitedErrorCountRetryPolicy&& rhs) noexcept + : TpuLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TpuLimitedErrorCountRetryPolicy( + TpuLimitedErrorCountRetryPolicy const& rhs) noexcept + : TpuLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TpuRetryPolicy; -using TpuLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - tpu_v2_internal::TpuRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + tpu_v2_internal::TpuRetryTraits> + impl_; +}; + +/** + * A retry policy for `TpuConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TpuLimitedTimeRetryPolicy : public TpuRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TpuLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TpuLimitedTimeRetryPolicy(TpuLimitedTimeRetryPolicy&& rhs) noexcept + : TpuLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TpuLimitedTimeRetryPolicy(TpuLimitedTimeRetryPolicy const& rhs) noexcept + : TpuLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using TpuLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - tpu_v2_internal::TpuRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TpuRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + tpu_v2_internal::TpuRetryTraits> + impl_; +}; /** * The `TpuConnection` object for `TpuClient`. diff --git a/google/cloud/trace/v1/trace_connection.h b/google/cloud/trace/v1/trace_connection.h index dbd944af04303..e46e6f34a9f06 100644 --- a/google/cloud/trace/v1/trace_connection.h +++ b/google/cloud/trace/v1/trace_connection.h @@ -35,17 +35,134 @@ namespace cloud { namespace trace_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TraceServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - trace_v1_internal::TraceServiceRetryTraits>; +/// The retry policy for `TraceServiceConnection`. +class TraceServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TraceServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TraceServiceLimitedErrorCountRetryPolicy + : public TraceServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TraceServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TraceServiceLimitedErrorCountRetryPolicy( + TraceServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : TraceServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TraceServiceLimitedErrorCountRetryPolicy( + TraceServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : TraceServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TraceServiceRetryPolicy; -using TraceServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - trace_v1_internal::TraceServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + trace_v1_internal::TraceServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `TraceServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TraceServiceLimitedTimeRetryPolicy : public TraceServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TraceServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TraceServiceLimitedTimeRetryPolicy( + TraceServiceLimitedTimeRetryPolicy&& rhs) noexcept + : TraceServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TraceServiceLimitedTimeRetryPolicy( + TraceServiceLimitedTimeRetryPolicy const& rhs) noexcept + : TraceServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using TraceServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - trace_v1_internal::TraceServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TraceServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + trace_v1_internal::TraceServiceRetryTraits> + impl_; +}; /** * The `TraceServiceConnection` object for `TraceServiceClient`. diff --git a/google/cloud/trace/v2/trace_connection.h b/google/cloud/trace/v2/trace_connection.h index 04a5e85644f08..cdf9dbad28684 100644 --- a/google/cloud/trace/v2/trace_connection.h +++ b/google/cloud/trace/v2/trace_connection.h @@ -34,17 +34,134 @@ namespace cloud { namespace trace_v2 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TraceServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - trace_v2_internal::TraceServiceRetryTraits>; +/// The retry policy for `TraceServiceConnection`. +class TraceServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TraceServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TraceServiceLimitedErrorCountRetryPolicy + : public TraceServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TraceServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TraceServiceLimitedErrorCountRetryPolicy( + TraceServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : TraceServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TraceServiceLimitedErrorCountRetryPolicy( + TraceServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : TraceServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TraceServiceRetryPolicy; -using TraceServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - trace_v2_internal::TraceServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + trace_v2_internal::TraceServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `TraceServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TraceServiceLimitedTimeRetryPolicy : public TraceServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TraceServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TraceServiceLimitedTimeRetryPolicy( + TraceServiceLimitedTimeRetryPolicy&& rhs) noexcept + : TraceServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TraceServiceLimitedTimeRetryPolicy( + TraceServiceLimitedTimeRetryPolicy const& rhs) noexcept + : TraceServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using TraceServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - trace_v2_internal::TraceServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TraceServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + trace_v2_internal::TraceServiceRetryTraits> + impl_; +}; /** * The `TraceServiceConnection` object for `TraceServiceClient`. diff --git a/google/cloud/translate/v3/translation_connection.h b/google/cloud/translate/v3/translation_connection.h index c29513e5a476a..fb0c736ad9412 100644 --- a/google/cloud/translate/v3/translation_connection.h +++ b/google/cloud/translate/v3/translation_connection.h @@ -38,17 +38,137 @@ namespace cloud { namespace translate_v3 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TranslationServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - translate_v3_internal::TranslationServiceRetryTraits>; +/// The retry policy for `TranslationServiceConnection`. +class TranslationServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TranslationServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TranslationServiceLimitedErrorCountRetryPolicy + : public TranslationServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TranslationServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TranslationServiceLimitedErrorCountRetryPolicy( + TranslationServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : TranslationServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + TranslationServiceLimitedErrorCountRetryPolicy( + TranslationServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : TranslationServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TranslationServiceRetryPolicy; -using TranslationServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - translate_v3_internal::TranslationServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + translate_v3_internal::TranslationServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `TranslationServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TranslationServiceLimitedTimeRetryPolicy + : public TranslationServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TranslationServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TranslationServiceLimitedTimeRetryPolicy( + TranslationServiceLimitedTimeRetryPolicy&& rhs) noexcept + : TranslationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TranslationServiceLimitedTimeRetryPolicy( + TranslationServiceLimitedTimeRetryPolicy const& rhs) noexcept + : TranslationServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using TranslationServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - translate_v3_internal::TranslationServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TranslationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + translate_v3_internal::TranslationServiceRetryTraits> + impl_; +}; /** * The `TranslationServiceConnection` object for `TranslationServiceClient`. diff --git a/google/cloud/video/livestream/v1/livestream_connection.h b/google/cloud/video/livestream/v1/livestream_connection.h index dba734ae43b4c..dde44c00ba142 100644 --- a/google/cloud/video/livestream/v1/livestream_connection.h +++ b/google/cloud/video/livestream/v1/livestream_connection.h @@ -38,17 +38,135 @@ namespace cloud { namespace video_livestream_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using LivestreamServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - video_livestream_v1_internal::LivestreamServiceRetryTraits>; +/// The retry policy for `LivestreamServiceConnection`. +class LivestreamServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `LivestreamServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LivestreamServiceLimitedErrorCountRetryPolicy + : public LivestreamServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit LivestreamServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + LivestreamServiceLimitedErrorCountRetryPolicy( + LivestreamServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : LivestreamServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + LivestreamServiceLimitedErrorCountRetryPolicy( + LivestreamServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : LivestreamServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = LivestreamServiceRetryPolicy; -using LivestreamServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - video_livestream_v1_internal::LivestreamServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + video_livestream_v1_internal::LivestreamServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `LivestreamServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class LivestreamServiceLimitedTimeRetryPolicy + : public LivestreamServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit LivestreamServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + LivestreamServiceLimitedTimeRetryPolicy( + LivestreamServiceLimitedTimeRetryPolicy&& rhs) noexcept + : LivestreamServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + LivestreamServiceLimitedTimeRetryPolicy( + LivestreamServiceLimitedTimeRetryPolicy const& rhs) noexcept + : LivestreamServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using LivestreamServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - video_livestream_v1_internal::LivestreamServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = LivestreamServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + video_livestream_v1_internal::LivestreamServiceRetryTraits> + impl_; +}; /** * The `LivestreamServiceConnection` object for `LivestreamServiceClient`. diff --git a/google/cloud/video/stitcher/v1/video_stitcher_connection.h b/google/cloud/video/stitcher/v1/video_stitcher_connection.h index a6dd19493d4ee..6f45f3db7515b 100644 --- a/google/cloud/video/stitcher/v1/video_stitcher_connection.h +++ b/google/cloud/video/stitcher/v1/video_stitcher_connection.h @@ -38,17 +38,138 @@ namespace cloud { namespace video_stitcher_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VideoStitcherServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - video_stitcher_v1_internal::VideoStitcherServiceRetryTraits>; +/// The retry policy for `VideoStitcherServiceConnection`. +class VideoStitcherServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VideoStitcherServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - video_stitcher_v1_internal::VideoStitcherServiceRetryTraits>; +/** + * A retry policy for `VideoStitcherServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VideoStitcherServiceLimitedErrorCountRetryPolicy + : public VideoStitcherServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VideoStitcherServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + VideoStitcherServiceLimitedErrorCountRetryPolicy( + VideoStitcherServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : VideoStitcherServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + VideoStitcherServiceLimitedErrorCountRetryPolicy( + VideoStitcherServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : VideoStitcherServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VideoStitcherServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + video_stitcher_v1_internal::VideoStitcherServiceRetryTraits> + impl_; +}; -using VideoStitcherServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - video_stitcher_v1_internal::VideoStitcherServiceRetryTraits>; +/** + * A retry policy for `VideoStitcherServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VideoStitcherServiceLimitedTimeRetryPolicy + : public VideoStitcherServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VideoStitcherServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VideoStitcherServiceLimitedTimeRetryPolicy( + VideoStitcherServiceLimitedTimeRetryPolicy&& rhs) noexcept + : VideoStitcherServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VideoStitcherServiceLimitedTimeRetryPolicy( + VideoStitcherServiceLimitedTimeRetryPolicy const& rhs) noexcept + : VideoStitcherServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VideoStitcherServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + video_stitcher_v1_internal::VideoStitcherServiceRetryTraits> + impl_; +}; /** * The `VideoStitcherServiceConnection` object for `VideoStitcherServiceClient`. diff --git a/google/cloud/video/transcoder/v1/transcoder_connection.h b/google/cloud/video/transcoder/v1/transcoder_connection.h index f5ff640eeb741..ba26962f261d0 100644 --- a/google/cloud/video/transcoder/v1/transcoder_connection.h +++ b/google/cloud/video/transcoder/v1/transcoder_connection.h @@ -35,17 +35,135 @@ namespace cloud { namespace video_transcoder_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using TranscoderServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - video_transcoder_v1_internal::TranscoderServiceRetryTraits>; +/// The retry policy for `TranscoderServiceConnection`. +class TranscoderServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using TranscoderServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - video_transcoder_v1_internal::TranscoderServiceRetryTraits>; +/** + * A retry policy for `TranscoderServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TranscoderServiceLimitedErrorCountRetryPolicy + : public TranscoderServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TranscoderServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TranscoderServiceLimitedErrorCountRetryPolicy( + TranscoderServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : TranscoderServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TranscoderServiceLimitedErrorCountRetryPolicy( + TranscoderServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : TranscoderServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TranscoderServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + video_transcoder_v1_internal::TranscoderServiceRetryTraits> + impl_; +}; -using TranscoderServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - video_transcoder_v1_internal::TranscoderServiceRetryTraits>; +/** + * A retry policy for `TranscoderServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TranscoderServiceLimitedTimeRetryPolicy + : public TranscoderServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TranscoderServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TranscoderServiceLimitedTimeRetryPolicy( + TranscoderServiceLimitedTimeRetryPolicy&& rhs) noexcept + : TranscoderServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TranscoderServiceLimitedTimeRetryPolicy( + TranscoderServiceLimitedTimeRetryPolicy const& rhs) noexcept + : TranscoderServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TranscoderServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + video_transcoder_v1_internal::TranscoderServiceRetryTraits> + impl_; +}; /** * The `TranscoderServiceConnection` object for `TranscoderServiceClient`. diff --git a/google/cloud/videointelligence/v1/video_intelligence_connection.h b/google/cloud/videointelligence/v1/video_intelligence_connection.h index 367bde3b38bc6..35cc94314343a 100644 --- a/google/cloud/videointelligence/v1/video_intelligence_connection.h +++ b/google/cloud/videointelligence/v1/video_intelligence_connection.h @@ -37,17 +37,145 @@ namespace cloud { namespace videointelligence_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VideoIntelligenceServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - videointelligence_v1_internal::VideoIntelligenceServiceRetryTraits>; +/// The retry policy for `VideoIntelligenceServiceConnection`. +class VideoIntelligenceServiceRetryPolicy + : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() + const = 0; +}; + +/** + * A retry policy for `VideoIntelligenceServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VideoIntelligenceServiceLimitedErrorCountRetryPolicy + : public VideoIntelligenceServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VideoIntelligenceServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + VideoIntelligenceServiceLimitedErrorCountRetryPolicy( + VideoIntelligenceServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : VideoIntelligenceServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + VideoIntelligenceServiceLimitedErrorCountRetryPolicy( + VideoIntelligenceServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : VideoIntelligenceServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique< + VideoIntelligenceServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VideoIntelligenceServiceRetryPolicy; -using VideoIntelligenceServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - videointelligence_v1_internal::VideoIntelligenceServiceRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + videointelligence_v1_internal::VideoIntelligenceServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `VideoIntelligenceServiceConnection` based on elapsed + * time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VideoIntelligenceServiceLimitedTimeRetryPolicy + : public VideoIntelligenceServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VideoIntelligenceServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VideoIntelligenceServiceLimitedTimeRetryPolicy( + VideoIntelligenceServiceLimitedTimeRetryPolicy&& rhs) noexcept + : VideoIntelligenceServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + VideoIntelligenceServiceLimitedTimeRetryPolicy( + VideoIntelligenceServiceLimitedTimeRetryPolicy const& rhs) noexcept + : VideoIntelligenceServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) { + } + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using VideoIntelligenceServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - videointelligence_v1_internal::VideoIntelligenceServiceRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VideoIntelligenceServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + videointelligence_v1_internal::VideoIntelligenceServiceRetryTraits> + impl_; +}; /** * The `VideoIntelligenceServiceConnection` object for diff --git a/google/cloud/vision/v1/image_annotator_connection.h b/google/cloud/vision/v1/image_annotator_connection.h index c1ddd258f6f16..b2b6c7602dc29 100644 --- a/google/cloud/vision/v1/image_annotator_connection.h +++ b/google/cloud/vision/v1/image_annotator_connection.h @@ -37,17 +37,134 @@ namespace cloud { namespace vision_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ImageAnnotatorRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - vision_v1_internal::ImageAnnotatorRetryTraits>; +/// The retry policy for `ImageAnnotatorConnection`. +class ImageAnnotatorRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ImageAnnotatorLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - vision_v1_internal::ImageAnnotatorRetryTraits>; +/** + * A retry policy for `ImageAnnotatorConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ImageAnnotatorLimitedErrorCountRetryPolicy + : public ImageAnnotatorRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ImageAnnotatorLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ImageAnnotatorLimitedErrorCountRetryPolicy( + ImageAnnotatorLimitedErrorCountRetryPolicy&& rhs) noexcept + : ImageAnnotatorLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ImageAnnotatorLimitedErrorCountRetryPolicy( + ImageAnnotatorLimitedErrorCountRetryPolicy const& rhs) noexcept + : ImageAnnotatorLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ImageAnnotatorRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + vision_v1_internal::ImageAnnotatorRetryTraits> + impl_; +}; -using ImageAnnotatorLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - vision_v1_internal::ImageAnnotatorRetryTraits>; +/** + * A retry policy for `ImageAnnotatorConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ImageAnnotatorLimitedTimeRetryPolicy : public ImageAnnotatorRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ImageAnnotatorLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ImageAnnotatorLimitedTimeRetryPolicy( + ImageAnnotatorLimitedTimeRetryPolicy&& rhs) noexcept + : ImageAnnotatorLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ImageAnnotatorLimitedTimeRetryPolicy( + ImageAnnotatorLimitedTimeRetryPolicy const& rhs) noexcept + : ImageAnnotatorLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ImageAnnotatorRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + vision_v1_internal::ImageAnnotatorRetryTraits> + impl_; +}; /** * The `ImageAnnotatorConnection` object for `ImageAnnotatorClient`. diff --git a/google/cloud/vision/v1/product_search_connection.h b/google/cloud/vision/v1/product_search_connection.h index 5492573ff852d..b63b66d77dd39 100644 --- a/google/cloud/vision/v1/product_search_connection.h +++ b/google/cloud/vision/v1/product_search_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace vision_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ProductSearchRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - vision_v1_internal::ProductSearchRetryTraits>; +/// The retry policy for `ProductSearchConnection`. +class ProductSearchRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ProductSearchConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProductSearchLimitedErrorCountRetryPolicy + : public ProductSearchRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ProductSearchLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ProductSearchLimitedErrorCountRetryPolicy( + ProductSearchLimitedErrorCountRetryPolicy&& rhs) noexcept + : ProductSearchLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ProductSearchLimitedErrorCountRetryPolicy( + ProductSearchLimitedErrorCountRetryPolicy const& rhs) noexcept + : ProductSearchLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProductSearchRetryPolicy; -using ProductSearchLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - vision_v1_internal::ProductSearchRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + vision_v1_internal::ProductSearchRetryTraits> + impl_; +}; + +/** + * A retry policy for `ProductSearchConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProductSearchLimitedTimeRetryPolicy : public ProductSearchRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ProductSearchLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ProductSearchLimitedTimeRetryPolicy( + ProductSearchLimitedTimeRetryPolicy&& rhs) noexcept + : ProductSearchLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ProductSearchLimitedTimeRetryPolicy( + ProductSearchLimitedTimeRetryPolicy const& rhs) noexcept + : ProductSearchLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using ProductSearchLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - vision_v1_internal::ProductSearchRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProductSearchRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + vision_v1_internal::ProductSearchRetryTraits> + impl_; +}; /** * The `ProductSearchConnection` object for `ProductSearchClient`. diff --git a/google/cloud/vmmigration/v1/vm_migration_connection.h b/google/cloud/vmmigration/v1/vm_migration_connection.h index 42696878fad40..8407a593760bf 100644 --- a/google/cloud/vmmigration/v1/vm_migration_connection.h +++ b/google/cloud/vmmigration/v1/vm_migration_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace vmmigration_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VmMigrationRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - vmmigration_v1_internal::VmMigrationRetryTraits>; +/// The retry policy for `VmMigrationConnection`. +class VmMigrationRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VmMigrationLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - vmmigration_v1_internal::VmMigrationRetryTraits>; +/** + * A retry policy for `VmMigrationConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VmMigrationLimitedErrorCountRetryPolicy : public VmMigrationRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VmMigrationLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VmMigrationLimitedErrorCountRetryPolicy( + VmMigrationLimitedErrorCountRetryPolicy&& rhs) noexcept + : VmMigrationLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VmMigrationLimitedErrorCountRetryPolicy( + VmMigrationLimitedErrorCountRetryPolicy const& rhs) noexcept + : VmMigrationLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VmMigrationRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + vmmigration_v1_internal::VmMigrationRetryTraits> + impl_; +}; -using VmMigrationLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - vmmigration_v1_internal::VmMigrationRetryTraits>; +/** + * A retry policy for `VmMigrationConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VmMigrationLimitedTimeRetryPolicy : public VmMigrationRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VmMigrationLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VmMigrationLimitedTimeRetryPolicy( + VmMigrationLimitedTimeRetryPolicy&& rhs) noexcept + : VmMigrationLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VmMigrationLimitedTimeRetryPolicy( + VmMigrationLimitedTimeRetryPolicy const& rhs) noexcept + : VmMigrationLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VmMigrationRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + vmmigration_v1_internal::VmMigrationRetryTraits> + impl_; +}; /** * The `VmMigrationConnection` object for `VmMigrationClient`. diff --git a/google/cloud/vmwareengine/v1/vmware_engine_connection.h b/google/cloud/vmwareengine/v1/vmware_engine_connection.h index 57e892a7a9971..c4c5da0a1e25a 100644 --- a/google/cloud/vmwareengine/v1/vmware_engine_connection.h +++ b/google/cloud/vmwareengine/v1/vmware_engine_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace vmwareengine_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VmwareEngineRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - vmwareengine_v1_internal::VmwareEngineRetryTraits>; +/// The retry policy for `VmwareEngineConnection`. +class VmwareEngineRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VmwareEngineLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - vmwareengine_v1_internal::VmwareEngineRetryTraits>; +/** + * A retry policy for `VmwareEngineConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VmwareEngineLimitedErrorCountRetryPolicy + : public VmwareEngineRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VmwareEngineLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VmwareEngineLimitedErrorCountRetryPolicy( + VmwareEngineLimitedErrorCountRetryPolicy&& rhs) noexcept + : VmwareEngineLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VmwareEngineLimitedErrorCountRetryPolicy( + VmwareEngineLimitedErrorCountRetryPolicy const& rhs) noexcept + : VmwareEngineLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VmwareEngineRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + vmwareengine_v1_internal::VmwareEngineRetryTraits> + impl_; +}; -using VmwareEngineLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - vmwareengine_v1_internal::VmwareEngineRetryTraits>; +/** + * A retry policy for `VmwareEngineConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class VmwareEngineLimitedTimeRetryPolicy : public VmwareEngineRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VmwareEngineLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VmwareEngineLimitedTimeRetryPolicy( + VmwareEngineLimitedTimeRetryPolicy&& rhs) noexcept + : VmwareEngineLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VmwareEngineLimitedTimeRetryPolicy( + VmwareEngineLimitedTimeRetryPolicy const& rhs) noexcept + : VmwareEngineLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VmwareEngineRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + vmwareengine_v1_internal::VmwareEngineRetryTraits> + impl_; +}; /** * The `VmwareEngineConnection` object for `VmwareEngineClient`. diff --git a/google/cloud/vpcaccess/v1/vpc_access_connection.h b/google/cloud/vpcaccess/v1/vpc_access_connection.h index 16edbfd6016b6..e95b2990f4cf1 100644 --- a/google/cloud/vpcaccess/v1/vpc_access_connection.h +++ b/google/cloud/vpcaccess/v1/vpc_access_connection.h @@ -38,17 +38,137 @@ namespace cloud { namespace vpcaccess_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using VpcAccessServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - vpcaccess_v1_internal::VpcAccessServiceRetryTraits>; +/// The retry policy for `VpcAccessServiceConnection`. +class VpcAccessServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using VpcAccessServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - vpcaccess_v1_internal::VpcAccessServiceRetryTraits>; +/** + * A retry policy for `VpcAccessServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class VpcAccessServiceLimitedErrorCountRetryPolicy + : public VpcAccessServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit VpcAccessServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + VpcAccessServiceLimitedErrorCountRetryPolicy( + VpcAccessServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : VpcAccessServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + VpcAccessServiceLimitedErrorCountRetryPolicy( + VpcAccessServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : VpcAccessServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = VpcAccessServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + vpcaccess_v1_internal::VpcAccessServiceRetryTraits> + impl_; +}; -using VpcAccessServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - vpcaccess_v1_internal::VpcAccessServiceRetryTraits>; +/** + * A retry policy for `VpcAccessServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + * - [`kUnknown`](@ref google::cloud::StatusCode) + */ +class VpcAccessServiceLimitedTimeRetryPolicy + : public VpcAccessServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit VpcAccessServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + VpcAccessServiceLimitedTimeRetryPolicy( + VpcAccessServiceLimitedTimeRetryPolicy&& rhs) noexcept + : VpcAccessServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + VpcAccessServiceLimitedTimeRetryPolicy( + VpcAccessServiceLimitedTimeRetryPolicy const& rhs) noexcept + : VpcAccessServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = VpcAccessServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + vpcaccess_v1_internal::VpcAccessServiceRetryTraits> + impl_; +}; /** * The `VpcAccessServiceConnection` object for `VpcAccessServiceClient`. diff --git a/google/cloud/webrisk/v1/web_risk_connection.h b/google/cloud/webrisk/v1/web_risk_connection.h index 659b2c23a06ba..43e694108b96c 100644 --- a/google/cloud/webrisk/v1/web_risk_connection.h +++ b/google/cloud/webrisk/v1/web_risk_connection.h @@ -37,17 +37,134 @@ namespace cloud { namespace webrisk_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using WebRiskServiceRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - webrisk_v1_internal::WebRiskServiceRetryTraits>; +/// The retry policy for `WebRiskServiceConnection`. +class WebRiskServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using WebRiskServiceLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - webrisk_v1_internal::WebRiskServiceRetryTraits>; +/** + * A retry policy for `WebRiskServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WebRiskServiceLimitedErrorCountRetryPolicy + : public WebRiskServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit WebRiskServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + WebRiskServiceLimitedErrorCountRetryPolicy( + WebRiskServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : WebRiskServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + WebRiskServiceLimitedErrorCountRetryPolicy( + WebRiskServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : WebRiskServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = WebRiskServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + webrisk_v1_internal::WebRiskServiceRetryTraits> + impl_; +}; -using WebRiskServiceLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - webrisk_v1_internal::WebRiskServiceRetryTraits>; +/** + * A retry policy for `WebRiskServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WebRiskServiceLimitedTimeRetryPolicy : public WebRiskServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit WebRiskServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + WebRiskServiceLimitedTimeRetryPolicy( + WebRiskServiceLimitedTimeRetryPolicy&& rhs) noexcept + : WebRiskServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + WebRiskServiceLimitedTimeRetryPolicy( + WebRiskServiceLimitedTimeRetryPolicy const& rhs) noexcept + : WebRiskServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = WebRiskServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + webrisk_v1_internal::WebRiskServiceRetryTraits> + impl_; +}; /** * The `WebRiskServiceConnection` object for `WebRiskServiceClient`. diff --git a/google/cloud/websecurityscanner/v1/web_security_scanner_connection.h b/google/cloud/websecurityscanner/v1/web_security_scanner_connection.h index 5721946c98eeb..0dbd6ae93ae6e 100644 --- a/google/cloud/websecurityscanner/v1/web_security_scanner_connection.h +++ b/google/cloud/websecurityscanner/v1/web_security_scanner_connection.h @@ -35,17 +35,137 @@ namespace cloud { namespace websecurityscanner_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using WebSecurityScannerRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - websecurityscanner_v1_internal::WebSecurityScannerRetryTraits>; +/// The retry policy for `WebSecurityScannerConnection`. +class WebSecurityScannerRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `WebSecurityScannerConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WebSecurityScannerLimitedErrorCountRetryPolicy + : public WebSecurityScannerRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit WebSecurityScannerLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + WebSecurityScannerLimitedErrorCountRetryPolicy( + WebSecurityScannerLimitedErrorCountRetryPolicy&& rhs) noexcept + : WebSecurityScannerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + WebSecurityScannerLimitedErrorCountRetryPolicy( + WebSecurityScannerLimitedErrorCountRetryPolicy const& rhs) noexcept + : WebSecurityScannerLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = WebSecurityScannerRetryPolicy; -using WebSecurityScannerLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - websecurityscanner_v1_internal::WebSecurityScannerRetryTraits>; + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + websecurityscanner_v1_internal::WebSecurityScannerRetryTraits> + impl_; +}; + +/** + * A retry policy for `WebSecurityScannerConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WebSecurityScannerLimitedTimeRetryPolicy + : public WebSecurityScannerRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit WebSecurityScannerLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + WebSecurityScannerLimitedTimeRetryPolicy( + WebSecurityScannerLimitedTimeRetryPolicy&& rhs) noexcept + : WebSecurityScannerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + WebSecurityScannerLimitedTimeRetryPolicy( + WebSecurityScannerLimitedTimeRetryPolicy const& rhs) noexcept + : WebSecurityScannerLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } -using WebSecurityScannerLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - websecurityscanner_v1_internal::WebSecurityScannerRetryTraits>; + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = WebSecurityScannerRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + websecurityscanner_v1_internal::WebSecurityScannerRetryTraits> + impl_; +}; /** * The `WebSecurityScannerConnection` object for `WebSecurityScannerClient`. diff --git a/google/cloud/workflows/executions/v1/executions_connection.h b/google/cloud/workflows/executions/v1/executions_connection.h index 7f45d1d44b3fa..634a37b6d14a8 100644 --- a/google/cloud/workflows/executions/v1/executions_connection.h +++ b/google/cloud/workflows/executions/v1/executions_connection.h @@ -35,16 +35,133 @@ namespace cloud { namespace workflows_executions_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ExecutionsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - workflows_executions_v1_internal::ExecutionsRetryTraits>; +/// The retry policy for `ExecutionsConnection`. +class ExecutionsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using ExecutionsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - workflows_executions_v1_internal::ExecutionsRetryTraits>; +/** + * A retry policy for `ExecutionsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ExecutionsLimitedErrorCountRetryPolicy : public ExecutionsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ExecutionsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ExecutionsLimitedErrorCountRetryPolicy( + ExecutionsLimitedErrorCountRetryPolicy&& rhs) noexcept + : ExecutionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ExecutionsLimitedErrorCountRetryPolicy( + ExecutionsLimitedErrorCountRetryPolicy const& rhs) noexcept + : ExecutionsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ExecutionsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + workflows_executions_v1_internal::ExecutionsRetryTraits> + impl_; +}; -using ExecutionsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - workflows_executions_v1_internal::ExecutionsRetryTraits>; +/** + * A retry policy for `ExecutionsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ExecutionsLimitedTimeRetryPolicy : public ExecutionsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ExecutionsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ExecutionsLimitedTimeRetryPolicy( + ExecutionsLimitedTimeRetryPolicy&& rhs) noexcept + : ExecutionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ExecutionsLimitedTimeRetryPolicy( + ExecutionsLimitedTimeRetryPolicy const& rhs) noexcept + : ExecutionsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ExecutionsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + workflows_executions_v1_internal::ExecutionsRetryTraits> + impl_; +}; /** * The `ExecutionsConnection` object for `ExecutionsClient`. diff --git a/google/cloud/workflows/v1/workflows_connection.h b/google/cloud/workflows/v1/workflows_connection.h index 97fee932475a3..7c91b2a66a348 100644 --- a/google/cloud/workflows/v1/workflows_connection.h +++ b/google/cloud/workflows/v1/workflows_connection.h @@ -38,16 +38,133 @@ namespace cloud { namespace workflows_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using WorkflowsRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< - workflows_v1_internal::WorkflowsRetryTraits>; +/// The retry policy for `WorkflowsConnection`. +class WorkflowsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using WorkflowsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - workflows_v1_internal::WorkflowsRetryTraits>; +/** + * A retry policy for `WorkflowsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WorkflowsLimitedErrorCountRetryPolicy : public WorkflowsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit WorkflowsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + WorkflowsLimitedErrorCountRetryPolicy( + WorkflowsLimitedErrorCountRetryPolicy&& rhs) noexcept + : WorkflowsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + WorkflowsLimitedErrorCountRetryPolicy( + WorkflowsLimitedErrorCountRetryPolicy const& rhs) noexcept + : WorkflowsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = WorkflowsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + workflows_v1_internal::WorkflowsRetryTraits> + impl_; +}; -using WorkflowsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - workflows_v1_internal::WorkflowsRetryTraits>; +/** + * A retry policy for `WorkflowsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WorkflowsLimitedTimeRetryPolicy : public WorkflowsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit WorkflowsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + WorkflowsLimitedTimeRetryPolicy( + WorkflowsLimitedTimeRetryPolicy&& rhs) noexcept + : WorkflowsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + WorkflowsLimitedTimeRetryPolicy( + WorkflowsLimitedTimeRetryPolicy const& rhs) noexcept + : WorkflowsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = WorkflowsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + workflows_v1_internal::WorkflowsRetryTraits> + impl_; +}; /** * The `WorkflowsConnection` object for `WorkflowsClient`. diff --git a/google/cloud/workstations/v1/workstations_connection.h b/google/cloud/workstations/v1/workstations_connection.h index c3201a9425963..b304506f4ae71 100644 --- a/google/cloud/workstations/v1/workstations_connection.h +++ b/google/cloud/workstations/v1/workstations_connection.h @@ -38,17 +38,134 @@ namespace cloud { namespace workstations_v1 { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using WorkstationsRetryPolicy = - ::google::cloud::internal::TraitBasedRetryPolicy< - workstations_v1_internal::WorkstationsRetryTraits>; +/// The retry policy for `WorkstationsConnection`. +class WorkstationsRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; -using WorkstationsLimitedTimeRetryPolicy = - ::google::cloud::internal::LimitedTimeRetryPolicy< - workstations_v1_internal::WorkstationsRetryTraits>; +/** + * A retry policy for `WorkstationsConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WorkstationsLimitedErrorCountRetryPolicy + : public WorkstationsRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit WorkstationsLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + WorkstationsLimitedErrorCountRetryPolicy( + WorkstationsLimitedErrorCountRetryPolicy&& rhs) noexcept + : WorkstationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + WorkstationsLimitedErrorCountRetryPolicy( + WorkstationsLimitedErrorCountRetryPolicy const& rhs) noexcept + : WorkstationsLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = WorkstationsRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + workstations_v1_internal::WorkstationsRetryTraits> + impl_; +}; -using WorkstationsLimitedErrorCountRetryPolicy = - ::google::cloud::internal::LimitedErrorCountRetryPolicy< - workstations_v1_internal::WorkstationsRetryTraits>; +/** + * A retry policy for `WorkstationsConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class WorkstationsLimitedTimeRetryPolicy : public WorkstationsRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit WorkstationsLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + WorkstationsLimitedTimeRetryPolicy( + WorkstationsLimitedTimeRetryPolicy&& rhs) noexcept + : WorkstationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + WorkstationsLimitedTimeRetryPolicy( + WorkstationsLimitedTimeRetryPolicy const& rhs) noexcept + : WorkstationsLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = WorkstationsRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + workstations_v1_internal::WorkstationsRetryTraits> + impl_; +}; /** * The `WorkstationsConnection` object for `WorkstationsClient`.