Files
redkale/src/com/wentch/redkale/net/Request.java
地平线 d81461ccc2
2015-03-16 18:55:36 +08:00

71 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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.*;
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;
}
/**
* 返回值Integer.MIN_VALUE: 帧数据; -1数据不合法 0解析完毕 >0: 需再读取的字节数。
*
* @param buffer
* @return
*/
protected abstract int readHeader(ByteBuffer buffer);
protected abstract void readBody(ByteBuffer buffer);
protected abstract void prepare();
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;
}
}