1 25 package org.objectweb.petals.jbi.component.thread; 26 27 import javax.jbi.JBIException; 28 import javax.jbi.component.Component; 29 import javax.jbi.component.ComponentContext; 30 import javax.management.ObjectName ; 31 32 44 public class ComponentLifeCycleThread extends AbstractThread { 45 46 49 private Component component; 50 51 54 private ComponentContext context; 55 56 59 private ObjectName objectName; 60 61 64 public static final int INIT = 0; 65 66 public static final int START = 1; 67 68 public static final int STOP = 2; 69 70 public static final int SHUTDOWN = 3; 71 72 public static final int MBEANNAME = 4; 73 74 80 public ComponentLifeCycleThread(Component component) { 81 super(); 82 this.component = component; 83 this.setName(component.toString() + "-life Cycle Thread"); 84 } 85 86 91 protected int doTask(int action) { 92 int result = 0; 93 try { 94 switch (action) { 95 case INIT: 96 getComponent().getLifeCycle().init(context); 97 break; 98 99 case START: 100 getComponent().getLifeCycle().start(); 101 break; 102 103 case STOP: 104 getComponent().getLifeCycle().stop(); 105 break; 106 107 case SHUTDOWN: 108 getComponent().getLifeCycle().shutDown(); 109 break; 110 111 case MBEANNAME: 112 objectName = getComponent().getLifeCycle() 113 .getExtensionMBeanName(); 114 break; 115 116 case SHUTDOWNTHREAD: 117 result = -1; 118 break; 119 120 default: 121 break; 123 } 124 125 } catch (JBIException jbie) { 126 jbiException = jbie; 127 } 128 129 return result; 130 } 131 132 135 public Component getComponent() { 136 return component; 137 } 138 139 143 public void doStart() throws JBIException { 144 execute(START); 145 146 JBIException jbie = getJbiException(); 147 if (jbie != null) { 148 throw jbie; 149 } 150 } 151 152 156 public void doStop() throws JBIException { 157 execute(STOP); 158 159 JBIException jbie = getJbiException(); 160 if (jbie != null) { 161 throw jbie; 162 } 163 } 164 165 169 public void doShutdown() throws JBIException { 170 execute(SHUTDOWN); 171 172 JBIException jbie = getJbiException(); 173 if (jbie != null) { 174 throw jbie; 175 } 176 } 177 178 183 public void doInit(ComponentContext context) throws JBIException { 184 this.context = context; 185 execute(INIT); 186 187 JBIException jbie = getJbiException(); 188 if (jbie != null) { 189 throw jbie; 190 } 191 } 192 193 198 public ObjectName getExtensionMBeanName() { 199 execute(MBEANNAME); 200 return objectName; 201 } 202 } | Popular Tags |