1 21 22 package org.apache.derby.impl.services.monitor; 23 24 import org.apache.derby.iapi.services.monitor.Monitor; 25 import org.apache.derby.iapi.reference.Property; 26 27 import org.apache.derby.iapi.services.io.FileUtil; 28 import org.apache.derby.iapi.services.info.ProductVersionHolder; 29 import org.apache.derby.iapi.services.info.ProductGenusNames; 30 31 import java.io.FileInputStream ; 32 import java.io.File ; 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 36 import java.net.URL ; 37 import java.util.Enumeration ; 38 import java.util.Properties ; 39 40 45 46 public final class FileMonitor extends BaseMonitor implements java.security.PrivilegedExceptionAction 47 { 48 49 50 private File home; 51 52 private ProductVersionHolder engineVersion; 53 54 public FileMonitor() { 55 initialize(true); 56 applicationProperties = readApplicationProperties(); 57 } 58 59 public FileMonitor(java.util.Properties properties, java.io.PrintStream log) { 60 runWithState(properties, log); 61 } 62 63 64 65 private InputStream PBapplicationPropertiesStream() 66 throws IOException { 67 68 File sr = FileUtil.newFile(home, Property.PROPERTIES_FILE); 69 70 if (!sr.exists()) 71 return null; 72 73 return new FileInputStream (sr); 74 } 75 76 public Object getEnvironment() { 77 return home; 78 } 79 80 81 82 91 private boolean PBinitialize(boolean lite) 92 { 93 if (!lite) { 94 try { 95 daemonGroup = new ThreadGroup ("derby.daemons"); 100 daemonGroup.setDaemon(true); 101 } catch (SecurityException se) { 102 } 103 } 104 105 InputStream versionStream = getClass().getResourceAsStream(ProductGenusNames.DBMS_INFO); 106 107 engineVersion = ProductVersionHolder.getProductVersionHolderFromMyEnv(versionStream); 108 109 String systemHome; 110 try { 112 systemHome = System.getProperty(Property.SYSTEM_HOME_PROPERTY); 114 } catch (SecurityException se) { 115 systemHome = null; 117 } 118 119 if (systemHome != null) { 120 home = new File (systemHome); 121 122 if (home.exists()) { 124 if (!home.isDirectory()) { 125 report(Property.SYSTEM_HOME_PROPERTY + "=" + systemHome 126 + " does not represent a directory"); 127 return false; 128 } 129 } else if (!lite) { 130 131 try { 132 home.mkdirs(); 134 } catch (SecurityException se) { 135 return false; 136 } 137 } 138 } 139 140 return true; 141 } 142 143 153 private String PBgetJVMProperty(String key) { 154 155 try { 156 return System.getProperty(key); 158 } catch (SecurityException se) { 159 return null; 160 } 161 } 162 163 166 167 private int action; 168 private String key3; 169 private Runnable task; 170 private int intValue; 171 172 175 synchronized final boolean initialize(boolean lite) 176 { 177 action = lite ? 0 : 1; 178 try { 179 Object ret = java.security.AccessController.doPrivileged(this); 180 181 return ((Boolean ) ret).booleanValue(); 182 } catch (java.security.PrivilegedActionException pae) { 183 throw (RuntimeException ) pae.getException(); 184 } 185 } 186 187 synchronized final Properties getDefaultModuleProperties() { 188 action = 2; 189 try { 190 return (Properties ) java.security.AccessController.doPrivileged(this); 191 } catch (java.security.PrivilegedActionException pae) { 192 throw (RuntimeException ) pae.getException(); 193 } 194 } 195 196 public synchronized final String getJVMProperty(String key) { 197 if (!key.startsWith("derby.")) 198 return PBgetJVMProperty(key); 199 200 try { 201 202 action = 3; 203 key3 = key; 204 String value = (String ) java.security.AccessController.doPrivileged(this); 205 key3 = null; 206 return value; 207 } catch (java.security.PrivilegedActionException pae) { 208 throw (RuntimeException ) pae.getException(); 209 } 210 } 211 212 public synchronized final Thread getDaemonThread(Runnable task, String name, boolean setMinPriority) { 213 214 action = 4; 215 key3 = name; 216 this.task = task; 217 this.intValue = setMinPriority ? 1 : 0; 218 219 try { 220 221 Thread t = (Thread ) java.security.AccessController.doPrivileged(this); 222 223 key3 = null; 224 task = null; 225 226 return t; 227 } catch (java.security.PrivilegedActionException pae) { 228 throw (RuntimeException ) pae.getException(); 229 } 230 } 231 232 public synchronized final void setThreadPriority(int priority) { 233 action = 5; 234 intValue = priority; 235 try { 236 java.security.AccessController.doPrivileged(this); 237 } catch (java.security.PrivilegedActionException pae) { 238 throw (RuntimeException ) pae.getException(); 239 } 240 } 241 242 synchronized final InputStream applicationPropertiesStream() 243 throws IOException { 244 action = 6; 245 try { 246 return (InputStream ) java.security.AccessController.doPrivileged(this); 248 } 249 catch (java.security.PrivilegedActionException pae) 250 { 251 throw (IOException ) pae.getException(); 252 } 253 } 254 255 256 public synchronized final Object run() throws IOException { 257 switch (action) { 258 case 0: 259 case 1: 260 return new Boolean (PBinitialize(action == 0)); 262 case 2: 263 return super.getDefaultModuleProperties(); 265 case 3: 266 return PBgetJVMProperty(key3); 268 case 4: 269 return super.getDaemonThread(task, key3, intValue != 0); 270 case 5: 271 super.setThreadPriority(intValue); 272 return null; 273 case 6: 274 return PBapplicationPropertiesStream(); 276 277 default: 278 return null; 279 } 280 } 281 282 public final ProductVersionHolder getEngineVersion() { 283 return engineVersion; 284 } 285 } 286 | Popular Tags |