This commit is contained in:
Redkale
2020-07-31 10:22:19 +08:00
parent de19861974
commit 29a21d060b
2 changed files with 12 additions and 6 deletions

View File

@@ -28,12 +28,8 @@ public class MessageProducers {
} }
public MessageProducer getProducer(MessageRecord message) { public MessageProducer getProducer(MessageRecord message) {
int hash; int hash = message.hash();
if (message.getGroupid() != null && !message.getGroupid().isEmpty()) { if (hash == 0) {
hash = message.getGroupid().hashCode();
} else if (message.getUserid() > 0) {
hash = message.getUserid();
} else {
hash = index.incrementAndGet(); hash = index.incrementAndGet();
if (index.get() > 1000 * producers.length) { if (index.get() > 1000 * producers.length) {
synchronized (index) { synchronized (index) {

View File

@@ -156,6 +156,16 @@ public class MessageRecord implements Serializable {
return this; return this;
} }
public int hash() {
if (groupid != null && !groupid.isEmpty()) {
return groupid.hashCode();
} else if (userid > 0) {
return userid;
} else {
return 0;
}
}
public MessageRecord version(int version) { public MessageRecord version(int version) {
this.version = version; this.version = version;
return this; return this;