-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
833ec12
commit 3a2d1c1
Showing
12 changed files
with
277 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/rs/iggy/clients/blocking/tcp/MessagesTcpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package rs.iggy.clients.blocking.tcp; | ||
|
||
import rs.iggy.clients.blocking.MessagesClient; | ||
import rs.iggy.consumergroup.Consumer; | ||
import rs.iggy.identifier.StreamId; | ||
import rs.iggy.identifier.TopicId; | ||
import rs.iggy.message.MessageToSend; | ||
import rs.iggy.message.Partitioning; | ||
import rs.iggy.message.PolledMessages; | ||
import rs.iggy.message.PollingStrategy; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import static rs.iggy.clients.blocking.tcp.BytesSerializer.toBytes; | ||
|
||
class MessagesTcpClient implements MessagesClient { | ||
|
||
private static final int POLL_MESSAGES_CODE = 100; | ||
private static final int SEND_MESSAGES_CODE = 101; | ||
|
||
private final TcpConnectionHandler connection; | ||
|
||
public MessagesTcpClient(TcpConnectionHandler connection) { | ||
this.connection = connection; | ||
} | ||
|
||
@Override | ||
public PolledMessages pollMessages(StreamId streamId, TopicId topicId, Optional<Long> partitionId, Consumer consumer, PollingStrategy strategy, Long count, boolean autoCommit) { | ||
var payload = toBytes(consumer); | ||
payload.writeBytes(toBytes(streamId)); | ||
payload.writeBytes(toBytes(topicId)); | ||
payload.writeIntLE(partitionId.orElse(0L).intValue()); | ||
payload.writeBytes(toBytes(strategy)); | ||
payload.writeIntLE(count.intValue()); | ||
payload.writeByte(autoCommit ? 1 : 0); | ||
|
||
var response = connection.send(POLL_MESSAGES_CODE, payload); | ||
|
||
return BytesDeserializer.readPolledMessages(response); | ||
} | ||
|
||
@Override | ||
public void sendMessages(StreamId streamId, TopicId topicId, Partitioning partitioning, List<MessageToSend> messages) { | ||
var payload = toBytes(streamId); | ||
payload.writeBytes(toBytes(topicId)); | ||
payload.writeBytes(toBytes(partitioning)); | ||
for (var message : messages) { | ||
payload.writeBytes(toBytes(message)); | ||
} | ||
|
||
connection.send(SEND_MESSAGES_CODE, payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
package rs.iggy.message; | ||
|
||
enum HeaderKind { | ||
Raw, | ||
String, | ||
Bool, | ||
Int8, | ||
Int16, | ||
Int32, | ||
Int64, | ||
Int128, | ||
Uint8, | ||
Uint16, | ||
Uint32, | ||
Uint64, | ||
Uint128, | ||
Float32, | ||
Float64, | ||
public enum HeaderKind { | ||
Raw(1), | ||
String(2), | ||
Bool(3), | ||
Int8(4), | ||
Int16(5), | ||
Int32(6), | ||
Int64(7), | ||
Int128(8), | ||
Uint8(9), | ||
Uint16(10), | ||
Uint32(11), | ||
Uint64(12), | ||
Uint128(13), | ||
Float32(14), | ||
Float64(15); | ||
|
||
private final int code; | ||
|
||
HeaderKind(int code) { | ||
this.code = code; | ||
} | ||
|
||
public static HeaderKind fromCode(int code) { | ||
for (HeaderKind kind : values()) { | ||
if (kind.code == code) { | ||
return kind; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown header kind: " + code); | ||
} | ||
|
||
public int asCode() { | ||
return code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
package rs.iggy.message; | ||
|
||
public enum MessageState { | ||
Available, | ||
Unavailable, | ||
Poisoned, | ||
MarkedForDeletion, | ||
Available(1), | ||
Unavailable(10), | ||
Poisoned(20), | ||
MarkedForDeletion(30); | ||
|
||
private final int code; | ||
|
||
MessageState(int code) { | ||
this.code = code; | ||
} | ||
|
||
public static MessageState fromCode(int code) { | ||
for (MessageState state : MessageState.values()) { | ||
if (state.code == code) { | ||
return state; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown message state code: " + code); | ||
} | ||
} |
Oops, something went wrong.