当前位置: 首页>>代码示例>>Java>>正文


Java SocketAddress类代码示例

本文整理汇总了Java中io.vertx.core.net.SocketAddress的典型用法代码示例。如果您正苦于以下问题:Java SocketAddress类的具体用法?Java SocketAddress怎么用?Java SocketAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SocketAddress类属于io.vertx.core.net包,在下文中一共展示了SocketAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFormattedElement

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Override
public String getFormattedElement(AccessLogParam accessLogParam) {
  HttpServerRequest request = accessLogParam.getRoutingContext().request();
  if (null == request) {
    return EMPTY_RESULT;
  }

  SocketAddress remoteAddress = request.remoteAddress();
  if (null == remoteAddress) {
    return EMPTY_RESULT;
  }

  String remoteHost = remoteAddress.host();
  if (StringUtils.isEmpty(remoteHost)) {
    return EMPTY_RESULT;
  }
  return remoteHost;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:RemoteHostElement.java

示例2: getFormattedElement

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Override
public String getFormattedElement(AccessLogParam accessLogParam) {
  HttpServerRequest request = accessLogParam.getRoutingContext().request();
  if (null == request) {
    return EMPTY_RESULT;
  }

  SocketAddress localAddress = request.localAddress();
  if (null == localAddress) {
    return EMPTY_RESULT;
  }

  String localHost = localAddress.host();
  if (StringUtils.isEmpty(localHost)) {
    return EMPTY_RESULT;
  }
  return localHost;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:LocalHostElement.java

示例3: getFormattedElement

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void getFormattedElement() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress localAddress = Mockito.mock(SocketAddress.class);

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.localAddress()).thenReturn(localAddress);
  Mockito.when(localAddress.port()).thenReturn(8080);

  String result = new LocalPortElement().getFormattedElement(param);

  assertEquals("8080", result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:LocalPortElementTest.java

示例4: getFormattedElement

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void getFormattedElement() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress localAddress = Mockito.mock(SocketAddress.class);
  String localHost = "testHost";

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.localAddress()).thenReturn(localAddress);
  Mockito.when(localAddress.host()).thenReturn(localHost);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals(localHost, result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:LocalHostElementTest.java

示例5: getFormattedElementOnHostIsNull

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void getFormattedElementOnHostIsNull() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress localAddress = Mockito.mock(SocketAddress.class);

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.localAddress()).thenReturn(localAddress);
  Mockito.when(localAddress.host()).thenReturn(null);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("-", result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:LocalHostElementTest.java

示例6: getFormattedElementIsEmpty

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void getFormattedElementIsEmpty() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress localAddress = Mockito.mock(SocketAddress.class);
  String localHost = "";

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.localAddress()).thenReturn(localAddress);
  Mockito.when(localAddress.host()).thenReturn(localHost);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("-", result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:LocalHostElementTest.java

示例7: getFormattedElement

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void getFormattedElement() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress address = Mockito.mock(SocketAddress.class);
  String remoteHost = "remoteHost";

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.remoteAddress()).thenReturn(address);
  Mockito.when(address.host()).thenReturn(remoteHost);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals(remoteHost, result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:RemoteHostElementTest.java

示例8: getFormattedElementOnHostIsNull

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void getFormattedElementOnHostIsNull() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress address = Mockito.mock(SocketAddress.class);

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.remoteAddress()).thenReturn(address);
  Mockito.when(address.host()).thenReturn(null);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("-", result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:RemoteHostElementTest.java

示例9: getFormattedElementOnHostIsEmpty

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void getFormattedElementOnHostIsEmpty() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress address = Mockito.mock(SocketAddress.class);
  String remoteHost = "";

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.remoteAddress()).thenReturn(address);
  Mockito.when(address.host()).thenReturn(remoteHost);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("-", result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:RemoteHostElementTest.java

示例10: requestBegin

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Override
public Map<HttpClientMetrics, ?> requestBegin(Map<HttpClientMetrics, ?> endpointMetric,
                                              Map<HttpClientMetrics, ?> socketMetric,
                                              SocketAddress localAddress, SocketAddress remoteAddress,
                                              HttpClientRequest request) {
    return null;
}
 
开发者ID:unbroken-dome,项目名称:vertx-spring,代码行数:8,代码来源:DispatchingHttpClientMetrics.java

示例11: fromJson

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Override
public FdfsClientOptions fromJson(JsonObject json) {

	super.fromJson(json);

	JsonArray array = json.getJsonArray(TRACKERS);

	if (array != null && array.size() > 0) {
		array.forEach(object -> {
			if (object instanceof JsonObject) {
				JsonObject tracker = (JsonObject) object;

				String host = tracker.getString(HOST, "");
				int port = tracker.getInteger(PORT, -1);

				if (!host.isEmpty() && port != -1) {
					trackers.add(SocketAddress.inetSocketAddress(port, host));
				}
			}
		});
	}
	
	return this;
}
 
开发者ID:gengteng,项目名称:vertx-fastdfs-client,代码行数:25,代码来源:FdfsClientOptions.java

示例12: parseStorage

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
private Future<FdfsStorageOptions> parseStorage(Buffer bodyBuffer, String charset, boolean hasPathIndex) {
	try {
		FdfsStorageOptions storageOptions = new FdfsStorageOptions(options);

		String group = FdfsUtils
				.fdfsTrim(bodyBuffer.getString(0, FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN, options.getCharset()));
		String ip = FdfsUtils.fdfsTrim(bodyBuffer.getString(FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN,
				FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN + FdfsProtocol.FDFS_IPADDR_SIZE - 1, options.getCharset()));
		long port = bodyBuffer.getLong(FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN + FdfsProtocol.FDFS_IPADDR_SIZE - 1);

		storageOptions.setGroup(group).setAddress(SocketAddress.inetSocketAddress((int) port, ip));

		if (hasPathIndex && bodyBuffer.length() > FdfsProtocol.TRACKER_QUERY_STORAGE_FETCH_BODY_LEN) {
			byte storePathIndex = bodyBuffer.getByte(FdfsProtocol.TRACKER_QUERY_STORAGE_FETCH_BODY_LEN);
			storageOptions.setStorePathIndex(storePathIndex);
		}

		return Future.succeededFuture(storageOptions);
	} catch (Exception e) {
		return Future.failedFuture(e);
	}
}
 
开发者ID:gengteng,项目名称:vertx-fastdfs-client,代码行数:23,代码来源:FdfsTrackerImpl.java

示例13: requestBegin

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
/**
 * Only requests that contain a tracking tag will be tracked
 */
@Override
@Nullable
public HttpRequestMetrics requestBegin(final Void endpointMetric,
                                       final SocketAddress socketMetric,
                                       final SocketAddress localAddress,
                                       final SocketAddress remoteAddress,
                                       final HttpClientRequest request) {

    // extract request tag to identify the metric and confirm that we want to track it
    String requestTag = request.headers().get(Tags.TRACK_HEADER.toString());

    HttpRequestMetrics metric = null;

    if (requestTag != null) {
        // Remove tracking header to avoid it propagating to clients
        request.headers().remove(Tags.TRACK_HEADER.toString());

        // Create client request metric
        metric = new HttpRequestMetrics(requestTag, remoteAddress, request.method());
        metric.start();
    }

    return metric;
}
 
开发者ID:statful,项目名称:statful-client-vertx,代码行数:28,代码来源:HttpClientMetricsImpl.java

示例14: testUntaggedRequest

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void testUntaggedRequest() {

    SocketAddress socketMetric = mock(SocketAddress.class);
    SocketAddress localAddress = mock(SocketAddress.class);
    SocketAddress remoteAddress = mock(SocketAddress.class);
    HttpClientRequest request = mock(HttpClientRequest.class);
    MultiMap headers = mock(MultiMap.class);

    when(headers.get(eq(Tags.TRACK_HEADER.toString()))).thenReturn(null);
    when(request.headers()).thenReturn(headers);

    HttpRequestMetrics metrics = victim.requestBegin(null, socketMetric, localAddress, remoteAddress, request);

    assertNull(metrics);
}
 
开发者ID:statful,项目名称:statful-client-vertx,代码行数:17,代码来源:HttpClientMetricsImplTest.java

示例15: testRequestBegin

import io.vertx.core.net.SocketAddress; //导入依赖的package包/类
@Test
public void testRequestBegin() {

    SocketAddress socketMetric = mock(SocketAddress.class);
    SocketAddress localAddress = mock(SocketAddress.class);
    SocketAddress remoteAddress = mock(SocketAddress.class);
    HttpClientRequest request = mock(HttpClientRequest.class);
    MultiMap headers = mock(MultiMap.class);

    when(headers.get(eq(Tags.TRACK_HEADER.toString()))).thenReturn("tag");
    when(request.headers()).thenReturn(headers);

    HttpRequestMetrics metrics = victim.requestBegin(null, socketMetric, localAddress, remoteAddress, request);

    assertNotNull(metrics);
    assertEquals(remoteAddress, metrics.getAddress());
}
 
开发者ID:statful,项目名称:statful-client-vertx,代码行数:18,代码来源:HttpClientMetricsImplTest.java


注:本文中的io.vertx.core.net.SocketAddress类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。