Commit 3054add1 authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Refactored namespaces to constants

parent 1c359cb8
......@@ -6,4 +6,6 @@ xmpp.component = server.test.com
host.ip = 123.456.789
host.macAddress = A1:B2:C3:D4:E5:67
host.name = agent
\ No newline at end of file
host.name = agent
green.TurnOffCommand = pm-suspend
\ No newline at end of file
......@@ -16,6 +16,7 @@ import org.xmpp.packet.IQ.Type;
public class AgentCommunicationComponent {
private static final String NAMESPACE = "org.fogbowcloud.green.IAmAlive";
Properties prop;
XMPPClient client;
......@@ -45,7 +46,7 @@ public class AgentCommunicationComponent {
client.getConnection().addPacketListener(new PacketListener() {
@Override
public void processPacket(Packet packet) {
new TurnOff().hibernate();
new TurnOff().suspend(prop.getProperty("green.TurnOffCommand"));
}
}, new PacketFilter() {
@Override
......@@ -71,7 +72,7 @@ public class AgentCommunicationComponent {
public void sendIamAliveSignal() {
IQ iq = new IQ(Type.get);
iq.setTo(this.prop.getProperty("xmpp.component"));
iq.getElement().addElement("query", "org.fogbowcloud.green.IAmAlive");
iq.getElement().addElement("query", NAMESPACE);
DefaultElement query = (DefaultElement) iq.getElement()
.elements("query").get(0);
......
......@@ -7,15 +7,14 @@ import java.util.logging.Logger;
public class TurnOff {
public void hibernate() {
String hibernateCommand = "";
String operatingSystem = System.getProperty("os.name");
if ("Linux".equals(operatingSystem)
|| "Mac OS X".equals(operatingSystem)) {
// Suspend or hibernate?
hibernateCommand = "pm-suspend";
public void suspend(String command) {
String suspendCommand = "pm-suspend";
if (command != ""){
suspendCommand = command;
}
ProcessBuilder pb = new ProcessBuilder("sudo", "-S", hibernateCommand);
ProcessBuilder pb = new ProcessBuilder("sudo", "-S", suspendCommand);
try {
pb.start();
} catch (IOException e) {
......
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