1 25 26 package org.objectweb.petals.jbi.component.lifecycle; 27 28 import javax.jbi.JBIException; 29 import javax.jbi.component.Component; 30 import javax.management.ObjectName ; 31 32 import org.objectweb.petals.jbi.component.context.ComponentContextImpl; 33 import org.objectweb.petals.jbi.component.thread.ComponentLifeCycleThread; 34 import org.objectweb.petals.jbi.management.systemstate.SystemState; 35 import org.objectweb.petals.jbi.messaging.DeliveryChannelImpl; 36 import org.objectweb.petals.tools.jbicommon.descriptor.ComponentDescription; 37 import org.objectweb.petals.util.LoggingUtil; 38 39 45 public class ComponentLifeCycle extends LifeCycleAbstract implements 46 ComponentLifeCycleMBean { 47 48 51 protected Component component; 52 53 56 private ComponentDescription componentDescription; 57 58 61 private ComponentContextImpl context; 62 63 66 private SystemState recoverySrv; 67 68 72 protected ComponentLifeCycleThread componentLifeCycleThread; 73 74 83 public ComponentLifeCycle(ComponentDescription componentDescription, 84 Component component, ComponentContextImpl context, 85 SystemState recoverySrv, ObjectName mbeanName, 86 ComponentLifeCycleThread componentLifeCycleThread, LoggingUtil log) { 87 super(mbeanName, log); 88 89 this.componentDescription = componentDescription; 90 91 this.component = component; 92 93 this.context = context; 94 95 this.recoverySrv = recoverySrv; 96 97 if (context != null) { 99 context.setComponent(component); 100 } 101 102 this.componentLifeCycleThread = componentLifeCycleThread; 104 } 105 106 @Override 107 public void doInit() throws JBIException { 108 log.start(); 109 componentLifeCycleThread.doInit(context); 110 log.end(); 111 } 112 113 @Override 114 public void doShutdown() throws JBIException { 115 log.start(); 116 componentLifeCycleThread.doShutdown(); 117 118 DeliveryChannelImpl channel = context.getDeliveryChannelImpl(); 120 if (channel != null && channel.isOpened()) 121 channel.close(); 122 123 log.end(); 124 } 125 126 @Override 127 public void doStart() throws JBIException { 128 log.start(); 129 componentLifeCycleThread.doStart(); 130 log.end(); 131 } 132 133 @Override 134 public void doStop() throws JBIException { 135 log.start(); 136 componentLifeCycleThread.doStop(); 137 log.end(); 138 } 139 140 143 public ObjectName getExtensionMBeanName() throws JBIException { 144 log.start(); 145 ObjectName on = componentLifeCycleThread.getExtensionMBeanName(); 146 log.end(); 147 return on; 148 } 149 150 154 public String getName() { 155 return componentDescription.getIdentification().getName(); 156 } 157 158 @Override 159 public synchronized void setState(String state) throws JBIException { 160 super.setState(state); 161 try { 162 recoverySrv.updateComponentLifeCycleState(getName(), state); 163 } catch (Exception e) { 164 String msg = "Component state can't be persisted for recovery"; 165 log.error(msg, e); 166 throw new JBIException(msg, e); 167 } 168 } 169 170 171 172 public Component getComponent() { 173 return component; 174 } 175 176 public ComponentContextImpl getComponentContext() { 177 return context; 178 } 179 180 public ComponentDescription getComponentDescription() { 181 return componentDescription; 182 } 183 184 } 185 | Popular Tags |