001package io.freefair.spring.okhttp.metrics; 002 003import io.micrometer.core.instrument.binder.okhttp3.OkHttpMetricsEventListener; 004import okhttp3.Request; 005import org.springframework.boot.context.properties.ConfigurationProperties; 006import java.util.ArrayList; 007import java.util.HashMap; 008import java.util.List; 009import java.util.Map; 010 011/** 012 * @author Lars Grefer 013 * @see OkHttpMetricsEventListener 014 * @see OkHttpMetricsAutoConfiguration 015 */ 016@ConfigurationProperties("okhttp.metrics") 017public class OkHttpMetricsProperties { 018 private boolean enabled = true; 019 /** 020 * Name for the metrics. 021 */ 022 private String name = "okhttp"; 023 /** 024 * Whether to include the {@code host} tag. 025 * 026 * @see OkHttpMetricsEventListener.Builder#includeHostTag(boolean) 027 */ 028 private boolean includeHostTag = true; 029 /** 030 * Tag keys for {@link Request#tag()} or {@link Request#tag(Class)}. 031 * 032 * @see OkHttpMetricsEventListener.Builder#requestTagKeys(Iterable) 033 */ 034 private List<String> requestTagKeys = new ArrayList<>(); 035 /** 036 * @see OkHttpMetricsEventListener.Builder#tags(Iterable) 037 */ 038 private Map<String, String> tags = new HashMap<>(); 039 040 public OkHttpMetricsProperties() { 041 } 042 043 public boolean isEnabled() { 044 return this.enabled; 045 } 046 047 /** 048 * Name for the metrics. 049 */ 050 public String getName() { 051 return this.name; 052 } 053 054 /** 055 * Whether to include the {@code host} tag. 056 * 057 * @see OkHttpMetricsEventListener.Builder#includeHostTag(boolean) 058 */ 059 public boolean isIncludeHostTag() { 060 return this.includeHostTag; 061 } 062 063 /** 064 * Tag keys for {@link Request#tag()} or {@link Request#tag(Class)}. 065 * 066 * @see OkHttpMetricsEventListener.Builder#requestTagKeys(Iterable) 067 */ 068 public List<String> getRequestTagKeys() { 069 return this.requestTagKeys; 070 } 071 072 /** 073 * @see OkHttpMetricsEventListener.Builder#tags(Iterable) 074 */ 075 public Map<String, String> getTags() { 076 return this.tags; 077 } 078 079 public void setEnabled(final boolean enabled) { 080 this.enabled = enabled; 081 } 082 083 /** 084 * Name for the metrics. 085 */ 086 public void setName(final String name) { 087 this.name = name; 088 } 089 090 /** 091 * Whether to include the {@code host} tag. 092 * 093 * @see OkHttpMetricsEventListener.Builder#includeHostTag(boolean) 094 */ 095 public void setIncludeHostTag(final boolean includeHostTag) { 096 this.includeHostTag = includeHostTag; 097 } 098 099 /** 100 * Tag keys for {@link Request#tag()} or {@link Request#tag(Class)}. 101 * 102 * @see OkHttpMetricsEventListener.Builder#requestTagKeys(Iterable) 103 */ 104 public void setRequestTagKeys(final List<String> requestTagKeys) { 105 this.requestTagKeys = requestTagKeys; 106 } 107 108 /** 109 * @see OkHttpMetricsEventListener.Builder#tags(Iterable) 110 */ 111 public void setTags(final Map<String, String> tags) { 112 this.tags = tags; 113 } 114 115 @Override 116 public boolean equals(final Object o) { 117 if (o == this) return true; 118 if (!(o instanceof OkHttpMetricsProperties)) return false; 119 final OkHttpMetricsProperties other = (OkHttpMetricsProperties) o; 120 if (!other.canEqual((Object) this)) return false; 121 if (this.isEnabled() != other.isEnabled()) return false; 122 if (this.isIncludeHostTag() != other.isIncludeHostTag()) return false; 123 final Object this$name = this.getName(); 124 final Object other$name = other.getName(); 125 if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; 126 final Object this$requestTagKeys = this.getRequestTagKeys(); 127 final Object other$requestTagKeys = other.getRequestTagKeys(); 128 if (this$requestTagKeys == null ? other$requestTagKeys != null : !this$requestTagKeys.equals(other$requestTagKeys)) return false; 129 final Object this$tags = this.getTags(); 130 final Object other$tags = other.getTags(); 131 if (this$tags == null ? other$tags != null : !this$tags.equals(other$tags)) return false; 132 return true; 133 } 134 135 protected boolean canEqual(final Object other) { 136 return other instanceof OkHttpMetricsProperties; 137 } 138 139 @Override 140 public int hashCode() { 141 final int PRIME = 59; 142 int result = 1; 143 result = result * PRIME + (this.isEnabled() ? 79 : 97); 144 result = result * PRIME + (this.isIncludeHostTag() ? 79 : 97); 145 final Object $name = this.getName(); 146 result = result * PRIME + ($name == null ? 43 : $name.hashCode()); 147 final Object $requestTagKeys = this.getRequestTagKeys(); 148 result = result * PRIME + ($requestTagKeys == null ? 43 : $requestTagKeys.hashCode()); 149 final Object $tags = this.getTags(); 150 result = result * PRIME + ($tags == null ? 43 : $tags.hashCode()); 151 return result; 152 } 153 154 @Override 155 public String toString() { 156 return "OkHttpMetricsProperties(enabled=" + this.isEnabled() + ", name=" + this.getName() + ", includeHostTag=" + this.isIncludeHostTag() + ", requestTagKeys=" + this.getRequestTagKeys() + ", tags=" + this.getTags() + ")"; 157 } 158}