Skip to content

Commit c08065d

Browse files
committed
IGNITE-27824 Reduce duplication in message topic handling
1 parent 0a15b6f commit c08065d

20 files changed

Lines changed: 357 additions & 423 deletions

File tree

modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedCls
336336
withNoSchema(CacheVersionedValue.class);
337337
withNoSchema(GridCacheVersion.class);
338338
withNoSchema(GridCacheVersionEx.class);
339+
withSchema(GridTopicMessage.class);
339340

340341
// [5700 - 5900]: Discovery originated messages.
341342
msgIdx = 5700;
@@ -572,7 +573,7 @@ public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedCls
572573
withNoSchema(NodeIdMessage.class);
573574
withNoSchema(HandshakeMessage.class);
574575
withNoSchema(HandshakeWaitMessage.class);
575-
withSchema(GridIoMessage.class);
576+
withNoSchema(GridIoMessage.class);
576577
withNoSchema(IgniteIoTestMessage.class);
577578
withSchema(GridIoUserMessage.class);
578579
withSchema(GridIoSecurityAwareMessage.class);

modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java

Lines changed: 10 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.ObjectOutput;
2424
import java.io.Serializable;
2525
import java.nio.charset.Charset;
26+
import java.nio.charset.StandardCharsets;
2627
import java.util.UUID;
2728
import org.apache.ignite.internal.util.distributed.DistributedProcess;
2829
import org.apache.ignite.internal.util.typedef.internal.S;
@@ -161,7 +162,7 @@ public enum GridTopic {
161162
private static final GridTopic[] VALS = values();
162163

163164
/** Default charset to work with strings. */
164-
private static final Charset DFLT_CHARSET = Charset.forName("UTF-8");
165+
private static final Charset DFLT_CHARSET = StandardCharsets.UTF_8;
165166

166167
/**
167168
* Efficiently gets enumerated value from its ordinal.
@@ -219,16 +220,6 @@ public Object topic(String id1, long id2) {
219220
return new T6(this, UUID.nameUUIDFromBytes(id1.getBytes(DFLT_CHARSET)), id2);
220221
}
221222

222-
/**
223-
* @param id1 ID1.
224-
* @param id2 ID2.
225-
* @param id3 ID3.
226-
* @return Grid message topic with specified IDs.
227-
*/
228-
public Object topic(String id1, int id2, long id3) {
229-
return new T5(this, UUID.nameUUIDFromBytes(id1.getBytes(DFLT_CHARSET)), id2, id3);
230-
}
231-
232223
/**
233224
* @param id1 ID1.
234225
* @param id2 ID2.
@@ -239,17 +230,6 @@ public Object topic(String id1, UUID id2, long id3) {
239230
return new T4(this, UUID.nameUUIDFromBytes(id1.getBytes(DFLT_CHARSET)), id2, id3);
240231
}
241232

242-
/**
243-
* @param id1 ID1.
244-
* @param id2 ID2.
245-
* @param id3 ID3.
246-
* @param id4 ID4.
247-
* @return Grid message topic with specified IDs.
248-
*/
249-
public Object topic(String id1, UUID id2, int id3, long id4) {
250-
return new T7(this, UUID.nameUUIDFromBytes(id1.getBytes(DFLT_CHARSET)), id2, id3, id4);
251-
}
252-
253233
/** */
254234
public static class T1 implements Externalizable {
255235
/** */
@@ -379,7 +359,7 @@ private T2(GridTopic topic, IgniteUuid id1, UUID id2) {
379359
}
380360

381361
/** {@inheritDoc} */
382-
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
362+
@Override public void readExternal(ObjectInput in) throws IOException {
383363
topic = fromOrdinal(in.readByte());
384364
id1 = U.readIgniteUuid(in);
385365
id2 = U.readUuid(in);
@@ -443,7 +423,7 @@ private T3(GridTopic topic, UUID id1) {
443423
}
444424

445425
/** {@inheritDoc} */
446-
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
426+
@Override public void readExternal(ObjectInput in) throws IOException {
447427
topic = fromOrdinal(in.readByte());
448428
id1 = U.readUuid(in);
449429
}
@@ -495,7 +475,7 @@ private T4(GridTopic topic, UUID id1, UUID id2, long id3) {
495475

496476
/** {@inheritDoc} */
497477
@Override public int hashCode() {
498-
return topic.ordinal() + id1.hashCode() + id2.hashCode() + (int)(id3 ^ (id3 >>> 32));
478+
return topic.ordinal() + id1.hashCode() + id2.hashCode() + Long.hashCode(id3);
499479
}
500480

501481
/** {@inheritDoc} */
@@ -518,7 +498,7 @@ private T4(GridTopic topic, UUID id1, UUID id2, long id3) {
518498
}
519499

520500
/** {@inheritDoc} */
521-
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
501+
@Override public void readExternal(ObjectInput in) throws IOException {
522502
topic = fromOrdinal(in.readByte());
523503
id1 = U.readUuid(in);
524504
id2 = U.readUuid(in);
@@ -531,83 +511,6 @@ private T4(GridTopic topic, UUID id1, UUID id2, long id3) {
531511
}
532512
}
533513

534-
/**
535-
*
536-
*/
537-
private static class T5 implements Externalizable {
538-
/** */
539-
private static final long serialVersionUID = 0L;
540-
541-
/** */
542-
private GridTopic topic;
543-
544-
/** */
545-
private UUID id1;
546-
547-
/** */
548-
private int id2;
549-
550-
/** */
551-
private long id3;
552-
553-
/**
554-
* No-arg constructor needed for {@link Serializable}.
555-
*/
556-
public T5() {
557-
// No-op.
558-
}
559-
560-
/**
561-
* @param topic Topic.
562-
* @param id1 ID1.
563-
* @param id2 ID2.
564-
* @param id3 ID3.
565-
*/
566-
private T5(GridTopic topic, UUID id1, int id2, long id3) {
567-
this.topic = topic;
568-
this.id1 = id1;
569-
this.id2 = id2;
570-
this.id3 = id3;
571-
}
572-
573-
/** {@inheritDoc} */
574-
@Override public int hashCode() {
575-
return topic.ordinal() + id1.hashCode() + id2 + (int)(id3 ^ (id3 >>> 32));
576-
}
577-
578-
/** {@inheritDoc} */
579-
@Override public boolean equals(Object obj) {
580-
if (obj.getClass() == T5.class) {
581-
T5 that = (T5)obj;
582-
583-
return topic == that.topic && id1.equals(that.id1) && id2 == that.id2 && id3 == that.id3;
584-
}
585-
586-
return false;
587-
}
588-
589-
/** {@inheritDoc} */
590-
@Override public void writeExternal(ObjectOutput out) throws IOException {
591-
out.writeByte(topic.ordinal());
592-
U.writeUuid(out, id1);
593-
out.writeInt(id2);
594-
out.writeLong(id3);
595-
}
596-
597-
/** {@inheritDoc} */
598-
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
599-
topic = fromOrdinal(in.readByte());
600-
id1 = U.readUuid(in);
601-
id2 = in.readInt();
602-
id3 = in.readLong();
603-
}
604-
605-
/** {@inheritDoc} */
606-
@Override public String toString() {
607-
return S.toString(T5.class, this);
608-
}
609-
}
610-
611514
/**
612515
*
613516
*/
@@ -644,7 +547,7 @@ private T6(GridTopic topic, UUID id1, long id2) {
644547

645548
/** {@inheritDoc} */
646549
@Override public int hashCode() {
647-
return topic.ordinal() + id1.hashCode() + (int)(id2 ^ (id2 >>> 32));
550+
return topic.ordinal() + id1.hashCode() + Long.hashCode(id2);
648551
}
649552

650553
/** {@inheritDoc} */
@@ -666,7 +569,7 @@ private T6(GridTopic topic, UUID id1, long id2) {
666569
}
667570

668571
/** {@inheritDoc} */
669-
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
572+
@Override public void readExternal(ObjectInput in) throws IOException {
670573
topic = fromOrdinal(in.readByte());
671574
id1 = U.readUuid(in);
672575
id2 = in.readLong();
@@ -678,91 +581,6 @@ private T6(GridTopic topic, UUID id1, long id2) {
678581
}
679582
}
680583

681-
/**
682-
*
683-
*/
684-
private static class T7 implements Externalizable {
685-
/** */
686-
private static final long serialVersionUID = 0L;
687-
688-
/** */
689-
private GridTopic topic;
690-
691-
/** */
692-
private UUID id1;
693-
694-
/** */
695-
private UUID id2;
696-
697-
/** */
698-
private int id3;
699-
700-
/** */
701-
private long id4;
702-
703-
/**
704-
* No-arg constructor needed for {@link Serializable}.
705-
*/
706-
public T7() {
707-
// No-op.
708-
}
709-
710-
/**
711-
* @param topic Topic.
712-
* @param id1 ID1.
713-
* @param id2 ID2.
714-
* @param id3 ID3.
715-
* @param id4 ID4.
716-
*/
717-
private T7(GridTopic topic, UUID id1, UUID id2, int id3, long id4) {
718-
this.topic = topic;
719-
this.id1 = id1;
720-
this.id2 = id2;
721-
this.id3 = id3;
722-
this.id4 = id4;
723-
}
724-
725-
/** {@inheritDoc} */
726-
@Override public int hashCode() {
727-
return topic.ordinal() + id1.hashCode() + id2.hashCode() + id3 + (int)(id4 ^ (id4 >>> 32));
728-
}
729-
730-
/** {@inheritDoc} */
731-
@Override public boolean equals(Object obj) {
732-
if (obj.getClass() == T7.class) {
733-
T7 that = (T7)obj;
734-
735-
return topic == that.topic && id1.equals(that.id1) && id2.equals(that.id2) && id3 == that.id3 &&
736-
id4 == that.id4;
737-
}
738-
739-
return false;
740-
}
741-
742-
/** {@inheritDoc} */
743-
@Override public void writeExternal(ObjectOutput out) throws IOException {
744-
out.writeByte(topic.ordinal());
745-
U.writeUuid(out, id1);
746-
U.writeUuid(out, id2);
747-
out.writeInt(id3);
748-
out.writeLong(id4);
749-
}
750-
751-
/** {@inheritDoc} */
752-
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
753-
topic = fromOrdinal(in.readByte());
754-
id1 = U.readUuid(in);
755-
id2 = U.readUuid(in);
756-
id3 = in.readInt();
757-
id4 = in.readLong();
758-
}
759-
760-
/** {@inheritDoc} */
761-
@Override public String toString() {
762-
return S.toString(T7.class, this);
763-
}
764-
}
765-
766584
/**
767585
*
768586
*/
@@ -799,7 +617,7 @@ private T8(GridTopic topic, IgniteUuid id1, long id2) {
799617

800618
/** {@inheritDoc} */
801619
@Override public int hashCode() {
802-
return topic.ordinal() + id1.hashCode() + (int)(id2 ^ (id2 >>> 32));
620+
return topic.ordinal() + id1.hashCode() + Long.hashCode(id2);
803621
}
804622

805623
/** {@inheritDoc} */
@@ -821,7 +639,7 @@ private T8(GridTopic topic, IgniteUuid id1, long id2) {
821639
}
822640

823641
/** {@inheritDoc} */
824-
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
642+
@Override public void readExternal(ObjectInput in) throws IOException {
825643
topic = fromOrdinal(in.readByte());
826644
id1 = U.readIgniteUuid(in);
827645
id2 = in.readLong();

0 commit comments

Comments
 (0)