当前位置: 首页>>代码示例>>Java>>正文


Java ChannelService.sendMessage方法代码示例

本文整理汇总了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;
}
 
开发者ID:omerio,项目名称:raspberrypi-appengine-portal,代码行数:34,代码来源:SensorDataEndpoint.java

示例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";
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:12,代码来源:ChannelAPI.java

示例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));
    
  }
}
 
开发者ID:satypro,项目名称:GAELivePubSub,代码行数:12,代码来源:LiveFeedChannel.java

示例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();
	}
}
 
开发者ID:hasier,项目名称:voxpopuli,代码行数:16,代码来源:Utils.java

示例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));
		}
	}
}
 
开发者ID:kwhinnery,项目名称:gae-chat,代码行数:41,代码来源:MultichannelChatManager.java

示例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"));
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:5,代码来源:ChannelTest.java


注:本文中的com.google.appengine.api.channel.ChannelService.sendMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。