Search in sources :

Example 6 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class DatabusHttpClientImpl method register.

@Override
public DatabusRegistration register(DatabusCombinedConsumer consumer, String... sources) throws DatabusClientException {
    if ((null == consumer))
        throw new DatabusClientException("No consumer callback has been specified.");
    if ((null == sources) || (sources.length == 0))
        throw new DatabusClientException("Please specify Databus sources to be consumed: register(consumer, source1, source2, ...");
    RegistrationId regId = RegistrationIdGenerator.generateNewId(consumer.getClass().getSimpleName(), DatabusSubscription.createSubscriptionList(Arrays.asList(sources)));
    DatabusV2RegistrationImpl reg = new DatabusV2RegistrationImpl(regId, this, getCheckpointPersistenceProvider());
    List<DatabusCombinedConsumer> consumers = new ArrayList<DatabusCombinedConsumer>();
    consumers.add(consumer);
    reg.addDatabusConsumers(consumers);
    reg.addSubscriptions(sources);
    _regList.add(reg);
    reg.onRegister();
    return reg;
}
Also used : RegistrationId(com.linkedin.databus.client.pub.RegistrationId) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) SelectingDatabusCombinedConsumer(com.linkedin.databus.client.consumer.SelectingDatabusCombinedConsumer) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer) DatabusV2RegistrationImpl(com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)

Example 7 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class DatabusHttpClientImpl method getAllClientClusters.

/**
 * Fetch all the client clusters which have been registered in this client instance keyed by their
 * registrationIds. This has been overridden by V3 client to provide both V2 and V3 clusters.
 *
 * Only a copy of the registration ids are returned. Hence modifying the registration ids should not
 * affect the global Registration Id map.
 * @return Client clusters registered in this client instance keyed by their registration ids.
 */
public Map<RegistrationId, DbusClusterInfo> getAllClientClusters() {
    Map<RegistrationId, DbusClusterInfo> clusters = new HashMap<RegistrationId, DbusClusterInfo>();
    Collection<DatabusMultiPartitionRegistration> regs = getAllClientClusterRegistrations();
    for (DatabusMultiPartitionRegistration reg : regs) {
        if (reg instanceof DatabusV2ClusterRegistrationImpl) {
            DatabusV2ClusterRegistrationImpl r = (DatabusV2ClusterRegistrationImpl) reg;
            clusters.put(new RegistrationId(r.getRegistrationId().getId()), r.getClusterInfo());
        }
    }
    return clusters;
}
Also used : DatabusV2ClusterRegistrationImpl(com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl) DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) HashMap(java.util.HashMap) DatabusMultiPartitionRegistration(com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId)

Example 8 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class DatabusHttpClientImpl method register.

@Override
public DatabusRegistration register(Collection<DatabusCombinedConsumer> consumers, String... sources) throws DatabusClientException {
    if ((null == consumers) || (consumers.isEmpty()))
        throw new DatabusClientException("No consumer callbacks have been specified.");
    if ((null == sources) || (sources.length == 0))
        throw new DatabusClientException("Please specify Databus sources to be consumed: register(consumer, source1, source2, ...");
    RegistrationId regId = RegistrationIdGenerator.generateNewId(consumers.iterator().next().getClass().getSimpleName(), DatabusSubscription.createSubscriptionList(Arrays.asList(sources)));
    DatabusV2RegistrationImpl reg = new DatabusV2RegistrationImpl(regId, this, getCheckpointPersistenceProvider());
    reg.addDatabusConsumers(consumers);
    reg.addSubscriptions(sources);
    _regList.add(reg);
    reg.onRegister();
    return reg;
}
Also used : RegistrationId(com.linkedin.databus.client.pub.RegistrationId) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) DatabusV2RegistrationImpl(com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)

Example 9 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class RegistrationIdGenerator method generateNewId.

/**
 * Queries the existing database of registrations inside the client and generates a new id different from
 * any of them
 *
 * @param prefix : A String prefix which can be specified to precede the id to be generated. Typically this
 *                 is the name of the Consumer class
 * @param subsSources : List of subscriptions the consumer is interested in
 * @return RegistrationId : Generated based on the prefix _ 8 byte md5 hash ( subscriptions ) _ count
 */
public static RegistrationId generateNewId(String prefix, Collection<DatabusSubscription> subsSources) {
    StringBuilder subscription = new StringBuilder();
    for (DatabusSubscription ds : subsSources) {
        if (ds != null)
            subscription.append(ds.generateSubscriptionString());
    }
    String id = generateUniqueString(prefix, subscription.toString());
    RegistrationId rid = new RegistrationId(id);
    return rid;
}
Also used : RegistrationId(com.linkedin.databus.client.pub.RegistrationId) DatabusSubscription(com.linkedin.databus.core.data_model.DatabusSubscription)

Example 10 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class RegistrationIdGenerator method generateNewId.

/**
 * For a given regId , this API queries the existing database of registrations inside the client.
 * If the id is available, it is returned as a registration id, otherwise a running counter
 * is appended to the suggested regId.
 *
 * @param id : A suggested name by the caller to be used as regId. If the id is not available, a running counter
 *             is appended
 * @return RegistrationId : Generated based on the id _count
 */
public static RegistrationId generateNewId(String id) {
    String r = generateUniqueString(id);
    RegistrationId rid = new RegistrationId(r);
    return rid;
}
Also used : RegistrationId(com.linkedin.databus.client.pub.RegistrationId)

Aggregations

RegistrationId (com.linkedin.databus.client.pub.RegistrationId)17 DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)7 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)5 DatabusClientException (com.linkedin.databus.client.pub.DatabusClientException)4 HashMap (java.util.HashMap)4 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)3 DatabusMultiPartitionRegistration (com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration)3 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)3 ClusterCheckpointPersistenceProvider (com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider)2 DatabusCombinedConsumer (com.linkedin.databus.client.pub.DatabusCombinedConsumer)2 DatabusV3MultiPartitionRegistration (com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration)2 DbusClusterInfo (com.linkedin.databus.client.pub.DbusClusterInfo)2 DatabusV2ClusterRegistrationImpl (com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl)2 DatabusV2RegistrationImpl (com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)2 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)2 InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 DbusPartitionInfoImpl (com.linkedin.databus.client.DbusPartitionInfoImpl)1