1 25 package org.objectweb.petals.jbi.component.thread; 26 27 import javax.jbi.JBIException; 28 import javax.jbi.component.Bootstrap; 29 import javax.jbi.component.Component; 30 import javax.jbi.component.InstallationContext; 31 import javax.management.ObjectName ; 32 33 import org.objectweb.petals.jbi.component.lifecycle.Installer; 34 35 42 public class BootstrapThread extends AbstractThread implements Bootstrap { 43 44 47 private Installer installer; 48 49 52 private Component jbiComponent; 53 54 57 private ObjectName objectName; 58 59 62 private Bootstrap jbiBootStrap; 63 64 68 private InstallationContext installContext; 69 70 73 74 public static final int INSTALL = 0; 75 76 public static final int UNINSTALL = 1; 77 78 public static final int INIT = 2; 79 80 public static final int CLEAN = 3; 81 82 public static final int EXTMBEAN = 4; 83 84 90 public BootstrapThread(Installer installer, Bootstrap jbiBootstrap) { 91 super(); 92 this.installer = installer; 93 this.jbiBootStrap = jbiBootstrap; 94 this.setName(this.installer.getComponentName() + "-Installer Thread"); 95 } 96 97 104 protected int doTask(int action) { 105 106 int result = 0; 107 try { 108 switch (action) { 109 case CLEAN: 110 jbiBootStrap.cleanUp(); 111 break; 112 113 case INSTALL: 114 jbiBootStrap.onInstall(); 115 break; 116 117 case UNINSTALL: 118 jbiBootStrap.onUninstall(); 119 break; 120 121 case INIT: 122 jbiBootStrap.init(installContext); 123 break; 124 125 case EXTMBEAN: 126 objectName = jbiBootStrap.getExtensionMBeanName(); 127 break; 128 129 case SHUTDOWNTHREAD: 130 result = -1; 131 break; 132 133 default: 134 break; 136 } 137 138 } catch (JBIException jbie) { 139 jbiException = jbie; 140 } 141 142 return result; 143 } 144 145 149 protected Component getJbiComponent() { 150 return jbiComponent; 151 } 152 153 158 public void cleanUp() throws JBIException { 159 execute(CLEAN); 160 161 JBIException jbie = getJbiException(); 162 if (jbie != null) { 163 throw jbie; 164 } 165 } 166 167 172 public ObjectName getExtensionMBeanName() { 173 execute(EXTMBEAN); 174 return objectName; 175 } 176 177 182 public void init(InstallationContext installContext) throws JBIException { 183 this.installContext = installContext; 184 execute(INIT); 185 186 JBIException jbie = getJbiException(); 187 if (jbie != null) { 188 throw jbie; 189 } 190 } 191 192 197 public void onInstall() throws JBIException { 198 execute(INSTALL); 199 200 JBIException jbie = getJbiException(); 201 if (jbie != null) { 202 throw jbie; 203 } 204 } 205 206 211 public void onUninstall() throws JBIException { 212 execute(UNINSTALL); 213 214 JBIException jbie = getJbiException(); 215 if (jbie != null) { 216 throw jbie; 217 } 218 } 219 } | Popular Tags |