This commit is contained in:
地平线
2015-03-11 17:49:20 +08:00
parent be89d407ac
commit 3a2f802500
169 changed files with 22269 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.wentch.redkale.net;
import java.nio.ByteBuffer;
import java.util.*;
/**
*
* @author zhangjx
*/
public abstract class Request {
protected final Context context;
protected long createtime;
protected boolean keepAlive;
protected AsyncConnection channel;
protected final Map<String, Object> attributes = new HashMap<>();
protected Request(Context context) {
this.context = context;
}
/**
* 返回值: -1数据不合法 0解析完毕 >0: 需再读取的字节数。
*
* @param buffer
* @return
*/
protected abstract int readHeader(ByteBuffer buffer);
protected abstract void readBody(ByteBuffer buffer);
protected void recycle() {
createtime = 0;
keepAlive = false;
attributes.clear();
channel = null; // close it by response
}
public void setAttribute(String name, Object value) {
attributes.put(name, value);
}
@SuppressWarnings("unchecked")
public <T> T getAttribute(String name) {
return (T) attributes.get(name);
}
public void removeAttribute(String name) {
attributes.remove(name);
}
public Map<String, Object> getAttributes() {
return attributes;
}
public Context getContext() {
return this.context;
}
}