View Javadoc

1   package cz.cuni.amis.pogamut.base.server;
2   
3   import java.net.URI;
4   import java.net.URISyntaxException;
5   
6   import com.google.inject.Inject;
7   
8   import cz.cuni.amis.pogamut.base.agent.IAgent;
9   import cz.cuni.amis.pogamut.base.agent.IAgentId;
10  import cz.cuni.amis.pogamut.base.agent.impl.AbstractGhostAgent;
11  import cz.cuni.amis.pogamut.base.communication.command.IAct;
12  import cz.cuni.amis.pogamut.base.communication.connection.impl.socket.SocketConnection;
13  import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView;
14  import cz.cuni.amis.pogamut.base.component.bus.IComponentBus;
15  import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
16  
17  /**
18   * @author ik
19   */
20  public abstract class AbstractWorldServer<WORLD_VIEW extends IWorldView, ACT extends IAct, A extends IAgent> extends AbstractGhostAgent<WORLD_VIEW, ACT> implements IWorldServer<A> {
21  
22      @Inject
23      public AbstractWorldServer(IAgentId agentId, IAgentLogger agentLogger, IComponentBus bus, WORLD_VIEW worldView, ACT act) {
24          super(agentId, bus, agentLogger, worldView, act);
25      }
26      
27      protected URI worldAddress = null;
28  
29      @Override
30      public URI getWorldAddress() {
31      	if (worldAddress == null) {
32      		SocketConnection conn = getEventBus().getComponent(SocketConnection.class);
33      		if (conn != null) {
34      			try {
35  					worldAddress = new URI("ut://" + conn.getAddress().getHost() + ":" + conn.getAddress().getPort());
36  				} catch (URISyntaxException e) {
37  					throw new RuntimeException("Failed to construct WorldAddress.");
38  				}
39      		}
40      	}
41          return worldAddress;
42      }
43      
44  }