Apace Mina Hello world
2279 단어 Hello world
public class TotalCallable implements Callable<Integer> {
private NioSocketConnector connector;
private ConnectFuture cf;
public TotalCallable(String ip, int port, Parameter parameter) {
connector = new NioSocketConnector();
//
int connectTimeout = p.getConnectTimeout();
if (connectTimeout == 0) {
connectTimeout = Parameter.TIMEOUT_CONNECT;
}
connector.setConnectTimeoutMillis(connectTimeout * 1000L);
DefaultIoFilterChainBuilder chain = connector.getFilterChain();
chain.addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
SocketSessionConfig cfg = connector.getSessionConfig();
cfg.setUseReadOperation(true);
//
cf = connector.connect(new InetSocketAddress(ip, port));
//
cf.awaitUninterruptibly();
public Integer call() {
IoSession session = cf.getSession();
try {
long s = System.currentTimeMillis();
int readTimeout = p.getSearchTimeout();
if (readTimeout == 0) {
readTimeout = Parameter.TIMEOUT_SEARCH;
}
//
session.write(p).awaitUninterruptibly();
//
ReadFuture readFuture = session.read();
if (readFuture.awaitUninterruptibly(readTimeout, TimeUnit.SECONDS)) {
Object msg = readFuture.getMessage();
if (msg instanceof Object[]) {
Object[] rt = (Object[]) msg;
if (rt.length > 1 && rt[0] instanceof Integer) {
Integer total = (Integer) rt[0];
return total;
}
}
} else {
//
}
long e = System.currentTimeMillis();
e = System.currentTimeMillis();
log.info(" :" + (e - s));
} catch (Exception e) {
log.error("ip " + ip + " port : " + port);
log.error(e.getMessage(), e);
//
cf = null;
} finally {
//
session.close(true);
session.getService().dispose();
connector.dispose();
}
return 0;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
고성능 웹 서버 Nginx 의 설정 및 배치 연구 (2) Nginx 입문 급 설정 및 배치 및 "Hello World"우 리 는 Linux/Unix:nginx-1.0.11.tar.gz 을 예 로 들 었 다.다운로드 및 압축 풀기: Nginx 는 많은 소프트웨어 에 의존 하기 때문에 저 희 는 리 눅 스 환경 이 '깨끗 하 다' 고 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.