Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: Administrator.java 22 2009-05-18 17:20:44Z mitcje $
   * $URL: https://ikasaneip.svn.sourceforge.net/svnroot/ikasaneip/tags/ikasan-0.7.3/common/src/main/java/org/ikasan/common/Administrator.java $
   * 
   * ====================================================================
   * Ikasan Enterprise Integration Platform
   * Copyright (c) 2003-2008 Mizuho International plc. and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the 
  * Free Software Foundation Europe e.V. Talstrasse 110, 40217 Dusseldorf, Germany 
  * or see the FSF site: http://www.fsfeurope.org/.
  * ====================================================================
  */
 package org.ikasan.common;
 
 import java.util.Map;
 
 
 
Administrator class.

Author(s):
Ikasan Development Team
 
 public class Administrator
 {
    
Serialise ID
 
     private static final long serialVersionUID = 1L;

    
The logger instance
 
     private static Logger logger = Logger.getLogger(Administrator.class);

    
Administrator context
 
     private CommonContext context;

    
Group name of the administered component
 
     private String groupName;

    
Name of the administered component
 
     private String componentName;

    
URL of the status instance for this component
 
     private String componentStatusURL;

    
Last offence handled by this bean
 
     private RapSheetEntry lastRapSheetEntry;

    
History of the rapSheet
 
     private Hashtable<StringRapSheetEntryrapSheetEntries = new Hashtable<StringRapSheetEntry>();

    
ScheduleInfo history
 
     private Hashtable<ScheduleInfoIntegerscheduleInfos = new Hashtable<ScheduleInfoInteger>();

    
Default constructor Creates a new instance of Administrator.
 
     public Administrator()
     {
         this. = ResourceLoader.getInstance().newContext();
     }

    
Setter for groupName

Parameters:
groupName The name of the group
 
     public void setGroupName(String groupName)
     {
         this. = groupName;
     }

    
Getter for groupName

Returns:
groupName
 
     public String getGroupName()
    {
        return this.;
    }

    
Setter for componentName

Parameters:
componentName The component name to set
    public void setComponentName(String componentName)
    {
        this. = componentName;
    }

    
Getter for componentName

Returns:
componentName
    public String getComponentName()
    {
        return this.;
    }

    
Setter for componentStatusURL

Parameters:
componentStatusURL The component status URL to set
    public void setComponentStatusURL(String componentStatusURL)
    {
        this. = componentStatusURL;
    }

    
Getter for componentStatusURL

Returns:
componentStatusURL
    public String getComponentStatusURL()
    {
        return this.;
    }

    
Set the componentStatus of this bean.

Parameters:
componentState The component state to set
Returns:
Status as set in the context
    public Status setComponentState(ComponentState componentState)
    {
        Status status = new Status(componentState, Calendar.getInstance().getTimeInMillis());
        try
        {
            if (this. != null)
            {
                this..bind(this.status);
                .debug("Setting ComponentStateURL [" + this. + "] ["
                        + status.getComponentState().getDescription() + "].");
                return status;
            }
        }
        catch (NameAlreadyBoundException e)
        {
            try
            {
                Status currentStatus = this.getComponentState();
                if (!currentStatus.getComponentState().equals(componentState))
                {
                    .info("Changing ComponentStateURL [" + this. + "] ["
                            + status.getComponentState().getDescription() + "].");
                }
                else
                {
                    .debug("Setting ComponentStateURL [" + this. + "] ["
                            + status.getComponentState().getDescription() + "].");
                }
                this..rebind(this.status);
                return status;
            }
            catch (NamingException e1)
            {
                .error("Failed to set componentStatus"e1); //$NON-NLS-1$
            }
        }
        catch (NamingException e)
        {
            // Don't throw any exceptions on failure to set componentStatus,
            // as we do not want to interfere with real exceptions
            .error("Failed to set componentStatus"e); //$NON-NLS-1$
        }
        return new Status(., Calendar.getInstance().getTimeInMillis());
    }

    
Updates the status of this component only if the incoming status equals the currently set status of this bean. If another method has since updated this status then this method will leave the status as is.

Parameters:
previousStatus The previous state
componentState The new state to update to
Returns:
Status as set in the context
    public Status updateComponentState(Status previousStatusComponentState componentState)
    {
        Status currentStatus = this.getComponentState();
        if (previousStatus.equals(currentStatus))
        {
            this.setComponentState(componentState);
            return this.getComponentState();
        }
        return currentStatus;
    }

    
Get the componentStatus of this bean.

Returns:
Status
    public Status getComponentState()
    {
        try
        {
            if (this. != null)
            {
                Object obj = this..lookup(this.);
                if (obj instanceof Status)
                {
                    return (Statusobj;
                }
                .error("ComponentState lookup returned object [" //$NON-NLS-1$
                        + obj.getClass().getName() + "] rather than 'Status' object " //$NON-NLS-1$
                        + "for URL [" + this. + "]"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
        catch (NamingException e)
        {
            .error("Failed to get componentStatus for [" //$NON-NLS-1$
                    + this. + "]"e); //$NON-NLS-1$
        }
        return new Status(., Calendar.getInstance().getTimeInMillis());
    }
    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("Group Name [").append(this.).append(']');
        sb.append(" Component Name [").append(this.).append(']');
        sb.append(" Status URL [").append(this.).append(']');
        return new String(sb);
    }

    
Setter for the lastRapSheetEntry.

Parameters:
rapSheetEntry The rap sheet entry to set
    public void setLastRapSheetEntry(final RapSheetEntry rapSheetEntry)
    {
        this. = rapSheetEntry;
        .debug("Setting lastRapSheetEntry [" + this. + "]"); //$NON-NLS-1$//$NON-NLS-2$
    }

    
Getter for the lastRapSheetEntry.

Returns:
rapSheetEntry
    {
        .debug("Getting lastRapSheetEntry [" + this. + "]"); //$NON-NLS-1$ //$NON-NLS-2$
        return this.;
    }

    

Returns:
the rapSheetEntries
    {
        .debug("Getting rapSheetEntries [" + this. + "]"); //$NON-NLS-1$//$NON-NLS-2$
        return this.;
    }

    

Parameters:
rapSheetEntries the rapSheetEntries to set
    public void setRapSheetEntries(final Hashtable<StringRapSheetEntryrapSheetEntries)
    {
        this. = rapSheetEntries;
        .debug("Setting rapSheetEntries [" + this. + "]"); //$NON-NLS-1$//$NON-NLS-2$
    }

    
Update the current rapSheet list and last rapSheetEntry based on the incoming offence
TODO rename method to be offence

Parameters:
throwable The offence to add
messageMaskPattern The pattern to apply
    public void addOffense(Throwable throwableString messageMaskPattern)
    {
        RapSheetEntry rse = new RapSheetEntry(throwable);
        StringMasker stringMasker = createStringMasker(messageMaskPattern);
        String key = this.getRapSheetEntryKey(rsestringMasker);
        // Existing entry found
        if (this..containsKey(key))
        {
            rse = this..get(key);
            rse.setTotalCount(rse.getTotalCount() + 1);
            rse.setLastOccurrence(Calendar.getInstance().getTimeInMillis());
            if (rse.equals(this.))
            {
                rse.setConsecutiveCount(rse.getConsecutiveCount() + 1);
            }
        }
        this..put(keyrse);
        this. = rse;
    }

    
Create a string mask pattern

Parameters:
messageMaskPattern The pattern to use
Returns:
a StringMasker for a given mask pattern (regexp) that masks matches with ####
    private StringMasker createStringMasker(String messageMaskPattern)
    {
        StringMasker stringMasker = null;
        if (messageMaskPattern != null)
        {
            stringMasker = new StringMasker(messageMaskPattern"####");
        }
        return stringMasker;
    }

    
Check to see if the thrown offence has previously occurred within the given period.

Parameters:
throwable The offence to check
period in milliseconds within which offence must occur to be considered a duplicate
messageMaskPattern The mask pattern to apply
Returns:
boolean
    public boolean isDuplicateOffense(Throwable throwablelong periodString messageMaskPattern)
    {
        RapSheetEntry rse = new RapSheetEntry(throwable);
        String key = this.getRapSheetEntryKey(rsecreateStringMasker(messageMaskPattern));
        if (this..containsKey(key))
        // Existing entry found
        {
            rse = this.getRapSheetEntries().get(key);
            long now = java.util.Calendar.getInstance().getTimeInMillis();
            long lastOccurred = rse.getLastOccurrence();
            long elapsed = now - lastOccurred;
            if (elapsed <= period)
            {
                return true;
            }
        }
        return false;
    }

    
Returns the Rap Sheet Entry key

Parameters:
rse The rap sheet entry to get the key from
stringMasker - may be null, a masker for masking aspects of the throwable message
Returns:
RapSheet entry Key
    private String getRapSheetEntryKey(RapSheetEntry rseStringMasker stringMasker)
    {
        StringBuffer key = new StringBuffer();
        ExceptionType exceptionType = null;
        Throwable offense = rse.getOffense();
        if (offense instanceof CommonException)
        {
            exceptionType = ((CommonExceptionoffense).getExceptionType();
        }
        key.append(offense.getClass().getName());
        String message = offense.getMessage();
        if (stringMasker != null)
        {
            message = stringMasker.mask(message);
        }
        key.append(message);
        if (exceptionType != null)
        {
            key.append(exceptionType.getClass().getName());
            key.append(exceptionType.getName());
        }
        return new String(key);
    }

    
Update the administrator

Parameters:
scheduleInfo The scheduled info
    public void updateAdministrator(final ScheduleInfo scheduleInfo)
    {
        // get this schedule info count
        Integer count = this..get(scheduleInfo);
        if (count == null)
        {
            this..put(scheduleInfonew Integer(1));
        }
        else
        {
            int cnt = count.intValue();
            this..put(scheduleInfonew Integer(cnt++));
        }
    }

    
Get the schedule informations

Returns:
The schedule informations
    {
        return this.;
    }
New to GrepCode? Check out our FAQ X