summaryrefslogtreecommitdiff
path: root/src/YalpServer/InputPluginHandler.java
blob: 746204ae3ba875a5fa795dbfa163677cd2c53a79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package YalpServer;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import YalpInterfaces.*;

public class InputPluginHandler {

	private ArrayList<InputPlugin> plugins;
	private static int inputIds = 0;

	private String log4jFile = "log4j_server.conf";

	private static Logger logger =
		Logger.getLogger("Yalp.Server.InputPluginHandler");

	public InputPluginHandler() {
		PropertyConfigurator.configureAndWatch(log4jFile);
		logger.debug("InputPluginHandler()");
		plugins = new ArrayList<InputPlugin>();
	}

	public PluginInfo addPlugin(InputPlugin plugin)
	{
		logger.debug("addPlugin("+plugin.info.name+")");
		plugin.info.id = inputIds++;
		plugins.add(plugin);
		return plugin.info;
	}

	/*
	 * @todo maybe each request in own thread
	 *	timeouts, maximum number of results ...
	 */

	public void search( String str, MediaType[] types, MediasHolder result,
											YalpErrorHolder err ) {
		logger.debug("search("+str+")");
		for( InputPlugin plugin : plugins ) {
			logger.debug("search for: \""+str+"\" @ plugin: "+plugin.info.name);
			plugin.itf.search(str, types, result, err);
		}

	}
}