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.sandbox;
016    
017    /**
018     * @author Igor Spasic
019     * @author Brian Wing Shun Chan
020     */
021    public class SandboxDeployScanner extends Thread {
022    
023            public SandboxDeployScanner(
024                    ThreadGroup threadGroup, String name,
025                    SandboxDeployDir sandboxDeployDir) {
026    
027                    super(threadGroup, name);
028    
029                    _sandboxDeployDir = sandboxDeployDir;
030    
031                    setContextClassLoader(getClass().getClassLoader());
032                    setDaemon(true);
033                    setPriority(MIN_PRIORITY);
034            }
035    
036            public void pause() {
037                    _started = false;
038            }
039    
040            @Override
041            public void run() {
042                    try {
043                            sleep(1000 * 10);
044                    }
045                    catch (InterruptedException ie) {
046                    }
047    
048                    while (_started) {
049                            try {
050                                    sleep(_sandboxDeployDir.getInterval());
051                            }
052                            catch (InterruptedException ie) {
053                            }
054    
055                            _sandboxDeployDir.scanDirectory();
056                    }
057            }
058    
059            private SandboxDeployDir _sandboxDeployDir;
060            private boolean _started = true;
061    
062    }