How to maintain the identity of an object in different virtual machines

To be specific, let me illustrate the question with the Spring http-remoting example.

Suppose we have this simple interface implementation:

public SearchServiceImpl implements SearchService {
    public SearchJdo processSearch(SearchJdo search) {
        search.name = "a funky name";
        return search;
    }
}

SearchJdo is just a POJO.

Now, when we call the method from the client through http-remoting (Spring is a mechanism for calling remote objects like EJB that uses serialization), we get:

public class HTTPClient {
    public static void main(final String[] arguments) {
        final ApplicationContext context = new ClassPathXmlApplicationContext(
            "spring-http-client-config.xml");
        final SearchService searchService =
            (SearchService) context.getBean("searchService");

        SearchJdo search = new SearchJdo();
        search.name = "myName"; 
        // this method actually returns the same object it gets as an argument
        SearchJdo search2 = searchService.processSearch(search);
        System.out.println(search == search2); // prints "false"
    }
}

The problem is that search objects differ due to serialization, although from the logical perspective they are the same.

The question is whether there is any method that allows you to support or emulate the identification of an object through virtual machines.

+3
3

, , . , , , , , .

, , ? Java GUID, , .

+1

- .

  • ==
  • .equals(..)

equals(), . hashCode() (). IDE .

( Teracotta VM , .)

+1

, , :

, , , . , , User ; .

, . , , , , . , .

, , .

: , , .

As soon as the new server detects that the session identifier is coherent, it will load the roles from the database as a reliable source of information.

Sorry if I could not write this before, but hope this helps someone.

0
source

Source: https://habr.com/ru/post/1748946/


All Articles