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) {
int hash;
if (message.getGroupid() != null && !message.getGroupid().isEmpty()) {
hash = message.getGroupid().hashCode();
} else if (message.getUserid() > 0) {
hash = message.getUserid();
} else {
int hash = message.hash();
if (hash == 0) {
hash = index.incrementAndGet();
if (index.get() > 1000 * producers.length) {
synchronized (index) {

View File

@@ -156,6 +156,16 @@ public class MessageRecord implements Serializable {
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) {
this.version = version;
return this;