Created
March 4, 2017 02:59
-
-
Save dramaticlly/21151c4c965a306a3f32cfc1e598bd9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//AdmMessage.java | |
//==================================================================================== | |
package common.messages; | |
import app_kvServer.model.Metadata; | |
import app_kvServer.model.Range; | |
public interface AdmMessage { | |
public enum StatusType { | |
INIT, | |
INIT_ERROR, | |
INIT_SUCCESS, | |
START, | |
START_ERROR, | |
START_SUCCESS, | |
STOP, | |
STOP_ERROR, | |
STOP_SUCCESS, | |
SHUTDOWN, | |
LOCKWRITE, | |
LOCKWRITE_ERROR, | |
LOCKWRITE_SUCCESS, | |
UNLOCKWRITE, | |
UNLOCKWRITE_ERROR, | |
UNLOCKWRITE_SUCCESS, | |
MOVEDATA, | |
MOVEDATA_ERROR, | |
MOVEDATA_COMPLETED, | |
UPDATE, | |
UPDATE_ERROR, | |
UPDATE_SUCCESS, | |
UNKNOWN_MIN, | |
} | |
public StatusType getStatus(); | |
public Metadata getMetadata(); | |
public String getCacheSize(); | |
public String getStrategy(); | |
public Range getRange(); | |
public String getServerId(); | |
} | |
//AdmMessageC.java | |
//==================================================================================== | |
package common.messages; | |
import app_kvServer.model.Metadata; | |
import app_kvServer.model.Range; | |
import javax.json.Json; | |
public class AdmMessageC implements AdmMessage { | |
private StatusType mCmd; | |
private String cacheSize; | |
private String strategy; | |
private Metadata metadata; | |
private Range range; | |
private String serverId; | |
public AdmMessageC(StatusType mCmd) { | |
this.mCmd = mCmd; | |
} | |
public static TextMessage toText(StatusType mCmd, | |
String cacheSize, | |
String strategy, | |
Metadata metadata, | |
Range range, | |
String serverId){ | |
cacheSize = (cacheSize!=null) ? cacheSize : "null"; | |
strategy = (strategy!=null) ? strategy : "null"; | |
String metadataVal = (metadata!=null) ? metadata.toString() : "null"; | |
String rangeVal = (range!=null) ? range.toString() : "null"; | |
serverId = (serverId!=null) ? serverId : "null"; | |
String json = Json.createObjectBuilder() | |
.add("status",mCmd.toString()) | |
.add("cacheSize",cacheSize) | |
.add("strategy",strategy) | |
.add("metadata",metadataVal) | |
.add("range",rangeVal) | |
.add("serverId",serverId).build().toString(); | |
return new TextMessage(json); | |
} | |
@Override | |
public StatusType getStatus() { | |
return mCmd; | |
} | |
@Override | |
public Metadata getMetadata() { | |
return metadata; | |
} | |
@Override | |
public String getCacheSize() { | |
return cacheSize; | |
} | |
@Override | |
public String getStrategy() { | |
return strategy; | |
} | |
@Override | |
public Range getRange() { | |
return range; | |
} | |
@Override | |
public String getServerId() { | |
return serverId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of AdmMessage sent from ECS to server
{"status":"INIT",
"cacheSize":"200",
"strategy":"FIFO",
"metadata":"Metadata{meta={
192.168.0.2=6F65E91667CF98DD13464DEAF2739FDE,
192.168.0.1=F0FDB4C3F58E3E3F8E77162D893D3055,
192.168.0.4=0252F5158DC3A9531907FB42C00A4138,
192.168.0.3=8C27F6B5DC0E9E5A536AA0371648FB4A,
192.168.0.0=447F32D25B7D55524675C64D649AE5D9,
192.168.0.9=6379559F580D7BF13DAB6C046EF88DF8,
192.168.0.6=F23C168FE4B03627754C52F632C547E2,
192.168.0.5=8EBAEC02E0D0F38566870133E565941B,
192.168.0.8=F4E4C0AE3FFCC5F281329A6DB3665E03,
192.168.0.7=BD1518783C060C100FB7EB82C619C5A6}}",
"range":"Range{startIndex='F4E4C0AE3FFCC5F281329A6DB3665E03', endIndex='0252F5158DC3A9531907FB42C00A4138'}",
"serverId":"192.168.0.4"}