1 /* 2 * hunt-amqp: AMQP library for D programming language, based on hunt-net. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 module hunt.amqp.streams.ProtonPublisherOptions; 12 13 14 /** 15 * Options for configuring Publisher attributes. 16 */ 17 class ProtonPublisherOptions { 18 private string linkName; 19 private bool durable; 20 private bool _shared; 21 private bool global; 22 private bool dynamic; 23 private int maxOutstandingCredit; 24 25 this() { 26 } 27 28 /** 29 * Sets the link name to be used for the subscription. 30 * 31 * @param linkName the name to use 32 * @return the options 33 */ 34 public ProtonPublisherOptions setLinkName(string linkName) { 35 this.linkName = linkName; 36 return this; 37 } 38 39 public string getLinkName() { 40 return linkName; 41 } 42 43 /** 44 * Sets whether the link to be used for the subscription should 45 * have 'source' terminus details indicating it is durable, that 46 * is a terminus-expiry-policy of "never" and terminus-durability 47 * of 2/unsettled-state, and that the link should detach rather than 48 * close when cancel is called on the subscription. 49 * 50 * @param durable true if the subscription should be considered durable 51 * @return the options 52 */ 53 public ProtonPublisherOptions setDurable(bool durable) { 54 this.durable = durable; 55 return this; 56 } 57 58 public bool isDurable() { 59 return durable; 60 } 61 62 /** 63 * Sets whether the link to be used for the subscription should 64 * have 'source' terminus capability indicating it is 'shared'. 65 * 66 * @param shared true if the subscription should be considered shared 67 * @return the options 68 */ 69 public ProtonPublisherOptions setShared(bool sd) { 70 this._shared = sd; 71 return this; 72 } 73 74 public bool isShared() { 75 return _shared; 76 } 77 78 /** 79 * Sets whether the link to be used for a shared subscription should 80 * also have 'source' terminus capability indicating it is 'global', 81 * that is its subscription can be shared across connections 82 * regardless of their container-id values. 83 * 84 * @param global true if the subscription should be considered global 85 * @return the options 86 */ 87 public ProtonPublisherOptions setGlobal(bool global) { 88 this.global = global; 89 return this; 90 } 91 92 public bool isGlobal() { 93 return global; 94 } 95 96 /** 97 * Sets whether the link to be used for the subscription should indicate 98 * a 'dynamic' source terminus, requesting the server peer names it with 99 * a dynamic address. The remote address can then be inspected using 100 * {@link ProtonPublisher#getRemoteAddress()} (or inspecting the remote 101 * source details directly) when the onSubscribe() handler is fired. 102 * 103 * @param dynamic true if the link should request a dynamic source address 104 * @return the options 105 */ 106 public ProtonPublisherOptions setDynamic(bool dynamic) { 107 this.dynamic = dynamic; 108 return this; 109 } 110 111 public bool isDynamic() { 112 return dynamic; 113 } 114 115 /** 116 * Sets the maximum credit the consumer link will leave outstanding at a time. 117 * If the total unfilled subscription requests remains below this level, the 118 * consumer credit issued will match the unfilled requests. If the requests 119 * exceeds this value, the consumer link will cap it and refresh it once the 120 * level drops below a threshold or more requests are made. If not set a 121 * reasonable default is used. 122 * 123 * @param maxOutstandingCredit the limit on outstanding consumer credit 124 * @return the options 125 */ 126 public ProtonPublisherOptions setMaxOutstandingCredit(int maxOutstandingCredit) { 127 this.maxOutstandingCredit = maxOutstandingCredit; 128 129 return this; 130 } 131 132 public int getMaxOutstandingCredit() { 133 return maxOutstandingCredit; 134 } 135 136 137 override size_t toHash() @trusted nothrow 138 { 139 int prime = 31; 140 141 int result = 1; 142 result = prime * result + cast(int)linkName.hashOf; 143 result = prime * result + (durable ? 1231 : 1237); 144 result = prime * result + (_shared ? 1231 : 1237); 145 result = prime * result + (global ? 1231 : 1237); 146 result = prime * result + (dynamic ? 1231 : 1237); 147 result = prime * result + maxOutstandingCredit; 148 149 return cast(size_t)result; 150 } 151 152 override 153 public bool opEquals(Object obj) { 154 if (this is obj) { 155 return true; 156 } 157 158 if (obj is null){ 159 return false; 160 } 161 162 ProtonPublisherOptions other = cast(ProtonPublisherOptions) obj; 163 if ((linkName != other.linkName)){ 164 return false; 165 } 166 167 if (durable != other.durable){ 168 return false; 169 } 170 171 if (_shared != other._shared){ 172 return false; 173 } 174 175 if (global != other.global){ 176 return false; 177 } 178 179 if (dynamic != other.dynamic){ 180 return false; 181 } 182 183 if (maxOutstandingCredit != other.maxOutstandingCredit){ 184 return false; 185 } 186 187 return true; 188 } 189 }