本文整理汇总了Java中org.axonframework.eventhandling.Cluster类的典型用法代码示例。如果您正苦于以下问题:Java Cluster类的具体用法?Java Cluster怎么用?Java Cluster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cluster类属于org.axonframework.eventhandling包,在下文中一共展示了Cluster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doSelectCluster
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Override
protected Cluster doSelectCluster(EventListener eventListener, Class<?> listenerType) {
final String packageName = listenerType.getPackage().getName();
final Matcher matcher = pattern.matcher(packageName);
final String group;
if ( ! matcher.matches()) {
group = "default";
LOGGER.error("No cluster name matched from package '{}' using regex '{}'. Using '{}' as default cluster name",
packageName, pattern, group);
} else {
group = matcher.group(1);
}
Cluster cluster = cache.get(group);
if (null == cluster) {
cluster = clusterFactory.create(group);
cache.put(group, cluster);
}
return cluster;
}
示例2: selectCluster_withTwoEventListenersOfTheSameDomain_returnTheSameInstance
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Test
public void selectCluster_withTwoEventListenersOfTheSameDomain_returnTheSameInstance() throws Exception {
// Given
final ClassnameDynamicClusterSelector clusterSelector = initClusterSelector();
final GroupB.EventListenerB eventListenerB = new GroupB.EventListenerB();
final GroupB.EventListenerA eventListenerA = new GroupB.EventListenerA();
// When
final Cluster cluster1 = clusterSelector.selectCluster(eventListenerB);
final Cluster cluster2 = clusterSelector.selectCluster(eventListenerA);
// Then
assertNotNull(cluster1);
assertNotNull(cluster2);
assertSame(cluster1, cluster2);
}
示例3: onClusterCreated_withOneEventListener_createOneCluster
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Test
public void onClusterCreated_withOneEventListener_createOneCluster() {
// Given
final String category = "fooBar";
final ConsumerConnector consumerConnector = mock(ConsumerConnector.class);
final ConsumerFactory consumerFactory = mock(ConsumerFactory.class);
when(consumerFactory.createConnector(category)).thenReturn(consumerConnector);
final Cluster cluster = mock(Cluster.class);
when(cluster.getName()).thenReturn(category);
when(cluster.getMembers()).thenReturn(Sets.<EventListener>newHashSet(mock(EventListener.class)));
final KafkaTerminal terminal = new KafkaTerminal(consumerFactory, mock(ProducerFactory.class));
// When
terminal.onClusterCreated(cluster);
// Then
assertEquals(1, terminal.getClusterListeners().size());
}
示例4: onClusterCreated_withTwoEventListeners_createOneCluster
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Test
public void onClusterCreated_withTwoEventListeners_createOneCluster() {
// Given
final String category = "fooBar";
final ConsumerConnector consumerConnector = mock(ConsumerConnector.class);
final ConsumerFactory consumerFactory = mock(ConsumerFactory.class);
when(consumerFactory.createConnector(category)).thenReturn(consumerConnector);
final Cluster cluster = mock(Cluster.class);
when(cluster.getName()).thenReturn(category);
when(cluster.getMembers()).thenReturn(Sets.<EventListener>newHashSet(mock(EventListener.class), mock(EventListener.class)));
final KafkaTerminal terminal = new KafkaTerminal(consumerFactory, mock(ProducerFactory.class));
// When
terminal.onClusterCreated(cluster);
// Then
assertEquals(1, terminal.getClusterListeners().size());
}
示例5: onApplicationEvent
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Override
public void onApplicationEvent(final ContextRefreshedEvent event) {
final ConfigurableApplicationContext context
= (ConfigurableApplicationContext) event.getSource();
final Collection<EventProcessingMonitor> monitors
= beansOfTypeIncludingAncestors(context.getBeanFactory(),
EventProcessingMonitor.class).values();
for (final Cluster cluster : beansOfTypeIncludingAncestors(
context.getBeanFactory(), Cluster.class).values())
monitors.forEach(cluster::subscribeEventProcessingMonitor);
}
示例6: KafkaClusterListener
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
public KafkaClusterListener(
final ConsumerFactory consumerFactory,
final KafkaMetricHelper metricHelper,
final TopicStrategy topicStrategy,
final Cluster cluster,
final int numberOfStreamListener
) {
checkNotNull(consumerFactory);
checkNotNull(metricHelper);
checkNotNull(topicStrategy);
this.cluster = checkNotNull(cluster);
checkArgument(numberOfStreamListener > 0, "The number of stream listener must be greater or equal to 1");
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("event-consumer-" + cluster.getName() + "-%d").build();
this.executor = Executors.newFixedThreadPool(numberOfStreamListener, threadFactory);
this.streamListeners = Lists.newArrayList();
this.consumer = consumerFactory.createConnector(cluster.getName());
final List<KafkaStream<byte[], EventMessage>> streams = consumerFactory.createStreams(numberOfStreamListener, consumer);
for (final KafkaStream<byte[], EventMessage> stream : streams) {
KafkaStreamListener streamListener = new KafkaStreamListener(cluster, stream, metricHelper);
streamListeners.add(streamListener);
executor.submit(streamListener);
}
LOGGER.debug("Created cluster listener on '{}'", cluster.getName());
}
示例7: KafkaStreamListener
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
public KafkaStreamListener(
final Cluster cluster,
final KafkaStream<byte[], EventMessage> stream,
final KafkaMetricHelper metricHelper
) {
this.cluster = checkNotNull(cluster);
this.stream = checkNotNull(stream);
this.metricHelper= checkNotNull(metricHelper);
this.terminateCallback = Optional.absent();
}
示例8: onClusterCreated
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Override
public void onClusterCreated(final Cluster cluster) {
checkNotNull(cluster);
final String group = cluster.getName();
if ( ! clusterListenerByGroup.containsKey(group)) {
clusterListenerByGroup.put(
group,
new KafkaClusterListener(consumerFactory, metricHelper, topicStrategy, cluster, 1)
);
}
}
示例9: selectCluster_withEventListenerB_returnClusterNamedAfterPackageOfListener
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Test
public void selectCluster_withEventListenerB_returnClusterNamedAfterPackageOfListener() throws Exception {
// Given
final ClassnameDynamicClusterSelector clusterSelector = initClusterSelector();
final GroupB.EventListenerB eventListenerB = new GroupB.EventListenerB();
// When
final Cluster cluster = clusterSelector.selectCluster(eventListenerB);
// Then
assertNotNull(cluster);
assertEquals("groupb", cluster.getName());
}
示例10: selectCluster_withEventListenerA_returnClusterNamedAfterPackageOfListener
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Test
public void selectCluster_withEventListenerA_returnClusterNamedAfterPackageOfListener() throws Exception {
// Given
final ClassnameDynamicClusterSelector clusterSelector = initClusterSelector();
final GroupA.EventListenerA eventListenerA = new GroupA.EventListenerA();
// When
final Cluster cluster = clusterSelector.selectCluster(eventListenerA);
// Then
assertNotNull(cluster);
assertEquals("groupa", cluster.getName());
}
示例11: createClusterSelectorFactory
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
public static ClusterSelectorFactory createClusterSelectorFactory(final String prefix) {
return new ClassnameDynamicClusterSelectorFactory(
prefix,
new ClusterFactory() {
@Override
public Cluster create(final String name) {
return new SimpleCluster(name);
}
}
);
}
示例12: onClusterCreated
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Override
public void onClusterCreated(Cluster cluster) {
if(m_subscriber != null && m_subscribed.get() == false) {
m_subscriber.subscribe(m_hzInstance,this);
m_subscribed.set(true);
}
m_clusters.add(cluster);
}
示例13: publish
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Override
public void publish(final EventMessage... events) {
for (final Cluster cluster : clusters)
cluster.publish(events);
}
示例14: onClusterCreated
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Override
public void onClusterCreated(final Cluster cluster) {
clusters.add(cluster);
}
示例15: simpleCluster
import org.axonframework.eventhandling.Cluster; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public Cluster simpleCluster(final OrderResolver orderResolver) {
return new SimpleCluster(properties.getName(), orderResolver);
}