1 19 package org.netbeans.modules.gsf; 20 21 import java.io.File ; 22 import java.lang.management.ManagementFactory ; 23 import javax.management.InstanceAlreadyExistsException ; 24 import javax.management.InstanceNotFoundException ; 25 import javax.management.MBeanRegistrationException ; 26 import javax.management.MBeanServer ; 27 import javax.management.MalformedObjectNameException ; 28 import javax.management.NotCompliantMBeanException ; 29 import javax.management.ObjectName ; 30 import org.netbeans.api.retouche.source.SourceTaskFactoryManager; 31 import org.netbeans.editor.Settings; 32 import org.netbeans.modules.retouche.source.ActivatedDocumentListener; 33 import org.netbeans.modules.retouche.source.usages.ClassIndexManager; 34 import org.netbeans.modules.retouche.source.usages.RepositoryUpdater; 35 import org.netbeans.modules.retouche.source.util.LowMemoryNotifierMBean; 36 import org.netbeans.modules.retouche.source.util.LowMemoryNotifierMBeanImpl; 37 import org.openide.ErrorManager; 38 import org.openide.filesystems.FileUtil; 39 import org.openide.modules.ModuleInstall; 40 import org.openide.windows.WindowManager; 41 42 43 public class GsfModuleInstaller extends ModuleInstall { 44 private static final boolean ENABLE_MBEANS = 45 Boolean.getBoolean("org.netbeans.modules.gsf.enableMBeans"); private static final String NB_USER_DIR = "netbeans.user"; private static final String LUCENE_LOCK_DIR = "org.apache.lucene.lockDir"; 49 @Override 50 public void restored() { 51 Settings.addInitializer(new GsfEditorSettings()); 53 Settings.reset(); 54 55 final String nbUserProp = System.getProperty(NB_USER_DIR); 56 assert nbUserProp != null; 57 final File nbUserDir = new File (nbUserProp); 58 File lockDir = FileUtil.normalizeFile(new File (nbUserDir,"var"+File.separatorChar+"lock"+File.separatorChar+"lucene-gsf")); if (lockDir.exists()) { 60 File [] orphanLocks = lockDir.listFiles(); 61 for (File lock: orphanLocks) { 62 lock.delete(); 63 } 64 } 65 else { 66 lockDir.mkdirs(); 67 } 68 69 70 SourceTaskFactoryManager.register(); 71 System.setProperty(LUCENE_LOCK_DIR,lockDir.getAbsolutePath()); 72 73 WindowManager.getDefault().invokeWhenUIReady(new Runnable () { 74 public void run() { 75 RepositoryUpdater.getDefault(); 76 ActivatedDocumentListener.register(); 77 } 78 }); 79 80 if (ENABLE_MBEANS) { 81 registerMBeans(); 82 } 83 } 84 85 @Override 87 public boolean closing() { 88 final boolean ret = super.closing(); 89 RepositoryUpdater.getDefault().close (); 90 ClassIndexManager.getDefault().close(); 91 if (ENABLE_MBEANS) { 92 unregisterMBeans(); 93 } 94 95 return ret; 96 } 97 98 private static void registerMBeans() { 99 try { 100 MBeanServer mgs = ManagementFactory.getPlatformMBeanServer(); 101 mgs.registerMBean(new LowMemoryNotifierMBeanImpl(), 102 new ObjectName (LowMemoryNotifierMBean.OBJECT_NAME)); 103 } catch (NotCompliantMBeanException e) { 104 ErrorManager.getDefault().notify(e); 105 } catch (MalformedObjectNameException e) { 106 ErrorManager.getDefault().notify(e); 107 } catch (InstanceAlreadyExistsException e) { 108 ErrorManager.getDefault().notify(e); 109 } catch (MBeanRegistrationException e) { 110 ErrorManager.getDefault().notify(e); 111 } 112 } 113 114 private static void unregisterMBeans() { 115 try { 116 MBeanServer mgs = ManagementFactory.getPlatformMBeanServer(); 117 mgs.unregisterMBean(new ObjectName (LowMemoryNotifierMBean.OBJECT_NAME)); 118 } catch (MalformedObjectNameException e) { 119 ErrorManager.getDefault().notify(e); 120 } catch (InstanceNotFoundException e) { 121 ErrorManager.getDefault().notify(e); 122 } catch (MBeanRegistrationException e) { 123 ErrorManager.getDefault().notify(e); 124 } 125 } 126 } 127 | Popular Tags |