3 Replies Latest reply on Dec 6, 2006 10:01 AM by tom.elrod

    always using the same target class on server side (POJO)

    mkulawin

      Hello All,

      I use jboss POJO's. If I run the client to the same server twice, the server use always the same instance of target pojo object (targetPOJO). Is there a solution, if I run the client to the same server may times, that every request create a new instance of the target pojo?

      regards
      Mike

        • 1. Re: always using the same target class on server side (POJO)
          ron_sigal

          Hi Mike,

          Could you elaborate a little? Are you talking about a Remoting server? Is targetPOJO the ServerInvocationHandler? Or are you talking about EJB3 POJOs?

          Thanks,
          Ron

          • 2. Re: always using the same target class on server side (POJO)
            mkulawin

            An example from me:

            Client code:
            --------------

            package client;
            
            import java.net.MalformedURLException;
            
            import org.jboss.remoting.InvokerLocator;
            import org.jboss.remoting.security.SSLSocketBuilder;
            import org.jboss.remoting.transporter.TransporterClient;
            
            import server.HandlerInterface;
            
            public class Client {
             /**
             * the Object containing all information about the Server location
             */
             protected InvokerLocator locator;
            
             /**
             * Constructor - initializes the locator and sets properties
             */
             public Client() {
             try {
             locator = new InvokerLocator("multiplex://127.0.0.1:7070");
             } catch (MalformedURLException e) {
             e.printStackTrace();
             }
             }
            
             /**
             * reqests the Server for an handle
             */
             public void requestHandle() {
             HandlerInterface handler;
             try {
             // here the program should throw an exception as no Object should be
             // created
             handler = (HandlerInterface) TransporterClient.createTransporterClient(
             locator, HandlerInterface.class);
             // this should not print a return string
             System.out.println("server returned: " + handler.doHandle());
             TransporterClient.destroyTransporterClient(handler);
            
             } catch (Exception e) {
             e.printStackTrace();
             }
             }
            
             public static void main(String[] args) {
             System.out.println("starting client");
             Client client = new Client();
             client.requestHandle();
             }
            }
            
            


            Server code:
            ---------------
            package server;
            
            import java.io.IOException;
            import java.util.HashMap;
            import java.util.Map;
            
            import org.jboss.remoting.security.SSLSocketBuilder;
            import org.jboss.remoting.transporter.TransporterServer;
            
            public class Server {
            
             /**
             * runs and starts the Server
             *
             * @param args
             */
             public static void main(String[] args) {
             String locatorURL = "multiplex://127.0.0.1:7070";
            
             HandlerInterface handler = new Handler();
             try {
             TransporterServer server = TransporterServer
             .createTransporterServer(locatorURL, handler, HandlerInterface.class
             .getName(), false);
             server.start();
             } catch (Exception e) {
             e.printStackTrace();
             }
            
             }
            
            }
            


            Pojo Code:
            -------------

            Interface:
            package server;
            
            public interface HandlerInterface {
            
             public abstract String doHandle();
            
            }
            


            class with the implemented interface

            package server;
            
            public class Handler implements HandlerInterface {
            
             int counter = 0;
            
             /* (non-Javadoc)
             * @see server.HandlerInterface#doHandle()
             */
             public String doHandle() {
             counter++;
             System.out.println("Counter: "+counter);
             return String.valueOf(counter);
            
             }
            }
            


            If you start the server and you run the client once. You can see follow on client side:

            starting client
            server returned: 1

            the second run:
            server returned: 2

            this show me, that every client use the same instance of class "Handler". I expect that another client (new connect to the server) get a new instance of class.
            expectation:

            starting client
            server returned: 1

            the second run:
            starting client
            server returned: 1

            Is there a JBoss remoting implementation to do this?

            • 3. Re: always using the same target class on server side (POJO)

              No way to do this currently. One of the problems is this could lead to a creating a target POJO per client request, which would slow things down. Ideally, would be able to do as is done with ejb where server instances are pooled, but since ejb already does this didn't see it as being high priority (ejb3 does this with POJOs).