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


Java Exchange类代码示例

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


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


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