本文整理汇总了Java中io.vertx.core.datagram.DatagramSocket类的典型用法代码示例。如果您正苦于以下问题:Java DatagramSocket类的具体用法?Java DatagramSocket怎么用?Java DatagramSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatagramSocket类属于io.vertx.core.datagram包,在下文中一共展示了DatagramSocket类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: start
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public void start() {
final DatagramSocket socket = vertx.createDatagramSocket(dsOptions);
socket.listen(udpPort, host, datagramSocketAsyncResult -> {
if (datagramSocketAsyncResult.succeeded()){
log.info("Listening on UDP port " + udpPort);
async.countDown();
socket.handler(packet -> {
String decoded = packet.data().getString(0, packet.data().length());
log.debug("=============== Received content on UDP " + udpPort +
" ================= \n" + decoded);
async.countDown();
});
} else {
log.warn("Listen failed on port " + udpPort, datagramSocketAsyncResult.cause());
}
});
}
开发者ID:oehf,项目名称:ipf-oht-atna,代码行数:19,代码来源:UDPSyslogServer.java
示例2: testMetricsCleanupedOnVertxClose
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Test
public void testMetricsCleanupedOnVertxClose() throws Exception {
CountDownLatch latch1 = new CountDownLatch(1);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestHandler(req -> {});
server.listen(onSuccess(res -> {
latch1.countDown();
}));
awaitLatch(latch1);
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
CountDownLatch latch2 = new CountDownLatch(1);
NetServer nServer = vertx.createNetServer(new NetServerOptions().setPort(1234));
nServer.connectHandler(conn -> {});
nServer.listen(res -> {
latch2.countDown();
});
awaitLatch(latch2);
NetClient nClient = vertx.createNetClient(new NetClientOptions());
DatagramSocket sock = vertx.createDatagramSocket(new DatagramSocketOptions());
EventBus eb = vertx.eventBus();
assertFalse(metricsService.getMetricsSnapshot(vertx).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(server).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(client).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(nServer).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(nClient).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(sock).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(eb).isEmpty());
vertx.close(res -> {
assertTrue(metricsService.getMetricsSnapshot(vertx).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(server).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(client).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(nServer).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(nClient).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(sock).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(eb).isEmpty());
testComplete();
});
await();
vertx = null;
}
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:41,代码来源:MetricsTest.java
示例3: start
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
DatagramSocket socket = vertx.createDatagramSocket();
socket.handler(this::handlePacket);
socket.listen(port, "0.0.0.0", result -> {
if (result.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(result.cause());
}
});
}
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:13,代码来源:CollectdServer.java
示例4: createMetrics
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
default DatagramSocketMetrics createMetrics(DatagramSocket socket, DatagramSocketOptions options) {
return DummyVertxMetrics.DummyDatagramMetrics.INSTANCE;
}
开发者ID:unbroken-dome,项目名称:vertx-spring,代码行数:5,代码来源:VertxMetricsAdapter.java
示例5: createMetrics
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public DatagramSocketMetrics createMetrics(DatagramSocket socket, DatagramSocketOptions options) {
return createSubMetrics(v -> v.createMetrics(socket, options),
d -> new DispatchingDatagramSocketMetrics(d));
}
开发者ID:unbroken-dome,项目名称:vertx-spring,代码行数:6,代码来源:DispatchingVertxMetrics.java
示例6: createMetrics
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public DatagramSocketMetrics createMetrics(DatagramSocket socket, DatagramSocketOptions options) {
return new DatagramSocketMetricsImpl(counterService, gaugeService, properties.getDatagramSocket());
}
开发者ID:unbroken-dome,项目名称:vertx-spring,代码行数:5,代码来源:VertxActuatorMetrics.java
示例7: createMetrics
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public @NotNull DatagramSocketMetrics createMetrics(@NotNull DatagramSocket socket, @NotNull DatagramSocketOptions datagramSocketOptions) {
return options.isEnabled(DatagramSocket)
? new DatagramSocketPrometheusMetrics(options.getRegistry())
: super.createMetrics(socket, datagramSocketOptions);
}
开发者ID:nolequen,项目名称:vertx-prometheus-metrics,代码行数:7,代码来源:VertxPrometheusMetrics.java
示例8: createDatagramSocket
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public DatagramSocket createDatagramSocket(DatagramSocketOptions options) {
return vertx.createDatagramSocket(options);
}
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:5,代码来源:SfsVertxImpl.java
示例9: createMetrics
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public DatagramSocketMetrics createMetrics(DatagramSocket socket, DatagramSocketOptions options) {
return new DatagramSocketMetricsImpl(defaultLabels, !this.options.isMetricsTypeDisabled(MetricsType.DATAGRAM_SOCKET));
}
开发者ID:slambour,项目名称:vertx-warp10-metrics,代码行数:5,代码来源:VertxMetricsImpl.java
示例10: createMetrics
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public DatagramSocketMetrics createMetrics(DatagramSocket socket, DatagramSocketOptions options) {
DatagramSocketMetricsSupplier supplier = (DatagramSocketMetricsSupplier) metricSuppliers.get(DATAGRAM_SOCKET);
return supplier != null ? new DatagramSocketMetricsImpl(supplier) : super.createMetrics(socket, options);
}
开发者ID:vert-x3,项目名称:vertx-hawkular-metrics,代码行数:6,代码来源:VertxMetricsImpl.java
示例11: createMetrics
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Override
public DatagramSocketMetrics createMetrics(DatagramSocket socket, DatagramSocketOptions options) {
return new DatagramSocketMetricsImpl(this, nameOf("datagram"));
}
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:5,代码来源:VertxMetricsImpl.java
示例12: testDatagramMetrics
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Test
public void testDatagramMetrics() throws Exception {
Buffer clientMax = randomBuffer(1823);
Buffer clientMin = randomBuffer(123);
AtomicBoolean complete = new AtomicBoolean(false);
DatagramSocket datagramSocket = vertx.createDatagramSocket(new DatagramSocketOptions()).listen(1236, "localhost", ar -> {
assertTrue(ar.succeeded());
DatagramSocket socket = ar.result();
socket.handler(packet -> {
if (complete.getAndSet(true)) {
testComplete();
}
});
socket.send(clientMin, 1236, "localhost", ds -> {
assertTrue(ar.succeeded());
});
socket.send(clientMax, 1236, "localhost", ds -> {
assertTrue(ar.succeeded());
});
});
await();
// Test sender/client (bytes-written)
JsonObject metrics = metricsService.getMetricsSnapshot(datagramSocket);
assertCount(metrics.getJsonObject("bytes-written"), 2L);
assertMinMax(metrics.getJsonObject("bytes-written"), (long) clientMin.length(), (long) clientMax.length());
// Test server (bytes-read)
assertCount(metrics.getJsonObject("localhost:1236.bytes-read"), 2L);
assertMinMax(metrics.getJsonObject("localhost:1236.bytes-read"), (long) clientMin.length(), (long) clientMax.length());
CountDownLatch latch = new CountDownLatch(1);
datagramSocket.close(ar -> {
assertTrue(ar.succeeded());
latch.countDown();
});
awaitLatch(latch);
assertWaitUntil(() -> metricsService.getMetricsSnapshot(datagramSocket).isEmpty());
}
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:42,代码来源:MetricsTest.java
示例13: testNothingToSend
import io.vertx.core.datagram.DatagramSocket; //导入依赖的package包/类
@Test
public void testNothingToSend(TestContext testContext) {
this.setup(false, Optional.empty(), Optional.empty());
Async async = testContext.async();
Vertx vertx = mock(Vertx.class);
when(vertx.setTimer(anyLong(), Matchers.any())).thenReturn(1L);
Context context = mock(Context.class);
Mockito.doNothing().when(context).runOnContext(Matchers.any());
DatagramSocket datagramSocket = mock(DatagramSocket.class);
when(vertx.createDatagramSocket()).thenReturn(datagramSocket);
StatfulMetricsOptions options = mock(StatfulMetricsOptions.class);
when(options.getFlushInterval()).thenReturn(10L);
when(options.getFlushSize()).thenReturn(10);
when(options.getMaxBufferSize()).thenReturn(5000);
UDPSender sender = new UDPSender(vertx, context, options);
sender.send(Collections.emptyList());
verify(datagramSocket, times(0)).send(anyString(), anyInt(), anyString(), Matchers.any());
this.teardown(async);
}
开发者ID:statful,项目名称:statful-client-vertx,代码行数:29,代码来源:UDPSenderTest.java
注:本文中的io.vertx.core.datagram.DatagramSocket类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论