|
9 | 9 | import io.scalecube.cluster.membership.MembershipProtocolImpl; |
10 | 10 | import io.scalecube.cluster.metadata.MetadataStore; |
11 | 11 | import io.scalecube.cluster.metadata.MetadataStoreImpl; |
| 12 | +import io.scalecube.cluster.monitor.ClusterMonitorMBean; |
| 13 | +import io.scalecube.cluster.monitor.ClusterMonitorModel; |
| 14 | +import io.scalecube.cluster.monitor.JmxClusterMonitorMBean; |
12 | 15 | import io.scalecube.cluster.transport.api.Message; |
13 | 16 | import io.scalecube.cluster.transport.api.Transport; |
14 | 17 | import io.scalecube.cluster.transport.api.TransportConfig; |
15 | 18 | import io.scalecube.net.Address; |
16 | 19 | import io.scalecube.transport.netty.TransportImpl; |
| 20 | +import java.lang.management.ManagementFactory; |
17 | 21 | import java.util.Collection; |
18 | 22 | import java.util.Collections; |
19 | 23 | import java.util.Objects; |
|
23 | 27 | import java.util.function.UnaryOperator; |
24 | 28 | import java.util.stream.Collectors; |
25 | 29 | import java.util.stream.Stream; |
| 30 | +import javax.management.MBeanServer; |
| 31 | +import javax.management.ObjectInstance; |
| 32 | +import javax.management.ObjectName; |
| 33 | +import javax.management.StandardMBean; |
26 | 34 | import org.slf4j.Logger; |
27 | 35 | import org.slf4j.LoggerFactory; |
28 | 36 | import reactor.core.Disposable; |
@@ -82,6 +90,7 @@ public final class ClusterImpl implements Cluster { |
82 | 90 | private MetadataStore metadataStore; |
83 | 91 | private Scheduler scheduler; |
84 | 92 | private CorrelationIdGenerator cidGenerator; |
| 93 | + private ClusterMonitorModel.Builder monitorModelBuilder; |
85 | 94 |
|
86 | 95 | public ClusterImpl() { |
87 | 96 | this(ClusterConfig.defaultConfig()); |
@@ -228,6 +237,7 @@ private Mono<Cluster> doStart0() { |
228 | 237 |
|
229 | 238 | cidGenerator = new CorrelationIdGenerator(localMember.id()); |
230 | 239 | scheduler = Schedulers.newSingle("sc-cluster-" + localMember.address().port(), true); |
| 240 | + monitorModelBuilder = new ClusterMonitorModel.Builder(); |
231 | 241 |
|
232 | 242 | failureDetector = |
233 | 243 | new FailureDetectorImpl( |
@@ -259,14 +269,16 @@ private Mono<Cluster> doStart0() { |
259 | 269 | metadataStore, |
260 | 270 | config, |
261 | 271 | scheduler, |
262 | | - cidGenerator); |
| 272 | + cidGenerator, |
| 273 | + monitorModelBuilder); |
263 | 274 |
|
264 | 275 | actionsDisposables.add( |
| 276 | + // Retransmit inner membership events to public api layer |
265 | 277 | membership |
266 | 278 | .listen() |
267 | 279 | /*.publishOn(scheduler)*/ |
268 | | - // dont uncomment, already beign executed inside sc-cluster thread |
269 | | - .subscribe(membershipSink::next, this::onError)); |
| 280 | + // Dont uncomment, already beign executed inside sc-cluster thread |
| 281 | + .subscribe(membershipSink::next, this::onError, membershipSink::complete)); |
270 | 282 |
|
271 | 283 | return Mono.fromRunnable(() -> failureDetector.start()) |
272 | 284 | .then(Mono.fromRunnable(() -> gossip.start())) |
@@ -301,7 +313,18 @@ private void startHandler() { |
301 | 313 | } |
302 | 314 |
|
303 | 315 | private Mono<Void> startJmxMonitor() { |
304 | | - return Mono.fromCallable(() -> AbstractMonitorMBean.register(new JmxMonitorMBean(this))).then(); |
| 316 | + return Mono.fromCallable(this::startJmxMonitor0).then(); |
| 317 | + } |
| 318 | + |
| 319 | + private ObjectInstance startJmxMonitor0() throws Exception { |
| 320 | + ClusterMonitorModel monitorModel = monitorModelBuilder.config(config).cluster(this).build(); |
| 321 | + |
| 322 | + JmxClusterMonitorMBean bean = new JmxClusterMonitorMBean(monitorModel); |
| 323 | + StandardMBean standardMBean = new StandardMBean(bean, ClusterMonitorMBean.class); |
| 324 | + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
| 325 | + ObjectName objectName = new ObjectName("io.scalecube.cluster:name=Cluster@" + member().id()); |
| 326 | + |
| 327 | + return server.registerMBean(standardMBean, objectName); |
305 | 328 | } |
306 | 329 |
|
307 | 330 | private void onError(Throwable th) { |
@@ -481,85 +504,6 @@ public boolean isShutdown() { |
481 | 504 | return onShutdown.isDisposed(); |
482 | 505 | } |
483 | 506 |
|
484 | | - @SuppressWarnings("unused") |
485 | | - public interface MonitorMBean { |
486 | | - |
487 | | - Collection<String> getId(); |
488 | | - |
489 | | - String getIdAsString(); |
490 | | - |
491 | | - Collection<String> getAlias(); |
492 | | - |
493 | | - String getAliasAsString(); |
494 | | - |
495 | | - Collection<String> getAddress(); |
496 | | - |
497 | | - String getAddressAsString(); |
498 | | - |
499 | | - Collection<String> getMetadata(); |
500 | | - |
501 | | - String getMetadataAsString(); |
502 | | - } |
503 | | - |
504 | | - public static class JmxMonitorMBean extends AbstractMonitorMBean implements MonitorMBean { |
505 | | - |
506 | | - private final ClusterImpl cluster; |
507 | | - |
508 | | - private JmxMonitorMBean(ClusterImpl cluster) { |
509 | | - this.cluster = cluster; |
510 | | - } |
511 | | - |
512 | | - @Override |
513 | | - public Collection<String> getId() { |
514 | | - return Collections.singleton(getIdAsString()); |
515 | | - } |
516 | | - |
517 | | - @Override |
518 | | - public String getIdAsString() { |
519 | | - return cluster.member().id(); |
520 | | - } |
521 | | - |
522 | | - @Override |
523 | | - public Collection<String> getAlias() { |
524 | | - return Collections.singleton(getAliasAsString()); |
525 | | - } |
526 | | - |
527 | | - @Override |
528 | | - public String getAliasAsString() { |
529 | | - return cluster.member().alias(); |
530 | | - } |
531 | | - |
532 | | - @Override |
533 | | - public Collection<String> getAddress() { |
534 | | - return Collections.singleton(getAddressAsString()); |
535 | | - } |
536 | | - |
537 | | - @Override |
538 | | - public String getAddressAsString() { |
539 | | - return String.valueOf(cluster.member().address()); |
540 | | - } |
541 | | - |
542 | | - @Override |
543 | | - public Collection<String> getMetadata() { |
544 | | - return Collections.singletonList(getMetadataAsString()); |
545 | | - } |
546 | | - |
547 | | - @Override |
548 | | - public String getMetadataAsString() { |
549 | | - return String.valueOf(cluster.metadataStore.metadata().map(Object::toString).orElse(null)); |
550 | | - } |
551 | | - |
552 | | - @Override |
553 | | - protected Class getBeanType() { |
554 | | - return MonitorMBean.class; |
555 | | - } |
556 | | - |
557 | | - @Override |
558 | | - protected String getObjectName() { |
559 | | - return "io.scalecube.cluster:name=Cluster@" + cluster.member().id(); |
560 | | - } |
561 | | - } |
562 | | - |
563 | 507 | private static class SenderAwareTransport implements Transport { |
564 | 508 |
|
565 | 509 | private final Transport transport; |
|
0 commit comments