Class BaseClientRequestHandler

java.lang.Object
com.smartfoxserver.extensions.BaseClientRequestHandler
All Implemented Interfaces:
IClientRequestHandler
Direct Known Subclasses:
SignUpAssistantComponent

public abstract class BaseClientRequestHandler extends Object implements IClientRequestHandler
Using SFSExtension as the base class for an Extension we can register separate request handlers for every supported client request.

This is typically done in the Extension's init() method:


 class RunHandler extends BaseClientRequestHandler
 {
 	void handleClientRequest(User sender, ISFSObject params, TransportType txType)
 	{
 		trace("Inside Run handler");
 	}
 }
 
 private RunHandler runHandler;
 
 @Override
 public void init()
 {
 	runHandler = new RunHandler();
 
 	// Using a class instance
 	addRequestHandler("Run", runHandler);	
 
 	// Using a method reference
 	addRequestHandler("Walk", this::walkHandler);
 
 	// Using a lambda
 	addRequestHandler("Fly", (User sender, ISFSObject params, TransportType txType) -> {
 		trace("Inside Fly handler");
 	});
 }
 
 private void walkHandler(User sender, ISFSObject params, TransportType txType)
 {
 	trace("Inside Walk handler");
 }
 
The example demonstrates three different ways to provide a handler for a specific Extension command:
  • A class extending BaseClientRequestHandler
  • A local method reference
  • A lambda
  • Constructor Details

    • BaseClientRequestHandler

      public BaseClientRequestHandler()
  • Method Details

    • getParentExtension

      public SFSExtension getParentExtension()
      Obtain a reference to the parent extension.
      Specified by:
      getParentExtension in interface IClientRequestHandler
      Returns:
      a reference to the parent extension
    • setParentExtension

      public void setParentExtension(SFSExtension ext)
      Specified by:
      setParentExtension in interface IClientRequestHandler
    • getApi

      protected ISFSApi getApi()
      Get a reference to the main server side API
      Returns:
      the server side API object
    • getBuddyApi

      protected ISFSBuddyApi getBuddyApi()
      Get a reference to the server side Buddy List API
      Returns:
      the server side API object
    • getGameApi

      protected ISFSGameApi getGameApi()
      Get a reference to the server side Game API
      Returns:
      the server side API object
    • getMMOApi

      protected ISFSMMOApi getMMOApi()
      Get a reference to the server side MMO API
      Returns:
      the server side API object
    • send

      protected void send(String cmdName, ISFSObject params, User recipient)
      Send a response back to a User
      Parameters:
      cmdName - name of the "command" (or action id)
      params - the parameters
      recipient - the recipient User
    • send

      protected void send(String cmdName, ISFSObject params, List<User> recipients)
      Broadcast a response back to multiple Users
      Parameters:
      cmdName - name of the "command" (or action id)
      params - the parameters
      recipients - a list of recipients
    • send

      protected void send(String cmdName, ISFSObject params, User recipient, TransportType txType)
      Send a response back to a User
      Parameters:
      cmdName - name of the "command" (or action id)
      params - the parameters
      recipient - the recipient User
      txType - the transport type (Tcp, Udp etc...)
    • send

      protected void send(String cmdName, ISFSObject params, List<User> recipients, TransportType txType)
      Broadcast a response back to multiple Users
      Parameters:
      cmdName - name of the "command" (or action id)
      params - the parameters
      recipients - a list of recipients
      txType - the transport type (Tcp, Udp etc...)
    • trace

      protected void trace(Object... args)
      Traces a message to the console and log files using the Logger INFO level
      Parameters:
      args - any number of strings/object to trace
    • trace

      protected void trace(ExtensionLogLevel level, Object... args)
      Trace a message to the console and log files using the specified logging level
      Parameters:
      level - the logging level
      args - any number of object to trace
    • getLogger

      protected org.slf4j.Logger getLogger()
      Obtain a direct reference to the Extension's logger
      Returns:
      the logger object.