📄 abstractport.java
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 notXX
* luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//package edu.tsinghua.lumaqq.qq.net;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.Queue;
/*
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.QQClient;
import edu.tsinghua.lumaqq.qq.events.QQEvent;
import edu.tsinghua.lumaqq.qq.packets.OutPacket;
*/
/**
* 部分实现包收发.
*
* @author notxx
* @author luma
*/
abstract class AbstractPort implements IPort, INIOHandler {
// private static final Log log = LogFactory.getLog(AbstractPort.class);
/** 发送缓冲区 */
protected ByteBuffer sendBuf;
/** 接收缓冲区 */
protected ByteBuffer receiveBuf;
/** 发送队列 */
protected Queue<OutPacket> sendQueue;
/** QQ客户端类 */
protected QQClient client;
/** 端口名称 */
protected String name;
/** 远程地址 */
protected InetSocketAddress remoteAddress;
/** 代理地址 */
protected InetSocketAddress proxyAddress;
/** 引用计数,port创建后,reference自动设为1 */
protected int reference;
/**
* 构造函数
*/
public AbstractPort(QQClient client, String name) {
this.client = client;
this.name = name;
reference = 1;
sendQueue = new LinkedList<OutPacket>();
sendBuf = ByteBuffer.allocateDirect(QQ.QQ_MAX_PACKET_SIZE);
receiveBuf = ByteBuffer.allocateDirect(QQ.QQ_MAX_PACKET_SIZE);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#getReference()
*/
public synchronized int getReference() {
return reference;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#increaseReference()
*/
public synchronized void increaseReference() {
reference++;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#decreaseReference()
*/
public synchronized void decreaseReference() {
reference--;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#getName()
*/
public String getName() {
return name;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#add(edu.tsinghua.lumaqq.qq.packets.OutPacket)
*/
public synchronized void add(OutPacket packet) {
sendQueue.offer(packet);
client.getPorter().wakeup();
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.IPort#clear()
*/
public synchronized void clear() {
sendQueue.clear();
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.IPort#isEmpty()
*/
public synchronized boolean isEmpty() {
return sendQueue.isEmpty();
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#remove()
*/
public synchronized OutPacket remove() {
return sendQueue.poll();
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#getNIOHandler()
*/
public INIOHandler getNIOHandler() {
return this;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.INIOHandler#processError(java.lang.Exception)
*/
public void processError(Exception e) {
try {
//log.debug("网络出错,关闭连接");
System.err.println("网络出错,关闭连接");
dispose();
} catch (IOException e1) {
//log.error("无法关闭当前连接");
System.err.println("无法关闭当前连接");
}
QQEvent event = new QQEvent(e);
event.type = QQEvent.QQ_NETWORK_ERROR;
client.fireQQEvent(event);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#getProxyAddress()
*/
public InetSocketAddress getProxyAddress() {
return proxyAddress;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.net.IPort#getRemoteAddress()
*/
public InetSocketAddress getRemoteAddress() {
return remoteAddress;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -