1 package cz.cuni.amis.pogamut.base.component; 2 3 import javax.management.MXBean; 4 5 import cz.cuni.amis.pogamut.base.agent.IAgentId; 6 import cz.cuni.amis.pogamut.base.component.controller.ComponentDependencies; 7 import cz.cuni.amis.pogamut.base.component.lifecyclebus.ILifecycleBus; 8 9 /** 10 * Every agent consists of components. Typically the component are ordinary {@link IComponent}. But there are times 11 * when is feasible that more agents shares the same instance of one component. That means such component must behave 12 * differently in terms of starting/stopping itself when it comes to lifecycle management of the component. Thus {@link ISharedComponent} 13 * was created. 14 * <p><p> 15 * Every implementor of {@link ISharedComponent} must be prepared to be used by multiple agent instances. That is, it must be carefully designed 16 * to be thread-safe. Moreover it should run if any of its users (agents) is running. That is the component must start together with 17 * the start of the first user-agent and stop itself with the stop of the last user-agent (i.e., when the last running agent is going to be 18 * stopped). 19 * <p><p> 20 * Again, the component itself does not need to know anything apart the {@link ILifecycleBus} the user-agent is using, therefore there is only 21 * a single simple method {@link ISharedComponent#addLifecycleBus(ILifecycleBus)} that informs the {@link ISharedComponent} that is has become 22 * used by another agent. 23 * 24 * @author Jimmy 25 */ 26 @MXBean 27 public interface ISharedComponent extends IComponent { 28 29 /** 30 * Informs the component that it is part of another {@link ILifecycleBus}, i.e., it has become used by new agent with 'agentId'. 31 * <p><p> 32 * The component is obliged to register to that bus a watch for the lifecycle state of various components inside the bus. 33 * 34 * @param agentId 35 * @param bus 36 */ 37 public void addComponentBus(IAgentId agentId, ILifecycleBus bus, ComponentDependencies dependencies); 38 39 /** 40 * Informs the component that it ceased to be the part of the {@link ILifecycleBus}, i.e., it has stopped to be used by agent with 'agentId'. 41 * 42 * @param agentId 43 * @param bus 44 */ 45 public void removeComponentBus(IAgentId agentId, ILifecycleBus bus); 46 47 }