Java Reference
In-Depth Information
public class UserInfoMgr implements UserInfoMgrMBean{
public UserInfoMgr(){
System.out.println("Creating UserInfoMgr MBean");
}
public UserInfo getUserInfo( String userName ){
int count=0;
UserInfo userInfo=null;
System.out.println("Getting UserQueryInfo:");
System.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.provider.url",
"localhost:1099");
try{
InitialContext jndiContext = new InitialContext();
System.out.println("Got context");
Object ref = jndiContext.lookup("jmxbook/ch14/UserInfo");
System.out.println("Got reference");
UserInfoHome home = (UserInfoHome)
PortableRemoteObject.narrow (ref, UserInfoHome.class);
userInfo=home.findByPrimaryKey(userName);
}
catch(Exception e){
System.out.println(e.toString());
}
B
Look up
EJB
return userInfo;
}
public int getQueryCount( String userName ){
int count=0;
UserInfo userInfo=null;
try{
userInfo=getUserInfo(userName);
count=userInfo.getNumberOfLogins();
System.out.println("Number of Logins:"+count);
}
catch(Exception e){
System.out.println(e.toString());
}
return count;
}
public void allowLogin( String userName, boolean isAllowed ){
UserInfo userInfo=null;
try{
userInfo=getUserInfo(userName);
userInfo.setLoginAllowed(isAllowed);
System.out.println("Set isLoginAllowed:"+isAllowed);
Search WWH ::




Custom Search