How to use RTC Java API with 2 accounts at the same time?
Accepted answer
Comments
Could you please tell me more about how to create multiple ITeamreporitory? As the description above, we get instance of repository by this API TeamPlatform.getTeamRepositoryService().getTeamRepository. But this always return the same instance (I am working with the same RTC server, so it has the same URI param).
Basic Java statements, works like all classes work.
// Log into repository 1 with user 1 ITeamRepository teamRepository1 = TeamPlatform .getTeamRepositoryService().getTeamRepository(repository1); teamRepository1.registerLoginHandler(new LoginHandler(user1, password1)); teamRepository1.login(monitor);// Log into repository 2 with user 2 ITeamRepository teamRepository2 = TeamPlatform .getTeamRepositoryService().getTeamRepository(repository2); teamRepository2.registerLoginHandler(new LoginHandler(user2, password2)); teamRepository2.login(monitor);
Then work with objects teamRepository1 and teamRepository2
That is what I am doing, but the case here is repository1 and repository2 is the same repository server.
Bummer. I used it against two repos and it worked. Maybe the connection is stored as a cookie. You can not be logged into the same repo with two users ID's in the same browser either for the very same reason. Not sure what to do. Log out and log in again if you want to change the user.
what is the use case for having two users connected to the same repo at the same time from the same process? you might need to split the function into two processes with communications between them if required.
@Ralph Schoon: I am working in multi thread environment. Each thread will use 1 connection to query different type of data in the same repo. The main point here it may need to run in the same time, so we cannot use the method logout an account then login another account.
I understand. but the runtime library only supports 1 connection per process.
Can you try again with the "unshared" flag like this? You will have to keep a registry of your team repositories or maybe even a thread local static since in this mode the team repository service singleton will not keep track.
// Log into repository 1 with user 1 ITeamRepository teamRepository1 = TeamPlatform .getTeamRepositoryService().getTeamRepository(repository, ITeamRepositoryService.UNSHARED); teamRepository1.registerLoginHandler(new LoginHandler(user1, password1)); teamRepository1.login(monitor);I hope that this helps,// Log into repository 2 with user 2 ITeamRepository teamRepository2 = TeamPlatform .getTeamRepositoryService().getTeamRepository(repository, <b>ITeamRepositoryService.UNSHARED</b>); teamRepository2.registerLoginHandler(new LoginHandler(user2, password2)); teamRepository2.login(monitor);
Chris
Hi @Chris, it worked exactly as my expectation. Thank you so much!.