• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Exchange类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: sweep

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
/**
 * Iterate through all entries and remove the obsolete ones.
 */
private void sweep() {
	int lifecycle = config.getInt(NetworkConfig.Keys.EXCHANGE_LIFETIME);
	long oldestAllowed = System.currentTimeMillis() - lifecycle;
	
	// Notice that the guarantees from the ConcurrentHashMap guarantee
	// the correctness for this iteration.
	for (Map.Entry<?,Exchange> entry:incommingMessages.entrySet()) {
		Exchange exchange = entry.getValue();
		if (exchange.getTimestamp() < oldestAllowed) {
			//TODO check if exchange of observe relationship is periodically created and sweeped
			LOGGER.finer("Mark-And-Sweep removes "+entry.getKey());
			incommingMessages.remove(entry.getKey());
		}
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:19,代码来源:SweepDeduplicator.java


示例2: sendRequest

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
/**
 * Schedules a retransmission for confirmable messages. 
 */
@Override
public void sendRequest(final Exchange exchange, final Request request) {

	LOGGER.finer("Send request, failed transmissions: "+exchange.getFailedTransmissionCount());
	
	if (request.getType() == null)
		request.setType(Type.CON);
	
	if (request.getType() == Type.CON) {
		prepareRetransmission(exchange, new RetransmissionTask(exchange, request) {
			public void retransmit() {
				sendRequest(exchange, request);
			}
		});
	}
	super.sendRequest(exchange, request);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:21,代码来源:ReliabilityLayer.java


示例3: prepareRetransmission

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
/**
 * Computes the back-off timer and schedules the specified retransmission
 * task.
 * 
 * @param exchange the exchange
 * @param task the retransmission task
 */
protected void prepareRetransmission(Exchange exchange, RetransmissionTask task) {
	
	// prevent RejectedExecutionException
	if (executor.isShutdown()) {
		LOGGER.info("Endpoint is being destroyed: skipping retransmission");
		return;
	}
	
	/*
	 * For a new confirmable message, the initial timeout is set to a
	 * random number between ACK_TIMEOUT and (ACK_TIMEOUT *
	 * ACK_RANDOM_FACTOR)
	 */
	int timeout;
	if (exchange.getFailedTransmissionCount() == 0) {
		timeout = getRandomTimeout(ack_timeout, (int) (ack_timeout*ack_random_factor));
	} else {
		timeout = (int) (ack_timeout_scale * exchange.getCurrentTimeout());
	}
	exchange.setCurrentTimeout(timeout);
	ScheduledFuture<?> f = executor.schedule(task , timeout, TimeUnit.MILLISECONDS);
	exchange.setRetransmissionHandle(f);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:31,代码来源:ReliabilityLayer.java


示例4: receiveResponse

import org.eclipse.californium.core.network.Exchange; //导入依赖的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);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:26,代码来源:ReliabilityLayer.java


示例5: processRTTmeasurement

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
@Override
public void processRTTmeasurement(long measuredRTT, Exchange exchange, int retransmissionCount){		
	
	RemoteEndpoint endpoint = getRemoteEndpoint(exchange);
	int rtoType = endpoint.getExchangeEstimatorState(exchange);
	
	if (rtoType == NOESTIMATOR || rtoType == WEAKRTOTYPE) {
		return;
	}

	//System.out.println("Measured RTT:" + measuredRTT);

	endpoint.matchCurrentRTO();
	if (endpoint.isBlindStrong() && rtoType == STRONGRTOTYPE) {
		// Received a strong RTT measurement for the first time, apply
		// strong RTO update
		endpoint.setBlindStrong(false);
		initializeRTOEstimators(measuredRTT, rtoType, endpoint);
	} else {
		// Perform normal update of the RTO
		updateEstimator(measuredRTT, rtoType, endpoint);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:24,代码来源:PeakhopperRto.java


示例6: processRTTmeasurement

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
@Override
public void processRTTmeasurement(long measuredRTT, Exchange exchange, int retransmissionCount){		
	RemoteEndpoint endpoint = getRemoteEndpoint(exchange);
	int rtoType = endpoint.getExchangeEstimatorState(exchange);
	
	if(rtoType == NOESTIMATOR || rtoType == WEAKRTOTYPE )
		return;
	
	// System.out.println("Measured RTT:" + measuredRTT);
	endpoint.matchCurrentRTO();
	if (endpoint.isBlindStrong() && rtoType == STRONGRTOTYPE) {
		// Received a strong RTT measurement for the first time, apply
		// strong RTO update
		endpoint.setBlindStrong(false);
		initializeRTOEstimators(measuredRTT, rtoType, endpoint);
	} else {
		// Perform normal update of the RTO
		updateEstimator(measuredRTT, rtoType, endpoint);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:21,代码来源:LinuxRto.java


示例7: processRTTmeasurement

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
@Override
public void processRTTmeasurement(long measuredRTT, Exchange exchange, int retransmissionCount){		
	//System.out.println("Measured an RTT of " + measuredRTT + " after using " + retransmissionCount + " retries." );	
	RemoteEndpoint endpoint = getRemoteEndpoint(exchange);
	int rtoType = endpoint.getExchangeEstimatorState(exchange);				
	
	if(rtoType == NOESTIMATOR || rtoType == WEAKRTOTYPE)
		return;
	endpoint.matchCurrentRTO();

	//System.out.println("Measured RTT:" + measuredRTT);
	
	// System.out.println("Endpoint status: blindweak/blindstrong/state : " + endpoint.isBlindWeak() + "/" + endpoint.isBlindStrong() + "/" + endpoint.getExchangeEstimatorState(exchange));
	if (endpoint.isBlindStrong() && rtoType == STRONGRTOTYPE) {
		// Received a strong RTT measurement for the first time, apply
		// strong RTO update
		endpoint.setBlindStrong(false);
		initializeRTOEstimators(measuredRTT, STRONGRTOTYPE, endpoint);
	} else {
		// Perform normal update of the RTO
		updateEstimator(measuredRTT, rtoType, endpoint);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:24,代码来源:CocoaStrong.java


示例8: checkObserveRelation

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
/**
 * This method is used to apply resource-specific knowledge on the exchange.
 * If the request was successful, it sets the Observe option for the
 * response. It is important to use the notificationOrderer of the resource
 * here. Further down the layer, race conditions could cause local
 * reordering of notifications. If the response has an error code, no
 * observe relation can be established and if there was one previously it is
 * canceled. When this resource allows to be observed by clients and the
 * request is a GET request with an observe option, the
 * {@link ServerMessageDeliverer} already created the relation, as it
 * manages the observing endpoints globally.
 * 
 * @param exchange the exchange
 * @param response the response
 */
public void checkObserveRelation(Exchange exchange, Response response) {
	/*
	 * If the request for the specified exchange tries to establish an observer
	 * relation, then the ServerMessageDeliverer must have created such a relation
	 * and added to the exchange. Otherwise, there is no such relation.
	 * Remember that different paths might lead to this resource.
	 */
	
	ObserveRelation relation = exchange.getRelation();
	if (relation == null) return; // because request did not try to establish a relation
	
	if (CoAP.ResponseCode.isSuccess(response.getCode())) {
		response.getOptions().setObserve(notificationOrderer.getCurrent());
		
		if (!relation.isEstablished()) {
			relation.setEstablished(true);
			addObserveRelation(relation);
		} else if (observeType != null) {
			// The resource can control the message type of the notification
			response.setType(observeType);
		}
	} // ObserveLayer takes care of the else case
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:39,代码来源:CoapResource.java


示例9: deliverRequest

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
@Override
public void deliverRequest(final Exchange exchange) {
	Request request = exchange.getRequest();
	List<String> path = request.getOptions().getUriPath();
	final Resource resource = findResource(path);
	if (resource != null) {
		checkForObserveOption(exchange, resource);
		
		// Get the executor and let it process the request
		Executor executor = resource.getExecutor();
		if (executor != null) {
			exchange.setCustomExecutor();
			executor.execute(new Runnable() {
				public void run() {
					resource.handleRequest(exchange);
				} });
		} else {
			resource.handleRequest(exchange);
		}
	} else {
		LOGGER.info("Did not find resource " + path.toString() + " requested by " + request.getSource()+":"+request.getSourcePort());
		exchange.sendResponse(new Response(ResponseCode.NOT_FOUND));
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:25,代码来源:ServerMessageDeliverer.java


示例10: CoapTransportResource

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
public CoapTransportResource(MsgProducer msgProducer, AttributesService attributesService, DeviceAuthService authService, String name, long timeout) {
  super(name);
  this.msgProducer = msgProducer;
  this.attributesService = attributesService;
  this.authService = authService;
  this.timeout = timeout;
  // This is important to turn off existing observable logic in
  // CoapResource. We will have our own observe monitoring due to 1:1
  // observe relationship.
  this.setObservable(false);
  observerField = ReflectionUtils.findField(Exchange.class, "observer");
  observerField.setAccessible(true);
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:14,代码来源:CoapTransportResource.java


示例11: CoapTransportResource

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
public CoapTransportResource(SessionMsgProcessor processor, DeviceAuthService authService, CoapTransportAdaptor adaptor, String name, long timeout) {
    super(name);
    this.processor = processor;
    this.authService = authService;
    this.adaptor = adaptor;
    this.timeout = timeout;
    // This is important to turn off existing observable logic in
    // CoapResource. We will have our own observe monitoring due to 1:1
    // observe relationship.
    this.setObservable(false);
    observerField = ReflectionUtils.findField(Exchange.class, "observer");
    observerField.setAccessible(true);
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:14,代码来源:CoapTransportResource.java


示例12: findPrevious

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
@Override
public Exchange findPrevious(KeyMID key, Exchange exchange) {
	int f = first;
	int s = second;
	Exchange prev = maps[f].putIfAbsent(key, exchange);
	if (prev != null || f==s) 
		return prev;
	prev = maps[s].putIfAbsent(key, exchange);
	return prev;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:11,代码来源:CropRotation.java


示例13: find

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
@Override
public Exchange find(KeyMID key) {
	int f = first;
	int s = second;
	Exchange prev = maps[f].get(key);
	if (prev != null || f==s)
		return prev;
	prev = maps[s].get(key);
	return prev;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:11,代码来源:CropRotation.java


示例14: reject

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
/**
 * Reject the specified message. Rejecting an ACK or RST is not allowed.
 *
 * @param exchange the exchange, can be null
 * @param message the message
 * @throws IllegalArgumentException if the message's type is ACK or RST
 */
public void reject(Exchange exchange, Message message) {
	/*
	 * From core-coap draft 14:
	 * More generally, Acknowledgement and Reset messages MUST NOT elicit
	 * any Acknowledgement or Reset message from their recipient. (draft-14)
	 */
	if (message.getType() == Type.ACK || message.getType() == Type.RST)
		throw new IllegalArgumentException("Rejecting an "+message.getType()+" is not allowed");
	sendEmptyMessage(exchange, EmptyMessage.newRST(message));
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:18,代码来源:AbstractLayer.java


示例15: receiveRequest

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
/**
 * When we receive a duplicate of a request, we stop it here and do not
 * forward it to the upper layer. If the server has already sent a response,
 * we send it again. If the request has only been acknowledged (but the ACK
 * has gone lost or not reached the client yet), we resent the ACK. If the
 * request has neither been responded, acknowledged or rejected yet, the
 * server has not yet decided what to do with the request and we cannot do
 * anything.
 */
@Override
public void receiveRequest(Exchange exchange, Request request) {
	
	if (request.isDuplicate()) {
		// Request is a duplicate, so resend ACK, RST or response
		if (exchange.getCurrentResponse() != null) {
			LOGGER.fine("Respond with the current response to the duplicate request");
			// Do not restart retransmission cycle
			super.sendResponse(exchange, exchange.getCurrentResponse());
			
		} else if (exchange.getCurrentRequest().isAcknowledged()) {
			LOGGER.fine("The duplicate request was acknowledged but no response computed yet. Retransmit ACK");
			EmptyMessage ack = EmptyMessage.newACK(request);
			sendEmptyMessage(exchange, ack);
		
		} else if (exchange.getCurrentRequest().isRejected()) {
			LOGGER.fine("The duplicate request was rejected. Reject again");
			EmptyMessage rst = EmptyMessage.newRST(request);
			sendEmptyMessage(exchange, rst);

		} else {
			LOGGER.fine("The server has not yet decided what to do with the request. We ignore the duplicate.");
			// The server has not yet decided, whether to acknowledge or
			// reject the request. We know for sure that the server has
			// received the request though and can drop this duplicate here.
		}

	} else {
		// Request is not a duplicate
		exchange.setCurrentRequest(request);
		super.receiveRequest(exchange, request);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:43,代码来源:ReliabilityLayer.java


示例16: receiveEmptyMessage

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
/**
 * If we receive an ACK or RST, we mark the outgoing request or response
 * as acknowledged or rejected respectively and cancel its retransmission.
 */
@Override
public void receiveEmptyMessage(Exchange exchange, EmptyMessage message) {
	exchange.setFailedTransmissionCount(0);
	// TODO: If this is an observe relation, the current response might not
	// be the one that is being acknowledged. The current response might
	// already be the next NON notification.
	
	if (message.getType() == Type.ACK) {
		if (exchange.getOrigin() == Origin.LOCAL) {
			exchange.getCurrentRequest().setAcknowledged(true);
		} else {
			exchange.getCurrentResponse().setAcknowledged(true);
		}
	} else if (message.getType() == Type.RST) {
		if (exchange.getOrigin() == Origin.LOCAL) {
			exchange.getCurrentRequest().setRejected(true);
		} else {
			exchange.getCurrentResponse().setRejected(true);
		}
	} else {
		LOGGER.warning("Empty messgae was not ACK nor RST: "+message);
	}

	LOGGER.finer("Cancel retransmission");
	exchange.setRetransmissionHandle(null);
	
	super.receiveEmptyMessage(exchange, message);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:33,代码来源:ReliabilityLayer.java


示例17: sendResponse

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
@Override
public void sendResponse(Exchange exchange, Response response) {
	BlockOption block1 = exchange.getBlock1ToAck();
	if (block1 != null)
		exchange.setBlock1ToAck(null);
	
	if (requireBlockwise(exchange, response)) {
		LOGGER.fine("Response payload "+response.getPayloadSize()+"/"+max_message_size+" requires Blockwise");
		
		BlockwiseStatus status = findResponseBlockStatus(exchange, response);
		
		Response block = getNextResponseBlock(response, status);
		
		if (block1 != null) // in case we still have to ack the last block1
			block.getOptions().setBlock1(block1);
		
		if (status.isComplete()) {
			// clean up blockwise status
			LOGGER.fine("Ongoing finished on first block "+status);
			exchange.setResponseBlockStatus(null);
			exchange.setBlockCleanupHandle(null);
		} else {
			LOGGER.fine("Ongoing started "+status);
		}
		
		exchange.setCurrentResponse(block);
		super.sendResponse(exchange, block);
		
	} else {
		if (block1 != null) response.getOptions().setBlock1(block1);
		exchange.setCurrentResponse(response);
		// Block1 transfer completed
		exchange.setBlockCleanupHandle(null);
		super.sendResponse(exchange, response);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:37,代码来源:BlockwiseLayer.java


示例18: earlyBlock2Negotiation

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
private void earlyBlock2Negotiation(Exchange exchange, Request request) {
	// Call this method when a request has completely arrived (might have
	// been sent in one piece without blockwise).
	if (request.getOptions().hasBlock2()) {
		BlockOption block2 = request.getOptions().getBlock2();
		BlockwiseStatus status2 = new BlockwiseStatus(request.getOptions().getContentFormat(), block2.getNum(), block2.getSzx());
		LOGGER.fine("Request with early block negotiation "+block2+". Create and set new Block2 status: "+status2);
		exchange.setResponseBlockStatus(status2);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:11,代码来源:BlockwiseLayer.java


示例19: findRequestBlockStatus

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
private BlockwiseStatus findRequestBlockStatus(Exchange exchange, Request request) {
	BlockwiseStatus status = exchange.getRequestBlockStatus();
	if (status == null) {
		status = new BlockwiseStatus(request.getOptions().getContentFormat());
		status.setCurrentSzx( computeSZX(preferred_block_size) );
		exchange.setRequestBlockStatus(status);
		LOGGER.finer("There is no assembler status yet. Create and set new Block1 status: "+status);
	} else {
		LOGGER.finer("Current Block1 status: "+status);
	}
	// sets a timeout to complete exchange
	prepareBlockCleanup(exchange);
	return status;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:15,代码来源:BlockwiseLayer.java


示例20: findResponseBlockStatus

import org.eclipse.californium.core.network.Exchange; //导入依赖的package包/类
private BlockwiseStatus findResponseBlockStatus(Exchange exchange, Response response) {
	BlockwiseStatus status = exchange.getResponseBlockStatus();
	if (status == null) {
		status = new BlockwiseStatus(response.getOptions().getContentFormat());
		status.setCurrentSzx( computeSZX(preferred_block_size) );
		exchange.setResponseBlockStatus(status);
		LOGGER.finer("There is no blockwise status yet. Create and set new Block2 status: "+status);
	} else {
		LOGGER.finer("Current Block2 status: "+status);
	}
	// sets a timeout to complete exchange
	prepareBlockCleanup(exchange);
	return status;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:15,代码来源:BlockwiseLayer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IMeshVertexBufferObject类代码示例发布时间:2022-05-22
下一篇:
Java StoredFieldsWriter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap