@Override public Application getApplicationForAddress(String address) { log.debug("Finding application for address: [%s]", address); Selector selector = Pelops.createSelector(schemaName); List<Column> columns = selector.getColumnsFromRow("addresses", address, false, ConsistencyLevel.ONE); if (columns != null && columns.size() > 0) { Column column = columns.get(0); return getApplication(Bytes.toUTF8(column.getValue())); } log.debug("No application found for address: [%s]", address); return null; }
@Override public GatewayCall getCall(String id) { log.debug("Getting call with id [%s]", id); Selector selector = Pelops.createSelector(schemaName); try { List<Column> columns = selector.getColumnsFromRow("calls", id, false, ConsistencyLevel.ONE); return buildCall(columns, id); } catch (PelopsException pe) { log.error(pe.getMessage(), pe); return null; } }
@Override public GatewayMixer getMixer(String name) { log.debug("Getting mixer with name [%s]", name); Selector selector = Pelops.createSelector(schemaName); try { List<Column> columns = selector.getColumnsFromRow("mixers", name, false, ConsistencyLevel.ONE); return buildMixer(columns, name); } catch (PelopsException pe) { log.error(pe.getMessage(), pe); return null; } }
@Override public Application getApplication(String jid) { if (jid == null) return null; log.debug("Finding application with jid: [%s]", jid); Application application = null; Selector selector = Pelops.createSelector(schemaName); List<Column> columns = selector.getColumnsFromRow("applications", jid, false, ConsistencyLevel.ONE); if (columns.size() > 0) { application = new Application(jid); populateApplicationData(application, columns); } return application; }
@Override public List<String> getFilteredApplications(String id) throws DatastoreException { log.debug("Getting the list of filtered jids for id [%s]", id); List<String> ids = new ArrayList<String>(); Selector selector = Pelops.createSelector(schemaName); try { List<Column> columns = selector.getColumnsFromRow("filters", id, false, ConsistencyLevel.ONE); for (Column column : columns) { ids.add(Bytes.toUTF8(column.getName())); } } catch (Exception e) { log.error(e.getMessage(), e); return Collections.EMPTY_LIST; } return ids; }
@Override public final UserAccount findUserAccountByUsername(final String username) { if (username == null) { throw new IllegalArgumentException("The passed username was null."); } final Selector selector = connectionPool.createSelector(); final List<Column> columns = selector.getColumnsFromRow(COLUMN_FAMILY_USERNAME, username, false, CONSISTENCY_LEVEL_READ); if (!columns.isEmpty()) { final String userid = Selector.getColumnStringValue(columns, "userid"); return findUserAccountByPrimaryKey(userid); } return null; }
@Override public GatewayVerb getVerb(String mixerName, String id) { log.debug("Getting the verb [%s] from mixer [%s]", id, mixerName); Selector selector = Pelops.createSelector(schemaName); try { List<Column> columns = selector.getColumnsFromRow("verbs", mixerName, false, ConsistencyLevel.ONE); for (Column column : columns) { if (Bytes.toUTF8(column.getName()).equals(id)) { return new GatewayVerb(mixerName, id, Bytes.toUTF8(column.getValue())); } } } catch (Exception e) { log.error(e.getMessage(), e); } return null; }
@SuppressWarnings("unchecked") @Override public List<String> getClientResources(String bareJid) { try { log.debug("Finding resources for clients with jid: [%s]", bareJid); Selector selector = Pelops.createSelector(schemaName); List<Column> resourceColumn = selector.getColumnsFromRow("clients", bareJid, false, ConsistencyLevel.ONE); List<String> resources = new ArrayList<String>(); for (Column column : resourceColumn) { String name = Bytes.toUTF8(column.getName()); if (!name.equals("appId")) { resources.add(Bytes.toUTF8(column.getName())); } } return resources; } catch (PelopsException pe) { log.error(pe.getMessage(), pe); return Collections.EMPTY_LIST; } }
@SuppressWarnings("unchecked") @Override public List<GatewayVerb> getVerbs(String mixerName) { log.debug("Getting the list of active verbs for mixer [%s]", mixerName); List<GatewayVerb> ids = new ArrayList<GatewayVerb>(); Selector selector = Pelops.createSelector(schemaName); try { List<Column> columns = selector.getColumnsFromRow("verbs", mixerName, false, ConsistencyLevel.ONE); for (Column column : columns) { GatewayVerb verb = new GatewayVerb( mixerName, Bytes.toUTF8(column.getName()), Bytes.toUTF8(column.getValue())); ids.add(verb); } } catch (Exception e) { log.error(e.getMessage(), e); return Collections.EMPTY_LIST; } return ids; }
@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; }