Created
July 6, 2016 16:16
-
-
Save iwata-n/572465bc468c96513cd6babd5f53e636 to your computer and use it in GitHub Desktop.
milkcocoa+javaでPushとSendをするサンプル
This file contains 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
package jp.dip.iwatan; | |
import com.mlkcca.client.*; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import java.util.ArrayList; | |
import java.util.Date; | |
public class Main { | |
public static void main(String[] args) throws InterruptedException, JSONException { | |
MilkCocoa milkCocoa = new MilkCocoa("flagiqah22fs.mlkcca.com"); | |
DataStore dataStore = milkCocoa.dataStore("message"); | |
Streaming streaming = dataStore.streaming(); | |
streaming.size(1); | |
streaming.addStreamingListener(new StreamingListener() { | |
@Override | |
public void onData(ArrayList<DataElement> arrayList) { | |
for (DataElement element : arrayList) { | |
System.out.print("onData:"); | |
System.out.println(element.getValue()); | |
} | |
} | |
@Override | |
public void onError(Exception e) { | |
System.out.print("onError:"); | |
e.printStackTrace(); | |
} | |
}); | |
streaming.next(); | |
dataStore.addDataStoreEventListener(new DataStoreEventListener() { | |
@Override | |
public void onPushed(DataElement dataElement) { | |
System.out.print("onPushed:"); | |
System.out.println(dataElement.getValue()); | |
} | |
@Override | |
public void onSetted(DataElement dataElement) { | |
} | |
@Override | |
public void onSended(DataElement dataElement) { | |
System.out.print("onSended:"); | |
// System.out.println(dataElement.getValue()); | |
} | |
@Override | |
public void onRemoved(DataElement dataElement) { | |
} | |
}); | |
dataStore.on("push"); | |
dataStore.on("send"); | |
while(true) { | |
Thread.sleep(500); | |
Date date = new Date(); | |
// DataElementValue params = new DataElementValue(); | |
// params.put("date", date.getTime()); | |
// dataStore.push(params); | |
JSONObject object = new JSONObject(); | |
object.put("date", date.getTime()); | |
dataStore.send(object); | |
System.out.println("Send"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment