001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */ 
017    package org.apache.commons.modeler;
018    
019    import javax.management.Notification;
020    
021    
022    /**
023     * Base JMX Notification. Supports in int code and notes - for faster 
024     * access and dispatching. 
025     *
026     * @author Costin Manolache
027     */
028    public final class BaseNotification extends Notification {
029    
030        // ----------------------------------------------------------- Constructors
031        private int code;
032        private String type;
033        private Object source;
034        private long seq;
035        private long tstamp;
036    
037        /**
038         * Private constructor.
039         */
040        private BaseNotification(String type,
041                                 Object source,
042                                 long seq,
043                                 long tstamp,
044                                 int code) {
045            super(type, source, seq, tstamp);
046            init( type, source, seq, tstamp, code );
047            this.code=code;
048        }
049    
050        public void recycle() {
051    
052        }
053    
054        public void init( String type, Object source,
055                          long seq, long tstamp, int code )
056        {
057            this.type=type;
058            this.source = source;
059            this.seq=seq;
060            this.tstamp=tstamp;
061            this.code = code;
062        }
063    
064        // -------------------- Override base methods  --------------------
065        // All base methods need to be overriden - in order to support recycling.
066    
067    
068        // -------------------- Information associated with the notification  ----
069        // Like events ( which Notification extends ), notifications may store
070        // informations related with the event that trigered it. Source and type is
071        // one piece, but it is common to store more info.
072    
073        /** Action id, useable in switches and table indexes
074         */
075        public int getCode() {
076            return code;
077        }
078    
079        // XXX Make it customizable - or grow it
080        private Object notes[]=new Object[32];
081    
082        public final Object getNote(int i ) {
083            return notes[i];
084        }
085    
086        public final void setNote(int i, Object o ) {
087            notes[i]=o;
088        }
089    }