001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.deploy.auto;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    
020    /**
021     * @author Ivica Cardic
022     * @author Brian Wing Shun Chan
023     */
024    public class AutoDeployScanner extends Thread {
025    
026            public AutoDeployScanner(
027                    ThreadGroup threadGroup, String name, AutoDeployDir autoDeployDir) {
028    
029                    super(threadGroup, name);
030    
031                    _autoDeployDir = autoDeployDir;
032    
033                    setContextClassLoader(getClass().getClassLoader());
034                    setDaemon(true);
035                    setPriority(MIN_PRIORITY);
036            }
037    
038            public void pause() {
039                    _started = false;
040            }
041    
042            @Override
043            public void run() {
044                    try {
045                            sleep(1000 * 10);
046                    }
047                    catch (InterruptedException ie) {
048                    }
049    
050                    while (_started) {
051                            try {
052                                    sleep(_autoDeployDir.getInterval());
053                            }
054                            catch (InterruptedException ie) {
055                            }
056    
057                            try {
058                                    _autoDeployDir.scanDirectory();
059                            }
060                            catch (Exception e) {
061                                    if (_log.isWarnEnabled()) {
062                                            _log.warn("Unable to scan the auto deploy directory", e);
063                                    }
064                            }
065                    }
066            }
067    
068            private static Log _log = LogFactoryUtil.getLog(AutoDeployScanner.class);
069    
070            private AutoDeployDir _autoDeployDir;
071            private boolean _started = true;
072    
073    }