| Method from org.jboss.deployment.scanner.URLDeploymentScanner Detail: |
public void addURL(URL url) {
if (url == null)
throw new NullArgumentException("url");
try
{
// check if this is a valid url
url.openConnection().connect();
}
catch (IOException e)
{
// either a bad configuration (non-existent url) or a transient i/o error
log.warn("addURL(), caught " + e.getClass().getName() + ": " + e.getMessage());
}
urlList.add(url);
log.debug("Added url: " + url);
}
|
public void addURL(String urlspec) throws MalformedURLException {
addURL(makeURL(urlspec));
}
|
protected void createService() throws Exception {
// Perform a couple of sanity checks
if (this.filter == null)
{
throw new IllegalStateException("'FilterInstance' attribute not configured");
}
if (this.sorter == null)
{
throw new IllegalStateException("'URLComparator' attribute not configured");
}
// ok, proceed with normal createService()
super.createService();
}
|
protected void deploy(URLDeploymentScanner.DeployedURL du) {
// If the deployer is null simply ignore the request
if (deployer == null)
return;
try
{
if (log.isTraceEnabled())
log.trace("Deploying: " + du);
deployer.deploy(du.url);
}
catch (IncompleteDeploymentException e)
{
lastIncompleteDeploymentException = e;
}
catch (Exception e)
{
log.debug("Failed to deploy: " + du, e);
}
du.deployed();
if (!deployedSet.contains(du))
{
deployedSet.add(du);
}
}
A helper to deploy the given URL with the deployer. |
public String getFilter() {
if (filter == null)
return null;
return filter.getClass().getName();
}
|
public URLFilter getFilterInstance() {
return filter;
}
|
public boolean getRecursiveSearch() {
return doRecursiveSearch;
}
|
public String getURLComparator() {
if (sorter == null)
return null;
return sorter.getClass().getName();
}
|
public List getURLList() {
// too bad, List isn't a cloneable
return new ArrayList(urlList);
}
|
public boolean hasURL(URL url) {
if (url == null)
throw new NullArgumentException("url");
return urlList.contains(url);
}
|
public boolean hasURL(String urlspec) throws MalformedURLException {
return hasURL(makeURL(urlspec));
}
|
protected boolean isDeployed(URL url) {
DeployedURL du = new DeployedURL(url);
return deployedSet.contains(du);
}
Checks if the url is in the deployed set. |
public String listDeployedURLs() {
StringBuffer sbuf = new StringBuffer();
for (Iterator i = deployedSet.iterator(); i.hasNext(); )
{
URL url = ((DeployedURL)i.next()).url;
if (sbuf.length() > 0)
{
sbuf.append("\n").append(url);
}
else
{
sbuf.append(url);
}
}
return sbuf.toString();
}
Lists all urls deployed by the scanner, each URL on a new line. |
protected URL makeURL(String urlspec) throws MalformedURLException {
// First replace URL with appropriate properties
//
urlspec = StringPropertyReplacer.replaceProperties (urlspec);
return new URL(serverHomeURL, urlspec);
}
A helper to make a URL from a full url, or a filespec. |
public ObjectName preRegister(MBeanServer server,
ObjectName name) throws Exception {
// get server's home for relative paths, need this for setting
// attribute final values, so we need to do it here
ServerConfig serverConfig = ServerConfigLocator.locate();
serverHome = serverConfig.getServerHomeDir();
serverHomeURL = serverConfig.getServerHomeURL();
return super.preRegister(server, name);
}
|
public void removeURL(URL url) {
if (url == null)
throw new NullArgumentException("url");
boolean success = urlList.remove(url);
if (success)
{
log.debug("Removed url: " + url);
}
}
|
public void removeURL(String urlspec) throws MalformedURLException {
removeURL(makeURL(urlspec));
}
|
public void resumeDeployment(URL url,
boolean markUpToDate) {
if (url == null)
throw new NullArgumentException("url");
if (skipSet.contains(url))
{
if (markUpToDate)
{
// look for the deployment and mark it as uptodate
for (Iterator i = deployedSet.iterator(); i.hasNext(); )
{
DeployedURL deployedURL = (DeployedURL)i.next();
if (deployedURL.url.equals(url))
{
// the module could have been removed..
log.debug("Marking up-to-date: " + url);
deployedURL.deployed();
break;
}
}
}
// don't skip this url anymore
skipSet.remove(url);
log.debug("Deployment URL removed from skipSet: " + url);
}
else
{
throw new IllegalStateException("Deployment URL not suspended: " + url);
}
}
Re-enables scanning of a particular deployment URL, previously suspended
using suspendDeployment(URL). If the markUpToDate flag is true then the
deployment module will be considered up-to-date during the next scan.
If the flag is false, at the next scan the scanner will check the
modification date to decide if the module needs deploy/redeploy/undeploy. |
public synchronized void scan() throws Exception {
lastIncompleteDeploymentException = null;
if (urlList == null)
throw new IllegalStateException("not initialized");
updateSorter();
boolean trace = log.isTraceEnabled();
List urlsToDeploy = new LinkedList();
// Scan for deployments
if (trace)
{
log.trace("Scanning for new deployments");
}
synchronized (urlList)
{
for (Iterator i = urlList.iterator(); i.hasNext();)
{
URL url = (URL) i.next();
try
{
if (url.toString().endsWith("/"))
{
// treat URL as a collection
URLLister lister = listerFactory.createURLLister(url);
// listMembers() will throw an IOException if collection url does not exist
urlsToDeploy.addAll(lister.listMembers(url, filter, doRecursiveSearch));
}
else
{
// treat URL as a deployable unit
// throws IOException if this URL does not exist
url.openConnection().connect();
urlsToDeploy.add(url);
}
}
catch (IOException e)
{
// Either one of the configured URLs is bad, i.e. points to a non-existent
// location, or it ends with a '/' but it is not a directory (so it
// is really user's fault), OR some other hopefully transient I/O error
// happened (e.g. out of file descriptors?) so log a warning.
log.warn("Scan URL, caught " + e.getClass().getName() + ": " + e.getMessage());
// We need to return because at least one of the listed URLs will
// return no results, and so all deployments starting from that point
// (e.g. deploy/) will get undeployed, see JBAS-3107.
// On the other hand, in case of a bad configuration nothing will get
// deployed. If really want independence of e.g. 2 deploy urls, more
// than one URLDeploymentScanners can be setup.
return;
}
}
}
if (trace)
{
log.trace("Updating existing deployments");
}
LinkedList urlsToRemove = new LinkedList();
LinkedList urlsToCheckForUpdate = new LinkedList();
synchronized (deployedSet)
{
// remove previously deployed URLs no longer needed
for (Iterator i = deployedSet.iterator(); i.hasNext();)
{
DeployedURL deployedURL = (DeployedURL) i.next();
if (skipSet.contains(deployedURL.url))
{
if (trace)
log.trace("Skipping update/removal check for: " + deployedURL.url);
}
else
{
if (urlsToDeploy.contains(deployedURL.url))
{
urlsToCheckForUpdate.add(deployedURL);
}
else
{
urlsToRemove.add(deployedURL);
}
}
}
}
// ********
// Undeploy
// ********
for (Iterator i = urlsToRemove.iterator(); i.hasNext();)
{
DeployedURL deployedURL = (DeployedURL) i.next();
if (trace)
{
log.trace("Removing " + deployedURL.url);
}
undeploy(deployedURL);
}
// ********
// Redeploy
// ********
// compute the DeployedURL list to update
ArrayList urlsToUpdate = new ArrayList(urlsToCheckForUpdate.size());
for (Iterator i = urlsToCheckForUpdate.iterator(); i.hasNext();)
{
DeployedURL deployedURL = (DeployedURL) i.next();
if (deployedURL.isModified())
{
if (trace)
{
log.trace("Re-deploying " + deployedURL.url);
}
urlsToUpdate.add(deployedURL);
}
}
// sort to update list
Collections.sort(urlsToUpdate, new Comparator()
{
public int compare(Object o1, Object o2)
{
return sorter.compare(((DeployedURL) o1).url, ((DeployedURL) o2).url);
}
});
// Undeploy in order
for (int i = urlsToUpdate.size() - 1; i >= 0;i--)
{
undeploy((DeployedURL) urlsToUpdate.get(i));
}
// Deploy in order
for (int i = 0; i < urlsToUpdate.size();i++)
{
deploy((DeployedURL) urlsToUpdate.get(i));
}
// ******
// Deploy
// ******
Collections.sort(urlsToDeploy, sorter);
for (Iterator i = urlsToDeploy.iterator(); i.hasNext();)
{
URL url = (URL) i.next();
DeployedURL deployedURL = new DeployedURL(url);
if (deployedSet.contains(deployedURL) == false)
{
if (skipSet.contains(url))
{
if (trace)
log.trace("Skipping deployment of: " + url);
}
else
{
if (trace)
log.trace("Deploying " + deployedURL.url);
deploy(deployedURL);
}
}
i.remove();
// Check to see if mainDeployer suffix list has changed.
// if so, then resort
if (i.hasNext() && updateSorter())
{
Collections.sort(urlsToDeploy, sorter);
i = urlsToDeploy.iterator();
}
}
// Validate that there are still incomplete deployments
if (lastIncompleteDeploymentException != null)
{
try
{
Object[] args = {};
String[] sig = {};
getServer().invoke(getDeployer(),
"checkIncompleteDeployments", args, sig);
}
catch (Exception e)
{
Throwable t = JMXExceptionDecoder.decode(e);
log.error(t);
}
}
}
|
public void setFilter(String classname) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Class filterClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
filter = (URLFilter) filterClass.newInstance();
}
|
public void setFilterInstance(URLFilter filter) {
this.filter = filter;
}
|
public void setRecursiveSearch(boolean recurse) {
doRecursiveSearch = recurse;
}
|
public void setURLComparator(String classname) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
sorter = (Comparator)Thread.currentThread().getContextClassLoader().loadClass(classname).newInstance();
}
|
public void setURLList(List list) {
if (list == null)
throw new NullArgumentException("list");
// start out with a fresh list
urlList.clear();
Iterator iter = list.iterator();
while (iter.hasNext())
{
URL url = (URL)iter.next();
if (url == null)
throw new NullArgumentException("list element");
addURL(url);
}
log.debug("URL list: " + urlList);
}
|
public void setURLs(String listspec) throws MalformedURLException {
if (listspec == null)
throw new NullArgumentException("listspec");
List list = new LinkedList();
StringTokenizer stok = new StringTokenizer(listspec, ",");
while (stok.hasMoreTokens())
{
String urlspec = stok.nextToken().trim();
log.debug("Adding URL from spec: " + urlspec);
URL url = makeURL(urlspec);
log.debug("URL: " + url);
list.add(url);
}
setURLList(list);
}
|
public void suspendDeployment(URL url) {
if (url == null)
throw new NullArgumentException("url");
if (skipSet.add(url))
log.debug("Deployment URL added to skipSet: " + url);
else
throw new IllegalStateException("Deployment URL already suspended: " + url);
}
Temporarily ignore changes (addition, updates, removal) to a particular
deployment, identified by its deployment URL. The deployment URL is different
from the 'base' URLs that are scanned by the scanner (e.g. the full path to
deploy/jmx-console.war vs. deploy/). This can be used to avoid an attempt
by the scanner to deploy/redeploy/undeploy a URL that is being modified.
To re-enable scanning of changes for a URL, use resumeDeployment(URL, boolean). |
protected void undeploy(URLDeploymentScanner.DeployedURL du) {
try
{
if (log.isTraceEnabled())
log.trace("Undeploying: " + du);
deployer.undeploy(du.url);
deployedSet.remove(du);
}
catch (Exception e)
{
log.error("Failed to undeploy: " + du, e);
}
}
A helper to undeploy the given URL from the deployer. |
protected boolean updateSorter() {
// Check to see if mainDeployer suffix list has changed.
if (sorter instanceof DefaultDeploymentSorter)
{
DefaultDeploymentSorter defaultSorter = (DefaultDeploymentSorter)sorter;
if (defaultSorter.getSuffixOrder() != mainDeployer.getSuffixOrder())
{
defaultSorter.setSuffixOrder(mainDeployer.getSuffixOrder());
return true;
}
}
return false;
}
|