本文整理汇总了Java中org.eclipse.californium.core.coap.Response.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getType方法的具体用法?Java Response.getType怎么用?Java Response.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.californium.core.coap.Response
的用法示例。
在下文中一共展示了Response.getType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveResponse
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
/**
* When we receive a Confirmable response, we acknowledge it and it also
* counts as acknowledgment for the request. If the response is a duplicate,
* we stop it here and do not forward it to the upper layer.
*/
@Override
public void receiveResponse(Exchange exchange, Response response) {
exchange.setFailedTransmissionCount(0);
exchange.getCurrentRequest().setAcknowledged(true);
LOGGER.finest("Cancel any retransmission");
exchange.setRetransmissionHandle(null);
if (response.getType() == Type.CON && !exchange.getRequest().isCanceled()) {
LOGGER.finer("Response is confirmable, send ACK");
EmptyMessage ack = EmptyMessage.newACK(response);
sendEmptyMessage(exchange, ack);
}
if (response.isDuplicate()) {
LOGGER.fine("Response is duplicate, ignore it");
} else {
super.receiveResponse(exchange, response);
}
}
示例2: isInTransit
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
/**
* Returns true if the specified response is still in transit. A response is
* in transit if it has not yet been acknowledged, rejected or its current
* transmission has not yet timed out.
*/
private boolean isInTransit(Response response) {
Type type = response.getType();
boolean acked = response.isAcknowledged();
boolean timeout = response.isTimedOut();
boolean result = type == Type.CON && !acked && !timeout;
return result;
}
示例3: onRetransmission
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Override
public void onRetransmission() {
synchronized (exchange) {
ObserveRelation relation = exchange.getRelation();
final Response next = relation.getNextControlNotification();
if (next != null) {
LOGGER.fine("The notification has timed out and there is a fresher notification for the retransmission");
// Cancel the original retransmission and send the fresh notification here
response.cancel();
// use the same MID
next.setMID(response.getMID());
// Convert all notification retransmissions to CON
if (next.getType() != Type.CON) {
next.setType(Type.CON);
prepareSelfReplacement(exchange, next);
}
relation.setCurrentControlNotification(next);
relation.setNextControlNotification(null);
// Create a new task for sending next response so that we can leave the sync-block
executor.execute(new Runnable() {
public void run() {
ObserveLayer.super.sendResponse(exchange, next);
}
});
}
}
}
示例4: CoapMessage
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
public CoapMessage(Response request, boolean incoming) {
this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request
.getPayload());
this.code = request.getCode().toString();
}
示例5: sendResponse
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
/**
* Makes sure that the response type is correct. The response type for a NON
* can be NON or CON. The response type for a CON should either be an ACK
* with a piggy-backed response or, if an empty ACK has already be sent, a
* CON or NON with a separate response.
*/
@Override
public void sendResponse(final Exchange exchange, final Response response) {
LOGGER.finer("Send response, failed transmissions: "+exchange.getFailedTransmissionCount());
// If a response type is set, we do not mess around with it.
// Only if none is set, we have to decide for one here.
Type respType = response.getType();
if (respType == null) {
Type reqType = exchange.getCurrentRequest().getType();
if (reqType == Type.CON) {
if (exchange.getCurrentRequest().isAcknowledged()) {
// send separate response
response.setType(Type.CON);
} else {
exchange.getCurrentRequest().setAcknowledged(true);
// send piggy-backed response
response.setType(Type.ACK);
response.setMID(exchange.getCurrentRequest().getMID());
}
} else {
// send NON response
response.setType(Type.NON);
}
LOGGER.finest("Switched response message type from "+respType+" to "+response.getType()+" (request was "+reqType+")");
} else if (respType == Type.ACK || respType == Type.RST) {
response.setMID(exchange.getCurrentRequest().getMID());
}
if (response.getType() == Type.CON) {
LOGGER.finer("Scheduling retransmission for " + response);
prepareRetransmission(exchange, new RetransmissionTask(exchange, response) {
public void retransmit() {
sendResponse(exchange, response);
}
});
}
super.sendResponse(exchange, response);
}
示例6: sendResponse
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Override
public void sendResponse(final Exchange exchange, Response response) {
final ObserveRelation relation = exchange.getRelation();
if (relation != null && relation.isEstablished()) {
if (exchange.getRequest().isAcknowledged() || exchange.getRequest().getType()==Type.NON) {
// Transmit errors as CON
if (!ResponseCode.isSuccess(response.getCode())) {
LOGGER.fine("Response has error code "+response.getCode()+" and must be sent as CON");
response.setType(Type.CON);
relation.cancel();
} else {
// Make sure that every now and than a CON is mixed within
if (relation.check()) {
LOGGER.fine("The observe relation check requires the notification to be sent as CON");
response.setType(Type.CON);
} else {
// By default use NON, but do not override resource decision
if (response.getType()==null) response.setType(Type.NON);
}
}
}
// This is a notification
response.setLast(false);
/*
* The matcher must be able to find the NON notifications to remove
* them from the exchangesByMID hashmap
*/
if (response.getType() == Type.NON) {
relation.addNotification(response);
}
/*
* Only one Confirmable message is allowed to be in transit. A CON
* is in transit as long as it has not been acknowledged, rejected,
* or timed out. All further notifications are postponed here. If a
* former CON is acknowledged or timeouts, it starts the freshest
* notification (In case of a timeout, it keeps the retransmission
* counter). When a fresh/younger notification arrives but must be
* postponed we forget any former notification.
*/
if (response.getType() == Type.CON) {
prepareSelfReplacement(exchange, response);
}
// The decision whether to postpone this notification or not and the
// decision which notification is the freshest to send next must be
// synchronized
synchronized (exchange) {
Response current = relation.getCurrentControlNotification();
if (current != null && isInTransit(current)) {
LOGGER.fine("A former notification is still in transit. Postpone " + response);
// use the same MID
response.setMID(current.getMID());
relation.setNextControlNotification(response);
// do not send now
return;
} else {
relation.setCurrentControlNotification(response);
relation.setNextControlNotification(null);
}
}
} // else no observe was requested or the resource does not allow it
super.sendResponse(exchange, response);
}
示例7: sendResponse
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
public void sendResponse(Exchange exchange, Response response) {
// ensure MID is set
if (response.getMID() == Message.NONE) {
response.setMID(currendMID.getAndIncrement()%(1<<16));
}
// ensure Token is set
response.setToken(exchange.getCurrentRequest().getToken());
// If this is a CON notification we now can forget all previous NON notifications
if (response.getType() == Type.CON || response.getType() == Type.ACK) {
ObserveRelation relation = exchange.getRelation();
if (relation != null) {
removeNotificatoinsOf(relation);
}
}
// Blockwise transfers are identified by URI and remote endpoint
if (response.getOptions().hasBlock2()) {
Request request = exchange.getCurrentRequest();
KeyUri idByUri = new KeyUri(request.getURI(), response.getDestination().getAddress(), response.getDestinationPort());
// Observe notifications only send the first block, hence do not store them as ongoing
if (exchange.getResponseBlockStatus()!=null && !response.getOptions().hasObserve()) {
// Remember ongoing blockwise GET requests
if (ongoingExchanges.put(idByUri, exchange)==null) {
LOGGER.fine("Ongoing Block2 started late, storing "+idByUri + " for " + request);
} else {
LOGGER.fine("Ongoing Block2 continued, storing "+idByUri + " for " + request);
}
} else {
LOGGER.fine("Ongoing Block2 completed, cleaning up "+idByUri + " for " + request);
ongoingExchanges.remove(idByUri);
}
}
// Insert CON and NON to match ACKs and RSTs to the exchange.
// Do not insert ACKs and RSTs.
if (response.getType() == Type.CON || response.getType() == Type.NON) {
KeyMID idByMID = new KeyMID(response.getMID(), null, 0);
exchangesByMID.put(idByMID, exchange);
}
// Only CONs and Observe keep the exchange active
if (response.getType() != Type.CON && response.isLast()) {
exchange.setComplete();
}
}
示例8: completed
import org.eclipse.californium.core.coap.Response; //导入方法依赖的package包/类
@Override
public void completed(Exchange exchange) {
/*
* Logging in this method leads to significant performance loss.
* Uncomment logging code only for debugging purposes.
*/
if (exchange.getOrigin() == Origin.LOCAL) {
// this endpoint created the Exchange by issuing a request
KeyMID idByMID = new KeyMID(exchange.getCurrentRequest().getMID(), null, 0);
KeyToken idByToken = new KeyToken(exchange.getCurrentRequest().getToken());
// LOGGER.fine("Exchange completed: Cleaning up "+idByTok);
exchangesByToken.remove(idByToken);
// in case an empty ACK was lost
exchangesByMID.remove(idByMID);
} else { // Origin.REMOTE
// this endpoint created the Exchange to respond to a request
Response response = exchange.getCurrentResponse();
if (response != null && response.getType() != Type.ACK) {
// only response MIDs are stored for ACK and RST, no reponse Tokens
KeyMID midKey = new KeyMID(response.getMID(), null, 0);
// LOGGER.fine("Remote ongoing completed, cleaning up "+midKey);
exchangesByMID.remove(midKey);
}
Request request = exchange.getCurrentRequest();
if (request != null && (request.getOptions().hasBlock1() || response.getOptions().hasBlock2()) ) {
KeyUri uriKey = new KeyUri(request.getURI(), request.getSource().getAddress(), request.getSourcePort());
LOGGER.fine("Remote ongoing completed, cleaning up "+uriKey);
ongoingExchanges.remove(uriKey);
}
// Remove all remaining NON-notifications if this exchange is an observe relation
ObserveRelation relation = exchange.getRelation();
if (relation != null) {
removeNotificatoinsOf(relation);
}
}
}