use of com.alipay.sofa.rpc.event.ServerStoppedEvent in project sofa-rpc by sofastack.
the class AbstractHttpServer method stop.
@Override
public void stop() {
if (!started) {
return;
}
synchronized (this) {
if (!started) {
return;
}
// 关闭端口,不关闭线程池
serverTransport.stop();
serverTransport = null;
// 关闭线程池
if (bizThreadPool != null) {
bizThreadPool.shutdown();
bizThreadPool = null;
serverHandler.setBizThreadPool(null);
}
started = false;
if (EventBus.isEnable(ServerStoppedEvent.class)) {
EventBus.post(new ServerStoppedEvent(serverConfig));
}
}
}
use of com.alipay.sofa.rpc.event.ServerStoppedEvent in project sofa-rpc by sofastack.
the class BoltServer method stop.
@Override
public void stop() {
if (!started) {
return;
}
synchronized (this) {
if (!started) {
return;
}
// 关闭端口,不关闭线程池
try {
remotingServer.stop();
} catch (IllegalStateException ignore) {
// NOPMD
}
if (EventBus.isEnable(ServerStoppedEvent.class)) {
EventBus.post(new ServerStoppedEvent(serverConfig));
}
remotingServer = null;
started = false;
}
}
use of com.alipay.sofa.rpc.event.ServerStoppedEvent in project sofa-rpc by sofastack.
the class SofaRpcMetricsTest method testMicrometerMetrics.
@Test
public void testMicrometerMetrics() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
SimpleMeterRegistry registry = new SimpleMeterRegistry();
try (SofaRpcMetrics metrics = new SofaRpcMetrics()) {
metrics.bindTo(registry);
Method handleEvent = EventBus.class.getDeclaredMethod("handleEvent", Subscriber.class, Event.class);
handleEvent.setAccessible(true);
SofaRequest request = buildRequest();
SofaResponse response = buildResponse();
RpcInternalContext.getContext().setAttachment(RpcConstants.INTERNAL_KEY_CLIENT_ELAPSE, 100).setAttachment(RpcConstants.INTERNAL_KEY_IMPL_ELAPSE, 10).setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, 3).setAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE, 4);
handleEvent.invoke(EventBus.class, metrics, new ClientEndInvokeEvent(request, response, null));
handleEvent.invoke(EventBus.class, metrics, new ServerSendEvent(request, response, null));
ServerConfig serverConfig = new ServerConfig();
handleEvent.invoke(EventBus.class, metrics, new ServerStartedEvent(serverConfig, new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>())));
handleEvent.invoke(EventBus.class, metrics, new ServerStoppedEvent(serverConfig));
handleEvent.invoke(EventBus.class, metrics, new ProviderPubEvent(new ProviderConfig<>()));
handleEvent.invoke(EventBus.class, metrics, new ConsumerSubEvent(new ConsumerConfig<>()));
Assert.assertEquals(12, registry.getMeters().size());
}
}
Aggregations