1 package cz.cuni.amis.pogamut.defcon.communication.command.impl;
2
3 import javabot.PogamutJBotSupport;
4
5 import com.google.inject.Inject;
6
7 import cz.cuni.amis.pogamut.base.communication.command.ICommandListener;
8 import cz.cuni.amis.pogamut.base.communication.command.impl.IJNIAct;
9 import cz.cuni.amis.pogamut.base.communication.messages.CommandMessage;
10 import cz.cuni.amis.pogamut.base.component.bus.IComponentBus;
11 import cz.cuni.amis.pogamut.base.component.bus.exception.ComponentNotRunningException;
12 import cz.cuni.amis.pogamut.base.component.bus.exception.ComponentPausedException;
13 import cz.cuni.amis.pogamut.base.utils.guice.AgentScoped;
14 import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
15 import cz.cuni.amis.pogamut.base.utils.logging.LogCategory;
16 import cz.cuni.amis.pogamut.defcon.communication.messages.commands.DefConCommand;
17 import cz.cuni.amis.utils.token.IToken;
18 import cz.cuni.amis.utils.token.Token;
19 import cz.cuni.amis.utils.token.Tokens;
20
21
22
23
24
25
26
27
28 @AgentScoped
29 public class DefConAct implements IJNIAct {
30
31 public static final Token COMPONENT_ID = Tokens.get("Act");
32
33 private LogCategory log;
34
35 private IComponentBus eventBus;
36
37 @Inject
38 public DefConAct(IComponentBus eventBus, IAgentLogger logger) {
39 this.log = logger.getCategory(getComponentId().getToken());
40
41 this.eventBus = eventBus;
42 }
43
44 @Override
45 public void act(CommandMessage command)
46 throws ComponentNotRunningException, ComponentPausedException {
47
48 if (command instanceof DefConCommand)
49 PogamutJBotSupport.addCommand((DefConCommand) command);
50 }
51
52 @Override
53 public void addCommandListener(Class commandClass, ICommandListener listener) {
54 PogamutJBotSupport.getDefConActExecutor().addCommandListener(
55 commandClass,
56 listener);
57 }
58
59 @Override
60 public boolean isCommandListening(Class commandClass,
61 ICommandListener listener) {
62 return PogamutJBotSupport.getDefConActExecutor().isCommandListening(
63 commandClass,
64 listener);
65 }
66
67 @Override
68 public void removeCommandListener(Class commandClass,
69 ICommandListener listener) {
70 PogamutJBotSupport.getDefConActExecutor().removeCommandListener(
71 commandClass,
72 listener);
73 }
74
75 @Override
76 public IToken getComponentId() {
77 return COMPONENT_ID;
78 }
79
80 }