Package com.google.appengine.api.channel

Examples of com.google.appengine.api.channel.ChannelService


  private Date to;

  @Override
  public void onMessage(Message message) {
    parseMessage(message);
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    for (PageEntity page : getDao().getPageDao().select()) {
      if (filter(page)) {
        channelService.sendMessage(new ChannelMessage(
            clientId, createHitJSON(page)));
      }
    }
    channelService.sendMessage(new ChannelMessage(clientId, "({end:true})"));
  }
View Full Code Here


        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                        throws ServletException, IOException {
                // Handle request and write response
                ChannelService channelService = ChannelServiceFactory.getChannelService();
                ChannelPresence presence = channelService.parsePresence(req);
              
                String email=presence.clientId();
              
                DataOperation.deletePlayerWithEmail(email);
                            
View Full Code Here

      return availableChannel.getChannelToken();
    } else {
      // Generate new client id
      log.info("gen rand");
      String newClientId = new BigInteger(130, rand).toString(32);
      ChannelService channelService = ChannelServiceFactory.getChannelService();
      // Open new channel
      log.info("duration minutes: " + CHANNEL_TOKEN_TIMEOUT_MINUTES);
      String newChannelToken = channelService.createChannel(newClientId, CHANNEL_TOKEN_TIMEOUT_MINUTES);
      // Save new entity
      long expires = new Date().getTime() + CHANNEL_TOKEN_TIMEOUT_MILIS;
      new ChannelConnection()
        .setClientId(newClientId)
        .setChannelToken(newChannelToken)
View Full Code Here

      return newChannelToken;
    }
  }
 
  public static String parsePresence(HttpServletRequest req) throws IOException {
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    ChannelPresence presence = channelService.parsePresence(req);
    String clientId = presence.clientId();
    return clientId;
  }
View Full Code Here

  // ========================================================================= //
  //        PUSH MESSAGES                         //
  // ========================================================================= //
   
  public static void pushMessage(String payload, MessageType type) {
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    // Find all active channels
    List<ChannelConnection> activeChannels = ObjectifyUtil.ofy().load().type(ChannelConnection.class).filter("active", true).list();
    for (ChannelConnection channel : activeChannels) {
      String clientId = channel.getClientId();
      // Payloads are not logged
      log.info("Sending message to " + clientId + " of type " + type);
      ChannelMessage msg = createMessage(clientId, type, payload);
      channelService.sendMessage(msg);
    }
  }
View Full Code Here

   * Send message to client over channel
   * @param channelKey channel-key
   * @param message the message to send
   */
  public void messageClient(String channelKey, Message message) {
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    System.out.println("Server " + channelKey + ": " + message + ".");
    channelService.sendMessage(new ChannelMessage(channelKey, pushServer.encodeMessage(message)));
  }
View Full Code Here

  public String test(Model model){
 
    String userId = new String("aaa");
    String token = new String("token");
    final UserService userService = UserServiceFactory.getUserService();
    final ChannelService channelService = ChannelServiceFactory.getChannelService();

    //vytvoreni ID pro uzivatele

    if(!userService.isUserLoggedIn()){
      model.addAttribute("link", userService.createLoginURL("/hra.do"));
      return "login";
    }
    else {
      if(userService != null) {
         userId = userService.getCurrentUser().getUserId();
      }
     
      //asi vytvoreni kanalu a prirazeni tokenu
      if (channelService != null){
         token = channelService.createChannel(userId);
      }
     
      String login = userService.getCurrentUser().getNickname();
      String email = userService.getCurrentUser().getEmail();
     
View Full Code Here

public class ServerServlet extends HttpServlet{
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException{
    final com.google.appengine.api.users.UserService userService = UserServiceFactory.getUserService();
    final ChannelService channelService = ChannelServiceFactory.getChannelService();
    //vytvoreni ID pro uzivatele
    String userId = userService.getCurrentUser().getUserId();
   
    //asi vytvoreni kanalu a prirazeni tokenu
    String token = channelService.createChannel(userId);
   
    //ted musime predat token do stranky uzivatele (asi :-) )
    //v googlu vemou obsah indexu a tam si daji nejaky tag ktery pak nahradi tim tokenem
    //viz index=index.replaceAll("\\{\\{ token \\}\\}",token);
    //pak nasleduje odeslani predelane stranky s tokenemn
View Full Code Here

     */
   
    System.out.println("prijata zprava:" + text + ";");
    // login bz slo posilat abz se nemusel tahat z google
    // Bych to takhle nechal z "bezpecnostnich duvodu" treba
    final ChannelService channel = ChannelServiceFactory.getChannelService();
    final UserService userService = UserServiceFactory.getUserService();
    String login = userService.getCurrentUser().getNickname();
    // return null;
   
    HashMap<String, String> zprava=new HashMap<String, String>();
   
   
    zprava.put("typ", "chat");
    zprava.put("login",login);
    zprava.put("zprava",text);
   
    JSONObject json=JSONObject.fromObject(zprava);

    Hra tmp = SpravceHer.getInstance().getHra(hraId);
    if (tmp == null) {
      System.out.println("neexistujici hra");
      return "zprava";
    }
    System.out.println(json.toString());
    for (Hrac s : tmp.getHraci().values()) {
      channel.sendMessage(new ChannelMessage(s.getUserId(), json.toString()));
    }
    return "zprava";
  }
View Full Code Here

 
 

  public static void presmeruj(Hra hra, String cil) {
   
    final ChannelService chanel = ChannelServiceFactory.getChannelService();
   
    HashMap<String, String> zprava=new HashMap<String, String>();
   
    zprava.put("typ", "redirect");
    zprava.put("cil", cil);
   
    JSONObject json=JSONObject.fromObject(zprava);
    String z = toUTF8(json.toString());
    for (Hrac h : hra.getHraci().values()) {
      chanel.sendMessage(new ChannelMessage(h.getUserId(), json.toString()));
    }
   
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.channel.ChannelService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.