Skip to content

Commit 8ab12a6

Browse files
committed
Removed jmx support
1 parent aeb2ad4 commit 8ab12a6

File tree

2 files changed

+3
-164
lines changed

2 files changed

+3
-164
lines changed

services-discovery/src/main/java/io/scalecube/services/discovery/ScalecubeServiceDiscovery.java

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,9 @@
1818
import io.scalecube.services.discovery.api.ServiceDiscovery;
1919
import io.scalecube.services.discovery.api.ServiceDiscoveryContext;
2020
import io.scalecube.services.discovery.api.ServiceDiscoveryEvent;
21-
import java.lang.management.ManagementFactory;
2221
import java.nio.ByteBuffer;
23-
import java.util.List;
2422
import java.util.StringJoiner;
25-
import java.util.concurrent.CopyOnWriteArrayList;
2623
import java.util.function.UnaryOperator;
27-
import java.util.stream.Collectors;
28-
import javax.management.MBeanServer;
29-
import javax.management.ObjectName;
30-
import javax.management.StandardMBean;
3124
import org.slf4j.Logger;
3225
import org.slf4j.LoggerFactory;
3326
import reactor.core.Exceptions;
@@ -129,6 +122,7 @@ public Mono<Void> start() {
129122
.config(options -> clusterConfig)
130123
.handler(
131124
cluster -> {
125+
//noinspection CodeBlock2Expr
132126
return new ClusterMessageHandler() {
133127
@Override
134128
public void onMembershipEvent(MembershipEvent event) {
@@ -142,7 +136,6 @@ public void onMembershipEvent(MembershipEvent event) {
142136
this.cluster = cluster;
143137
discoveryContextBuilder.address(this.cluster.address());
144138
})
145-
.then(Mono.fromCallable(() -> JmxMonitorMBean.start(this)))
146139
.then();
147140
});
148141
}
@@ -176,10 +169,8 @@ private void onMembershipEvent(MembershipEvent membershipEvent) {
176169
return;
177170
}
178171

179-
if (discoveryEvent != null) {
180-
LOGGER.debug("Publish discoveryEvent: {}", discoveryEvent);
181-
sink.emitNext(discoveryEvent, RETRY_NON_SERIALIZED);
182-
}
172+
LOGGER.debug("Publish discoveryEvent: {}", discoveryEvent);
173+
sink.emitNext(discoveryEvent, RETRY_NON_SERIALIZED);
183174
}
184175

185176
private ServiceDiscoveryEvent toServiceDiscoveryEvent(MembershipEvent membershipEvent) {
@@ -214,61 +205,4 @@ public String toString() {
214205
.add("clusterConfig=" + clusterConfig)
215206
.toString();
216207
}
217-
218-
@SuppressWarnings("unused")
219-
public interface MonitorMBean {
220-
221-
String getClusterConfig();
222-
223-
String getRecentDiscoveryEvents();
224-
}
225-
226-
private static class JmxMonitorMBean implements MonitorMBean {
227-
228-
private static final String OBJECT_NAME_FORMAT = "io.scalecube.services.discovery:name=%s@%s";
229-
230-
public static final int RECENT_DISCOVERY_EVENTS_SIZE = 128;
231-
232-
private final ScalecubeServiceDiscovery discovery;
233-
private final List<ServiceDiscoveryEvent> recentDiscoveryEvents = new CopyOnWriteArrayList<>();
234-
235-
private JmxMonitorMBean(ScalecubeServiceDiscovery discovery) {
236-
this.discovery = discovery;
237-
}
238-
239-
private static JmxMonitorMBean start(ScalecubeServiceDiscovery instance) throws Exception {
240-
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
241-
JmxMonitorMBean jmxMBean = new JmxMonitorMBean(instance);
242-
jmxMBean.init();
243-
ObjectName objectName =
244-
new ObjectName(
245-
String.format(OBJECT_NAME_FORMAT, instance.cluster.member().id(), System.nanoTime()));
246-
StandardMBean standardMBean = new StandardMBean(jmxMBean, MonitorMBean.class);
247-
mbeanServer.registerMBean(standardMBean, objectName);
248-
return jmxMBean;
249-
}
250-
251-
private void init() {
252-
discovery.listen().subscribe(this::onDiscoveryEvent);
253-
}
254-
255-
@Override
256-
public String getClusterConfig() {
257-
return String.valueOf(discovery.clusterConfig);
258-
}
259-
260-
@Override
261-
public String getRecentDiscoveryEvents() {
262-
return recentDiscoveryEvents.stream()
263-
.map(ServiceDiscoveryEvent::toString)
264-
.collect(Collectors.joining(",", "[", "]"));
265-
}
266-
267-
private void onDiscoveryEvent(ServiceDiscoveryEvent event) {
268-
recentDiscoveryEvents.add(event);
269-
if (recentDiscoveryEvents.size() > RECENT_DISCOVERY_EVENTS_SIZE) {
270-
recentDiscoveryEvents.remove(0);
271-
}
272-
}
273-
}
274208
}

services/src/main/java/io/scalecube/services/Microservices.java

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import io.scalecube.services.exceptions.ServiceProviderErrorMapper;
1717
import io.scalecube.services.gateway.Gateway;
1818
import io.scalecube.services.gateway.GatewayOptions;
19-
import io.scalecube.services.methods.MethodInfo;
20-
import io.scalecube.services.methods.ServiceMethodInvoker;
2119
import io.scalecube.services.methods.ServiceMethodRegistry;
2220
import io.scalecube.services.methods.ServiceMethodRegistryImpl;
2321
import io.scalecube.services.registry.ServiceRegistryImpl;
@@ -29,7 +27,6 @@
2927
import io.scalecube.services.transport.api.ServerTransport;
3028
import io.scalecube.services.transport.api.ServiceMessageDataDecoder;
3129
import io.scalecube.services.transport.api.ServiceTransport;
32-
import java.lang.management.ManagementFactory;
3330
import java.net.InetAddress;
3431
import java.net.UnknownHostException;
3532
import java.util.ArrayList;
@@ -41,17 +38,13 @@
4138
import java.util.NoSuchElementException;
4239
import java.util.Objects;
4340
import java.util.Optional;
44-
import java.util.StringJoiner;
4541
import java.util.UUID;
4642
import java.util.concurrent.ConcurrentHashMap;
4743
import java.util.concurrent.CopyOnWriteArrayList;
4844
import java.util.function.Function;
4945
import java.util.function.Supplier;
5046
import java.util.function.UnaryOperator;
5147
import java.util.stream.Collectors;
52-
import javax.management.MBeanServer;
53-
import javax.management.ObjectName;
54-
import javax.management.StandardMBean;
5548
import org.slf4j.Logger;
5649
import org.slf4j.LoggerFactory;
5750
import reactor.core.Disposable;
@@ -233,7 +226,6 @@ this, new ServiceDiscoveryOptions().serviceEndpoint(serviceEndpoint))
233226
.then(startGateway(new GatewayOptions().call(call)))
234227
.publishOn(scheduler)
235228
.then(Mono.fromCallable(() -> Injector.inject(this, serviceInstances)))
236-
.then(Mono.fromCallable(() -> JmxMonitorMBean.start(this)))
237229
.then(compositeDiscovery.startListen())
238230
.publishOn(scheduler)
239231
.thenReturn(this);
@@ -834,91 +826,4 @@ private Mono<Void> shutdown() {
834826
.then());
835827
}
836828
}
837-
838-
@SuppressWarnings("unused")
839-
public interface MonitorMBean {
840-
841-
String getServiceEndpoint();
842-
843-
String getAllServiceEndpoints();
844-
845-
String getServiceMethodInvokers();
846-
847-
String getServiceInfos();
848-
}
849-
850-
private static class JmxMonitorMBean implements MonitorMBean {
851-
852-
private static final String OBJECT_NAME_FORMAT = "io.scalecube.services:name=%s@%s";
853-
854-
private final Microservices microservices;
855-
856-
private static JmxMonitorMBean start(Microservices instance) throws Exception {
857-
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
858-
JmxMonitorMBean jmxMBean = new JmxMonitorMBean(instance);
859-
ObjectName objectName =
860-
new ObjectName(String.format(OBJECT_NAME_FORMAT, instance.id(), System.nanoTime()));
861-
StandardMBean standardMBean = new StandardMBean(jmxMBean, MonitorMBean.class);
862-
mbeanServer.registerMBean(standardMBean, objectName);
863-
return jmxMBean;
864-
}
865-
866-
private JmxMonitorMBean(Microservices microservices) {
867-
this.microservices = microservices;
868-
}
869-
870-
@Override
871-
public String getServiceEndpoint() {
872-
return String.valueOf(microservices.serviceEndpoint);
873-
}
874-
875-
@Override
876-
public String getAllServiceEndpoints() {
877-
return microservices.serviceRegistry.listServiceEndpoints().stream()
878-
.map(ServiceEndpoint::toString)
879-
.collect(Collectors.joining(",", "[", "]"));
880-
}
881-
882-
@Override
883-
public String getServiceMethodInvokers() {
884-
return microservices.methodRegistry.listInvokers().stream()
885-
.map(JmxMonitorMBean::asString)
886-
.collect(Collectors.joining(",", "[", "]"));
887-
}
888-
889-
@Override
890-
public String getServiceInfos() {
891-
return microservices.methodRegistry.listServices().stream()
892-
.map(JmxMonitorMBean::asString)
893-
.collect(Collectors.joining(",", "[", "]"));
894-
}
895-
896-
private static String asString(ServiceMethodInvoker invoker) {
897-
return new StringJoiner(", ", ServiceMethodInvoker.class.getSimpleName() + "[", "]")
898-
.add("methodInfo=" + asString(invoker.methodInfo()))
899-
.add(
900-
"serviceMethod="
901-
+ invoker.service().getClass().getCanonicalName()
902-
+ "."
903-
+ invoker.methodInfo().methodName()
904-
+ "("
905-
+ invoker.methodInfo().parameterCount()
906-
+ ")")
907-
.toString();
908-
}
909-
910-
private static String asString(MethodInfo methodInfo) {
911-
return new StringJoiner(", ", MethodInfo.class.getSimpleName() + "[", "]")
912-
.add("qualifier=" + methodInfo.qualifier())
913-
.add("auth=" + methodInfo.isSecured())
914-
.toString();
915-
}
916-
917-
private static String asString(ServiceInfo serviceInfo) {
918-
return new StringJoiner(", ", ServiceMethodInvoker.class.getSimpleName() + "[", "]")
919-
.add("serviceInstance=" + serviceInfo.serviceInstance())
920-
.add("tags=" + serviceInfo.tags())
921-
.toString();
922-
}
923-
}
924829
}

0 commit comments

Comments
 (0)