FileDocCategorySizeDatePackage
AdminEventResult.javaAPI DocGlassfish v2 API18880Fri May 04 22:33:34 BST 2007com.sun.enterprise.admin.event

AdminEventResult

public class AdminEventResult extends Object implements Serializable
Admin Event Result objects are used to communicate result of admin event notification. AdminEventResult object can be either used to represent composite result of multiple instances. getResultCode() returns one of the valid result codes either ERROR, SUCCESS or others like TRANSMISSION_ERROR, RESTART_NEEDED etc. This is composite result of all event's recipients' results. In order to get individual recipient's result getResultCodes() can be used. It returns hash map of instance name and result code. If some recipients got the notification and the others did not receive the notification or failed to process it for any reason.The composite result would be MIXED_RESULT. Similarly hash map of messages and exceptions can be obtained using getMessages and getExceptions respectively. All the methods (setters/getters) of AdminEventResult (except setResultCode and getResultCode) take instance name as argument. Helper methods are also available to format the results and messages/exceptions into a string format. Please look at getAllResultCodesAsString() and getAllMessagesAsString() for details. This class is not thread safe and usage from AdminEventMulticaster does not require it to be thread safe. The methods add/remove Attribute do synchronize internally but that might not be sufficient.

Fields Summary
private static final Class
SERIALIZABLE
Constant denoting Serializable class
public static final String
RESTART_NEEDED
Constant denoting - restart of server required.
public static final String
RUNTIME_EXCEPTION
Constant denoting - runtime exception while processing event
public static final String
RUNTIME_ERROR
Constant denoting - runtime error while processing event
public static final String
TRANSMISSION_ERROR
Constant denoting - event transmission error
public static final String
LISTENER_ERROR
Constant denoting - error while processing event in listener
public static final String
CONFIG_SNAPSHOT_ERROR
Constant denoting - error while creating snapshot of config context
public static final String
MBEAN_NOT_FOUND
Constant denoting - MBean not found.
public static final String
MBEAN_ATTR_NOT_FOUND
Constant denoting - MBean attribute not found. This is used to denote invalid attribute name for Monitoring GET command.
public static final String
SUCCESS
Constant denoting - successful event processing
public static final String
MIXED_RESULT
Constant denoting - some events failed and some events passsed
public static final String
ERROR
Constant denoting - that event notification was not successful, resultCodes needs to checked for individual status
private static HashMap
resultList
private long
eventId
private String
resultCode
private HashMap
resultCodes
private HashMap
allMessages
private HashMap
allExceptions
private HashMap
allAttributes
private AdminEventListenerException
firstAle
private Throwable
firstThr
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public AdminEventResult(long eventId)
Create a new admin event result for specified event id.


                   
    // FIX - Review whether public constructor is required, there is a
    // package factory method.
       
        this.eventId = eventId;
        resultCode = SUCCESS;
    
Methods Summary
voidaddAttribute(java.lang.String target, java.lang.String name, java.lang.Object value)
Add specified attribute. This method can be used to add any Serializable object to event result. The method throws IllegalArgumentException, if name is null or the value is not Serializable.

param
target name of the target for this event
param
name name of the attribute
param
value value of the specified attribute
throws
IllegalArgumentException if name is null or value is not Serializable.

        attributeCheck(name, value);
        synchronized (allAttributes) {
            HashMap attributes = (HashMap) allAttributes.get(target);
            if ( attributes == null ) {
                attributes = new HashMap();
                allAttributes.put(target, attributes);
            }
            attributes.put(name, value);
        }
    
public voidaddEventResult(java.lang.String target, com.sun.enterprise.admin.event.AdminEventResult eventResult)
Merge another event result into the current EventResult

        if ( eventResult == null )
            return;

        this.allMessages.put( target,
            eventResult.getMessages().get(target));
        this.allExceptions.put( target,
            eventResult.getExceptions().get(target));
        this.allAttributes.put(target, 
            (HashMap)eventResult.getAttributes(target));

        if ( resultCodes == null ) {
            resultCodes = new HashMap();
            resultCodes.put(target, eventResult.getResultCode());
        }
    
public voidaddException(java.lang.String target, java.lang.Throwable tt)
Add an exception to the result.

param
tt the exception to add.

        Collection excs = (Collection)allExceptions.get(target);
        if (excs == null) {
            excs = new ArrayList();
            allExceptions.put(target, excs);
        }
        excs.add(tt);
        if ((firstAle == null) && (tt instanceof AdminEventListenerException)) {
            firstAle = (AdminEventListenerException)tt;
        }
        if (firstThr == null) {
            firstThr = tt;
        }
    
public voidaddMessage(java.lang.String target, java.lang.String message)
Add another message

        Collection msgs = (Collection)allMessages.get(target);
        if ( msgs == null) {
            msgs = new ArrayList();
            allMessages.put(target, msgs);
        }
        msgs.add(message);
    
voidattributeCheck(java.lang.String name, java.lang.Object value)

        if (name == null) {
			String msg = localStrings.getString( "admin.event.null_attribute_name" );
            throw new IllegalArgumentException( msg );
        }
        if (value != null) {
            if (!SERIALIZABLE.isInstance(value)) {
				String msg = localStrings.getString( "admin.event.value_not_serializable" );
                throw new IllegalArgumentException( msg );
            }
        }
    
static voidclearAdminEventResultFromCache(AdminEvent event)
Remove specified event from cache

        resultList.remove(event);
    
public static com.sun.enterprise.admin.event.AdminEventResultgetAdminEventResult(AdminEvent event)
Get admin event result from the cache

        AdminEventResult result = (AdminEventResult)resultList.get(event);
        if (result == null) {
            result = new AdminEventResult(event.getSequenceNumber());
            resultList.put(event, result);
        }
        return result;
    
public java.lang.StringgetAllMessagesAsString()
Return all the messages as a String. Note that the Returned String can be really big. Returns a non null empty string if there are no messages. Never returns a null.

        StringBuffer sb = new StringBuffer();
        // Process messages array list
        Set messageSet = allMessages.entrySet();

        Iterator iter = messageSet.iterator();

        while (( iter != null) && (iter.hasNext())) {
            Entry nextMapEntry = (Entry) iter.next();
            sb.append(localStrings.getString("admin.event.target_string"));
            sb.append(nextMapEntry.getKey());
            sb.append("            ");
            Collection msgCol = (Collection) nextMapEntry.getValue();
            Iterator msgs = null;
            if ( msgCol != null) {
                msgs = msgCol.iterator();
            }
            int msgCount = 0;
            if (msgs != null) {
                while (msgs.hasNext()) {
                    msgCount++; 
                    sb.append(localStrings.getString(
                       "admin.event.msg_string", new Integer(msgCount).toString()));
                    String msg = (String) msgs.next();
                    sb.append(msg);
                    sb.append("            ");
                }
            }
        }
        // Process exceptions array list
        Set exceptionSet = allExceptions.entrySet();

        iter = exceptionSet.iterator();
        while ( (iter != null) && (iter.hasNext())) {
            Entry nextMapEntry = (Entry) iter.next();

            Collection excsCol = (Collection) nextMapEntry.getValue();
            Iterator excs = null;
            if ( excsCol != null) {
                excs = excsCol.iterator();
            }

            if (excs !=null) {
                sb.append(localStrings.getString("admin.event.target_string"));
                sb.append(nextMapEntry.getKey());
                sb.append("            ");
                int excCount = 0;
                while ( excs.hasNext()) {
                    Throwable tt = (Throwable) excs.next();
                    excCount++;
                    if (tt != null) {
                        sb.append(localStrings.getString(
                           "admin.event.exp_string", 
                           new Integer(excCount).toString()));
                        String nextStr = tt.getMessage();
                        sb.append(nextStr);
                        sb.append(System.getProperty("line.separator"));
                        StringWriter sw = new StringWriter();
                        tt.printStackTrace(new PrintWriter(sw));
                        sb.append(sw.toString());
                        sb.append(System.getProperty("line.separator"));
                    }
                }
            }
        }
        return (sb.toString());
    
public java.lang.StringgetAllResultCodesAsString()
Return all the result codes as a String. Note that the Returned String can be really big. Returns a non null empty string if there are no messages. Never returns a null.

        StringBuffer sb = new StringBuffer();
        // Process messages array list
        Set resultCodeSet = resultCodes.entrySet();

        Iterator iter = resultCodeSet.iterator();

        while (( iter != null) && (iter.hasNext())) {
            Entry nextMapEntry = (Entry) iter.next();
            sb.append(localStrings.getString("admin.event.target_string"));
            sb.append(nextMapEntry.getKey());
            sb.append("            ");
            sb.append(localStrings.getString("admin.event.result_code_string"));
            sb.append(nextMapEntry.getValue());
            sb.append("            ");
        }
        return (sb.toString());
    
public java.lang.ObjectgetAttribute(java.lang.String target, java.lang.String name)
Get value of attribute with specified name.

param
name name of the attribute
throws
IllegalArgumentException if name is null.
return
Value of the specified attribute name, if it exists, null, otherwise. A null return value may also mean that a null value was associated with specified name.

        if (name == null) {
			String msg = localStrings.getString( "admin.event.null_attribute_name" );
            throw new IllegalArgumentException( msg );
        }
        HashMap attributes = (HashMap) allAttributes.get(target);
        if (attributes != null) {
            return attributes.get(name);
        } else {
            return null;
        }
    
public java.util.SetgetAttributeNames(java.lang.String target)
Get names of all attributes for a target.The returned Set is empty if there are no attributes associated to this event result, otherwise it contains String objects representing names of all attributes.

param
target name of the target
return
a set of all attribute names.

        HashMap h = (HashMap) allAttributes.get(target);
        if ( h!=null) {
            return h.keySet();
        } else {
            return null;
        }
    
public java.util.HashMapgetAttributes(java.lang.String target)
Returns all the attributes for a target as a map

return
attributes hash map

        return (HashMap) allAttributes.get(target);
    
public longgetEventId()
Get event id

        return eventId;
    
public java.util.HashMapgetExceptions()
Get all event exceptions occured during the event delivery. This method should be used in clustered environment

        return allExceptions;
     
public java.util.CollectiongetExceptions(java.lang.String target)
Get all event exceptions occured during the event delivery. This method should be used in clustered environment

        return (Collection)allExceptions.get(target);
     
public AdminEventListenerExceptiongetFirstAdminEventListenerException()
This method returns the first exception added to AdminEventResult on behalf of any target.

return
AdminEventListenerException It is the first added AdminEventListenerException to this AdminEventResult.

        return firstAle;
    
public java.lang.ThrowablegetFirstThrowable()
This method returns the first throwbale added to AdminEventResult on behalf of any target.

return
Throwable It is the first added Throwable to this AdminEventResult.

        return firstThr;
    
public java.util.HashMapgetMessages()
Get all event messages, used in clustered environment

        return allMessages;
     
public java.util.CollectiongetMessages(java.lang.String target)
Get all event messages for an event sent to a target

        return (Collection)allMessages.get(target);
     
public java.lang.StringgetResultCode()
Get result code

        return resultCode;
    
public java.util.HashMapgetResultCodes()
Get result codes, used in clustered environment

        return resultCodes;
     
voidremoveAttribute(java.lang.String target, java.lang.String name)
Remove specified attribute. This method can be used to remove any previously added attribute to event result. If name is null, IllegalArgumentException is thrown.

param
target name of the target
param
name name of the attribute
throws
IllegalArgumentException if name is null.

        if (name == null) {
			String msg = localStrings.getString( "admin.event.null_attribute_name" );
            throw new IllegalArgumentException( msg );
        }
        synchronized (allAttributes) {
            HashMap attributes = (HashMap) allAttributes.get(target);
            if ( attributes != null) {
                attributes.remove(name);
            }
        }
    
public voidsetResultCode(java.lang.String resultCode)
/** Set result code to specified value WARNING: This should be used for setting indiviual instance result code.

        if (!RESTART_NEEDED.equals(this.resultCode)) {
            this.resultCode = resultCode;
        }