[jboss-cvs] JBossAS SVN: r85574 - in branches/Branch_5_x: system/src/main/org/jboss/system/server/profileservice/hotdeploy and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 6 17:05:15 EST 2009
Author: alesj
Date: 2009-03-06 17:05:14 -0500 (Fri, 06 Mar 2009)
New Revision: 85574
Added:
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/Scanner.java
Modified:
branches/Branch_5_x/profileservice/src/resources/hdscanner-jboss-beans.xml
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java
branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentRepositoryAdapter.java
branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentScanner.java
branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentScannerMBean.java
branches/Branch_5_x/system/src/main/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java
Log:
[JBAS-6330]; enhance Tool's api.
Modified: branches/Branch_5_x/profileservice/src/resources/hdscanner-jboss-beans.xml
===================================================================
--- branches/Branch_5_x/profileservice/src/resources/hdscanner-jboss-beans.xml 2009-03-06 22:00:44 UTC (rev 85573)
+++ branches/Branch_5_x/profileservice/src/resources/hdscanner-jboss-beans.xml 2009-03-06 22:05:14 UTC (rev 85574)
@@ -8,10 +8,8 @@
<deployment xmlns="urn:jboss:bean-deployer:2.0">
<!-- Hotdeployment of applications -->
- <bean name="HDScanner"
- class="org.jboss.system.server.profileservice.hotdeploy.HDScanner">
+ <bean name="HDScanner" class="org.jboss.system.server.profileservice.hotdeploy.HDScanner">
<property name="deployer"><inject bean="ProfileServiceDeployer"/></property>
- <property name="controller"><inject bean="jboss.kernel:service=KernelController"/></property>
<property name="profileService"><inject bean="ProfileService"/></property>
<property name="scanPeriod">5000</property>
<property name="scanThreadName">HDScanner</property>
@@ -26,6 +24,7 @@
<bean name="ProfileServiceDeploymentRepositoryAdapter" class="org.jboss.system.tools.ProfileServiceDeploymentRepositoryAdapter">
<constructor>
+ <parameter><inject bean="HDScanner"/></parameter>
<parameter><inject bean="ProfileService"/></parameter>
</constructor>
</bean>
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java 2009-03-06 22:00:44 UTC (rev 85573)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java 2009-03-06 22:05:14 UTC (rev 85574)
@@ -29,7 +29,6 @@
import java.util.concurrent.TimeUnit;
import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.logging.Logger;
import org.jboss.profileservice.spi.ModificationInfo;
import org.jboss.profileservice.spi.MutableProfile;
@@ -45,68 +44,66 @@
* is really just a simple ExecutorService Runnable that knows nothing
* about how to detect changed deployers. The ProfileService determines
* this.
- *
- * @see MainDeployer
- * @see ProfileService
- *
+ *
* @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
* @author Scott.Stark at jboss.org
* @author adrian at jboss.org
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
* @version $Revision$
+ * @see MainDeployer
+ * @see ProfileService
*/
-public class HDScanner
- implements Runnable
+public class HDScanner implements Runnable, Scanner
{
private static final Logger log = Logger.getLogger(HDScanner.class);
- // Private Data --------------------------------------------------
- /** The MainDeployer used to deploy modifications */
+
+ /**
+ * The MainDeployer used to deploy modifications
+ */
private MainDeployerAdapter deployer;
- /** The controller */
- private KernelController controller;
- /** The ProfileService used to determine modified deployments */
+ /**
+ * The ProfileService used to determine modified deployments
+ */
private ProfileService profileService;
- /** The ExecutorService/ThreadPool for performing scans */
+ /**
+ * The ExecutorService/ThreadPool for performing scans
+ */
private ScheduledExecutorService scanExecutor;
private ScheduledFuture activeScan;
- /** Thread name used when the ScheduledExecutorService is created internally */
+
+ /**
+ * Thread name used when the ScheduledExecutorService is created internally
+ */
private String scanThreadName = "HDScanner";
- /** Period in ms between deployment scans */
+ /**
+ * Period in ms between deployment scans
+ */
private long scanPeriod = 5000;
- /** The number of scans that have been done */
+
+ /**
+ * The number of scans that have been done
+ */
private int scanCount;
- // Constructor ---------------------------------------------------
-
- public HDScanner()
- {
- // empty
- }
-
- // Attributes ----------------------------------------------------
+ /**
+ * The suspended flag
+ */
+ private boolean suspended;
public void setDeployer(MainDeployerAdapter deployer)
{
this.deployer = deployer;
}
- public KernelController getController()
- {
- return controller;
- }
-
- public void setController(KernelController controller)
- {
- this.controller = controller;
- }
-
public ProfileService getProfileService()
{
return profileService;
}
+
public void setProfileService(ProfileService profileService)
{
this.profileService = profileService;
@@ -145,17 +142,18 @@
{
return scanPeriod;
}
+
/* (non-Javadoc)
- * @see org.jboss.deployment.scanner.VFSDeploymentScanner#setScanPeriod(long)
- */
+ * @see org.jboss.deployment.scanner.VFSDeploymentScanner#setScanPeriod(long)
+ */
public void setScanPeriod(long period)
{
this.scanPeriod = period;
}
- /**
+ /**
* Are deployment scans enabled.
- *
+ *
* @return whether scan is enabled
*/
public boolean isScanEnabled()
@@ -167,6 +165,7 @@
{
return scanCount;
}
+
public synchronized void resetScanCount()
{
this.scanCount = 0;
@@ -174,52 +173,54 @@
/**
* Enable/disable deployment scans.
+ *
* @param scanEnabled true to enable scans, false to disable.
*/
public synchronized void setScanEnabled(boolean scanEnabled)
{
- if( scanEnabled == true && activeScan == null )
+ if (scanEnabled == true && activeScan == null)
{
- activeScan = this.scanExecutor.scheduleWithFixedDelay(this, 0,
- scanPeriod, TimeUnit.MILLISECONDS);
+ start();
}
- else if( scanEnabled == false && activeScan != null )
+ else if (scanEnabled == false && activeScan != null)
{
- activeScan.cancel(true);
- activeScan = null;
+ stop();
}
}
-
- // Operations ----------------------------------------------------
-
public void create() throws Exception
{
// Default to a single thread executor
- if( scanExecutor == null )
+ if (scanExecutor == null)
{
scanExecutor = Executors.newSingleThreadScheduledExecutor(
- new ThreadFactory()
- {
- public Thread newThread(Runnable r)
+ new ThreadFactory()
{
- return new Thread(r, HDScanner.this.getScanThreadName());
+ public Thread newThread(Runnable r)
+ {
+ return new Thread(r, HDScanner.this.getScanThreadName());
+ }
}
- }
- );
+ );
}
}
-
-
- public void start() throws Exception
+
+ public void start()
{
- activeScan = scanExecutor.scheduleWithFixedDelay(this, 0,
- scanPeriod, TimeUnit.MILLISECONDS);
+ activeScan = scanExecutor.scheduleWithFixedDelay(this, 0, scanPeriod, TimeUnit.MILLISECONDS);
}
+ public synchronized void stop()
+ {
+ if (activeScan != null)
+ {
+ activeScan.cancel(true);
+ activeScan = null;
+ }
+ }
+
/**
- * Executes scan
- *
+ * Executes scan
*/
public void run()
{
@@ -227,7 +228,7 @@
{
scan();
}
- catch(Throwable e)
+ catch (Throwable e)
{
log.warn("Scan failed", e);
}
@@ -237,67 +238,82 @@
}
}
- public void stop()
+ public synchronized void suspend()
{
- if( activeScan != null )
+ suspended = (activeScan != null);
+ if (suspended)
{
- activeScan.cancel(true);
+ activeScan.cancel(false);
+ while(activeScan.isDone() == false)
+ {
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException ignored)
+ {
+ }
+ }
activeScan = null;
}
}
+ public synchronized void resume()
+ {
+ if (suspended)
+ {
+ start();
+ }
+ suspended = false;
+ }
+
public synchronized void scan() throws Exception
{
boolean trace = log.isTraceEnabled();
// Query the ProfileService for deployments
- if( trace )
+ if (trace)
log.trace("Begin deployment scan");
// Get the active profiles
Collection<ProfileKey> activeProfiles = profileService.getActiveProfileKeys();
- if(activeProfiles == null || activeProfiles.isEmpty())
+ if (activeProfiles == null || activeProfiles.isEmpty())
{
- if( trace )
+ if (trace)
log.trace("End deployment scan, no active profiles");
return;
}
- // Current workaround for JBAS-4206
- Profile firstProfile = null;
// Get the modified deployments
boolean modified = false;
- for(ProfileKey key : activeProfiles)
+ for (ProfileKey key : activeProfiles)
{
// The profile
- Profile profile = null;
+ Profile profile;
try
{
profile = profileService.getActiveProfile(key);
}
- catch(NoSuchProfileException ignore)
+ catch (NoSuchProfileException ignore)
{
- if(trace)
- log.debug("failed to get profile for key: "+ key);
+ if (trace)
+ log.debug("failed to get profile for key: " + key);
continue;
}
// Check if it's a mutable profile
- if( profile.isMutable() == false)
+ if (profile.isMutable() == false)
{
- if( trace )
- log.trace("Ignoring not mutable profile: "+ key);
+ if (trace)
+ log.trace("Ignoring not mutable profile: " + key);
continue;
}
- MutableProfile activeProfile = (MutableProfile) profile;
- // Current workaround for JBAS-4206
- if(firstProfile == null)
- firstProfile = activeProfile;
-
+
+ MutableProfile activeProfile = (MutableProfile)profile;
Collection<ModificationInfo> modifiedDeployments = activeProfile.getModifiedDeployments();
- for(ModificationInfo info : modifiedDeployments)
+ for (ModificationInfo info : modifiedDeployments)
{
ProfileDeployment ctx = info.getDeployment();
- switch( info.getStatus() )
+ switch (info.getStatus())
{
case ADDED:
case MODIFIED:
@@ -308,32 +324,20 @@
break;
}
}
-
- if(modifiedDeployments.size() > 0)
+
+ if (modifiedDeployments.size() > 0)
modified = true;
}
// Process the changes
try
{
- if( modified )
+ if (modified)
{
- // Current workaround for JBAS-4206
-// ClassLoader oldTCL = Thread.currentThread().getContextClassLoader();
-// ClassLoader tcl = getTCL(firstProfile);
- try
- {
-// if (tcl != null)
-// Thread.currentThread().setContextClassLoader(tcl);
- deployer.process();
- // Can be nulled by a shutdown
- if(deployer != null)
- deployer.checkComplete();
- }
- finally
- {
-// Thread.currentThread().setContextClassLoader(oldTCL);
- }
+ deployer.process();
+ // Can be nulled by a shutdown
+ if (deployer != null)
+ deployer.checkComplete();
}
}
catch (Exception e)
@@ -342,53 +346,18 @@
// TODO: somehow need to ignore bad deployments to avoid repeated errors
return;
}
-
- if( trace )
+
+ if (trace)
log.trace("End deployment scan");
}
/**
* Inc the scanCount and to a notifyAll.
- *
*/
protected synchronized void incScanCount()
{
- scanCount ++;
+ scanCount++;
notifyAll();
}
-
- // Private -------------------------------------------------------
-
- /**
- * Current workaround for JBAS-4206
- */
-// private ClassLoader getTCL(Profile activeProfile)
-// throws Exception
-// {
-// MainDeployerStructure structure = (MainDeployerStructure) mainDeployer;
-// Collection<VFSDeployment> ctxs = activeProfile.getDeployments();
-// if (ctxs != null && ctxs.isEmpty() == false)
-// {
-// for (VFSDeployment deployment : ctxs)
-// {
-// DeploymentUnit unit = structure.getDeploymentUnit(deployment.getName());
-// if (unit != null)
-// {
-// try
-// {
-// ClassLoader cl = unit.getClassLoader();
-// if (cl != null)
-// return cl;
-// }
-// catch (Exception ignored)
-// {
-// }
-// }
-//
-// }
-// }
-// log.warn("No bootstrap deployments? profile=" + activeProfile);
-// return null;
-// }
}
Copied: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/Scanner.java (from rev 85545, branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java)
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/Scanner.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/hotdeploy/Scanner.java 2009-03-06 22:05:14 UTC (rev 85574)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.hotdeploy;
+
+/**
+ * Simple scanner interface.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface Scanner
+{
+ /**
+ * Suspend scanning.
+ */
+ void suspend();
+
+ /**
+ * Resume scanning.
+ */
+ void resume();
+
+ /**
+ * Do scan.
+ *
+ * @throws Exception for any error
+ */
+ void scan() throws Exception;
+}
\ No newline at end of file
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentRepositoryAdapter.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentRepositoryAdapter.java 2009-03-06 22:00:44 UTC (rev 85573)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentRepositoryAdapter.java 2009-03-06 22:05:14 UTC (rev 85574)
@@ -56,4 +56,20 @@
* @throws URISyntaxException for any error
*/
void removeURL(URL url) throws URISyntaxException;
+
+ /**
+ * Do this repository contain a url.
+ *
+ * @param url the url
+ * @return true if the url is contained
+ * @throws URISyntaxException for any error
+ */
+ boolean hasURL(URL url) throws URISyntaxException;
+
+ /**
+ * List deployed urls.
+ *
+ * @return the list of deployed urls
+ */
+ URL[] listDeployedURLs();
}
\ No newline at end of file
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentScanner.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentScanner.java 2009-03-06 22:00:44 UTC (rev 85573)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentScanner.java 2009-03-06 22:05:14 UTC (rev 85574)
@@ -77,24 +77,57 @@
public void addURL(String url) throws MalformedURLException, URISyntaxException
{
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
addURL(makeURL(url));
}
public void addURL(URL url) throws URISyntaxException
{
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
adapter.addURL(url);
}
public void removeURL(String url) throws MalformedURLException, URISyntaxException
{
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
removeURL(makeURL(url));
}
public void removeURL(URL url) throws URISyntaxException
{
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
adapter.removeURL(url);
}
+ public boolean hasURL(String url) throws MalformedURLException, URISyntaxException
+ {
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
+ return hasURL(makeURL(url));
+ }
+
+ public boolean hasURL(URL url) throws URISyntaxException
+ {
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
+ return adapter.hasURL(url);
+ }
+
+ public URL[] listDeployedURLs()
+ {
+ return adapter.listDeployedURLs();
+ }
+
/**
* A helper to make a URL from a full url, or a filespec.
*
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentScannerMBean.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentScannerMBean.java 2009-03-06 22:00:44 UTC (rev 85573)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/tools/DeploymentScannerMBean.java 2009-03-06 22:05:14 UTC (rev 85574)
@@ -75,4 +75,30 @@
* @throws URISyntaxException for any error
*/
void removeURL(URL url) throws URISyntaxException;
+
+ /**
+ * Do this repository contain a url.
+ *
+ * @param url the url
+ * @return true if the url is contained
+ * @throws MalformedURLException for any error
+ * @throws URISyntaxException for any error
+ */
+ boolean hasURL(String url) throws MalformedURLException, URISyntaxException;
+
+ /**
+ * Do this repository contain a url.
+ *
+ * @param url the url
+ * @return true if the url is contained
+ * @throws URISyntaxException for any error
+ */
+ boolean hasURL(URL url) throws URISyntaxException;
+
+ /**
+ * List deployed urls.
+ *
+ * @return the list of deployed urls
+ */
+ URL[] listDeployedURLs();
}
\ No newline at end of file
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java 2009-03-06 22:00:44 UTC (rev 85573)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java 2009-03-06 22:05:14 UTC (rev 85574)
@@ -32,10 +32,14 @@
import org.jboss.logging.Logger;
import org.jboss.profileservice.spi.ModificationInfo;
import org.jboss.profileservice.spi.MutableProfile;
+import org.jboss.profileservice.spi.NoSuchProfileException;
+import org.jboss.profileservice.spi.Profile;
import org.jboss.profileservice.spi.ProfileDeployment;
import org.jboss.profileservice.spi.ProfileKey;
import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.system.server.profileservice.hotdeploy.Scanner;
import org.jboss.system.server.profileservice.repository.MutableDeploymentRepository;
+import org.jboss.virtual.VirtualFile;
/**
* Profile deployment repository adapter.
@@ -48,14 +52,18 @@
private static final Logger log = Logger.getLogger(ProfileServiceDeploymentRepositoryAdapter.class);
private static final ProfileKey profileName = new ProfileKey("deployment-scanner-profile");
+ private Scanner scanner;
private ProfileService ps;
private DeploymentScannerProfile profile;
- public ProfileServiceDeploymentRepositoryAdapter(ProfileService ps)
+ public ProfileServiceDeploymentRepositoryAdapter(Scanner scanner, ProfileService ps)
{
+ if (scanner == null)
+ throw new IllegalArgumentException("Null scanner");
if (ps == null)
- throw new IllegalArgumentException("Null profile service.");
+ throw new IllegalArgumentException("Null profile service");
+ this.scanner = scanner;
this.ps = ps;
}
@@ -99,12 +107,12 @@
public void resume()
{
- profile.enableModifiedDeploymentChecks(true);
+ scanner.resume();
}
public void suspend()
{
- profile.enableModifiedDeploymentChecks(false);
+ scanner.suspend();
}
/**
@@ -136,17 +144,67 @@
public void addURL(URL url) throws URISyntaxException
{
- // TODO
+ profile.getURIs().add(url.toURI());
}
public void removeURL(URL url) throws URISyntaxException
{
- // TODO
+ profile.getURIs().remove(url.toURI());
}
+ public boolean hasURL(URL url) throws URISyntaxException
+ {
+ URI uri = url.toURI();
+ // TODO - this only checks this profile
+ return profile.getURIs().contains(uri);
+ }
+
+ public URL[] listDeployedURLs()
+ {
+ List<URL> urls = new ArrayList<URL>();
+
+ Collection<ProfileKey> activeProfiles = ps.getActiveProfileKeys();
+ if (activeProfiles != null && activeProfiles.isEmpty() == false)
+ {
+ for (ProfileKey key : activeProfiles)
+ {
+ // The profile
+ Profile profile;
+ try
+ {
+ profile = ps.getActiveProfile(key);
+ }
+ catch (NoSuchProfileException ignore)
+ {
+ continue;
+ }
+ Collection<ProfileDeployment> deployments = profile.getDeployments();
+ if (deployments != null && deployments.isEmpty() == false)
+ {
+ for (ProfileDeployment pd : deployments)
+ {
+ VirtualFile root = pd.getRoot();
+ if (root != null)
+ {
+ try
+ {
+ urls.add(root.toURL());
+ }
+ catch (Exception e)
+ {
+ log.warn("Exception while reading root's URL: " + root);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return urls.toArray(new URL[urls.size()]);
+ }
+
public static class DeploymentScannerProfile extends MutableDeploymentRepository implements MutableProfile
{
- private List<URI> uris = new ArrayList<URI>();
private volatile boolean enableHotDeployment;
public DeploymentScannerProfile()
@@ -154,22 +212,16 @@
super(profileName, new URI[0]);
}
- @Override
- public URI[] getRepositoryURIs()
+ /**
+ * Expose uris.
+ *
+ * @return the uris
+ */
+ Collection<URI> getURIs()
{
- return this.uris.toArray(new URI[this.uris.size()]);
- }
-
- public List<URI> getUris()
- {
return uris;
}
- public void setUris(List<URI> uris)
- {
- this.uris = uris;
- }
-
public void addDeployment(ProfileDeployment deployment) throws Exception
{
super.addDeployment(deployment.getName(), deployment);
More information about the jboss-cvs-commits
mailing list