Hi all, 

I'm trying to write a basic MBean. 
This Mean runs a Thread which checks the file system for new files. If a 
new file is found it should perform some action. 

My problem however is that whenever I undeploy, or stop the MBean using 
the jmx-console application, the MBean keeps running. 

I have no idea what I'm doing wrong here.

Below is my code. Could somebody please tell me what it is that I'm doing 
wrong here?

Thanks a lot,

Harm de Laat
Informatiefabriek
The Netherlands


package nl.informatiefabriek.jmxlizard;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;

import org.jboss.system.ServiceMBeanSupport;

/**
 * @author harm
 */
public class JBossLizard
        extends ServiceMBeanSupport
        implements JBossLizardMBean, Runnable {

        private Thread lizard;

        public JBossLizard() {
        }

        public String getName() {
                return "JBossJMXLizard";
        }

        /* (non-Javadoc)
         * @see java.lang.Runnable#run()
         */
        public void run() {

                boolean running = true;
                while (running) {
                        /* wait for interval milliseconds */
                        sleep(interval);

                        /* do some checking */
                        File checkDir = new File(absoluteCheckPath);
                        if (!checkDir.exists()) {
                                log.warn(
                                        "Directory does not exist: " + 
checkDir.getAbsolutePath());
                                sleep(1000 * 5);
                                // we wait for five seconds to avoid a 
huge system load
                                continue;
                        }

                        if (!checkDir.isDirectory()) {
                                log.warn(
                                        "Directory: "
                                                + 
checkDir.getAbsolutePath()
                                                + "is not a directory.");
                                sleep(1000 * 5);
                                continue;
                        }

                        /* retrieve the listing */
                        String[] dirlist1 = checkDir.list();
                        for (int i = 0; i < dirlist1.length; i++) {
                                /* don't touch hidden files */
                                if (dirlist1[i].startsWith(".")) {
                                        // System.out.println("Hidden 
file... Leaving it untouched: " + dirlist1[i]);
                                        break;
                                }

                                /* get file extension */
                                int index = dirlist1[i].lastIndexOf('.');
                                String checkFileExtension =
                                        dirlist1[i]
                                                .substring(index + 1, 
dirlist1[i].length())
                                                .toLowerCase();
                                System.out.println(
                                        "File extension is: " + 
checkFileExtension);
                                /* see if it is a file we should process 
*/
                                if (checkFileExtension
                                        .equals(this
.getFileExtension().toLowerCase())) {
                                        System.out.println(
                                                "This is the correct file 
extension.");
                                        /* Create a file handler */
                                        File f = new File(checkDir, 
dirlist1[i]);
 
                                        // process the file here!
                                }
 
                        }
                }
                System.out.println("Lizard stopped...");
        }

        private void sleep(long howlong) {
                try {
                        Thread.sleep(howlong);
                } catch (Exception e) {
                }
        }

        /* MBean methods */
        protected void startService() throws Exception {
                // Create a new thread with this monitor
                lizard = new Thread(this, "JBossMonitor");
                // Set it as a daemon
                lizard.setDaemon(true);
                // start the thread
                lizard.start();
        }

        protected void stopService() {
                lizard.interrupt();
        }
}


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to