public abstract class SFSExtension extends BaseSFSExtension
Developers can create each request/event handlers as separate classes and then register them in the SFSExtension which will take care of the invocation details.
SFSExtension also provides a servlet-like Filter system. Extension Filters are added to a filter chain and executed in the order of insertion. They can be used to log, filter, or handle specific requests or events before they get to the Extension itself. The advantage of pluggable Filters is that they don't get in the way of your Extension code, their execution order can be altered and they can be used to stop the execution flow, if necessary.
An example of this could be a custom ban filter where User credentials are checked against a black list before the request is passed to your Login Handler. Another example of usage would be logging or filtering public and private messages.
For a more detailed overview of Extensions please check this doc-page
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MULTIHANDLER_REQUEST_ID |
lagOscillation, lagSimulationMillis, logger, sfsApi
Constructor and Description |
---|
SFSExtension() |
Modifier and Type | Method and Description |
---|---|
protected void |
addEventHandler(SFSEventType eventType,
java.lang.Class<?> theClass)
Add a request handler for a specific event type.
|
protected void |
addEventHandler(SFSEventType eventType,
IServerEventHandler handler) |
void |
addFilter(java.lang.String filterName,
SFSExtensionFilter filter)
Add a filter to the Extension
|
protected void |
addRequestHandler(java.lang.String requestId,
java.lang.Class<?> theClass)
Add a request handler for a specific request id.
|
protected void |
addRequestHandler(java.lang.String requestId,
IClientRequestHandler requestHandler) |
protected void |
clearAllHandlers()
Removes all event and request handlers
|
void |
clearFilters()
Removes all filters from the Extension
|
void |
destroy()
This method is called once by the Server when the Extension must be shut down (e.g. before a server restart
or before the Extension code is reloaded)
Here you can put all the necessary code to release any resources that was acquired/started in the init() method.
|
void |
handleClientRequest(java.lang.String requestId,
User sender,
ISFSObject params)
This method is called whenever a client sends a request to this Extension
|
void |
handleServerEvent(ISFSEvent event)
Handle server event
|
protected void |
removeEventHandler(SFSEventType eventType)
Remove an event handler
|
void |
removeFilter(java.lang.String filterName)
Removes a filter from the Extension
|
protected void |
removeRequestHandler(java.lang.String requestId)
Remove a request handler
|
addEventListener, getApi, getBuddyApi, getConfigProperties, getCurrentFolder, getExtensionFileName, getGameApi, getLevel, getLogger, getMMOApi, getName, getParentRoom, getParentZone, getPropertiesFileName, getReloadMode, getType, handleInternalMessage, isActive, removeEventListener, removeEventsForListener, send, send, send, send, setActive, setExtensionFileName, setLevel, setName, setParentRoom, setParentZone, setPropertiesFileName, setReloadMode, setType, toString, trace, trace
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
init
public static final java.lang.String MULTIHANDLER_REQUEST_ID
public void destroy()
ISFSExtension
Here you can put all the necessary code to release any resources that was acquired/started in the init() method. (e.g. event listeners, threads, scheduled tasks, files etc...)
protected void addRequestHandler(java.lang.String requestId, java.lang.Class<?> theClass)
Examples:
addRequestHandler("myapp.chessGame", ChessGameHandler.class);If the ChessGameHandler is annotated with as
MultiHandler
it will receive all commands starting with myapp.ChessGame
or in other words myapp.ChessGame.*
NOTE: multiple handlers for the same request is not supported.
requestId
- the requestId, optionally using dot-syntaxtheClass
- the handler Class ( must implement IClientRequestHandler
)protected void addRequestHandler(java.lang.String requestId, IClientRequestHandler requestHandler)
protected void addEventHandler(SFSEventType eventType, java.lang.Class<?> theClass)
NOTE:Each event can have only one handler.
eventType
- the type of eventtheClass
- the handler Class ( must implement IServerEventHandler
)addRequestHandler(String, Class)
protected void addEventHandler(SFSEventType eventType, IServerEventHandler handler)
protected void removeRequestHandler(java.lang.String requestId)
requestId
- name of the requestprotected void removeEventHandler(SFSEventType eventType)
eventType
- the type of eventprotected void clearAllHandlers()
public void handleClientRequest(java.lang.String requestId, User sender, ISFSObject params)
requestId
- the request command namesender
- the sender of the requestparams
- the custom parameters of the requestpublic void handleServerEvent(ISFSEvent event) throws java.lang.Exception
handleServerEvent
in interface ISFSEventListener
handleServerEvent
in class BaseSFSExtension
event
- the Eventjava.lang.Exception
SFSEvent
public final void addFilter(java.lang.String filterName, SFSExtensionFilter filter)
filterName
- name of the filterfilter
- the filterpublic void removeFilter(java.lang.String filterName)
filterName
- name of the filterpublic void clearFilters()