Hi Peter,

I had to do something similar. I was thinking about adding a static variable to 
the instance that I wanted to use. Something like the one below:

MyRpcServer(int port,Communicator comm) throws Exception {
         super(port);
 
         this.comm = comm;
 
         XmlRpcServer xmlRpcServer = this.getXmlRpcServer();
 
         PropertyHandlerMapping phm = new PropertyHandlerMapping();
         phm.addHandler("Foo",Foo.class);

         // ---- Code Added
         Foo.commInstance = this.comm;
         //-----------------------

Now when the upcall is made the the server to the method, it could access the 
commInstance. 

Thanks,
Arvind 

--- On Wed, 21/5/08, Petr Šimek <[EMAIL PROTECTED]> wrote:

> From: Petr Šimek <[EMAIL PROTECTED]>
> Subject: Passing values from WebServer to handler
> To: xmlrpc-dev@ws.apache.org
> Date: Wednesday, 21 May, 2008, 5:05 PM
> Hello,
> I need solution for this:
> My application when started have its own thread and in
> another thread I want
> to start XML-RPC WebServer class. Both classes got instance
> of Communicator
> class that is handling communication between these two
> classes via
> synchronized methods.
> 
> Something like this:
> 
> public class MyApp extends Thread {
> 
>     public static void main(String[] args) throws Exception
> {
> 
>        Communicator comm = new Communicator();
>        MyApp app = new MyApp(comm);
>        app.start();
>         MyRpcServer server = new MyRpcServer(8080,comm);
>         server.start();
>     }
> }
> 
> And MyRpcServer class:
> 
> import org.apache.xmlrpc.server.*;
> import org.apache.xmlrpc.webserver.*;
> 
> public class MyRpcServer extends WebServer {
> 
>     private Communicator comm;
> 
>     MyRpcServer(int port,Communicator comm) throws
> Exception {
>         super(port);
> 
>         this.comm = comm;
> 
>         XmlRpcServer xmlRpcServer = this.getXmlRpcServer();
> 
>         PropertyHandlerMapping phm = new
> PropertyHandlerMapping();
>         phm.addHandler("Foo",Foo.class);
> 
>         xmlRpcServer.setHandlerMapping(phm);
> 
>         XmlRpcServerConfigImpl serverConfig =
> (XmlRpcServerConfigImpl)
> xmlRpcServer
>                 .getConfig();
>         serverConfig.setEnabledForExtensions(true);
>         serverConfig.setContentLengthOptional(false);
> 
>     }
> 
> }
> 
> (MyRpcServer is little adjusted example from Apache XML-RPC
> site)
> 
> Until there everything is ok.
> But where is problem:
> 
> When there comes request to do something with any Foo class
> method via
> XML-RPC I need to do something in Foo class but I need
> there the instance of
> Communicator! Because after doing something in Foo I have
> to send command
> via Communicator to the MyApp thread.
> So I have to know how I can pass the comm instance of
> Communicator (private
> property of MyRpcServer) to Foo class method.
> 
> If I have something like this:
> 
> public class Foo {
>     public int doSomething(int rpcParam1, int rpcParam2) {
>         //do something what I want to tell to MyApp thread
>         return x;
>     }
> }
> 
> I imagine (naively :-) something like this
> 
> public class Foo {
>     public int doSomething(Communicator comm, int
> rpcParam1, int rpcParam2)
> {
>         comm.addCommand(rpcParam1);
>         return x;
>     }
> }
> 
> where comm parameter is the instance passed from
> MyRpcServer automatically
> when Foo.doSomething is requested.
> 
> Is there any other way how to get this instance?
> 
> Thank you very much for any advice or pointing to any url
> for solution.
> 
> Petr Simek


      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

Reply via email to