Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

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,

0 votes


Accepted answer

Permanent link
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

0 votes

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

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

Thanks,

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.

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.

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.

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

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

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

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

showing 5 of 9 show 4 more comments

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,936
× 233
× 201

Question asked: Oct 16 '15, 4:45 a.m.

Question was seen: 3,205 times

Last updated: Oct 21 '15, 6:28 a.m.

Confirmation Cancel Confirm