本文整理汇总了Java中com.google.appengine.api.channel.ChannelMessage类的典型用法代码示例。如果您正苦于以下问题:Java ChannelMessage类的具体用法?Java ChannelMessage怎么用?Java ChannelMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChannelMessage类属于com.google.appengine.api.channel包,在下文中一共展示了ChannelMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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));
}
示例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());
}
示例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));
}
示例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));
}
示例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;
}
示例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);
}
}
示例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() );
}
}
}
}
}
示例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";
}
示例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());
}
示例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());
}
示例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));
}
示例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));
}
}
示例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();
}
}
示例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);
}
}