Package org.drasyl.remote.handler
Class RateLimiter
- java.lang.Object
-
- org.drasyl.pipeline.skeleton.HandlerAdapter
-
- org.drasyl.pipeline.skeleton.AddressHandlerAdapter<A>
-
- org.drasyl.pipeline.skeleton.SimpleInboundEventAwareHandler<I,Event,A>
-
- org.drasyl.pipeline.skeleton.SimpleInboundHandler<I,A>
-
- org.drasyl.pipeline.handler.filter.InboundMessageFilter<RemoteEnvelope<? extends com.google.protobuf.MessageLite>,Address>
-
- org.drasyl.remote.handler.RateLimiter
-
- All Implemented Interfaces:
Handler
public class RateLimiter extends InboundMessageFilter<RemoteEnvelope<? extends com.google.protobuf.MessageLite>,Address>
This handler rate limitsProtocol.Acknowledgement
,Protocol.Discovery
, andProtocol.Unite
messages addressed to us. 1 message per type per sender per 100ms is allowed. Messages exceeding the rate limit are dropped.
-
-
Constructor Summary
Constructors Constructor Description RateLimiter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
accept(HandlerContext ctx, Address sender, RemoteEnvelope<? extends com.google.protobuf.MessageLite> msg)
This method is called for every inbound message.protected void
messageRejected(HandlerContext ctx, Address sender, RemoteEnvelope<? extends com.google.protobuf.MessageLite> msg, CompletableFuture<Void> future)
This method is called ifmsg
gets rejected byInboundMessageFilter.accept(HandlerContext, Address, Object)
.-
Methods inherited from class org.drasyl.pipeline.handler.filter.InboundMessageFilter
matchedInbound
-
Methods inherited from class org.drasyl.pipeline.skeleton.SimpleInboundHandler
matchedEvent, onEvent
-
Methods inherited from class org.drasyl.pipeline.skeleton.SimpleInboundEventAwareHandler
acceptEvent, acceptInbound, onInbound
-
Methods inherited from class org.drasyl.pipeline.skeleton.AddressHandlerAdapter
acceptAddress
-
Methods inherited from class org.drasyl.pipeline.skeleton.HandlerAdapter
onAdded, onException, onOutbound, onRemoved
-
-
-
-
Method Detail
-
accept
protected boolean accept(HandlerContext ctx, Address sender, RemoteEnvelope<? extends com.google.protobuf.MessageLite> msg) throws Exception
Description copied from class:InboundMessageFilter
This method is called for every inbound message.- Specified by:
accept
in classInboundMessageFilter<RemoteEnvelope<? extends com.google.protobuf.MessageLite>,Address>
- Returns:
true
if message should be passed through.false
is message should be dropped.- Throws:
Exception
-
messageRejected
protected void messageRejected(HandlerContext ctx, Address sender, RemoteEnvelope<? extends com.google.protobuf.MessageLite> msg, CompletableFuture<Void> future) throws Exception
Description copied from class:InboundMessageFilter
This method is called ifmsg
gets rejected byInboundMessageFilter.accept(HandlerContext, Address, Object)
. You should override it if you would like to handle (e.g. respond to) rejected messages.- Overrides:
messageRejected
in classInboundMessageFilter<RemoteEnvelope<? extends com.google.protobuf.MessageLite>,Address>
- Throws:
Exception
-
-