Class DefaultNetworkProtocol
- java.lang.Object
-
- io.github.dhruv1110.jcachex.distributed.DefaultNetworkProtocol
-
- All Implemented Interfaces:
NetworkProtocol
public class DefaultNetworkProtocol extends Object implements NetworkProtocol
Default implementation of NetworkProtocol.This is a basic implementation that can be extended for production use. In a real implementation, this would handle actual network communication.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.github.dhruv1110.jcachex.distributed.NetworkProtocol
NetworkProtocol.CacheOperation, NetworkProtocol.CompressionType, NetworkProtocol.GetOperation, NetworkProtocol.InvalidateOperation, NetworkProtocol.NetworkStats, NetworkProtocol.OperationHandler, NetworkProtocol.OperationResponse, NetworkProtocol.OperationType, NetworkProtocol.ProtocolBuilder, NetworkProtocol.ProtocolType, NetworkProtocol.PutOperation, NetworkProtocol.SerializationType
-
-
Constructor Summary
Constructors Constructor Description DefaultNetworkProtocol(NetworkProtocol.ProtocolBuilder config)
-
Method Summary
All Methods Instance Methods Concrete 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.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.
-
-
-
Constructor Detail
-
DefaultNetworkProtocol
public DefaultNetworkProtocol(NetworkProtocol.ProtocolBuilder config)
-
-
Method Detail
-
send
public CompletableFuture<NetworkProtocol.OperationResponse> send(String nodeId, NetworkProtocol.CacheOperation operation)
Description copied from interface:NetworkProtocol
Sends a cache operation to the specified node.- Specified by:
send
in interfaceNetworkProtocol
- Parameters:
nodeId
- the target node IDoperation
- the operation to send- Returns:
- CompletableFuture containing the response
-
broadcast
public CompletableFuture<Map<String,NetworkProtocol.OperationResponse>> broadcast(Collection<String> nodeIds, NetworkProtocol.CacheOperation operation)
Description copied from interface:NetworkProtocol
Broadcasts a cache operation to multiple nodes.- Specified by:
broadcast
in interfaceNetworkProtocol
- Parameters:
nodeIds
- the target node IDsoperation
- the operation to broadcast- Returns:
- CompletableFuture containing responses from all nodes
-
registerHandler
public void registerHandler(NetworkProtocol.OperationHandler handler)
Description copied from interface:NetworkProtocol
Registers a handler for incoming cache operations.- Specified by:
registerHandler
in interfaceNetworkProtocol
- Parameters:
handler
- the operation handler
-
start
public CompletableFuture<Void> start()
Description copied from interface:NetworkProtocol
Starts the network protocol.- Specified by:
start
in interfaceNetworkProtocol
- Returns:
- CompletableFuture that completes when the protocol is started
-
stop
public CompletableFuture<Void> stop()
Description copied from interface:NetworkProtocol
Stops the network protocol.- Specified by:
stop
in interfaceNetworkProtocol
- Returns:
- CompletableFuture that completes when the protocol is stopped
-
getNetworkStats
public NetworkProtocol.NetworkStats getNetworkStats()
Description copied from interface:NetworkProtocol
Returns network statistics.- Specified by:
getNetworkStats
in interfaceNetworkProtocol
- Returns:
- network protocol statistics
-
-