Custom plug-in sample notifier class
When an object is created, updated, or deleted, the sample notification plug-in writes a corresponding message to the WebSphere® Application Server log file.
The notifier creates a logger object with a component name of "pluginsample.notifier". This means that if you enable WebSphere Application Server tracing for that component, the server logs the calls of the notifier methods.
See the Related link for more details on creating a notification plug-in class.
The source code for the custom service discovery sample configuration instance class is as follows:
package pluginsample.notifier;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.ibm.serviceregistry.ServiceRegistryException;
import com.ibm.serviceregistry.ServiceRegistryNotifier;
import com.ibm.serviceregistry.sdo.BaseObject;
import com.ibm.serviceregistry.sdo.OriginalObject;
public class LogActivity implements ServiceRegistryNotifier {
private static Logger logger = Logger.getLogger("pluginsample.notifier");
private static final String CLASS_NAME = LogActivity.class.getName();
// Write a message to the system out to log the create action
// and indicate if it was successful.
public void create(OriginalObject newObject, boolean success,
ServiceRegistryException exception) {
final String METHOD_NAME = "create";
if (logger.isLoggable(Level.FINEST)) {
logger.entering(CLASS_NAME, METHOD_NAME);
}
// Create was successful
if (success) {
System.out.println(newObject.getName() + " was created successfully");
}
// Create failed, so log the exception message and what we were trying
// to create
else {
System.out.println("A problem occured when trying to create "
+ newObject.getName() + ". Exception message was: "
+ exception.getMessage());
}
if (logger.isLoggable(Level.FINEST)) {
logger.exiting(CLASS_NAME, METHOD_NAME);
}
}
// Write a message to the system out to log the delete action
// and indicate if it was successful.
public void delete(OriginalObject oldObject, boolean success,
ServiceRegistryException exception) {
final String METHOD_NAME = "delete";
if (logger.isLoggable(Level.FINEST)) {
logger.entering(CLASS_NAME, METHOD_NAME);
}
// Delete was successful
if (success) {
System.out.println(oldObject.getName() + " was deleted successfully");
}
// Delete failed, so log the exception message and what we were trying
// to delete
else {
System.out.println("A problem occured when trying to delete "
+ oldObject.getName() + ". Exception message was: "
+ exception.getMessage());
}
if (logger.isLoggable(Level.FINEST)) {
logger.exiting(CLASS_NAME, METHOD_NAME);
}
}
// Write a message to the system out to log the update action
// and indicate if it was successful.
public void update(BaseObject oldObject, BaseObject newObject,
boolean success, ServiceRegistryException exception) {
final String METHOD_NAME = "update";
if (logger.isLoggable(Level.FINEST)) {
logger.entering(CLASS_NAME, METHOD_NAME);
}
// Update was successful
if (success) {
System.out.println(oldObject.getName() + " was updated successfully");
}
// Update failed, so log the exception message and what we were trying
// to update
else {
System.out.println("A problem occured when trying to update "
+ oldObject.getName() + ". Exception message was: "
+ exception.getMessage());
}
if (logger.isLoggable(Level.FINEST)) {
logger.exiting(CLASS_NAME, METHOD_NAME);
}
}
}