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.camel.example.jmx;
018    
019    import java.text.SimpleDateFormat;
020    import java.util.Date;
021    import javax.management.AttributeChangeNotification;
022    import javax.management.NotificationBroadcasterSupport;
023    
024    /**
025     * Our business logic which also is capable of broadcasting JMX notifications,
026     * such as an attribute being changed.
027     */
028    public class SimpleBean extends NotificationBroadcasterSupport implements ISimpleMXBean {
029        private int sequence;
030        private int tick;
031    
032        public void tick() throws Exception {
033            tick++;
034    
035            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-dd-MM'T'HH:mm:ss");
036            Date date = sdf.parse("2010-07-01T10:30:15");
037            long timeStamp = date.getTime();
038    
039            AttributeChangeNotification acn = new AttributeChangeNotification(
040                    this, sequence++, timeStamp, "attribute changed", "stringValue", "string", tick - 1, tick);
041            sendNotification(acn);
042        }
043    
044    }