Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
Expand All @@ -33,6 +35,8 @@
import org.apache.servicecomb.foundation.vertx.stream.BufferInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;

import io.netty.buffer.ByteBuf;
import io.vertx.core.AbstractVerticle;
Expand All @@ -42,7 +46,8 @@
import io.vertx.core.VertxOptions;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.file.impl.FileResolver;
import io.vertx.core.impl.VertxImplEx;
import io.vertx.core.impl.VertxImpl;
import io.vertx.core.impl.VertxThreadFactory;
import io.vertx.core.logging.SLF4JLogDelegateFactory;

/**
Expand All @@ -62,12 +67,12 @@ public final class VertxUtils {
private static final long BLOCKED_THREAD_CHECK_INTERVAL = Long.MAX_VALUE / 2;

// key为vertx实例名称,以支撑vertx功能分组
private static Map<String, VertxImplEx> vertxMap = new ConcurrentHashMapEx<>();
private static Map<String, Vertx> vertxMap = new ConcurrentHashMapEx<>();

private VertxUtils() {
}

public static Map<String, VertxImplEx> getVertxMap() {
public static Map<String, Vertx> getVertxMap() {
return vertxMap;
}

Expand Down Expand Up @@ -111,7 +116,7 @@ public static <VERTICLE extends Verticle> boolean blockDeploy(Vertx vertx,
}

public static Vertx getOrCreateVertxByName(String name, VertxOptions vertxOptions) {
return vertxMap.computeIfAbsent(name, vertxName -> (VertxImplEx) init(vertxName, vertxOptions));
return vertxMap.computeIfAbsent(name, vertxName -> init(vertxName, vertxOptions));
}

public static Vertx init(VertxOptions vertxOptions) {
Expand All @@ -130,7 +135,24 @@ public static Vertx init(String name, VertxOptions vertxOptions) {
}

configureVertxFileCaching();
return new VertxImplEx(name, vertxOptions);
Vertx vertx = Vertx.vertx(vertxOptions);
enhanceVertx(name, vertx);
return vertx;
}

private static void enhanceVertx(String name, Vertx vertx) {
if (StringUtils.isEmpty(name)) {
return;
}
Field field = ReflectionUtils.findField(VertxImpl.class, "eventLoopThreadFactory");
field.setAccessible(true);
VertxThreadFactory eventLoopThreadFactory = (VertxThreadFactory) ReflectionUtils.getField(field, vertx);

field = ReflectionUtils.findField(eventLoopThreadFactory.getClass(), "prefix");
field.setAccessible(true);

String prefix = (String) ReflectionUtils.getField(field, eventLoopThreadFactory);
ReflectionUtils.setField(field, eventLoopThreadFactory, name + "-" + prefix);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.spectator.api.Meter;

import io.vertx.core.impl.VertxImplEx;
import io.vertx.core.Vertx;

public class DefaultLogPublisher implements MetricsInitializer {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLogPublisher.class);
Expand Down Expand Up @@ -432,10 +432,11 @@ protected void printVertxMetrics(MeasurementTree tree, StringBuilder sb) {

appendLine(sb, " instances:");
appendLine(sb, " name eventLoopContext-created");
for (Entry<String, VertxImplEx> entry : VertxUtils.getVertxMap().entrySet()) {
for (Entry<String, Vertx> entry : VertxUtils.getVertxMap().entrySet()) {
appendLine(sb, " %-10s %d",
entry.getKey(),
entry.getValue().getEventLoopContextCreatedCount());
// TODO will be fixed by next vertx update.entry.getValue().getEventLoopContextCreatedCount()
0);
}

ClientEndpointsLogPublisher client = new ClientEndpointsLogPublisher(tree, sb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ public void init() throws InterruptedException {
result = transportVertxFactory;
}
};
// TODO will be fixed by next vertx update.
// new Expectations(VertxUtils.class) {
// {

// VertxUtils.getEventLoopContextCreatedCount(anyString);
// result = 4;
// }
// };

globalRegistry.add(registry);
vertxMetersInitializer.init(globalRegistry, eventBus, null);
Expand Down Expand Up @@ -158,7 +166,7 @@ private void testLog(LogCollector logCollector, List<Meter> meters, List<Measure
String expect = "vertx:\n"
+ " instances:\n"
+ " name eventLoopContext-created\n"
+ " transport 4\n"
+ " transport 0\n"
+ " transport:\n"
+ " client.endpoints:\n"
+ " remote connectCount disconnectCount connections send(Bps) receive(Bps)\n";
Expand All @@ -172,7 +180,6 @@ private void testLog(LogCollector logCollector, List<Meter> meters, List<Measure
+ " listen connectCount disconnectCount rejectByLimit connections send(Bps) receive(Bps)\n"
+ " 0.0.0.0:0 1 0 0 1 21 4 \n"
+ " (summary) 1 0 0 1 21 4 \n\n";

Assert.assertEquals(expect, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import com.google.common.eventbus.EventBus;
import com.netflix.spectator.api.Measurement;

import io.vertx.core.impl.VertxImplEx;
import io.vertx.core.impl.VertxImpl;
import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
Expand Down Expand Up @@ -132,13 +132,14 @@ public void onPolledEvent_failed() {
}

@Test
public void onPolledEvent(@Mocked VertxImplEx vertxImplEx, @Mocked MeasurementTree tree) {
public void onPolledEvent(@Mocked VertxImpl vertxImpl, @Mocked MeasurementTree tree) {
new Expectations(VertxUtils.class) {
{
VertxUtils.getVertxMap();
result = Collections.singletonMap("v", vertxImplEx);
vertxImplEx.getEventLoopContextCreatedCount();
result = 1;
result = Collections.singletonMap("v", vertxImpl);
// TODO will be fixed by next vertx update.
// vertxImpl.getEventLoopContextCreatedCount();;
// result = 1;
}
};

Expand Down Expand Up @@ -245,7 +246,7 @@ MeasurementTree getTree() {
+ "vertx:\n"
+ " instances:\n"
+ " name eventLoopContext-created\n"
+ " v 1\n"
+ " v 0\n"
+ "threadPool:\n"
+ " corePoolSize maxThreads poolSize currentThreadsBusy queueSize taskCount completedTaskCount name\n"
+ " 0 0 0 0 0 0.0 0.0 test\n"
Expand Down