本文整理汇总了Java中com.google.appengine.api.channel.ChannelMessage类的典型用法代码示例。如果您正苦于以下问题:Java ChannelMessage类的具体用法?Java ChannelMessage怎么用?Java ChannelMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChannelMessage类属于com.google.appengine.api.channel包,在下文中一共展示了ChannelMessage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: broadcast
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
public void broadcast(JSONObject notification, String account) {
try {
Iterator<String> it = notification.keys();
HashMap<String, Object> valueMap = new HashMap<String, Object>();
while (it.hasNext()) {
String key = it.next();
if (!(notification.get(key) instanceof JSONObject))
valueMap.put(key, notification.get(key));
}
sendGCMNotification(account, valueMap);
sendiOSNotificationAsJson(account, valueMap); //TODO rename
// sendGlassNotification(account, valueMap);
log.log(Level.WARNING, "about to send channel message to "+account);
channelService.sendMessage(new ChannelMessage(account, notification.toString()));
log.log(Level.WARNING, "channel message sent to ");
} catch (Exception e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:24,代码来源:NotificationDelegator.java
示例2: testSendObjects_noResults
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* Test method for {@link Channels#sendObjects}.
*/
@Test
public void testSendObjects_noResults() {
ArgumentCaptor<ChannelMessage> messageCapture = ArgumentCaptor.forClass(ChannelMessage.class);
channels.sendObjects(CHANNEL_KEY, Lists.newArrayList(), TAG, REQUEST_ID);
verify(channelService).sendMessage(messageCapture.capture());
assertEquals(CHANNEL_KEY, messageCapture.getValue().getClientId());
@SuppressWarnings("unchecked") // That's the defined message format.
Map<String, Map<String, String>> message =
gson.fromJson(messageCapture.getValue().getMessage(), Map.class);
assertTrue(message.containsKey(Channels.INFO_TAG));
assertEquals(TAG, message.get(Channels.INFO_TAG).get(Channels.TAG));
assertTrue(message.get(Channels.INFO_TAG).containsKey(Channels.MESSAGE));
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:20,代码来源:ChannelsTest.java
示例3: testSendPage
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* Test method for {@link Channels#sendPage}.
*/
@Test
public void testSendPage()
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Page page = new Page();
List<Object> list = Lists.newArrayList(new Object());
page.getResults().addAll(list);
ArgumentCaptor<ChannelMessage> messageCapture = ArgumentCaptor.forClass(ChannelMessage.class);
channels.sendPage(CHANNEL_KEY, page, TAG, REQUEST_ID);
verify(channelService).sendMessage(messageCapture.capture());
assertEquals(CHANNEL_KEY, messageCapture.getValue().getClientId());
assertEquals(jsonFromList(REQUEST_ID, list), messageCapture.getValue().getMessage());
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:19,代码来源:ChannelsTest.java
示例4: testSendInfoMessage
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* Test method for {@link Channels#sendInfoMessage}.
*/
@Test
public void testSendInfoMessage() {
ArgumentCaptor<ChannelMessage> messageCapture = ArgumentCaptor.forClass(ChannelMessage.class);
channels.sendInfoMessage(CHANNEL_KEY, TAG, REQUEST_ID, MY_MESSAGE);
verify(channelService).sendMessage(messageCapture.capture());
assertEquals(CHANNEL_KEY, messageCapture.getValue().getClientId());
@SuppressWarnings("unchecked") // That's the defined message format.
Map<String, Map<String, String>> message =
gson.fromJson(messageCapture.getValue().getMessage(), Map.class);
assertTrue(message.containsKey(Channels.INFO_TAG));
assertEquals(TAG, message.get(Channels.INFO_TAG).get(Channels.TAG));
assertEquals(MY_MESSAGE, message.get(Channels.INFO_TAG).get(Channels.MESSAGE));
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:20,代码来源:ChannelsTest.java
示例5: testSendErrorChannelMessage
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* Test method for {@link Channels#sendErrorChannelMessage}.
*/
@Test
public void testSendErrorChannelMessage() {
ArgumentCaptor<ChannelMessage> messageCapture = ArgumentCaptor.forClass(ChannelMessage.class);
channels.sendErrorChannelMessage(CHANNEL_KEY, TAG, REQUEST_ID, MY_MESSAGE);
verify(channelService).sendMessage(messageCapture.capture());
assertEquals(CHANNEL_KEY, messageCapture.getValue().getClientId());
@SuppressWarnings("unchecked") // That's the defined message format.
Map<String, Map<String, String>> message =
gson.fromJson(messageCapture.getValue().getMessage(), Map.class);
assertTrue(message.containsKey(Channels.ERROR_TAG));
assertEquals(TAG, message.get(Channels.ERROR_TAG).get(Channels.TAG));
assertEquals(MY_MESSAGE, message.get(Channels.ERROR_TAG).get(Channels.MESSAGE));
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:20,代码来源:ChannelsTest.java
示例6: create
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的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
示例7: sendData
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
private void sendData(ClientId clientId, String data) {
log.info("Sending to " + clientId + ", " + Util.abbrev(data, 50));
try {
channelService.sendMessage(new ChannelMessage(clientId.getId(), data));
} catch (ChannelFailureException e) {
// Channel service is best-effort anyway, so it's safe to discard the
// exception after taking note of it.
log.log(Level.SEVERE, "Channel service failed for " + clientId, e);
}
}
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:11,代码来源:SlobMessageRouter.java
示例8: broadcast
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* broadcast PresenceRoom over all user connected to this room.
* @param p_room
*/
protected static void broadcast(PresenceRoom p_room)
{
AppRoot.logger.fine( "ChannelManager.broadcast room "+ p_room.getGameId() );
String response = Serializer.toClient( p_room );
if( response != null )
{
for( Presence presence : p_room )
{
if( presence.getClientType() == ClientType.XMPP )
{
if( presence.getJabberId() != null )
{
// send presence to xmpp clients
XMPPProbeServlet.sendPresence( new JID( presence.getJabberId() ) );
}
else
{
AppRoot.logger.severe( "Send a PresenceRoom, but his XMPP presence have a JabberId null !" );
}
}
else
{
// send presence to web client
try
{
AppRoot.logger.finer( "ChannelManager.sendMessage "+ presence.getChannelId() );
s_channelService.sendMessage( new ChannelMessage( presence.getChannelId(), response ) );
} catch( Exception e )
{
AppRoot.logger.severe( e.getMessage() );
}
}
}
}
}
开发者ID:kroc702,项目名称:fullmetalgalaxy,代码行数:42,代码来源:ChannelManager.java
示例9: getRun
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的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
示例10: testSendObject
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* Test method for {@link Channels#sendSingleObject}.
*/
@Test
public void testSendObject() {
Object object = new Object();
ArgumentCaptor<ChannelMessage> messageCapture = ArgumentCaptor.forClass(ChannelMessage.class);
channels.sendSingleObject(CHANNEL_KEY, object, TAG, REQUEST_ID);
verify(channelService).sendMessage(messageCapture.capture());
assertEquals(CHANNEL_KEY, messageCapture.getValue().getClientId());
assertEquals(jsonFromList(REQUEST_ID, Lists.newArrayList(object)),
messageCapture.getValue().getMessage());
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:17,代码来源:ChannelsTest.java
示例11: testSendObjects_singleBatch
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* Test method for {@link Channels#sendObjects}.
*/
@Test
public void testSendObjects_singleBatch() {
List<Object> list = makeList(Channels.BATCH_SIZE);
ArgumentCaptor<ChannelMessage> messageCapture = ArgumentCaptor.forClass(ChannelMessage.class);
channels.sendObjects(CHANNEL_KEY, list, TAG, REQUEST_ID);
verify(channelService).sendMessage(messageCapture.capture());
assertEquals(jsonFromList(REQUEST_ID, list), messageCapture.getValue().getMessage());
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:15,代码来源:ChannelsTest.java
示例12: testSendObjects_multipleBatches
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* Test method for {@link Channels#sendObjects}.
*/
@Test
public void testSendObjects_multipleBatches() {
List<Object> list = makeList(Channels.BATCH_SIZE + 1);
channels.sendObjects(CHANNEL_KEY, list, TAG, REQUEST_ID);
verify(channelService, times(2)).sendMessage(any(ChannelMessage.class));
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:12,代码来源:ChannelsTest.java
示例13: sendUpdateToUser
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的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
示例14: pushUpdates
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的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
示例15: push
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
@Override
@ApiMethod(path = "pushToAppEngineChannel")
public void push(@Named("subscribeId") String subscribeId,
@Nullable @Named("messageType") String messageType, @Named("message") String msg) {
try {
channelService.sendMessage(new ChannelMessage(subscribeId, msg));
} catch (ChannelFailureException e) {
// Channel service is best-effort anyway, so it's safe to discard the
// exception after taking note of it.
log.log(Level.SEVERE, "Channel service failed for " + subscribeId, e);
}
}
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:13,代码来源:AppEngineChannelService.java
示例16: sendMessage
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的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
示例17: disconnect
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
public static void disconnect(Presence p_presence)
{
if( p_presence == null )
{
return;
}
AppRoot.logger.fine( "ChannelManager.disconnect "+ p_presence.getGameId()+" - "+p_presence.getChannelId() );
PresenceRoom room = getRoom( p_presence.getGameId() );
room.remove( p_presence );
// ask all other presence with similar pseudo to send a presence empty
// message
String response = Serializer.toClient( new ChatMessage() );
for(Presence presence : room)
{
if( presence.getClientType() != ClientType.XMPP
&& presence.getPseudo().equalsIgnoreCase( p_presence.getPseudo() ) )
{
try
{
// client have 4 seconds to answer
presence.getLastConnexion().setTime(
System.currentTimeMillis() - CACHE_PRESENCE_TTL_MS + 4000 );
s_channelService.sendMessage( new ChannelMessage( presence.getChannelId(), response ) );
} catch( Exception e )
{
AppRoot.logger.severe( e.getMessage() );
}
}
}
if( room.isEmpty() )
{
// room empty: clear cache
getCache().delete( p_presence.getGameId() );
}
else
{
// room was updated: update cache
getCache()
.put( p_presence.getGameId(), room, Expiration.byDeltaSeconds( CACHE_ROOM_TTL_SEC ) );
// then broadcast connection to all connected users
broadcast( room );
}
}
开发者ID:kroc702,项目名称:fullmetalgalaxy,代码行数:48,代码来源:ChannelManager.java
示例18: notify
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
public void notify(String account, String message) {
if (account != null) channelService.sendMessage(new ChannelMessage(account, message));
}
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:4,代码来源:ChannelNotificator.java
示例19: sendUpdate
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
public static void sendUpdate(String channelKey) {
ChannelService channelService = ChannelServiceFactory.getChannelService();
channelService.sendMessage(new ChannelMessage(channelKey, "hallo"));
}
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:5,代码来源:ChannelTest.java
示例20: createMessage
import com.google.appengine.api.channel.ChannelMessage; //导入依赖的package包/类
/**
* Creates a {@link ChannelMessage} with the JSON representation of the data map.
*
* @param channelKey the key to send a message via the Channel API
* @param data the data map
* @return a {@link ChannelMessage}
*/
private ChannelMessage createMessage(String channelKey, Map<String, ?> data) {
return new ChannelMessage(channelKey, gson.toJson(data));
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:11,代码来源:Channels.java
注:本文中的com.google.appengine.api.channel.ChannelMessage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论