📄 servicehandler.java
字号:
/**
* Project:ms4j (Message Server for Java)
* Date:2007-2-21
* Authoer : jobsun@gmail.com
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
*/
package com.sunjob.ms4j.server;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.HashMap;
/**
* @author sunjob
*
*/
public class ServiceHandler implements Runnable {
private final Socket socket;
private final HashMap context;
public ServiceHandler(Socket socket,HashMap context) {
this.socket = socket;
this.context = context;
}
public void run() {
try
{
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
SocketAddress address = socket.getRemoteSocketAddress();
ProtocolParser mtp = (ProtocolParser)this.context.get("@ParseProtocol");
mtp.parse(address, is, os);
}catch(Exception e)
{
this.proErr(e);
}finally
{
try
{
if(socket != null && !socket.isClosed())
socket.close();
}catch(Exception e)
{
this.proErr(e);
}
}
}
public void proErr(Throwable exp)
{
exp.printStackTrace();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -