UserContext: Threadsafe singleton, inject using ComponentContext, spring di failsafe

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Rohit Yadav 2013-01-24 16:59:17 -08:00
parent b6f780fa33
commit b63b7ddf60
1 changed files with 6 additions and 4 deletions

View File

@ -16,12 +16,10 @@
// under the License.
package com.cloud.user;
import com.cloud.utils.component.ComponentContext;
import javax.inject.Inject;
public class UserContext {
@Inject AccountService _accountMgr;
private static ThreadLocal<UserContext> s_currentContext = new ThreadLocal<UserContext>();
private long userId;
@ -30,9 +28,10 @@ public class UserContext {
private long startEventId = 0;
private long accountId;
private String eventDetails;
private boolean apiServer;
@Inject private AccountService _accountMgr = null;
public UserContext() {
}
@ -48,6 +47,9 @@ public class UserContext {
}
public User getCallerUser() {
if (_accountMgr == null) {
_accountMgr = ComponentContext.getComponent(AccountService.class);
}
return _accountMgr.getActiveUser(userId);
}