1 9 10 package org.jboss.deployment.cache; 11 12 import java.net.URL ; 13 14 import javax.management.ObjectName ; 15 import javax.management.MBeanServer ; 16 17 import org.jboss.system.ServiceMBeanSupport; 18 import org.jboss.system.MissingAttributeException; 19 20 import org.jboss.deployment.Deployer; 21 import org.jboss.deployment.DeploymentException; 22 23 import org.jboss.util.NullArgumentException; 24 import org.jboss.mx.util.MBeanProxyExt; 25 import org.jboss.mx.util.MBeanProxyInstance; 26 27 39 public class DeploymentCache 40 extends ServiceMBeanSupport 41 implements Deployer, DeploymentCacheMBean 42 { 43 44 protected Deployer deployer; 45 46 47 protected DeploymentStore store; 48 49 50 54 57 public void setDeployer(final ObjectName deployerName) 58 { 59 if (deployerName == null) 60 throw new NullArgumentException("deployerName"); 61 62 deployer = (Deployer) 63 MBeanProxyExt.create(Deployer.class, deployerName, server); 64 } 65 66 69 public ObjectName getDeployer() 70 { 71 return ((MBeanProxyInstance)deployer).getMBeanProxyObjectName(); 72 } 73 74 77 public void setStore(final ObjectName storeName) 78 { 79 if (storeName == null) 80 throw new NullArgumentException("storeName"); 81 82 store = (DeploymentStore) 83 MBeanProxyExt.create(DeploymentStore.class, storeName, server); 84 } 85 86 89 public ObjectName getStore() 90 { 91 return ((MBeanProxyInstance)store).getMBeanProxyObjectName(); 92 } 93 94 95 99 protected boolean isInvalid(final URL orig, final URL stored) 100 throws Exception 101 { 102 boolean trace = log.isTraceEnabled(); 103 104 long omod = orig.openConnection().getLastModified(); 105 long smod = stored.openConnection().getLastModified(); 106 107 if (trace) { 108 log.trace("Modfication times (orig, stored): " + omod + ", " + smod); 109 } 110 111 return omod > smod; 112 } 113 114 public void deploy(final URL url) throws DeploymentException 115 { 116 boolean debug = log.isDebugEnabled(); 117 118 try { 119 URL storedURL = store.get(url); 120 if (storedURL != null) { 121 123 if (isInvalid(url, storedURL)) { 124 log.info("Cached deployment is invalid; refreshing store for URL: " + url); 126 storedURL = store.put(url); 127 } 128 else { 129 if (debug) { 130 log.debug("Using cached deployment URL: " + storedURL); 131 } 132 } 133 } 134 else { 135 log.info("Deployment not in cache; adding URL to store: " + url); 137 storedURL = store.put(url); 138 } 139 140 deployer.deploy(storedURL); 142 } 143 catch (Exception e) { 144 throw new DeploymentException(e); 145 } 146 } 147 148 public void undeploy(final URL url) throws DeploymentException 149 { 150 boolean debug = log.isDebugEnabled(); 151 152 try { 153 URL storedURL = store.get(url); 154 if (storedURL != null) { 155 deployer.undeploy(storedURL); 157 } 158 else { 159 if (debug) { 160 log.debug("Not found in store; ignoring URL: " + url); 161 } 162 } 163 } 164 catch (Exception e) { 165 throw new DeploymentException(e); 166 } 167 } 168 169 public boolean isDeployed(final URL url) 170 { 171 try { 172 URL storedURL = store.get(url); 173 174 return storedURL != null && deployer.isDeployed(url); 177 } 178 catch (Exception e) { 179 return false; 180 } 181 } 182 183 184 188 protected void createService() throws Exception 189 { 190 } 192 193 protected void startService() throws Exception 194 { 195 if (deployer == null) 196 throw new MissingAttributeException("Deployer"); 197 if (store == null) 198 throw new MissingAttributeException("Store"); 199 200 } 202 203 protected void stopService() throws Exception 204 { 205 } 207 208 protected void destroyService() throws Exception 209 { 210 deployer = null; 211 store = null; 212 } 213 } 214 | Popular Tags |