Interface NetworkProtocol
-
- All Known Implementing Classes:
DefaultNetworkProtocol
public interface NetworkProtocol
Network protocol abstraction for distributed cache communication.This interface provides a pluggable network layer that supports different protocols (TCP, UDP, HTTP) and serialization formats (Java, JSON, Protocol Buffers). The protocol handles node-to-node communication for cache operations, cluster management, and failure detection.
Key Features:
- Protocol Agnostic: Supports TCP, UDP, HTTP, WebSocket
- Pluggable Serialization: Java, JSON, Avro, Protocol Buffers
- Compression Support: GZIP, LZ4, Snappy compression
- Security: TLS encryption and authentication
- Flow Control: Backpressure and rate limiting
Usage Examples:
// TCP with Java serialization NetworkProtocol protocol = NetworkProtocol.tcp() .serialization(SerializationType.JAVA) .compression(CompressionType.GZIP) .encryption(true) .port(8080) .build(); // Send cache operation CacheOperation operation = new PutOperation("key1", "value1"); protocol.send("node-2", operation).thenAccept(response -> { System.out.println("Operation completed: " + response); }); // HTTP with JSON for cross-platform compatibility NetworkProtocol httpProtocol = NetworkProtocol.http() .serialization(SerializationType.JSON) .port(8080) .build();
- Since:
- 1.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
NetworkProtocol.CacheOperation
Base class for cache operations.static class
NetworkProtocol.CompressionType
Compression algorithms supported.static class
NetworkProtocol.GetOperation
Get operation for distributed cache.static class
NetworkProtocol.InvalidateOperation
Invalidate operation for distributed cache.static class
NetworkProtocol.NetworkStats
Network protocol statistics.static interface
NetworkProtocol.OperationHandler
Handler for incoming cache operations.static class
NetworkProtocol.OperationResponse
Response to a cache operation.static class
NetworkProtocol.OperationType
Types of cache operations.static class
NetworkProtocol.ProtocolBuilder
Builder for network protocols.static class
NetworkProtocol.ProtocolType
Protocol types supported.static class
NetworkProtocol.PutOperation
Put operation for distributed cache.static class
NetworkProtocol.SerializationType
Serialization formats supported.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description CompletableFuture<Map<String,NetworkProtocol.OperationResponse>>
broadcast(Collection<String> nodeIds, NetworkProtocol.CacheOperation operation)
Broadcasts a cache operation to multiple nodes.NetworkProtocol.NetworkStats
getNetworkStats()
Returns network statistics.static NetworkProtocol.ProtocolBuilder
http()
Creates an HTTP protocol builder.void
registerHandler(NetworkProtocol.OperationHandler handler)
Registers a handler for incoming cache operations.CompletableFuture<NetworkProtocol.OperationResponse>
send(String nodeId, NetworkProtocol.CacheOperation operation)
Sends a cache operation to the specified node.CompletableFuture<Void>
start()
Starts the network protocol.CompletableFuture<Void>
stop()
Stops the network protocol.static NetworkProtocol.ProtocolBuilder
tcp()
Creates a TCP protocol builder.static NetworkProtocol.ProtocolBuilder
udp()
Creates a UDP protocol builder.static NetworkProtocol.ProtocolBuilder
websocket()
Creates a WebSocket protocol builder.
-
-
-
Method Detail
-
send
CompletableFuture<NetworkProtocol.OperationResponse> send(String nodeId, NetworkProtocol.CacheOperation operation)
Sends a cache operation to the specified node.- Parameters:
nodeId
- the target node IDoperation
- the operation to send- Returns:
- CompletableFuture containing the response
-
broadcast
CompletableFuture<Map<String,NetworkProtocol.OperationResponse>> broadcast(Collection<String> nodeIds, NetworkProtocol.CacheOperation operation)
Broadcasts a cache operation to multiple nodes.- Parameters:
nodeIds
- the target node IDsoperation
- the operation to broadcast- Returns:
- CompletableFuture containing responses from all nodes
-
registerHandler
void registerHandler(NetworkProtocol.OperationHandler handler)
Registers a handler for incoming cache operations.- Parameters:
handler
- the operation handler
-
start
CompletableFuture<Void> start()
Starts the network protocol.- Returns:
- CompletableFuture that completes when the protocol is started
-
stop
CompletableFuture<Void> stop()
Stops the network protocol.- Returns:
- CompletableFuture that completes when the protocol is stopped
-
getNetworkStats
NetworkProtocol.NetworkStats getNetworkStats()
Returns network statistics.- Returns:
- network protocol statistics
-
tcp
static NetworkProtocol.ProtocolBuilder tcp()
Creates a TCP protocol builder.- Returns:
- TCP protocol builder
-
udp
static NetworkProtocol.ProtocolBuilder udp()
Creates a UDP protocol builder.- Returns:
- UDP protocol builder
-
http
static NetworkProtocol.ProtocolBuilder http()
Creates an HTTP protocol builder.- Returns:
- HTTP protocol builder
-
websocket
static NetworkProtocol.ProtocolBuilder websocket()
Creates a WebSocket protocol builder.- Returns:
- WebSocket protocol builder
-
-