001    // jademx - JADE management using JMX
002    // Copyright 2005 Caboodle Networks, Inc.
003    //
004    // This library is free software; you can redistribute it and/or
005    // modify it under the terms of the GNU Lesser General Public
006    // License as published by the Free Software Foundation; either
007    // version 2.1 of the License, or (at your option) any later version.
008    //
009    // This library is distributed in the hope that it will be useful,
010    // but WITHOUT ANY WARRANTY; without even the implied warranty of
011    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012    // Lesser General Public License for more details.
013    //
014    // You should have received a copy of the GNU Lesser General Public
015    // License along with this library; if not, write to the Free Software
016    // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
017    
018    package jade.jademx.agent;
019    
020    import javax.management.Attribute;
021    import javax.management.AttributeList;
022    import javax.management.MBeanException;
023    import javax.management.ReflectionException;
024    
025    //import jade.util.Logger;
026    
027    
028    /** 
029     * sample agent to demonstrate building agent using jademx.
030     * @author David Bernstein, <a href="http://www.caboodlenetworks.com"
031     *  >Caboodle Networks, Inc.</a>
032     */
033    public class JademxNopAgent extends JademxAgent {
034    
035        /**
036         * make a Jademx ping agent 
037         */
038        public JademxNopAgent() {
039        }
040    
041        ///** my logger */
042        //private final Logger logger = 
043        //    Logger.getMyLogger(JademxNopAgent.class.getName());
044        
045        /* (non-Javadoc)
046         * @see jade.core.Agent#setup()
047         */
048        protected void setup() {
049            // make sure set up as a JademxAgent
050            super.setup();
051            
052            //MBeanInfo mbi = getMBeanInfo();
053            
054            boolean reachedUnreachable = false;
055            AttributeList aList = null;
056            
057            try {
058                reachedUnreachable = false;
059                aList = getAttributes( new String[] { "FuBar "});
060                reachedUnreachable = true;
061            }
062            catch ( RuntimeException re ) {
063                // expected
064            }
065            if ( reachedUnreachable ) {
066                throw new RuntimeException(
067                "shouldn't have gotten past getAttributes() call");
068            }
069            
070            aList = new AttributeList(1);
071            aList.add( new Attribute("foo","bar") );
072            try {
073                reachedUnreachable = false;
074                setAttributes( aList );
075                reachedUnreachable = true;
076            }
077            catch ( RuntimeException re ) {
078                // expected
079            }
080            if ( reachedUnreachable ) {
081                throw new RuntimeException(
082                "shouldn't have gotten past setAttributes() call");
083            }
084            
085            try {
086                invoke( "foo", new Object[0], new String[0]);
087            }
088            catch ( MBeanException e ) {
089                throw new RuntimeException("unexpected MBeanException", e );
090            }
091            catch (ReflectionException e) {
092                // expected
093            }
094            
095            
096        }
097    
098    
099    
100        
101    }