How to add a Module programmatically when an Application starts

We have been looking at how add a module automatically when an application starts for some time and we found a hint when we generated an error and it showed the following

	at com.wowza.wms.util.ModuleUtils.addModuleToApp(Unknown Source)
	at com.wowza.wms.util.ApplicationUtils.loadModules(Unknown Source)
	at com.wowza.wms.util.ApplicationUtils.loadConfigFile(Unknown Source)

We then very simply implemented ApplicationInstanceStart as part of IApplicationInstanceNotify. After a couple of hours of testing various options we found the following worked and a module is added and works as expected. The below assumes an application called live and an instance called _definst_

IApplicationInstanceNotify Class

package guru.thewowza.example.ApplicationModulesUpdate;

import com.wowza.wms.application.IApplicationInstance;
import com.wowza.wms.application.IApplicationInstanceNotify;
import com.wowza.wms.module.ModuleItem;
import com.wowza.wms.module.ModuleList;
import com.wowza.wms.util.ModuleUtils;

public class ApplicationInstanceStart implements IApplicationInstanceNotify {

	public void onApplicationInstanceCreate(IApplicationInstance applicationInstance) {
		if ( applicationInstance.getApplication().getName().equalsIgnoreCase("live") ) { 
			if ( applicationInstance.getName().equals("_definst_") ) {
				ModuleItem TestModule = new ModuleItem("basic","basic");
			    Object instance = null;
			    try	{
			    	instance = ModuleUtils.addModuleToApp(applicationInstance, "basic", "guru.thewowza.example.Application.Basic");
			    	} catch (Exception moduleCreF) { instance = null; }
			    if ( instance != null ) {
			    	ModuleList AppInsModList = applicationInstance.getModuleList();
			    	AppInsModList.put("basic", TestModule); }
	public void onApplicationInstanceDestroy(IApplicationInstance applicationInstance) { }

In order to use the IApplicationInstanceNotify you do need to set up listeners for application and if you download the complete zip file the full code is provided.

To use the example code you will need to add a ServerListener into your Server.xml as follows


and also copy the two jar files into the lib/ folder of your Wowza installation.

The module base class you are adding is ‘guru.thewowza.example.Application.Basic’ and as long as the class can be found then it will be added as expected. The jar file is provided in the download which has this module already compiled.

Download the moduleĀ here.

Comments are closed.