SFSExtension class and Example Programs (com.smartfoxserver.v2.extensions.SFSExtension)


SFSExtension

com.smartfoxserver.v2.extensions package holds this abstract class, if any class extend this class they can be treated as ExtensionPrograms.

SFSExtension contains the key methods init(), destroy(), addRequestHandler(), addEventHandler() etc.

SFSExtension

Sno Method Syntax
1 init() public void init();
2 addRequestHandler() protected void addRequestHandler(String requestid,Class<?> handlerClass);
3 addEventHandler() protected void addEventHandler(SFSEventType eventype,Class<?> handlerClass);
4 destroy public void destroy();
5 send() will sends the command/event (very useful method)

Sample Code Snippet to Illustrate above methods

package com.tutorialtous.smartfoxserver;

import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class MySFSExtension extends SFSExtension {

	public void init() {
		trace("MySFSExtension Init method fired");
		initEventHandlers();
		initClientRequestHandlers();
	}

	private void initClientRequestHandlers() {
		addRequestHandler("echochips", MyCustomRequestHandler.class);
	}

	private void initEventHandlers() {
		addEventHandler(SFSEventType.USER_LOGIN, MyEventHandler.class);
	}
	
	@Override
	public void destroy() {
		trace("MySFSExtension destroy fired while Smartfox is going down");
	}

}

Note

trace() method is similar to System.out.println() it will echos the msg to console as well as log file.