From ab841adc06acd2a6ff161ea866579674ce5ff99e Mon Sep 17 00:00:00 2001 From: guest Date: Wed, 24 Sep 2008 20:38:37 +0000 Subject: added YalpServer InputPluginHandling (incomplete) git-svn-id: http://manut.eu/svn/yalp/trunk@5 f059d3a0-6783-47b7-97ff-1fe0bbf25129 --- idlj.sh | 4 +- log4j_input_plugin.conf | 8 ++++ .../YalpPGSqlInput/YalpInputPluginImpl.java | 14 ++++++- src/YalpServer/InitServer.java | 18 ++++---- src/YalpServer/InputPlugin.java | 29 +++++++++++++ src/YalpServer/InputPluginHandler.java | 48 ++++++++++++++++++++++ src/YalpServer/OutputPlugin.java | 30 ++++++++++++++ src/YalpServer/ServerControlImpl.java | 39 +++++++++++++----- 8 files changed, 169 insertions(+), 21 deletions(-) create mode 100644 log4j_input_plugin.conf create mode 100644 src/YalpServer/InputPlugin.java create mode 100644 src/YalpServer/InputPluginHandler.java create mode 100644 src/YalpServer/OutputPlugin.java diff --git a/idlj.sh b/idlj.sh index f85e7b2..4344b70 100755 --- a/idlj.sh +++ b/idlj.sh @@ -1,3 +1,3 @@ #!/bin/bash -#/opt/sun-jdk-1.6.0.07/bin/idlj -fall $@ -/opt/ibm-java-i386-60/bin/idlj -fall $@ +/opt/sun-jdk-1.6.0.07/bin/idlj -fall $@ +#/opt/ibm-java-i386-60/bin/idlj -fall $@ diff --git a/log4j_input_plugin.conf b/log4j_input_plugin.conf new file mode 100644 index 0000000..79c355b --- /dev/null +++ b/log4j_input_plugin.conf @@ -0,0 +1,8 @@ +log4j.rootLogger=debug, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n + diff --git a/src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java b/src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java index 7f599be..4d0a602 100644 --- a/src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java +++ b/src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java @@ -10,6 +10,9 @@ import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + import YalpInterfaces.*; public class YalpInputPluginImpl extends InputPluginInterfacePOA { @@ -19,12 +22,20 @@ public class YalpInputPluginImpl extends InputPluginInterfacePOA { private String dbpasswd; private Statement stat; private Connection con; + private PluginInfo pluginInfo; + + private String log4jFile = "log4j_input_plugin.conf"; + + private static Logger logger = + Logger.getLogger("Yalp.InputPlugins.PGSqlInput.YalpInputPluginImpl"); + private ORB orb; public YalpInputPluginImpl() { - System.out.println("YalpInputPluginImpl()"); + PropertyConfigurator.configureAndWatch(log4jFile); + logger.debug("YalpInputPluginImpl()"); } public void setORB(ORB _orb) @@ -98,6 +109,7 @@ public class YalpInputPluginImpl extends InputPluginInterfacePOA { * List with Results matching search criteria */ public void search(String str, MediaType[] types, MediasHolder result, YalpErrorHolder err) { + System.out.println("juhu: searching for: "+str); /* t.b.d. alter this to new database design try{ ArrayList searchWords=stringCut(media.str); diff --git a/src/YalpServer/InitServer.java b/src/YalpServer/InitServer.java index a5f7c99..3e77ea5 100755 --- a/src/YalpServer/InitServer.java +++ b/src/YalpServer/InitServer.java @@ -52,12 +52,15 @@ import YalpInterfaces.*; public class InitServer { - private ServerSettings settings = new ServerSettings(); + private static ServerSettings settings = new ServerSettings(); + public static InputPluginHandler inputHandler = new InputPluginHandler(); + private ServerControlImpl srvCon; private ServerControlInterface srv; private ORB orb; private String[] orbArgs; private POA poa; + private String serverIP; /* @@ -94,12 +97,13 @@ public class InitServer { System.out.println("poa inactive"); } - this.srvCon = new ServerControlImpl(); - this.srvCon.setORB(this.orb); + srvCon = new ServerControlImpl(); + srvCon.setORB(orb); + srvCon.init(this); try { - org.omg.CORBA.Object ref = poa.servant_to_reference(this.srvCon); - this.srv = ServerControlInterfaceHelper.narrow(ref); + org.omg.CORBA.Object ref = poa.servant_to_reference(srvCon); + srv = ServerControlInterfaceHelper.narrow(ref); org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); @@ -107,10 +111,10 @@ public class InitServer { NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); String name = "YALP_Server"; NameComponent path[] = ncRef.to_name(name); - ncRef.rebind(path, this.srv); + ncRef.rebind(path, srv); System.out.println("YALP Server ready"); - this.orb.run(); + orb.run(); } catch( org.omg.CosNaming.NamingContextPackage.InvalidName e) { /* t.b.d. error handling */ diff --git a/src/YalpServer/InputPlugin.java b/src/YalpServer/InputPlugin.java new file mode 100644 index 0000000..97c0d76 --- /dev/null +++ b/src/YalpServer/InputPlugin.java @@ -0,0 +1,29 @@ +package YalpServer; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import YalpInterfaces.*; + +public class InputPlugin { + + private String log4jFile = "log4j_server.conf"; + + public InputPluginInterface itf; + public PluginInfo info; + + private static Logger logger = + Logger.getLogger("Yalp.Server.InputPlugin"); + + public InputPlugin() { + PropertyConfigurator.configureAndWatch(log4jFile); + logger.debug("InputPlugin()"); + } + + public InputPlugin(InputPluginInterface _itf, PluginInfo _info) { + PropertyConfigurator.configureAndWatch(log4jFile); + logger.debug("InputPlugin("+_info.name+")"); + info = _info; + itf = _itf; + } +} diff --git a/src/YalpServer/InputPluginHandler.java b/src/YalpServer/InputPluginHandler.java new file mode 100644 index 0000000..746204a --- /dev/null +++ b/src/YalpServer/InputPluginHandler.java @@ -0,0 +1,48 @@ +package YalpServer; + +import java.util.ArrayList; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import YalpInterfaces.*; + +public class InputPluginHandler { + + private ArrayList 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(); + } + + 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); + } + + } +} diff --git a/src/YalpServer/OutputPlugin.java b/src/YalpServer/OutputPlugin.java new file mode 100644 index 0000000..605aa5f --- /dev/null +++ b/src/YalpServer/OutputPlugin.java @@ -0,0 +1,30 @@ +package YalpServer; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import YalpInterfaces.*; + +public class OutputPlugin { + + private String log4jFile = "log4j_server.conf"; + + public OutputPluginInterface itf; + public PluginInfo info; + + private static Logger logger = + Logger.getLogger("Yalp.Server.OutputPlugin"); + + public OutputPlugin() { + PropertyConfigurator.configureAndWatch(log4jFile); + logger.debug("OutputPlugin()"); + } + + public OutputPlugin(OutputPluginInterface _itf, PluginInfo _info) { + PropertyConfigurator.configureAndWatch(log4jFile); + logger.debug("OutputPlugin("+_info.name+")"); + info = _info; + itf = _itf; + } + +} diff --git a/src/YalpServer/ServerControlImpl.java b/src/YalpServer/ServerControlImpl.java index 0f33ff6..3947cdd 100755 --- a/src/YalpServer/ServerControlImpl.java +++ b/src/YalpServer/ServerControlImpl.java @@ -38,9 +38,14 @@ import org.apache.log4j.PropertyConfigurator; public class ServerControlImpl extends ServerControlInterfacePOA { private ORB orb; + private InitServer srv; + private InputPluginHandler inputHandler; + private String log4jFile = "log4j_server.conf"; - private static Logger logger = Logger.getLogger("Yalp.Server"); + + private static Logger logger = + Logger.getLogger("Yalp.Server.ServerControlImpl"); public ServerControlImpl() { PropertyConfigurator.configureAndWatch(log4jFile); @@ -52,9 +57,10 @@ public ServerControlImpl() { orb = _orb; } - public void init(InitServer srv) { + public void init(InitServer _srv) { logger.debug("init()"); - this.srv=srv; + srv = _srv; + inputHandler = srv.inputHandler; } /* @@ -194,8 +200,7 @@ public ServerControlImpl() { YalpErrorHolder err ) { logger.debug("search()"); YalpError error = new YalpError(); - error.code = YalpErrorCode.OK; - err = new YalpErrorHolder(error); + inputHandler.search(str, types, result, err); } /* @@ -268,12 +273,23 @@ public ServerControlImpl() { public void registerInputPlugin( org.omg.CORBA.Object itf, PluginInfoHolder info, YalpErrorHolder err ) { - logger.debug("registerInputPlugins()"); - /* t.b.d. itf handling */ - System.out.println("registering input plugin: " + info.value.name ); + logger.info("registering input plugin: " + info.value.name ); + InputPluginInterface inputItf; + try { + inputItf = InputPluginInterfaceHelper.narrow(itf); + } catch( Exception e ) { + e.printStackTrace(); + return; + } + logger.debug("create new InputPlugin"); + InputPlugin newPlugin = new InputPlugin(inputItf, info.value); + logger.debug("add new InputPlugin to Handler"); + if( newPlugin != null ) + inputHandler.addPlugin( newPlugin ); + logger.debug("error handling"); YalpError error = new YalpError(); - error.msg = "huhu"; - error.descr = "hihi"; + error.msg = "plugin registered"; + error.descr = ""; error.code = YalpErrorCode.OK; error.level = YalpErrorLevel.ERROR_LEVEL_INFO; err.value = error; @@ -286,7 +302,8 @@ public ServerControlImpl() { inf.access = info.value.access; inf.maxClients = info.value.maxClients; inf.actClients = info.value.actClients; - info.value = inf; } + info.value = inf; + } /* * remove input plugin -- cgit v1.2.3