org.eclipse.californium.core.coap.Request.getDestination()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.eclipse.californium.core.coap.Request.getDestination方法的一些代码示例,展示了Request.getDestination的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getDestination方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:getDestination

Request.getDestination介绍

暂无

代码示例

代码示例来源:origin: eclipse/californium

@Override
public void sendRequest(Request request) {
  LOGGER.log(Level.INFO, "{0}:{1} <== req {2}", new Object[]{request.getDestination(), request.getDestinationPort(), request});
}

代码示例来源:origin: eclipse/californium

private void assignClientUriIfEmpty(Request request) {
  // request.getUri() is a computed getter and never returns null so checking destination
  if (request.getDestination() == null) {
    request.setURI(uri);
  }
}

代码示例来源:origin: eclipse/californium

/**
 * Validate before sending that there is a destination set.
 */
private void validateBeforeSending() {
  if (getDestination() == null)
    throw new NullPointerException("Destination is null");
  if (getDestinationPort() == 0)
    throw new NullPointerException("Destination port is 0");
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Validate before sending that there is a destination set.
 */
private void validateBeforeSending() {
  if (getDestination() == null)
    throw new NullPointerException("Destination is null");
  if (getDestinationPort() == 0)
    throw new NullPointerException("Destination port is 0");
}

代码示例来源:origin: org.eclipse.californium/californium-core

@Override
public void sendRequest(Request request) {
  LOGGER.info(String.format("%s:%d <== req %s", request.getDestination(), request.getDestinationPort(), request));
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Serializes the specified request. Message identifier, message code,
 * token, options and payload are converted into a byte array and wrapped in
 * a {@link RawData} object. The request's destination address and port are
 * stored as address and port in the RawData object.
 * 
 * @param request
 *            the request
 * @return the request as raw data
 */
public RawData serialize(Request request) {
  byte[] bytes = request.getBytes();
  if (bytes == null)
    bytes = new DataSerializer().serializeRequest(request);
  request.setBytes(bytes);
  return new RawData(bytes, request.getDestination(), request.getDestinationPort());
}

代码示例来源:origin: eclipse/californium

/**
 * Serializes a request and caches the result on the request object to skip future serializations.
 * <p>
 * NB: The byte array cached in the message is encoded according to the specific serializer implementation's
 * supported wire format. Any subsequent invocation of this method with the same request object will therefore
 * simply return the cached byte array. This may cause problems when the first invocation was done on a different
 * type of serializer than the second.
 * <p>
 * Clients should use the {@link #getByteArray(Request)} method in order to prevent caching of the resulting
 * byte array.
 * 
 * @param request The request to serialize.
 * @param outboundCallback The callback to invoke once the message's correlation context
 *                         has been established. 
 * @return The object containing the serialized request and the callback.
 */
public final RawData serializeRequest(final Request request, final MessageCallback outboundCallback) {
  if (request.getBytes() == null) {
    request.setBytes(getByteArray(request));
  }
  return RawData.outbound(
          request.getBytes(),
          new InetSocketAddress(request.getDestination(),
          request.getDestinationPort()),
          outboundCallback,
          false);
}

代码示例来源:origin: eclipse/californium

/**
 * Returns the endpoint responsible for the given exchange.
 * @param exchange the exchange
 * @return the endpoint for the exchange
 */
public RemoteEndpoint getRemoteEndpoint(Exchange exchange){ //int remotePort, InetAddress remoteAddress){
  
  InetAddress remoteAddress = exchange.getRequest().getDestination();
  int remotePort = exchange.getRequest().getDestinationPort();
  
  // TODO: One IP-Address is considered to be a destination endpoint, for higher granularity (portnumber) changes are necessary
  if (!remoteEndpointsList.containsKey(remoteAddress)){
    RemoteEndpoint unusedRemoteEndpoint = new RemoteEndpoint(remotePort, remoteAddress, config);
    remoteEndpointsList.put(remoteAddress,unusedRemoteEndpoint);
    
    //System.out.println("Number of RemoteEndpoint objects stored:" + remoteEndpointsList.size());
  }
  
  return remoteEndpointsList.get(remoteAddress);
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Returns the endpoint responsible for the given exchange.
 * @param exchange the exchange
 * @return the endpoint for the exchange
 */
public RemoteEndpoint getRemoteEndpoint(Exchange exchange){ //int remotePort, InetAddress remoteAddress){
  
  InetAddress remoteAddress = exchange.getRequest().getDestination();
  int remotePort = exchange.getRequest().getDestinationPort();
  
  // TODO: One IP-Address is considered to be a destination endpoint, for higher granularity (portnumber) changes are necessary
  if (!remoteEndpointsList.containsKey(remoteAddress)){
    RemoteEndpoint unusedRemoteEndpoint = new RemoteEndpoint(remotePort, remoteAddress, config);
    remoteEndpointsList.put(remoteAddress,unusedRemoteEndpoint);
    
    //System.out.println("Number of RemoteEndpoint objects stored:" + remoteEndpointsList.size());
  }
  
  return remoteEndpointsList.get(remoteAddress);
}

代码示例来源:origin: org.eclipse.californium/californium-core

@Override
public void sendRequest(Exchange exchange, Request request) {
  if (request.getDestination() == null)
    throw new NullPointerException("Request has no destination address");
  if (request.getDestinationPort() == 0)

代码示例来源:origin: eclipse/californium

@Test
public void testSetURISetsDestination() {
  InetSocketAddress dest = InetSocketAddress.createUnresolved("192.168.0.1", 12000);
  Request req = Request.newGet().setURI("coap://192.168.0.1:12000");
  assertThat(req.getDestination().getHostAddress(), is(dest.getHostString()));
  assertThat(req.getDestinationPort(), is(dest.getPort()));
}

代码示例来源:origin: eclipse/californium

/**
 * Send request with option "cancel observe" (GET with Observe=1).
 */
private void sendCancelObserve() {
  Request request = this.request;
  Request cancel = Request.newGet();
  cancel.setDestination(request.getDestination());
  cancel.setDestinationPort(request.getDestinationPort());
  // use same Token
  cancel.setToken(request.getToken());
  // copy options, but set Observe to cancel
  cancel.setOptions(request.getOptions());
  cancel.setObserveCancel();
  // dispatch final response to the same message observers
  for (MessageObserver mo : request.getMessageObservers()) {
    cancel.addMessageObserver(mo);
  }
  endpoint.sendRequest(cancel);
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Send request with option "cancel observe" (GET with Observe=1).
 */
private void sendCancelObserve() {
  Request request = this.request;
  Request cancel = Request.newGet();
  cancel.setDestination(request.getDestination());
  cancel.setDestinationPort(request.getDestinationPort());
  // use same Token
  cancel.setToken(request.getToken());
  // copy options, but set Observe to cancel
  cancel.setOptions(request.getOptions());
  cancel.setObserveCancel();
  
  // dispatch final response to the same message observers
  for (MessageObserver mo: request.getMessageObservers()) {
    cancel.addMessageObserver(mo);
  }
  
  endpoint.sendRequest(cancel);
}

代码示例来源:origin: eclipse/californium

@Test
public void testSetURISetsUriHostOptionToHostName() {
  assumeTrue(dnsIsWorking());
  Request req = Request.newGet().setURI("coaps://localhost");
  assertNotNull(req.getDestination());
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
  assertThat(req.getOptions().getUriHost(), is("localhost"));
}

代码示例来源:origin: eclipse/californium

refresh.setDestination(request.getDestination());
refresh.setDestinationPort(request.getDestinationPort());

代码示例来源:origin: eclipse/californium

Level.WARNING,
      "exchange observer has been completed on unregistered exchange [peer: {0}:{1}, origin: {2}]",
      new Object[]{ originRequest.getDestination(), originRequest.getDestinationPort(),
          exchange.getOrigin()});
} else {

代码示例来源:origin: eclipse/californium

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

代码示例来源:origin: org.eclipse.californium/californium-core

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

代码示例来源:origin: eclipse/californium

private static Response responseFor(final Request request) {
    Response response = new Response(ResponseCode.CONTENT);
    response.setMID(request.getMID());
    response.setToken(request.getToken());
    response.setBytes(new byte[]{});
    response.setSource(request.getDestination());
    response.setSourcePort(request.getDestinationPort());
    response.setDestination(request.getSource());
    response.setDestinationPort(request.getSourcePort());
    return response;
  }
}

代码示例来源:origin: eclipse/californium

private Response responseFor(final Request request) {
    Response response = new Response(ResponseCode.CONTENT);
    response.setMID(request.getMID());
    response.setToken(request.getToken());
    response.setBytes(new byte[]{});
    response.setSource(request.getDestination());
    response.setSourcePort(request.getDestinationPort());
    response.setDestination(request.getSource());
    response.setDestinationPort(request.getSourcePort());
    return response;
  }
}

相关文章

微信公众号

最新文章

更多