connectinfo.java

来自「同步接收web services请求」· Java 代码 · 共 67 行

JAVA
67
字号
/**
 *
 */
package com.aceway.vas.commons.tcp.impl;

import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;

public class ConnectInfo {
    private int connectId= -1;
    private ByteBuffer recvBuff = null;
    private List sendDataList = new ArrayList();
    private Object attachObj = null;
    private SelectionKey key = null;

    public void setAttachObj(Object attachObj){
	this.attachObj = attachObj;
    }
    public Object getAttachObj(){
	return this.attachObj;
    }

    public void setKey(SelectionKey key){
	this.key = key;
    }

    public SelectionKey getKey(){
	return this.key;
    }

    public ConnectInfo(int connectId, int bufferCapacity){
	this.connectId = connectId;
	recvBuff = ByteBuffer.allocate(bufferCapacity);
    }
    public int getConnectId(){
	return connectId;
    }

    public void addSendData(byte[] bytes){
	this.sendDataList.add(ByteBuffer.wrap(bytes));
    }

    public List getSendData(){
	return this.sendDataList;
    }


    public SocketAddress getRemoteAddress(){
	SocketChannel sc = (SocketChannel)key.channel();
	return sc.socket().getRemoteSocketAddress() ;
    }

    public ByteBuffer getRecvBuff(){
	return this.recvBuff;
    }

    public void setRecvBuff(ByteBuffer buff){
	this.recvBuff = buff;
    }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?