1 36 package org.ungoverned.oscar; 37 38 import java.security.AccessController ; 39 import java.util.ArrayList ; 40 import java.util.List ; 41 42 import org.osgi.framework.AdminPermission; 43 import org.osgi.framework.Bundle; 44 import org.osgi.service.startlevel.StartLevel; 45 46 52 public class StartLevelImpl implements StartLevel, Runnable  53 { 54 private Oscar m_oscar = null; 55 private List m_requestList = null; 56 private static AdminPermission m_adminPerm = new AdminPermission(); 58 59 public StartLevelImpl(Oscar oscar) 60 { 61 m_oscar = oscar; 62 m_requestList = new ArrayList (); 63 64 Thread t = new Thread (this, "OscarStartLevel"); 66 t.setDaemon(true); 67 t.start(); 68 } 69 70 73 public int getStartLevel() 74 { 75 return m_oscar.getStartLevel(); 76 } 77 78 81 public void setStartLevel(int startlevel) 82 { 83 if (System.getSecurityManager() != null) 84 { 85 AccessController.checkPermission(m_adminPerm); 86 } 87 else if (startlevel <= 0) 88 { 89 throw new IllegalArgumentException ( 90 "Start level must be greater than zero."); 91 } 92 synchronized (m_requestList) 93 { 94 m_requestList.add(new Integer (startlevel)); 95 m_requestList.notifyAll(); 96 } 97 } 98 99 102 public int getBundleStartLevel(Bundle bundle) 103 { 104 return m_oscar.getBundleStartLevel(bundle); 105 } 106 107 110 public void setBundleStartLevel(Bundle bundle, int startlevel) 111 { 112 m_oscar.setBundleStartLevel(bundle, startlevel); 113 } 114 115 118 public int getInitialBundleStartLevel() 119 { 120 return m_oscar.getInitialBundleStartLevel(); 121 } 122 123 126 public void setInitialBundleStartLevel(int startlevel) 127 { 128 m_oscar.setInitialBundleStartLevel(startlevel); 129 } 130 131 134 public boolean isBundlePersistentlyStarted(Bundle bundle) 135 { 136 return m_oscar.isBundlePersistentlyStarted(bundle); 137 } 138 139 public void run() 140 { 141 int startLevel = 0; 142 143 while (true) 146 { 147 synchronized (m_requestList) 148 { 149 while (m_requestList.size() == 0) 151 { 152 try { 153 m_requestList.wait(); 154 } catch (InterruptedException ex) { 155 } 156 } 157 158 startLevel = ((Integer ) m_requestList.remove(0)).intValue(); 160 } 161 162 m_oscar.setStartLevelInternal(startLevel); 164 } 165 } 166 }
| Popular Tags
|