It's all about the answers!

Ask a question

How to use RTC Java API with 2 accounts at the same time?


han huynh (198) | asked Oct 16 '15, 4:45 a.m.
edited Oct 16 '15, 8:37 a.m. by Ralph Schoon (57.2k23642)
Hello, I`m facing an issue about RTC Java API. I try to connect RTC with 2 accounts to query in the same time. But RTC API only allow one account at a time.
It seems TeamPlatform.getTeamRepositoryService().getTeamRepository always return the same instance of repository.
So if you have any idea about this. Please help me.

Thanks,

Accepted answer


permanent link
Ralph Schoon (57.2k23642) | answered Oct 16 '15, 4:53 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 16 '15, 4:55 a.m.
You have to create separate connections e.g manage multiple ITeamrepository objects with separate URI's and logins for each repository/user. I have done that in the past and it works. This is basic Java.
han huynh selected this answer as the correct answer

Comments
han huynh commented Oct 16 '15, 5:27 a.m.

 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).

Do you have some link or document related to create multiple ITeamrepository objects?

Thanks,


Ralph Schoon commented Oct 16 '15, 5:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


han huynh commented Oct 16 '15, 6:21 a.m.

That is what I am doing, but the case here is repository1 and repository2 is the same repository server.

So the teamRepository1 and teamRepository2 is the same reference. And the session contain only the last login account. In this case, both teamRepository1 and teamRepository2 will use the same account - user2 to query API.


Ralph Schoon commented Oct 16 '15, 6:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


sam detweiler commented Oct 16 '15, 7:46 a.m.

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.


han huynh commented Oct 19 '15, 12:09 a.m.

 @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.

@Sam detweiler: All the function is using in the same app and it's hard to split it into 2 apps. So that why I need to create 2 connections in the same app.


sam detweiler commented Oct 19 '15, 8:16 a.m.

I understand. but the runtime library only supports 1 connection per process.


Chris McGee commented Oct 20 '15, 1:41 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

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);

// 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);

I hope that this helps,
Chris


han huynh commented Oct 21 '15, 6:28 a.m.

Hi @Chris, it worked exactly as my expectation. Thank you so much!. 

showing 5 of 9 show 4 more comments

Your answer


Register or to post your answer.