001    /**
002     * Copyright (c) 2000-present 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    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                    Class<?> clazz = getClass();
034    
035                    setContextClassLoader(clazz.getClassLoader());
036    
037                    setDaemon(true);
038                    setPriority(MIN_PRIORITY);
039            }
040    
041            public void pause() {
042                    _started = false;
043            }
044    
045            @Override
046            public void run() {
047                    try {
048                            sleep(1000 * 10);
049                    }
050                    catch (InterruptedException ie) {
051                    }
052    
053                    while (_started) {
054                            try {
055                                    sleep(_autoDeployDir.getInterval());
056                            }
057                            catch (InterruptedException ie) {
058                            }
059    
060                            try {
061                                    _autoDeployDir.scanDirectory();
062                            }
063                            catch (Exception e) {
064                                    if (_log.isWarnEnabled()) {
065                                            _log.warn("Unable to scan the auto deploy directory", e);
066                                    }
067                            }
068                    }
069            }
070    
071            private static final Log _log = LogFactoryUtil.getLog(
072                    AutoDeployScanner.class);
073    
074            private final AutoDeployDir _autoDeployDir;
075            private boolean _started = true;
076    
077    }