当前位置: 首页>>代码示例>>Java>>正文


Java TextLineCodecFactory类代码示例

本文整理汇总了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));
	}
 
开发者ID:handexing,项目名称:frameworkAggregate,代码行数:17,代码来源:MinaTimeServer.java

示例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));
}
 
开发者ID:subaochen,项目名称:java-tutorial,代码行数:17,代码来源:MinaTimeServer.java

示例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);
	}
}
 
开发者ID:East196,项目名称:maker,代码行数:24,代码来源:BeatServer.java

示例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());
}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:24,代码来源:PostfixTcpTableService.java

示例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();
}
 
开发者ID:phat-trien-phan-mem-phan-tan,项目名称:dynamicpool,代码行数:19,代码来源:NIOSocketServerController.java

示例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);
  }
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:23,代码来源:MailsterPop3Service.java

示例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);
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:16,代码来源:MinaCubeClient.java

示例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());
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:11,代码来源:CubeClientTest.java

示例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();
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:15,代码来源:MinaTimeClient.java

示例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();// 启动监听
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:13,代码来源:MinaTimeServer.java

示例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);
	}
}
 
开发者ID:DTStack,项目名称:jlogstash-input-plugin,代码行数:32,代码来源:Tcp.java

示例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;
}
 
开发者ID:EthanCo,项目名称:Halo-Turbo,代码行数:8,代码来源:MinaUtil.java

示例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);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:ReverserServer.java

示例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));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:Mina2ReverserServer.java

示例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);
        }
    }
 
开发者ID:384401056,项目名称:itheima,代码行数:38,代码来源:MinaService.java


注:本文中的org.apache.mina.filter.codec.textline.TextLineCodecFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。