Archived

This forum has been archived. Please start a new discussion on GitHub.

var set nothing change

Hello,

i have this problem...

Client.java

HomeImpl TestHaus=new HomeImpl(); Create TestHaus.
TestHaus.comment="Test"; Set the comment

serviceHome.getComment(TestHaus);
Output: Test -> OK

serviceHome.setComment(TestHaus, "Strasse, Ort"); send and change the comment over the network

serviceHome.getComment(TestHaus);
Output: Test -> false, OK is "Strasse, Ort";

Can anyone help me.

Thanks

Comments

  • matthew
    matthew NL, Canada
    Sorry, but I'm afraid you haven't given us much to go on. If you post a fully working example that demonstrates your issue, I'm sure we can resolve your problem.
  • Hello,

    i habe attach the Project.

    Thank
  • matthew
    matthew NL, Canada
    Ok, I took a look at the project, but its not clear from looking at the client what you expect to occur?
            String endpoint = communicator.getProperties().getProperty("ServiceAdapter.Proxy");
            
            Ice.ObjectPrx baseHome = communicator.stringToProxy("AdhocoHome:"+endpoint);
            Benchmark.HomePrx serviceHome = Benchmark.HomePrxHelper.checkedCast(baseHome);
            if (serviceHome == null) throw new Error("Invalid proxy");
             
            serviceHome.setName("Bahnhofstrasse 29, 8854 Siebnen");
    

    This will call the setName here
    	public void setName(String name, Current __current) {
    		// TODO Auto-generated method stub
    		
    	}
    

    which does nothing. Are you perhaps confused about pass-by-proxy, and pass-by-object?
    	interface Home {
    		void removeRoom(RoomImpl room);
    		void addRoom(RoomImpl room);
    

    This will pass the RoomImpl object to the server, where the server will then have a lock copy of the object. Do you really mean to pass a proxy to an object to the server? If so, you should do:
    	interface Home {
    		void removeRoom(RoomImpl* room);
    		void addRoom(RoomImpl* room);
    
  • Also, looking at the generated code in your Benchmark directory, it appears that the Slice definitions were compiled with slice2javae, not with slice2java. You should compile them with slice2java. (Ice-E for Java is no longer supported.)

    Cheers,

    Michi.
  • Hello,

    thanks for answer very soon.
    I have changed the ice-File to

    interface Home {
    void removeRoom(RoomImpl* room);
    void addRoom(RoomImpl* room);
    string getName();
    void setName(string name);
    string getId();
    string getType();
    string getComment();
    void setComment(string comment);

    In the Server.java i have create the TestHaus Object.

    Server.java

    private static int run(String[] args, Ice.Communicator communicator)
    {
    HomeImpl TestHaus=new HomeImpl();


    Now i would like the set or get some atributte to the Object.


    ServiceHome.java

    public class ServiceHome extends _HomeDisp {

    public void addRoom(RoomImplPrx room, Current __current) {
    // Add Room at TestHaus Object at the Server

    this.addRoom(room);
    }

    public String getComment(Current __current) {
    // Return the comment from TestHaus Object at the Server

    return null;
    }

    public String getId(Current __current) {
    // Return the Id from TestHaus Object at the Server
    return null;
    }

    public String getName(Current __current) {
    // Return the Name from TestHaus Object at the Server
    return null;
    }

    public String getType(Current __current) {
    // Return the Type from TestHaus Object at the Server
    return null;
    }

    public void removeRoom(RoomImplPrx room, Current __current) {
    // Remove Room from TestHaus Object at the Server

    }

    public void setComment(String comment, Current __current) {
    // Set the comment TestHaus Object at the Server
    // TODO Auto-generated method stub

    }

    public void setName(String name, Current __current) {
    // Set the Name TestHaus Object at the Server

    }

    }

    Soory for the basic question, i am new in ICE.

    Thanks for help
  • matthew
    matthew NL, Canada
    I'm sorry, but I don't see a question. BTW, this code looks incorrect:
    public void addRoom(RoomImplPrx room, Current __current) {
    //	 Add Room at TestHaus Object at the Server 
    
    this.addRoom(room);
    }
    

    Presumably you need some list to which to add the rooms. Something like:
    java.util.List _rooms = new java.util.ArrayList();
    public void addRoom(RoomImplPrx room, Current __current) {
      //	 Add Room at TestHaus Object at the Server
      _rooms.add(room);
    }
    

    From a coding style perspective, I would change the name of RoomImpl to Room, since the Impl object is normally the implementation of the Ice object.

    If you are having trouble getting started, I would start by reading some of the newsletter articles (http://www.zeroc.com/newsletter/index.html), or perhaps the chat demo (http://www.zeroc.com/chat/download.html).
  • Thanks.

    The question are, how can i set or get the ServerObject.

    Like:

    setcomment ("Test");
    or
    getcomment () -> Result= Test

    But the Object are at the Server.

    Thanks
  • matthew
    matthew NL, Canada
    setcomment ("Test");
    

    This would change the object on the server. In this case, you must implement the setComment method. Something like the following would be a good initial start.
    private String _comment = "";
    public String getComment(Current __current) {
    //	 Return the comment from TestHaus Object at the Server 
    return _comment;
    
    }
    
    public void setComment(String comment, Current __current) {
    //	 Set the comment TestHaus Object at the Server
    _comment = comment;
    }
    
  • Perfect, it's work fine.

    only the last question, i hope.

    I would like the add a room.

    .ice
    void addRoom(RoomImpl* room);

    client
    RoomImpl TestRaum1=new RoomImpl("TestRaum1", "1", "3", "4");

    serviceHome.addRoom(TestRaum1);

    I can not start, then the TestRaum must be a RoomImplPrx, when i cast the RoomImpl to RoomImplPrx it's come a error.

    Thanks
  • If you want to create an object in the server, the server must provide a method to allow this. I suggest reading the life cycle chapter in the manual, especially the section about object factories.

    You can of course pass your RoomImpl as a parameter to the server. but a RoomImplPrx isn't the same as as a RoomImpl itself. The RoomImpl is a class that you can send by value. RoomImplPrx is a proxy to a class, that is, a pointer to an instance of the class in (possibly) a different address space.

    So, you can either pass an instance of the RoomImpl by value to the server, and have the server then add that instance to some list, or you can pass a proxy to a RoomImpl (RoomImplPrx), in which case the server can add the proxy to the list, but the RoomImpl the proxy points at would have to be implemented somewhere else.

    My suggestion is that you read through the introduction and the Slice chapter in the manual, and look at a few of the demos that ship with Ice. Once you have the fundamental concepts sorted out, the remainder will fall into place quickly.


    Cheers,

    Michi.