public class CorfuMsgHandler extends Object
AbstractServer
implementations.
Servers define methods with signatures which follow the signature of the Handler
functional interface, and generate a handler using the
this#generateHandler(MethodHandles.Lookup, AbstractServer)
method.
For maximum performance, make the handlers static whenever possible. Handlers should be as short as possible (not block), since handler threads come from a shared pool used by all servers. Blocking operations should be offloaded to I/O threads.
Created by mwei on 7/26/16.
Constructor and Description |
---|
CorfuMsgHandler()
Construct a new instance of CorfuMsgHandler.
|
Modifier and Type | Method and Description |
---|---|
<T extends CorfuMsg> |
addHandler(CorfuMsgType messageType,
org.corfudb.infrastructure.CorfuMsgHandler.Handler<T> handler)
Add a handler to this message handler.
|
static CorfuMsgHandler |
generateHandler(MethodHandles.Lookup caller,
AbstractServer server)
Generate handlers for a particular server.
|
Set<CorfuMsgType> |
getHandledTypes()
Get the types this handler will handle.
|
org.corfudb.infrastructure.CorfuMsgHandler.Handler<CorfuMsg> |
getHandler(CorfuMsgType type)
Get a handler for a specific message type.
|
boolean |
handle(CorfuMsg message,
io.netty.channel.ChannelHandlerContext ctx,
IServerRouter r)
Handle an incoming CorfuMsg.
|
public CorfuMsgHandler()
public Set<CorfuMsgType> getHandledTypes()
public org.corfudb.infrastructure.CorfuMsgHandler.Handler<CorfuMsg> getHandler(CorfuMsgType type)
type
- The type to retrieve a handler for.public <T extends CorfuMsg> CorfuMsgHandler addHandler(CorfuMsgType messageType, org.corfudb.infrastructure.CorfuMsgHandler.Handler<T> handler)
T
- A CorfuMsg type.messageType
- The type of CorfuMsg this handler will handle.handler
- The handler itself.public boolean handle(CorfuMsg message, io.netty.channel.ChannelHandlerContext ctx, IServerRouter r)
message
- The message to handle.ctx
- The channel handler context.r
- The server router.public static CorfuMsgHandler generateHandler(@Nonnull MethodHandles.Lookup caller, @Nonnull AbstractServer server)
caller
- The context that is being used. Call MethodHandles.lookup() to obtain.server
- The object that implements the server.Copyright © 2019 CorfuDB. All rights reserved.