ЛР 3: масштабирование и отказоустойчивость API
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.example.mtusi_messenger.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record Chat(UUID id, String title, List<UUID> memberIds, Instant createdAt) {
|
||||
public Chat {
|
||||
memberIds = List.copyOf(memberIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.example.mtusi_messenger.model;
|
||||
|
||||
public record IdempotentMessage(byte[] requestHash, Message message) {}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.example.mtusi_messenger.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public record Message(UUID id, UUID chatId, UUID senderId, String text, Instant createdAt) {}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.example.mtusi_messenger.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public record MessageKey(Instant createdAt, UUID id)
|
||||
implements Comparable<MessageKey> {
|
||||
|
||||
private static int compareUuidV7(UUID a, UUID b) {
|
||||
int result = Long.compareUnsigned(
|
||||
a.getMostSignificantBits(),
|
||||
b.getMostSignificantBits()
|
||||
);
|
||||
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return Long.compareUnsigned(
|
||||
a.getLeastSignificantBits(),
|
||||
b.getLeastSignificantBits()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MessageKey other) {
|
||||
int result = createdAt.compareTo(other.createdAt);
|
||||
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return compareUuidV7(id, other.id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.mtusi_messenger.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public record Session(UUID id, UUID userId, byte[] tokenHash, Instant createdAt, Instant expiresAt) {
|
||||
public Session {
|
||||
tokenHash = tokenHash.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] tokenHash() {
|
||||
return tokenHash.clone();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.example.mtusi_messenger.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public record User(UUID id, String username, String displayName, Instant createdAt) {}
|
||||
Reference in New Issue
Block a user