本文整理汇总了Java中org.apache.mina.filter.codec.textline.TextLineCodecFactory类的典型用法代码示例。如果您正苦于以下问题:Java TextLineCodecFactory类的具体用法?Java TextLineCodecFactory怎么用?Java TextLineCodecFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextLineCodecFactory类属于org.apache.mina.filter.codec.textline包,在下文中一共展示了TextLineCodecFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
IoAcceptor acceptor = new NioSocketAcceptor();
// 这个过滤器用来记录所有的信息,比如创建session(会话),接收消息,发送消息,关闭会话等
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
// 用来转换二进制或协议的专用数据到消息对象中
acceptor.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
// 实时处理客户端的连接和请求
acceptor.setHandler(new TimeServerHandler());
acceptor.getSessionConfig().setReadBufferSize(2048);
// 方法将定时调用一次会话,保持空闲状态。来设定时间间隔。
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
acceptor.bind(new InetSocketAddress(PORT));
}
示例2: main
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
// 创建服务器端的监听器对象
IoAcceptor acceptor = new NioSocketAcceptor();
// 增加日志过滤器:用于日志存储
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
// 增加消息编码过滤器,采用UTF-8编码
acceptor.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
// 设置具体的事物逻辑处理器
acceptor.setHandler(new TimeServerHandler());
// 设置IoSession的一些属性
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
// 设置服务器监听的端口
acceptor.bind(new InetSocketAddress(PORT));
}
示例3: main
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public static void main(String[] args) {
int port = U.getInt("cleaner.server.port");
int idleTime = U.getInt("cleaner.server.time");
NioSocketAcceptor clientAcceptor = new NioSocketAcceptor();
clientAcceptor.setReuseAddress(true);
DefaultIoFilterChainBuilder chain = clientAcceptor.getFilterChain();
SocketSessionConfig config = clientAcceptor.getSessionConfig();
config.setIdleTime(IdleStatus.READER_IDLE, idleTime);// 读空闲 10秒
config.setReuseAddress(true);
config.setReadBufferSize(4096);// 默认2048
config.setKeepAlive(true);
config.setTcpNoDelay(true);// 开启nagle算法
// 编解码
chain.addLast("coder", new ProtocolCodecFilter(new TextLineCodecFactory(U.UTF8)));
clientAcceptor.setHandler(new CleanerHandler());
try {
clientAcceptor.bind(new InetSocketAddress(port));
log.info("心跳模块启动..");
} catch (IOException e) {
log.error("心跳模块启动失败", e);
}
}
示例4: start
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
/** */
@PostConstruct
public void start() throws IOException
{
if (this.acceptor != null)
throw new IllegalStateException("TcpTableService already running");
InetAddress binding = null;
String bindAddress = System.getProperty("jboss.bind.address");
if (bindAddress != null && !"0.0.0.0".equals(bindAddress))
binding = InetAddress.getByName(bindAddress);
log.log(Level.INFO,"Starting TcpTableService: {0}:{1}", new Object[]{(binding==null ? "*" : binding),port});
this.acceptor = new SocketAcceptor();
this.acceptor.getFilterChain().addLast(
"codec",
new ProtocolCodecFilter(
new TextLineCodecFactory(Charset.forName("UTF-8"))));
this.acceptor.bind(new InetSocketAddress(binding, this.port), new Handler());
}
示例5: NIOSocketServerController
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public NIOSocketServerController(SocketServerConfig config) {
this.setConfig(config);
this.acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
acceptor.getFilterChain().addLast(
"codec",
new ProtocolCodecFilter(new TextLineCodecFactory(Charset
.forName("UTF-8"))));
acceptor.setHandler(this);
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
json = new JSON();
this.processorManager = new ProcessorManager();
}
示例6: initService
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
private void initService() throws Exception
{
IoBuffer.setUseDirectBuffer(false);
acceptor = new NioSocketAcceptor(
Runtime.getRuntime().availableProcessors() + 1);
config = acceptor.getSessionConfig();
config.setReuseAddress(true);
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
chain.addLast("codec", new ProtocolCodecFilter(
new TextLineCodecFactory(
MailsterConstants.DEFAULT_CHARSET,
LineDelimiter.CRLF,
LineDelimiter.CRLF)));
executor = Executors.newCachedThreadPool(
ThreadFactoryUtilities.createFactory("POP3 Thread"));
chain.addLast("threadPool", new ExecutorFilter(executor));
handler = new Pop3ProtocolHandler(userManager);
}
示例7: MinaCubeClient
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public MinaCubeClient(String hostname, int port) {
this.hostname = hostname;
this.port = port;
connector = new NioSocketConnector(1);
connector.setConnectTimeoutMillis(2000);
connector.getFilterChain().addLast("logger", new LoggingFilter());
TextLineCodecFactory codecFactory = new TextLineCodecFactory(UTF_8, LineDelimiter.CRLF, LineDelimiter.AUTO);
codecFactory.setDecoderMaxLineLength(4096);
codecFactory.setEncoderMaxLineLength(4096);
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
handler = new ConnectHandler();
connector.setHandler(handler);
}
示例8: start
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public void start() throws IOException {
// enable for debug
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
TextLineCodecFactory codecFactory = new TextLineCodecFactory(UTF_8, LineDelimiter.CRLF, LineDelimiter.CRLF);
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
acceptor.setHandler(handler);
acceptor.bind(new InetSocketAddress(0) );
acceptor.setCloseOnDeactivation(true);
logger.info("Cube server bound to [{}]", acceptor.getLocalAddress());
}
示例9: main
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public static void main(String[] args) {
// 创建客户端连接器.
NioSocketConnector connector = new NioSocketConnector();
connector.getFilterChain().addLast("logger", new LoggingFilter());
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8")))); // 设置编码过滤器
connector.setConnectTimeout(30);
connector.setHandler(new TimeClientHandler());// 设置事件处理器
ConnectFuture cf = connector.connect(new InetSocketAddress("127.0.0.1", 9123));// 建立连接
cf.awaitUninterruptibly();// 等待连接创建完成
cf.getSession().write("hello");// 发送消息
cf.getSession().write("quit");// 发送消息
cf.getSession().getCloseFuture().awaitUninterruptibly();// 等待连接断开
connector.dispose();
}
示例10: main
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
IoAcceptor acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));// 指定编码过滤器
acceptor.setHandler(new TimeServerHandler());// 指定业务逻辑处理器
//读写 通道均在3 秒内无任何操作就进入空闲状态
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 3);
acceptor.setDefaultLocalAddress(new InetSocketAddress(PORT));// 设置端口号
acceptor.bind();// 启动监听
}
示例11: emit
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
@Override
public void emit() {
// TODO Auto-generated method stub
try {
// ssl 认证
if (sslEnable) {
SslFilter sslFilter = new SslFilter(getSslContext());
acceptor.getFilterChain().addLast("sslFilter", sslFilter);
logger.warn("ssl authenticate is open");
}
LoggingFilter loggingFilter = new LoggingFilter();
acceptor.getFilterChain().addLast("logger", loggingFilter);
TextLineCodecFactory textLineCodecFactory = new TextLineCodecFactory(
Charset.forName(encodiing));
textLineCodecFactory.setDecoderMaxLineLength(maxLineLength);
textLineCodecFactory.setEncoderMaxLineLength(maxLineLength);
acceptor.getFilterChain().addLast("codec",
new ProtocolCodecFilter(textLineCodecFactory));
acceptor.setHandler(minaBizHandler);
acceptor.getSessionConfig().setReadBufferSize(bufSize);
acceptor.getSessionConfig().setWriteTimeout(10);
// acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE,
// 10);//空闲状态
acceptor.bind(new InetSocketAddress(InetAddress.getByName(host),
port));
} catch (Exception e) {
// TODO Auto-generated catch block
logger.error(e.getMessage());
System.exit(1);
}
}
示例12: getTextLineCodecFactory
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
@NonNull
static TextLineCodecFactory getTextLineCodecFactory() {
TextLineCodecFactory codec = new TextLineCodecFactory();
codec.setDecoderMaxLineLength(MAX_LINE_LENGTH);
codec.setEncoderMaxLineLength(MAX_LINE_LENGTH);
return codec;
}
示例13: start
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public void start() throws Exception {
acceptor = new SocketAcceptor();
// Prepare the configuration
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.setReuseAddress(true);
Charset charset = Charset.forName("UTF-8");
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));
// Bind
acceptor.bind(new InetSocketAddress(port), new ReverseProtocolHandler(), cfg);
}
示例14: start
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
public void start() throws Exception {
acceptor = new NioSocketAcceptor();
// Prepare the configuration
((NioSocketAcceptor) acceptor).setReuseAddress(true);
Charset charset = Charset.forName("UTF-8");
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));
acceptor.setHandler(new Mina2ReverseProtocolHandler());
// Bind
acceptor.bind(new InetSocketAddress(port));
}
示例15: startMinaServer
import org.apache.mina.filter.codec.textline.TextLineCodecFactory; //导入依赖的package包/类
private void startMinaServer() {
initNotify();
// serverThread = new Thread(new Runnable() {
// @Override
// public void run() {
//
// }
// });
// serverThread.start();
try{
//创建一个非阻塞的server端的Socket
acceptor = new NioSocketAcceptor();
//设置过滤器(使用mina提供的文本换行符编解码器)
acceptor.getFilterChain().addLast(
"codec", new ProtocolCodecFilter(
new TextLineCodecFactory(
Charset.forName("UTF-8"),
LineDelimiter.WINDOWS.getValue(),
LineDelimiter.WINDOWS.getValue()
)
)
);
//自定义的编解码器
//acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new CharsetCodecFactory()));
//设置读取数据的换从区大小
acceptor.getSessionConfig().setReadBufferSize(2048);
//读写通道10秒内无操作进入空闲状态
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
//为接收器设置管理服务
acceptor.setHandler(new ServerHandler());
//绑定端口
acceptor.bind(new InetSocketAddress(PORT));
LogUtils.i("服务器启动成功... 端口号:"+PORT);
}catch (Exception e){
LogUtils.e("服务器异常.."+e);
}
}