[jboss-user] [Remoting] - Re: always using the same target class on server side (POJO)
mkulawin
do-not-reply at jboss.com
Wed Dec 6 04:31:39 EST 2006
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?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3991574#3991574
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3991574
More information about the jboss-user
mailing list