Bill commented on a change in pull request #6684:
URL: https://github.com/apache/geode/pull/6684#discussion_r675219366
##########
File path:
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProxyMembershipID.java
##########
@@ -176,149 +177,114 @@ public static ClientProxyMembershipID
getClientId(DistributedMember member) {
return new ClientProxyMembershipID(member);
}
- public static byte[] initializeAndGetDSIdentity(DistributedSystem sys) {
- byte[] client_side_identity = null;
+ public static byte[] initializeAndGetDSIdentity(final DistributedSystem sys)
{
+ final byte[] client_side_identity;
if (sys == null) {
- // DistributedSystem is required now before handshaking -Kirk
+ // DistributedSystem is required now before handshaking
throw new IllegalStateException(
"Attempting to handshake with CacheServer before creating
DistributedSystem and Cache.");
}
- {
- systemMemberId = sys.getDistributedMember();
- try (HeapDataOutputStream hdos = new HeapDataOutputStream(256,
KnownVersion.CURRENT)) {
- if (systemMemberId != null) {
- // update the durable id of the member identifier before serializing
in case
- // a pool name has been established
- DurableClientAttributes attributes =
systemMemberId.getDurableClientAttributes();
- if (attributes != null && attributes.getId().length() > 0) {
- ((InternalDistributedMember)
systemMemberId).setDurableId(attributes.getId());
- }
+ systemMemberId = sys.getDistributedMember();
+ try (HeapDataOutputStream hdos = new HeapDataOutputStream(256,
KnownVersion.CURRENT)) {
+ if (systemMemberId != null) {
+ // update the durable id of the member identifier before serializing
in case
+ // a pool name has been established
+ DurableClientAttributes attributes =
systemMemberId.getDurableClientAttributes();
+ if (attributes != null && attributes.getId().length() > 0) {
+ ((InternalDistributedMember)
systemMemberId).setDurableId(attributes.getId());
}
- DataSerializer.writeObject(systemMemberId, hdos);
- client_side_identity = hdos.toByteArray();
- } catch (IOException ioe) {
- throw new InternalGemFireException(
- "Unable to serialize identity",
- ioe);
}
-
- system = sys;
+ DataSerializer.writeObject(systemMemberId, hdos);
+ client_side_identity = hdos.toByteArray();
+ } catch (IOException ioe) {
+ throw new InternalGemFireException("Unable to serialize identity", ioe);
}
+ system = sys;
return client_side_identity;
-
}
private ClientProxyMembershipID(int id, byte[] clientSideIdentity) {
- boolean specialCase = Boolean.getBoolean(GeodeGlossary.GEMFIRE_PREFIX +
"SPECIAL_DURABLE");
- String durableID =
this.system.getProperties().getProperty(DURABLE_CLIENT_ID);
+ this(clientSideIdentity, getUniqueId(id), systemMemberId);
+ }
+
+ private static int getUniqueId(final int id) {
+ final boolean specialCase =
+ Boolean.getBoolean(GeodeGlossary.GEMFIRE_PREFIX + "SPECIAL_DURABLE");
+ final String durableID =
system.getProperties().getProperty(DURABLE_CLIENT_ID);
if (specialCase && durableID != null && (!durableID.equals(""))) {
- this.uniqueId = durable_synch_counter;
+ return durable_synch_counter;
} else {
- this.uniqueId = id;
+ return id;
}
- this.identity = clientSideIdentity;
- this.memberId = systemMemberId;
}
public ClientProxyMembershipID() {}
- public ClientProxyMembershipID(DistributedMember member) {
- this.uniqueId = 1;
- this.memberId = member;
+ public ClientProxyMembershipID(final DistributedMember member) {
+ this(null, 1, member);
updateID(member);
}
+ @VisibleForTesting
+ ClientProxyMembershipID(final byte[] identity, final int uniqueId,
+ final DistributedMember memberId) {
+ this.identity = identity;
+ this.uniqueId = uniqueId;
+ this.memberId = memberId;
+ }
private transient String _toString;
- // private transient int transientPort; // variable for debugging member ID
issues
-
@Override
public String toString() {
- if (this.identity != null
+ if (identity != null
&& ((InternalDistributedMember)
getDistributedMember()).getMembershipPort() == 0) {
- return this.toStringNoCache();
+ return toStringNoCache();
}
- if (this._toString == null) {
- this._toString = this.toStringNoCache();
+ if (_toString == null) {
+ _toString = toStringNoCache();
}
- return this._toString;
+ return _toString;
}
/**
* returns a string representation of this identifier, ignoring the toString
cache
*/
public String toStringNoCache() {
- StringBuffer sb = new
StringBuffer("identity(").append(getDSMembership()).append(",connection=")
- .append(uniqueId);
+ StringBuilder sb =
+ new
StringBuilder("identity(").append(getDSMembership()).append(",connection=")
+ .append(uniqueId);
if (identity != null) {
DurableClientAttributes dca = getDurableAttributes();
if (dca.getId().length() > 0) {
- sb.append(",durableAttributes=").append(dca).append(')').toString();
+ sb.append(",durableAttributes=").append(dca).append(')');
}
}
return sb.toString();
}
- /**
- * For Externalizable
- *
- * @see Externalizable
- */
@Override
public void writeExternal(ObjectOutput out) throws IOException {
- // if (this.transientPort == 0) {
- // InternalDistributedSystem.getLogger().warning(
- // String.format("%s",
- // "externalizing a client ID with zero port: " + this.toString(),
- // new Exception("Stack trace")));
- // }
- Assert.assertTrue(this.identity.length <= BYTES_32KB);
- out.writeShort(this.identity.length);
- out.write(this.identity);
- out.writeInt(this.uniqueId);
-
- }
+ if (identity.length > Short.MAX_VALUE) {
+ throw new IOException("HandShake identity length is too big");
+ }
- /** returns the externalized size of this object */
- public int getSerializedSize() {
- return 4 + identity.length + 4;
+ out.writeShort(identity.length);
+ out.write(identity);
+ out.writeInt(uniqueId);
}
- /**
- * For Externalizable
- *
- * @see Externalizable
- */
@Override
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
int identityLength = in.readShort();
- if (identityLength > BYTES_32KB) {
- throw new IOException(
- "HandShake identity length is too big");
Review comment:
yep!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]