Datapublic class Data extends VerbBase Data representation of client/server interaction.
window.parent.cometd.deliver([
{
// user-sent data
"data": {
"someField": ["some", "random", "values"],
},
// the usual message meta-data
"channel": "/originating/channel",
// event ID
"id": "slkjdlkj32",
"timestamp": "TimeAtServer",
// optional meta-data
"authToken": "SOME_NONCE_THAT_NEEDS_TO_BE_PROVIDED_SUBSEQUENTLY"
},
{
"data": {
"blah blah": ["more", "random", "values"],
},
// the usual message meta-data
"channel": "/originating/channel",
// event ID
"id": "slkjdlkj31",
"timestamp": "TimeAtServer",
"authToken": "SOME_NONCE_THAT_NEEDS_TO_BE_PROVIDED_SUBSEQUENTLY"
}
// , ...
]); |
Fields Summary |
---|
private Random | random | private HashMap | data | private String | connectionId | private String | clientId | private String | id | private String | timestamp |
Constructors Summary |
---|
public Data()
type = Verb.DATA;
|
Methods Summary |
---|
public java.lang.String | getClientId()
return clientId;
| public java.lang.String | getConnectionId()
return connectionId;
| public java.util.HashMap | getData()
return data;
| public java.lang.String | getJSONData()
StringBuffer response = new StringBuffer();
response.append("\n{");
response.append("\"id\":\"");
response.append(Long.toHexString(random.nextLong()));
response.append("\",");
response.append("\"timestamp\":\"");
response.append(FastHttpDateFormat.getCurrentDate());
response.append("\",");
response.append("\"data\":{");
Iterator<String> iterator = data.keySet().iterator();
String key = "";
Object value;
int size = data.size() -1;
int i = 0;
while(iterator.hasNext()){
key = iterator.next();
value = data.get(key);
response.append("\"");
response.append(key);
response.append("\":");
if (value instanceof String){
response.append("\"" + value + "\"");
} else {
response.append(value);
}
if (i++ < size){
response.append(",");
}
}
response.append("},");
response.append("\"channel\":\"");
response.append(channel);
response.append("\"");
response.append("}]");
return response.toString();
| public void | setClientId(java.lang.String clientId)
this.clientId = clientId;
| public void | setConnectionId(java.lang.String connectionId)
this.connectionId = connectionId;
| public void | setData(java.util.HashMap data)
this.data = data;
| public java.lang.String | toJSON()
return "[{"
+ "\"error\":\"" + error + "\","
+ "\"successful\":" + successful + ","
+ "\"channel\":\"" + channel + "\"},"
+ getJSONData();
|
|