Californium CoapStack 分析

Californium : Coap for java

1. CoapEndpoint.java

成员变量有CoapStack:

/** The stack of layers that make up the CoAP protocol */
protected final CoapStack coapstack;
	/**
	 * Standard coap-stack-factory.
	 * 
	 * This will be also the default, if no other default gets provided with
	 * {@link #setDefaultCoapStackFactory(CoapStackFactory)}. If an other
	 * default factory is used, this one may be used to build a standard
	 * coap-stack on demand.
	 */
	public static final CoapStackFactory STANDARD_COAP_STACK_FACTORY = new CoapStackFactory() {

		public CoapStack createCoapStack(String protocol, NetworkConfig config, Outbox outbox, Object customStackArgument) {
			if (CoAP.isTcpProtocol(protocol)) {
				return new CoapTcpStack(config, outbox);
			} else {
				return new CoapUdpStack(config, outbox);
			}
		}
	};

	/**
	 * Creates a new stack for UDP as the transport.
	 * 
	 * @param config The configuration values to use.
	 * @param outbox The adapter for submitting outbound messages to the transport.
	 */
	public CoapUdpStack(final NetworkConfig config, final Outbox outbox) {
		super(outbox);
		Layer layers[] = new Layer[] {
				createExchangeCleanupLayer(config),
				createObserveLayer(config),
				createBlockwiseLayer(config),
				createReliabilityLayer(config)};

		setLayers(layers);
	}

2. Layer相关类、结构

AbstractLayer.java

通过成员变量upperLayer、lowerLayer,把coap协议栈上下层关系,串联起来(双向关系);

接收数据时,从coap协议栈,自下而上处理;

发送数据时,从coap协议栈,自上而下处理;

(其中,单向处理,有点像责任链模式,不过,责任链模式的单个Handler环节,只有单向关联关系;这里的协议栈单个layer,有双向关联关系)

3. 逻辑结构

coap协议栈的设计模式,挺巧妙的,把coap协议层的解析,很形象的进行分层拆分;

(后面在分析其他开源协议解析框架时,可以作为对比;)

TODO coap协议栈每层layer的功能

参考:

https://github.com/eclipse/californium

https://github.com/eclipse/leshan

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值