001    /**
002     * Copyright (c) 2000-2013 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                    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    }