Package org.buildndeploy.server.model

Examples of org.buildndeploy.server.model.ChannelConnection


 
  public static String proccesClientId(String username) {
    long now = new Date().getTime();
    // Check for available channel
    log.info("begin query");
    ChannelConnection availableChannel = ObjectifyUtil.ofy().load()
      .type(ChannelConnection.class)
      .filter("active", false)
      .filter("expires >", now + FIVE_MINUTES)
      .first().get();
    if (availableChannel != null) {
      log.info("found available channel " + availableChannel.getChannelToken());
      availableChannel.setUsername(username).save();
      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)
        .setExpires(expires)
        .setActive(false)
        .setUsername(username)
View Full Code Here


  private static Logger log = Logger.getLogger(ConnectServlet.class.getName());
 
  public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
    String clientId = ChannelUtil.parsePresence(req);
    // Have to query on indexed clientId property, should only be one result
    ChannelConnection s = ObjectifyUtil.ofy().load().type(ChannelConnection.class).id(clientId).get();
    s.setActive(true).save();
    String username = s.getUsername();
    ChannelUtil.pushMessage(username, MessageType.ConnectedEvent);
    log.info("User connected to Channel " + username);
  }
View Full Code Here

 
  private static Logger log = Logger.getLogger(DisconnectServlet.class.getName());
 
  public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
    String clientId = ChannelUtil.parsePresence(req);
    ChannelConnection s = ObjectifyUtil.ofy().load().type(ChannelConnection.class).id(clientId).get();
    s.setActive(false).save();
    String username = s.getUsername();
    ChannelUtil.pushMessage(username, MessageType.DisconnectedEvent);
    log.info("User disconnected from Channel " + username);
  }
View Full Code Here

TOP

Related Classes of org.buildndeploy.server.model.ChannelConnection

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.