Skip to content

Commit

Permalink
Merge pull request #32 from rwth-acis/SocialBotFramework
Browse files Browse the repository at this point in the history
Social bot framework
  • Loading branch information
AlexanderNeumann authored Jun 8, 2018
2 parents 1f1fc47 + c0f79b1 commit ee7e8e4
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public enum MonitoringEvent {
SERVICE_INVOCATION_FAILED(-7210),

SERVICE_ADD_TO_MONITORING(7300), // Used by the LoggingObserver itself
BOT_ADD_TO_MONITORING(7400), // Used by the LoggingObserver itself

// To be used by the service developer
SERVICE_MESSAGE(7500),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package i5.las2peer.logging.bot;

public interface BotContentGenerator {

public boolean trainStep(String input, String output);

public boolean train(String out_dir, double learning_rate, int num_training_steps);

public Object inference(String input);

}
85 changes: 85 additions & 0 deletions core/src/main/java/i5/las2peer/logging/bot/BotMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package i5.las2peer.logging.bot;

import java.io.Serializable;

import i5.las2peer.api.logging.MonitoringEvent;

public class BotMessage implements Serializable {
private static final long serialVersionUID = 1L;

private Long timestamp;
private MonitoringEvent event;
private String sourceNode;
private String sourceAgentId;
private String destinationNode;
private String destinationAgentId;
private String remarks;

public BotMessage(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId,
String destinationNode, String destinationAgentId, String remarks) {
this.timestamp = timestamp;
this.event = event;
this.sourceNode = sourceNode;
this.sourceAgentId = sourceAgentId;
this.destinationNode = destinationNode;
this.destinationAgentId = destinationAgentId;
this.remarks = remarks;
}

public Long getTimestamp() {
return timestamp;
}

public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}

public MonitoringEvent getEvent() {
return event;
}

public void setEvent(MonitoringEvent event) {
this.event = event;
}

public String getSourceNode() {
return sourceNode;
}

public void setSourceNode(String sourceNode) {
this.sourceNode = sourceNode;
}

public String getSourceAgentId() {
return sourceAgentId;
}

public void setSourceAgentId(String sourceAgentId) {
this.sourceAgentId = sourceAgentId;
}

public String getDestinationNode() {
return destinationNode;
}

public void setDestinationNode(String destinationNode) {
this.destinationNode = destinationNode;
}

public String getDestinationAgentId() {
return destinationAgentId;
}

public void setDestinationAgentId(String destinationAgentId) {
this.destinationAgentId = destinationAgentId;
}

public String getRemarks() {
return remarks;
}

public void setRemarks(String remarks) {
this.remarks = remarks;
}

}
20 changes: 20 additions & 0 deletions core/src/main/java/i5/las2peer/logging/bot/BotStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package i5.las2peer.logging.bot;

public enum BotStatus {
DISABLED(0),
READY(1),
RUNNING(2),
TRAINING(3),
BUSY(4);

private int status;

public int getStatusCode() {
return status;
}

BotStatus(int status) {
this.status = status;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,38 @@ public class MonitoringObserver implements NodeObserver {
*/
public MonitoringObserver(int messageCache, Node registeredAt) {
this.registeredAt = registeredAt;
waitUntilSend = 1000 * 60 * 5; // 5 min
waitUntilSend = 1000 * 30 * 5; // 5 min
Thread sendingThread = new Thread() {
public void run() {
try {
while (true) {
Thread.sleep(waitUntilSend);
if (messagesCount > 0) {
// Send messages after waitUntilSend ms
if (initializedDone) {
// Do not send old messages...
int counter = messagesCount;
while (counter < monitoringMessages.length) {
monitoringMessages[counter] = null;
counter++;
}
// reset messageCount before sending messages
// otherwise StackOverflow...
messagesCount = 0;
sendMessages();
} else {
messagesCount = 0;
System.out.println("Monitoring: Problems with initializing Agents..");
}
}
}
} catch (InterruptedException v) {
System.out.println(v);
}
}
};

sendingThread.start();
if (messageCache < 50) {
messageCache = 50; // Minimum cache to give the observer enough time to initialize before first sending
}
Expand Down Expand Up @@ -179,7 +210,7 @@ public void log(Long timestamp, MonitoringEvent event, String sourceNode, String
}
}
}

/**
* Checks whether the queue is ready to be flushed, either due to reaching
* the limit or because enough time has passed
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/i5/las2peer/p2p/LocalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import i5.las2peer.security.AgentContext;
import i5.las2peer.security.AgentImpl;
import i5.las2peer.security.AnonymousAgentImpl;
import i5.las2peer.security.BotAgent;
import i5.las2peer.security.MessageReceiver;
import i5.las2peer.security.UserAgentImpl;
import i5.las2peer.serialization.MalformedXMLException;
Expand Down Expand Up @@ -264,6 +265,8 @@ public void storeAgent(AgentImpl agent) throws AgentException {

if (agent instanceof UserAgentImpl) {
getUserManager().registerUserAgent((UserAgentImpl) agent);
} else if (agent instanceof BotAgent) {
getUserManager().registerUserAgent((BotAgent) agent);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/i5/las2peer/p2p/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import i5.las2peer.security.AgentContext;
import i5.las2peer.security.AgentImpl;
import i5.las2peer.security.AgentStorage;
import i5.las2peer.security.BotAgent;
import i5.las2peer.security.GroupAgentImpl;
import i5.las2peer.security.InternalSecurityException;
import i5.las2peer.security.Mediator;
Expand Down Expand Up @@ -316,7 +317,8 @@ public void removeObserver(NodeObserver observer) {
*/
public void setServiceMonitoring(ServiceAgentImpl service) {
observerNotice(MonitoringEvent.SERVICE_ADD_TO_MONITORING, this.getNodeId(), service.getIdentifier(), null, null,
service.getServiceNameVersion().toString());
"{\"serviceName\":\"" + service.getServiceNameVersion().toString() + "\",\"serviceAlias\":\""
+ service.getServiceInstance().getAlias() + "\"}");
}

/**
Expand Down Expand Up @@ -635,6 +637,8 @@ public void registerReceiver(MessageReceiver receiver) throws AgentAlreadyRegist
observerNotice(MonitoringEvent.AGENT_REGISTERED, this.getNodeId(), agent, "GroupAgent");
} else if (agent instanceof MonitoringAgent) {
observerNotice(MonitoringEvent.AGENT_REGISTERED, this.getNodeId(), agent, "MonitoringAgent");
} else if (agent instanceof BotAgent) {
observerNotice(MonitoringEvent.AGENT_REGISTERED, this.getNodeId(), agent, "BotAgent");
}
} else if (receiver instanceof Mediator) {
// ok, we have a mediator
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/i5/las2peer/p2p/PastryNodeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import i5.las2peer.security.AgentContext;
import i5.las2peer.security.AgentImpl;
import i5.las2peer.security.AnonymousAgentImpl;
import i5.las2peer.security.BotAgent;
import i5.las2peer.security.MessageReceiver;
import i5.las2peer.security.UserAgentImpl;
import i5.las2peer.serialization.MalformedXMLException;
Expand Down Expand Up @@ -546,6 +547,12 @@ public void storeAgent(AgentImpl agent) throws AgentException {
} catch (AgentAlreadyExistsException e) {
logger.log(Level.FINE, "Could not register user agent", e);
}
} else if (agent instanceof BotAgent) {
try {
getUserManager().registerUserAgent((BotAgent) agent);
} catch (AgentAlreadyExistsException e) {
logger.log(Level.FINE, "Could not register bot agent", e);
}
}
observerNotice(MonitoringEvent.AGENT_UPLOAD_SUCCESS, pastryNode, agent, "");
} catch (CryptoException | SerializationException | EnvelopeException e) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/i5/las2peer/security/AgentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ public static AgentImpl createFromXml(Element rootElement) throws MalformedXMLEx
return ServiceAgentImpl.createFromXml(rootElement);
} else if ("monitoring".equalsIgnoreCase(type)) {
return MonitoringAgent.createFromXml(rootElement);
} else if ("bot".equalsIgnoreCase(type)) {
return BotAgent.createFromXml(rootElement);
} else {
throw new MalformedXMLException("Unknown agent type: " + type);
}
Expand Down
Loading

0 comments on commit ee7e8e4

Please sign in to comment.