Search in sources :

Example 1 with WanPublisher

use of com.hazelcast.wan.WanPublisher in project hazelcast by hazelcast.

the class WanEventContainerReplicationOperation method forAllReplicationContainers.

private void forAllReplicationContainers(BiConsumer<WanPublisher, Object> publisherContainerConsumer) {
    WanReplicationService service = getWanReplicationService();
    for (Entry<String, Map<String, Object>> wanReplicationSchemeEntry : eventContainers.entrySet()) {
        String wanReplicationScheme = wanReplicationSchemeEntry.getKey();
        Map<String, Object> eventContainersByPublisherId = wanReplicationSchemeEntry.getValue();
        for (Entry<String, Object> publisherEventContainer : eventContainersByPublisherId.entrySet()) {
            String publisherId = publisherEventContainer.getKey();
            Object eventContainer = publisherEventContainer.getValue();
            WanPublisher publisher = service.getPublisherOrFail(wanReplicationScheme, publisherId);
            publisherContainerConsumer.accept(publisher, eventContainer);
        }
    }
}
Also used : WanPublisher(com.hazelcast.wan.WanPublisher) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map)

Example 2 with WanPublisher

use of com.hazelcast.wan.WanPublisher in project hazelcast by hazelcast.

the class DelegatingWanScheme method prepareEventContainerReplicationData.

/**
 * Collect all replication data matching the replication event and collection
 * of namespaces being replicated.
 * Returns containers for WAN replication events grouped by WAN publisher ID.
 * Silently skips publishers not supporting replication.
 *
 * @param event      the replication event
 * @param namespaces the object namespaces which are being replicated
 * @return a map from WAN publisher ID to container object for WAN replication events
 */
public Map<String, Object> prepareEventContainerReplicationData(PartitionReplicationEvent event, Collection<ServiceNamespace> namespaces) {
    Map<String, Object> eventContainers = createHashMap(publishers.size());
    for (Entry<String, WanPublisher> publisherEntry : publishers.entrySet()) {
        WanPublisher publisher = publisherEntry.getValue();
        if (publisher instanceof WanMigrationAwarePublisher) {
            Object eventContainer = ((WanMigrationAwarePublisher) publisher).prepareEventContainerReplicationData(event, namespaces);
            if (eventContainer != null) {
                String publisherId = publisherEntry.getKey();
                eventContainers.put(publisherId, eventContainer);
            }
        }
    }
    return eventContainers;
}
Also used : WanPublisher(com.hazelcast.wan.WanPublisher) WanMigrationAwarePublisher(com.hazelcast.wan.WanMigrationAwarePublisher)

Example 3 with WanPublisher

use of com.hazelcast.wan.WanPublisher in project hazelcast by hazelcast.

the class DelegatingWanScheme method getStats.

/**
 * Silently skips publishers not supporting statistics.
 *
 * @return publisher statistics, grouped by publisher ID
 */
public Map<String, LocalWanPublisherStats> getStats() {
    final Map<String, LocalWanPublisherStats> statsMap = createHashMap(publishers.size());
    for (Entry<String, WanPublisher> publisherEntry : publishers.entrySet()) {
        WanPublisher publisher = publisherEntry.getValue();
        if (publisher instanceof InternalWanPublisher) {
            String publisherId = publisherEntry.getKey();
            LocalWanPublisherStats stats = ((InternalWanPublisher) publisher).getStats();
            if (stats != null) {
                statsMap.put(publisherId, stats);
            }
        }
    }
    return statsMap;
}
Also used : LocalWanPublisherStats(com.hazelcast.internal.monitor.LocalWanPublisherStats) WanPublisher(com.hazelcast.wan.WanPublisher)

Example 4 with WanPublisher

use of com.hazelcast.wan.WanPublisher in project hazelcast by hazelcast.

the class WanReplicationServiceImpl method createPublishers.

private ConcurrentMap<String, WanPublisher> createPublishers(WanReplicationConfig wanReplicationConfig) {
    List<WanCustomPublisherConfig> customPublisherConfigs = wanReplicationConfig.getCustomPublisherConfigs();
    int publisherCount = customPublisherConfigs.size();
    if (publisherCount == 0) {
        return createConcurrentHashMap(1);
    }
    ConcurrentMap<String, WanPublisher> publishers = createConcurrentHashMap(publisherCount);
    Map<String, AbstractWanPublisherConfig> publisherConfigs = createHashMap(publisherCount);
    customPublisherConfigs.forEach(publisherConfig -> {
        String publisherId = getWanPublisherId(publisherConfig);
        if (publishers.containsKey(publisherId)) {
            throw new InvalidConfigurationException("Detected duplicate publisher ID '" + publisherId + "' for a single WAN replication config");
        }
        WanPublisher publisher = createPublisher(publisherConfig);
        publishers.put(publisherId, publisher);
        publisherConfigs.put(publisherId, publisherConfig);
    });
    for (Entry<String, WanPublisher> publisherEntry : publishers.entrySet()) {
        String publisherId = publisherEntry.getKey();
        WanPublisher publisher = publisherEntry.getValue();
        ManagedContext managedContext = node.getSerializationService().getManagedContext();
        publisher = (WanPublisher) managedContext.initialize(publisher);
        publisher.init(wanReplicationConfig, publisherConfigs.get(publisherId));
    }
    return publishers;
}
Also used : WanPublisher(com.hazelcast.wan.WanPublisher) WanCustomPublisherConfig(com.hazelcast.config.WanCustomPublisherConfig) AbstractWanPublisherConfig(com.hazelcast.config.AbstractWanPublisherConfig) ManagedContext(com.hazelcast.core.ManagedContext) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

WanPublisher (com.hazelcast.wan.WanPublisher)4 AbstractWanPublisherConfig (com.hazelcast.config.AbstractWanPublisherConfig)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 WanCustomPublisherConfig (com.hazelcast.config.WanCustomPublisherConfig)1 ManagedContext (com.hazelcast.core.ManagedContext)1 LocalWanPublisherStats (com.hazelcast.internal.monitor.LocalWanPublisherStats)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 WanMigrationAwarePublisher (com.hazelcast.wan.WanMigrationAwarePublisher)1 Map (java.util.Map)1