Java Reference
In-Depth Information
14.3.2
Constructing the user information management MBean
By using an MBean to access the EJB , you have an elegant way to manage the login
process of particular users. The MBean will be able to disable and enable user
accounts, as well as retrieve information from the account.
The MBean interface
Listing 14.4 shows the MBean interface for the UserInfoMgr MBean class.
Listing 14.4
UserInfoMgrMBean.java
package jmxbook.ch14;
public interface UserInfoMgrMBean{
public int getQueryCount( String userName );
public void allowLogin( String userName,boolean isAllowed );
}
The MBean will expose two methods in its management:
getQueryCount() —Exposes a read-only attribute that stores the number of
successful logins for a particular user.
allowLogin() —Exposes an operation to enable or disable a user's account.
This method takes a user name and a boolean (the boolean value indicates
the account status change).
UserInfoMgr MBean code
Listing 14.5 shows the MBean implementation class. This MBean is different
from others you have created in that it uses a main() method to register itself
into your JMXBookAgent class. In this chapter, you do not need a process to
receive any notification, so you don't necessarily need a separate class to register
this MBean in the agent.
Listing 14.5
UserInfoMgr.java
package jmxbook.ch14;
import com.sun.jdmk.comm.*;
import javax.management.*;
import jmxbook.ch3.RMIClientFactory;
import javax.naming.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
Search WWH ::




Custom Search