Commit 4b3d14a7 authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Changed the name of the package "XMPP" for "Communication"

parent 01b07d7a
package org.fogbowcloud.green.server.communication;
public class Agent {
private String hostName;
private String ip;
private String jid;
public Agent(String hostName, String jid, String ip) {
this.hostName = hostName;
this.jid = jid;
this.ip = ip;
}
public String getHostName() {
return hostName;
}
public String getIp() {
return ip;
}
public String getJid() {
return jid;
}
}
package org.fogbowcloud.green.server.communication;
import java.util.LinkedList;
import java.util.Properties;
import org.fogbowcloud.green.server.communication.Agent;
import org.fogbowcloud.green.server.core.greenStrategy.GreenStrategy;
import org.jamppa.component.XMPPComponent;
public class GreenSitterCommunicationComponent extends XMPPComponent {
private GreenStrategy gs;
private LinkedList<Agent> listAgent = new LinkedList<Agent>();
public GreenSitterCommunicationComponent(Properties prop, GreenStrategy gs) {
super(prop.getProperty("xmpp.jid"), prop.getProperty("xmpp.password"),
prop.getProperty("xmpp.host"), Integer.parseInt(prop.getProperty("xmpp.port")));
this.gs = gs;
addHandlers();
}
public void setAgentAddress(String hostName, String jid, String ip) {
Agent agent = new Agent(hostName, jid, ip);
listAgent.add(agent);
}
public void sendHostToBed(String host){
}
public void wakeUpHost(String host){
}
private void addHandlers() {
IAmAliveHandler alive = new IAmAliveHandler(gs);
WakeUpRequestHandler wakeup = new WakeUpRequestHandler(gs);
addGetHandler(alive);
addGetHandler(wakeup);
}
}
package org.fogbowcloud.green.server.communication;
import org.fogbowcloud.green.server.core.greenStrategy.GreenStrategy;
import org.jamppa.component.handler.AbstractQueryHandler;
import org.xmpp.packet.IQ;
public class IAmAliveHandler extends AbstractQueryHandler {
private static final String NAMESPACE = "org.fogbowcloud.green.IAmAlive";
private final GreenStrategy gs;
public IAmAliveHandler(GreenStrategy gs) {
super(NAMESPACE);
this.gs = gs;
}
@Override
public IQ handle(IQ query) {
//expected content format: IP plus host name (eg. "123.456.789 bobo")
String ip = query.getElement().element("query").elementText("ip");
String hostName = query.getElement().element("query").elementText("hostName");
String jid = query.getFrom().toString();
gs.setAgentAddress(hostName, jid, ip);
IQ resultIQ = IQ.createResultIQ(query);
return resultIQ;
}
}
package org.fogbowcloud.green.server.communication;
import org.fogbowcloud.green.server.core.greenStrategy.GreenStrategy;
import org.jamppa.component.handler.AbstractQueryHandler;
import org.xmpp.packet.IQ;
public class WakeUpRequestHandler extends AbstractQueryHandler {
private static final String NAMESPACE = "org.fogbowcloud.green.WakeUpRequest";
private final GreenStrategy gs;
public WakeUpRequestHandler(GreenStrategy gs) {
super(NAMESPACE);
this.gs = gs;
}
@Override
public IQ handle(IQ query) {
//expected content format: the minimum CPU and the RAM (in GigaBytes) capacity required (eg. "1 8")
int minCPU = Integer.parseInt(query.getElement().element("query").elementText("cpu"));
int minRAM = Integer.parseInt(query.getElement().element("query").elementText("ram"));
gs.wakeUpSleepingHost(minCPU, minRAM);
IQ resultIQ = IQ.createResultIQ(query);
return resultIQ;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment