001package org.apache.commons.jcs.engine.control.event;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.EventObject;
023
024import org.apache.commons.jcs.engine.control.event.behavior.ElementEventType;
025import org.apache.commons.jcs.engine.control.event.behavior.IElementEvent;
026
027/**
028 * Element events will trigger the creation of Element Event objects. This is a wrapper around the
029 * cache element that indicates the event triggered.
030 */
031public class ElementEvent<T>
032    extends EventObject
033    implements IElementEvent<T>
034{
035    /** Don't change */
036    private static final long serialVersionUID = -5364117411457467056L;
037
038    /** default event code */
039    private ElementEventType elementEvent = ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND;
040
041    /**
042     * Constructor for the ElementEvent object
043     * <p>
044     * @param source The Cache Element
045     * @param elementEvent The event id defined in the enum class.
046     */
047    public ElementEvent( T source, ElementEventType elementEvent )
048    {
049        super( source );
050        this.elementEvent = elementEvent;
051    }
052
053    /**
054     * Gets the elementEvent attribute of the ElementEvent object
055     * <p>
056     * @return The elementEvent value. The List of values is defined in ElementEventType.
057     */
058    @Override
059    public ElementEventType getElementEvent()
060    {
061        return elementEvent;
062    }
063
064    /**
065     * @return the source of the event.
066     */
067    @SuppressWarnings("unchecked") // Generified
068    @Override
069    public T getSource()
070    {
071        return (T) super.getSource();
072
073    }
074}