Package com.google.appengine.api.channel

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


  public void dataclient(String userID, String userNickname, String param1) {
    String str = "[";
    str += "{\"serverNodeData\":\"true\",\"netID\":\""+userID+"\",\"netNickname\":\""+userNickname+"\",\"param1\":\""+param1+"\"}";
    str += "]";
   
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    for(int n = 0; n < this.arrNetNodesIds.size(); n++) {   
      String channelKey = getChannelKey(this.arrNetNodesIds.get(n));
      channelService.sendMessage(new ChannelMessage(channelKey, str));
    }
  }
View Full Code Here


  public void disconnect(String userID, String userNickname) {
    String str = "[";
    str += "{\"disconnectNetNode\":\"true\",\"netID\":\""+userID+"\",\"netNickname\":\""+userNickname+"\"}";
    str += "]";
   
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    for(int n = 0; n < this.arrNetNodesIds.size(); n++) {
      String channelKey = getChannelKey(this.arrNetNodesIds.get(n));
      channelService.sendMessage(new ChannelMessage(channelKey, str));
    }
   
    int idxToDel = 0;
    for(int n = 0; n < this.arrNetNodesIds.size(); n++) {  
      if(this.arrNetNodesIds.get(n).equals(userID)) {
View Full Code Here

      gameKey = KeyFactory.keyToString(stormChannel.getKey());
    }
       
    pm.close();

    ChannelService channelService = ChannelServiceFactory.getChannelService();
   
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    this.token = channelService.createChannel(stormChannel.getChannelKey(user.getUserId()));  
     
    //this.token = channelService.createChannel( gameKey );  
    //token = channelService.createChannel( KeyFactory.keyToString(stormChannel.getKey()) ); 
   
   
View Full Code Here

   */
  private static final long serialVersionUID = 1L;

  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    ChannelPresence presence = channelService.parsePresence(req);
    String userId = presence.clientId();
   
    User u = Checkers.userMap.remove(userId);
    //send a note to all connected users
    Enumeration<String> keys = Checkers.userMap.keys();
    String key;
    String message = "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.USER_SIGNOUT+"\"}";
    Gson gson = new Gson();
    String gsu = gson.toJson(u);
   
    while(keys.hasMoreElements()){
      key = keys.nextElement();
      if( key.equals("123321")) continue;
      try{
        channelService.sendMessage(new ChannelMessage(key, message));
        channelService.sendMessage(new ChannelMessage(key, gsu));
      }catch(Exception e){
        e.printStackTrace();
      }
    }   
  }
View Full Code Here

    String action = req.getParameter(Constant.ACTION).toString();
    char cBrd[][];
    char turn;
    String userId;
    String userName;
    ChannelService channelService ;
    log.info("++++++++++OnlineCHeckers++++++++++++ : "+action);
    switch(action){
      case Constant.NEW_GAME_TOKEN:
        userId = req.getParameter(Constant.USER_ID).toString();
        if(userMap.get(userId) == null)
          break;
        String ngToken = String.valueOf(UUID.randomUUID().getMostSignificantBits());
          channelService = ChannelServiceFactory.getChannelService();
          channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.NEW_GAME_TOKEN+"\"}"));
          channelService.sendMessage(new ChannelMessage(userId, gson.toJson(ngToken)))
          gameTokenList.put(ngToken, userId);
          break;
      case Constant.NEW_GAME:
        cBrd = CheckerModel.checkerBoard();
        r = gson.toJson(cBrd);
        break;
      case Constant.PLAY:
        cBrd = gson.fromJson(req.getParameter("cBoard[][]").toString(), char[][].class);
        turn = gson.fromJson(req.getParameter("player").toString(), char.class);
       
        Position[][] mt = MoveTable.moveTable(cBrd, turn);
       
        r = gson.toJson(mt);
        break;
      case Constant.NEW_TOKEN:
        userId = req.getParameter(Constant.USER_ID).toString();
        userName = req.getParameter(Constant.USER_NAME).toString();
        User user = new User(userId, userName);
        inSignIn.put(userId, user);
        //XXXXXXXXXXXTest if user exist xxxxxxxxxxxxxxxxxxxxxxx
          channelService = ChannelServiceFactory.getChannelService();
          String token = channelService.createChannel(userId);
          r = token;
          break;
      case Constant.CONNECTED_USER_LIST:
        userId = req.getParameter(Constant.USER_ID).toString();
        if( userMap.get(userId) != null){
              channelService = ChannelServiceFactory.getChannelService();
              channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.CONNECTED_USER_LIST+"\"}"));
              channelService.sendMessage(new ChannelMessage(userId, gson.toJson(userMap)));
        }else
          r = "You are not connected!!!";
        break;
    }   
    resp.getWriter().print(r)
View Full Code Here

    String userId;
    char piece;
    String rId;
    String tk;
    Game gm;
    ChannelService channelService ;
    Checkers.log.info("++++++++++++GameServlet+++++++++++++++ : "+action);
    switch(action){
     
      case Constant.GAME_MOVE:
        Checkers.log.info("++++++++++++GAME_MOVE++++++++++++");
        userId = req.getParameter(Constant.USER_ID).toString();
        tk = req.getParameter(Constant.GAME_TOKEN).toString();
        piece = req.getParameter(Constant.GAME_PIECE).toString().charAt(0);
        Position[] mtr = gson.fromJson(req.getParameter("mt[]").toString(), Position[].class);
       
        gm = gameMap.get(tk)
       
        if( gm != null && gm.move(mtr, piece) == true){
          rId = gm.getUserId(userId);
          Checkers.log.info("++++++++++++GAME_MOVE    Sending Move to remote host id "+rId+"++++++++++++");
          channelService = ChannelServiceFactory.getChannelService();
          channelService.sendMessage(new ChannelMessage(rId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_MOVE+"\"}"));
            channelService.sendMessage(new ChannelMessage(rId, gson.toJson(mtr)));   
           
            if( gm.getMTable() == null ){
              channelService.sendMessage(new ChannelMessage(rId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_PLAY+"\"}"));
              channelService.sendMessage(new ChannelMessage(rId, gson.toJson(Constant.GAME_PLAY)));               
            }
           
        }else
          Checkers.log.info("++++++++++++GAME_MOVE  game not "+gm+" OR invalid move for token "+tk+" AND mtr "+mtr+" ++++++++++++");
       
        break
      case Constant.GAME_MTABLE:
        userId = req.getParameter(Constant.USER_ID).toString();
        tk = req.getParameter(Constant.GAME_TOKEN).toString();
        piece = req.getParameter(Constant.GAME_PIECE).toString().charAt(0);
        gm = gameMap.get(tk)
       
        if( gm != null ){
          Position[][] mt = gm.getMTable(piece);
         
          channelService = ChannelServiceFactory.getChannelService();
          channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_MTABLE+"\"}"));
            channelService.sendMessage(new ChannelMessage(userId, gson.toJson(mt)));           
        }
       
        break;
      case Constant.JOIN_GAME :
        userId = req.getParameter(Constant.USER_ID).toString();
        tk = req.getParameter(Constant.GAME_TOKEN).toString();
        rId = Checkers.gameTokenList.get(tk);
       
        channelService = ChannelServiceFactory.getChannelService();
        if( rId != null && Checkers.userMap.get(rId) != null /*&& playerMap.get(rId) == null && playerMap.get(userId)== null */){ 
         
          Checkers.gameTokenList.remove(tk);
          Checkers.playerMap.put(userId, Checkers.userMap.get(userId));
          Checkers.playerMap.put(rId, Checkers.userMap.get(rId));
         
          gm = new Game(userId, rId);
          gameMap.put(tk, gm);
         
          //----USER 1
          channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.JOIN_GAME+"\"}"));
            channelService.sendMessage(new ChannelMessage(userId, gson.toJson(Checkers.userMap.get(rId))));           
          channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_BOARD+"\"}"));
            channelService.sendMessage(new ChannelMessage(userId, gson.toJson(gm.getCBoard())))
          channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_PIECE+"\"}"));
            channelService.sendMessage(new ChannelMessage(userId, gson.toJson(gm.getTurn())))
           
            channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_PLAY+"\"}"));
            channelService.sendMessage(new ChannelMessage(userId, gson.toJson(Constant.GAME_PLAY)))
           
           
            //----USER 2
            channelService.sendMessage(new ChannelMessage(rId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.JOIN_GAME+"\"}"));
            channelService.sendMessage(new ChannelMessage(rId, gson.toJson(Checkers.userMap.get(userId))));  
          channelService.sendMessage(new ChannelMessage(rId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_BOARD+"\"}"));
            channelService.sendMessage(new ChannelMessage(rId, gson.toJson(gm.getCBoard())))
          channelService.sendMessage(new ChannelMessage(rId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_PIECE+"\"}"));
            channelService.sendMessage(new ChannelMessage(rId, gson.toJson(gm.getRTurn())))
        }else{
            channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.GAME_JOINING_FAILED+"\"}"));
            channelService.sendMessage(new ChannelMessage(userId, gson.toJson(tk)))
        }
        break;
    }
    resp.getWriter().print(r);
  }
View Full Code Here

   */
  private static final long serialVersionUID = 1L;

  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    ChannelPresence presence = channelService.parsePresence(req);
    String userId = presence.clientId();

    User user = Checkers.inSignIn.get(userId);
    User u = EMF.getUser(userId);
    if( u == null ){
      EMF.insert(user);
    }else{
      user.setUser(u);
      EMF.update(user);
    }
   
    if( user != null ){     
      //send a note to all connected users
      Enumeration<String> keys = Checkers.userMap.keys();
      String key;
      String message = "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.USER_SIGNIN+"\"}";
      Gson gson = new Gson();
      String gsu = gson.toJson(user);
     
      while(keys.hasMoreElements()){
        key = keys.nextElement();
        if( key.equals("123321")) continue;
        try{
          channelService.sendMessage(new ChannelMessage(key, message));
          channelService.sendMessage(new ChannelMessage(key, gsu));
        }catch(Exception e){
          e.printStackTrace();
        }
      }
      Checkers.inSignIn.remove(userId);
View Full Code Here

      Message msg = gson.fromJson(req.getParameter(Constant.MESSAGE).toString(), Message.class);
      String rId = msg.getrId();
     
      if( userId.equals(msg.getsId()) && Checkers.userMap.get(userId) != null && Checkers.userMap.get(rId) != null ){
        //---------ICI Tester la valider du message-------------
        ChannelService channelService = ChannelServiceFactory.getChannelService();
          channelService.sendMessage(new ChannelMessage(rId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.MESSAGE+"\"}"));
          channelService.sendMessage(new ChannelMessage(rId, gson.toJson(msg)));
      }else if(userId.equals(msg.getsId()) ){
        ChannelService channelService = ChannelServiceFactory.getChannelService();
          channelService.sendMessage(new ChannelMessage(userId, "{\""+Constant.MESSAGE_TYPE+"\":\""+Constant.ERROR+"\"}"));
          channelService.sendMessage(new ChannelMessage(userId, gson.toJson(new String("Code : "+Constant.ERR_CODEOO1+" Message has not been sent to : "+rId))));       
      }
     
    }
   
  }
View Full Code Here

   
    List<String> pathlist = Arrays.asList( path.split("/") ) ;
    Datastore datastore = new Datastore();
    Datastore.EntityWrap e = datastore.updateEntity(pathlist, input, meta);
   
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    channelService.sendMessage( new ChannelMessage("/" + path, "M" ) );
    channelService.sendMessage( new ChannelMessage(e.getParentPath()+"/", "M" ) );
       
   
    resp.setContentType("application/json");
    String msg = Utils.makeGson().toJson(entityToMap(e.entity,e.getParentPath()), Map.class );
    resp.getWriter().println(msg);
View Full Code Here

      throws IOException {
    String path = req.getPathInfo();
    if ( path == null || path.length() == 0 ) {
      path = "/";
    }
    ChannelService channelService = ChannelServiceFactory.getChannelService();
    String token = channelService.createChannel(path);
    resp.setContentType("text/plain");
    resp.getWriter().write(token);

  }
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.