本文整理汇总了Java中com.google.appengine.api.channel.ChannelService.sendMessage方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelService.sendMessage方法的具体用法?Java ChannelService.sendMessage怎么用?Java ChannelService.sendMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.channel.ChannelService
的用法示例。
在下文中一共展示了ChannelService.sendMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.google.appengine.api.channel.ChannelService; //导入方法依赖的package包/类
@ApiMethod(name = "data.create", httpMethod = "post")
public SensorData create(SensorData data, User user) {
// check the user is authenticated and authorised
if(user == null) {
log.warning("User is not authenticated");
throw new RuntimeException("Authentication required!");
} else if(!Constants.EMAIL_ADDRESS.equals(user.getEmail())) {
log.warning("User is not authorised, email: " + user.getEmail());
throw new RuntimeException("Not authorised!");
}
data.save();
try {
// notify the client channels
ChannelService channelService = ChannelServiceFactory.getChannelService();
List<Client> clients = Client.findAll();
String json = GSON.toJson(data);
for(Client client: clients) {
channelService.sendMessage(new ChannelMessage(client.getId(), json));
}
} catch(Exception e) {
log.log(Level.SEVERE, "Failed to notify connected clients", e);
}
return data;
}
示例2: getRun
import com.google.appengine.api.channel.ChannelService; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/run/{account}")
public String getRun(@PathParam("account") String account) {
ChannelService channelService = ChannelServiceFactory.getChannelService();
Run r = new Run();
r.setGameId(123l);
r.setTitle("een game");
channelService.sendMessage(new ChannelMessage(account, toJson(r)));
return "sent";
}
示例3: sendUpdateToUser
import com.google.appengine.api.channel.ChannelService; //导入方法依赖的package包/类
public static void sendUpdateToUser(Message model) {
if (model.getSendTo() != null && model.getSendTo()!="") {
PubsubJSONSerializer<Message> serialize = new PubsubJSONSerializer<Message>();
String messagePayload = serialize.POJOSerializer(model);
ChannelService channelService = ChannelServiceFactory.getChannelService();
String channelKey = LiveFeedChannel.getChannelKey(model.getSendTo());
channelService.sendMessage(new ChannelMessage(channelKey, messagePayload));
}
}
示例4: pushUpdates
import com.google.appengine.api.channel.ChannelService; //导入方法依赖的package包/类
public static void pushUpdates(List<User> users, String message, String url) {
ChannelService channelService = ChannelServiceFactory
.getChannelService();
try {
JSONObject json = new JSONObject();
json.put("message", message);
json.put("link", url);
for (User user : users) {
channelService.sendMessage(new ChannelMessage(KeyFactory
.keyToString(user.getKey()), json.toString()));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
示例5: sendMessage
import com.google.appengine.api.channel.ChannelService; //导入方法依赖的package包/类
public static void sendMessage(String body, String source) {
Iterator<String> it = subs.iterator();
while (it.hasNext()) {
String sub = it.next();
String messageBody = source + ": " + body;
// We assume an at symbol is an XMPP client...
if (sub.indexOf("@") >= 0) {
JID jid = new JID(sub);
Message msg = new MessageBuilder().withRecipientJids(jid).withBody(messageBody).build();
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
xmpp.sendMessage(msg);
}
// If it starts with a "+" it's an SMS number...
else if (sub.startsWith("+")) {
TwilioRestClient client = new TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN");
Map<String, String> params = new HashMap<String, String>();
params.put("Body", messageBody);
params.put("To", sub);
params.put("From", "+16122948105");
SmsFactory messageFactory = client.getAccount().getSmsFactory();
try {
Sms message = messageFactory.create(params);
System.out.println(message.getSid());
} catch (TwilioRestException e) {
e.printStackTrace();
}
}
// Otherwise, it's a browser-based client
else {
ChannelService channelService = ChannelServiceFactory.getChannelService();
channelService.sendMessage(new ChannelMessage(sub,messageBody));
}
}
}
示例6: sendUpdate
import com.google.appengine.api.channel.ChannelService; //导入方法依赖的package包/类
public static void sendUpdate(String channelKey) {
ChannelService channelService = ChannelServiceFactory.getChannelService();
channelService.sendMessage(new ChannelMessage(channelKey, "hallo"));
}