|
Problem |
Can I check to see if JNDI is available to bind objects
into in WebSphere 5.0? |
|
Solution |
One method of checking to see if JNDI is available to bind
objects into is to register a CustomService as a JMX notification listener
for the server.started event. In doing this, you can know for sure that
JNDI is available to bind objects into. This ability to register for a
public callback notification when the server has completed startup is new
in Websphere Application Server 5.0.
Here is some sample code :
import java.util.Properties;
import javax.management.Notification;
import javax.management.NotificationFilterSupport;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import com.ibm.websphere.management.AdminServiceFactory;
import com.ibm.websphere.management.NotificationConstants;
import com.ibm.websphere.runtime.CustomService;
public class MyCustomService implements CustomService,
NotificationListener
{
public void initialize(Properties props) throws Exception
{
System.out.println("CustomService.initialize("+props+")");
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(NotificationConstants.TYPE_J2EE_STATE_RUNNING);
ObjectName target = new ObjectName("WebSphere:*,type=Server");
AdminServiceFactory.getAdminService().addNotificationListenerExtended(ta
rget, this, filter, null);
}
public void shutdown()
{
System.out.println("CustomService.shutdown()");
}
public void handleNotification(Notification n, Object handback){
System.out.println("It's ready to bind into JNDI.");
}
} |
|
|
|
Cross Reference information |
Segment |
Product |
Component |
Platform |
Version |
Edition |
Application Servers |
Runtimes for Java Technology |
Java SDK |
|
|
|
|
|
|
|