001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.deploy.auto;
016    
017    /**
018     * @author Ivica Cardic
019     * @author Brian Wing Shun Chan
020     */
021    public class AutoDeployScanner extends Thread {
022    
023            public AutoDeployScanner(
024                    ThreadGroup threadGroup, String name, AutoDeployDir autoDeployDir) {
025    
026                    super(threadGroup, name);
027    
028                    _autoDeployDir = autoDeployDir;
029    
030                    setContextClassLoader(getClass().getClassLoader());
031                    setDaemon(true);
032                    setPriority(MIN_PRIORITY);
033            }
034    
035            @Override
036            public void run() {
037                    try {
038                            sleep(1000 * 10);
039                    }
040                    catch (InterruptedException ie) {
041                    }
042    
043                    while (_started) {
044                            try {
045                                    sleep(_autoDeployDir.getInterval());
046                            }
047                            catch (InterruptedException ie) {
048                            }
049    
050                            _autoDeployDir.scanDirectory();
051                    }
052            }
053    
054            public void pause() {
055                    _started = false;
056            }
057    
058            private AutoDeployDir _autoDeployDir;
059            private boolean _started = true;
060    
061    }