示例#1
0
  @Override
  public GatewayClient removeClient(String jid) throws DatastoreException {

    log.debug("Removing client with jid: [%s]", jid);
    GatewayClient client = getClient(jid);
    if (client != null) {
      Mutator mutator = Pelops.createMutator(schemaName);
      String bareJid = JIDUtils.getBareJid(jid);
      String resource = JIDUtils.getResource(jid);
      mutator.deleteColumn("clients", bareJid, resource);
      mutator.execute(ConsistencyLevel.ONE);

      List<String> resources = getClientResources(bareJid);
      if (resources.size() == 0) {
        RowDeletor deletor = Pelops.createRowDeletor(schemaName);
        deletor.deleteRow("clients", bareJid, ConsistencyLevel.ONE);
      }
      log.debug("Client with jid: [%s] removed successfully", jid);
    }

    return client;
  }
示例#2
0
  @Override
  public GatewayClient getClient(String jid) {

    log.debug("Finding client with jid: [%s]", jid);
    GatewayClient client = null;
    try {
      String bareJid = JIDUtils.getBareJid(jid);
      String resource = JIDUtils.getResource(jid);
      boolean resourceFound = false;

      Selector selector = Pelops.createSelector(schemaName);
      List<Column> columns =
          selector.getColumnsFromRow("clients", bareJid, false, ConsistencyLevel.ONE);
      if (columns != null && columns.size() > 0) {
        for (Column column : columns) {
          String name = Bytes.toUTF8(column.getName());
          if (name.equals(resource)) {
            resourceFound = true;
          }
        }
      }

      if (resourceFound) {
        Application application = getApplication(JIDUtils.getBareJid(jid));
        if (application != null) {
          client = new GatewayClient();
          client.setJid(jid);
          client.setPlatform(application.getPlatform());
        }
      }

    } catch (PelopsException pe) {
      log.error(pe.getMessage(), pe);
    }
    return client;
  }