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


Java LoggingFilter类代码示例

本文整理汇总了Java中org.apache.mina.filter.logging.LoggingFilter的典型用法代码示例。如果您正苦于以下问题:Java LoggingFilter类的具体用法?Java LoggingFilter怎么用?Java LoggingFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LoggingFilter类属于org.apache.mina.filter.logging包,在下文中一共展示了LoggingFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的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: start

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
public synchronized void start ()
{
    if ( this.started )
    {
        return;
    }

    this.started = true;

    this.executorService = ScheduledExportedExecutorService.newSingleThreadExportedScheduledExecutor ( "ArduninoDevice/" + this.address );

    this.connector = new NioDatagramConnector ();

    this.connector.setHandler ( this );
    if ( this.activateLogger )
    {
        this.connector.getFilterChain ().addLast ( "logger", new LoggingFilter ( this.getClass ().getName () ) );
    }

    final ArduinoCodec codec = new ArduinoCodec ();
    this.connector.getFilterChain ().addLast ( "codec", new ProtocolCodecFilter ( codec, codec ) );

    this.connector.connect ( this.address );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:ArduinoDevice.java

示例3: configureConnector

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
@Override
protected void configureConnector ( final NioSocketConnector connector )
{
    logger.debug ( "Configuring connector: {}", connector );

    switch ( this.protocolType )
    {
        case TYPE_TCP:
            connector.getFilterChain ().addLast ( "modbusPdu", new ProtocolCodecFilter ( new ModbusTcpEncoder (), new ModbusTcpDecoder () ) );
            connector.getFilterChain ().addLast ( "modbus", new ModbusMasterProtocolFilter () );
            break;
        case TYPE_RTU:
            // convert milliseconds to microseconds to allow more accurate timing
            final ModbusRtuDecoder rtuDecoder = new ModbusRtuDecoder ( getExecutor (), Double.valueOf ( this.interFrameDelay * 1000 ).longValue (), TimeUnit.MICROSECONDS );
            connector.getFilterChain ().addLast ( "modbusPdu", new ModbusRtuProtocolCodecFilter ( new ModbusRtuEncoder (), rtuDecoder ) );
            connector.getFilterChain ().addLast ( "modbus", new ModbusMasterProtocolFilter () );
            break;
        default:
            throw new IllegalArgumentException ( String.format ( "'%s' is not an allowed modbus device type", this.protocolType ) );
    }

    if ( Boolean.getBoolean ( "org.eclipse.scada.da.server.osgi.modbus.trace" ) )
    {
        connector.getFilterChain ().addFirst ( "logger", new LoggingFilter ( ModbusMaster.class.getName () + ".protocol" ) );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:ModbusMaster.java

示例4: startServer

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
void startServer(final NetworkInterface networkInterface, List<DiscoveredCube> cubes) throws Exception {
    if (networkInterface == null) {
        throw new IllegalArgumentException("Network interface may not be null");
    }

    acceptor.getFilterChain().addLast("logging", new LoggingFilter());
    acceptor.setHandler(new DiscoveryServerHandler(cubes));
    acceptor.getSessionConfig().setReuseAddress(true);
    acceptor.setCloseOnDeactivation(true);
    Optional<InetAddress> ipv4Address = Collections.list(networkInterface.getInetAddresses()).stream()
            .filter(addr -> addr instanceof Inet4Address).findFirst();
    if (!ipv4Address.isPresent()) {
        throw new IllegalStateException("No ipv4 address found for interface: " + networkInterface.getName());
    }
    acceptor.bind(new InetSocketAddress(ipv4Address.get(), port));
    logger.debug("MinaDiscoveryClient bound to [{}]", acceptor.getLocalAddress());
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:18,代码来源:MinaDiscoveryClient.java

示例5: main

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的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

示例6: main

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
        IoAcceptor acceptor = new NioSocketAcceptor();
//        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, IDELTIMEOUT);

        acceptor.getFilterChain().addLast("logger", new LoggingFilter());
        acceptor.getFilterChain().addLast("myfliter", new MyFilter());
        acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new CommandCodecFactory("UTF-8")));

        KeepAliveMessageFactoryImpl kamfi = new KeepAliveMessageFactoryImpl();
        KeepAliveFilter kaf = new KeepAliveFilter(kamfi, IdleStatus.BOTH_IDLE);
        /** 是否回发 */
        kaf.setForwardEvent(true);
        acceptor.getFilterChain().addLast("heart", kaf);

        acceptor.setHandler(new CalculatorHandler());
        acceptor.bind(new InetSocketAddress(PORT));

        log.debug("socket通信服务端已启动,端口是" + PORT);
    }
 
开发者ID:Keybo1013,项目名称:mina,代码行数:20,代码来源:CalculatorServer.java

示例7: init

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
private void init(Config config) {
    address = new InetSocketAddress(config.sourcePort);
    acceptor = new NioSocketAcceptor();
    if (acceptor.getFilterChain().get(LOGGER) == null) {
        acceptor.getFilterChain().addLast(LOGGER, new LoggingFilter());
    }
    if (acceptor.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        acceptor.getFilterChain().addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    acceptor.setHandler(new MinaServerHandler());
    acceptor.getSessionConfig().setReadBufferSize(config.bufferSize);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
    acceptor.setReuseAddress(true); //避免重启时提示地址被占用
    //设置主服务监听端口的监听队列的最大值为50,如果当前已经有50个连接,新的连接将被服务器拒绝
    acceptor.setBacklog(50);

    KeepAliveFilter keepAliveFilter = MinaUtil.initServerKeepAlive(config, this);
    if (keepAliveFilter != null) {
        acceptor.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
 
开发者ID:EthanCo,项目名称:Halo-Turbo,代码行数:24,代码来源:MinaTcpServerSocket.java

示例8: init

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
private void init(Config config) {
    connector = new NioDatagramConnector();
    connector.setHandler(new MinaClientHandler());
    DefaultIoFilterChainBuilder chain = connector.getFilterChain();
    if (connector.getFilterChain().get(LOGGER) == null) {
        chain.addLast(LOGGER, new LoggingFilter());
    }
    if (connector.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        chain.addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    connector.getSessionConfig().setReadBufferSize(config.bufferSize);
    connector.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
    connector.getSessionConfig().setBroadcast(true);
    KeepAliveFilter keepAliveFilter = MinaUtil.initClientKeepAlive(config, this);
    if (keepAliveFilter != null) {
        connector.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
 
开发者ID:EthanCo,项目名称:Halo-Turbo,代码行数:21,代码来源:MinaUdpClientSocket.java

示例9: init

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
private void init(Config config) {
    address = new InetSocketAddress(config.targetIP, config.targetPort);
    connector = new NioSocketConnector();
    connector.setDefaultRemoteAddress(address);
    if (connector.getFilterChain().get(LOGGER) == null) {
        connector.getFilterChain().addLast(LOGGER, new LoggingFilter());
    }
    if (connector.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        connector.getFilterChain().addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    connector.setHandler(new MinaClientHandler());
    connector.getSessionConfig().setReadBufferSize(config.bufferSize);
    connector.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
    KeepAliveFilter keepAliveFilter = MinaUtil.initClientKeepAlive(config, this);
    if (keepAliveFilter != null) {
        connector.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
 
开发者ID:EthanCo,项目名称:Halo-Turbo,代码行数:21,代码来源:MinaTcpClientSocket.java

示例10: init

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
private void init(Config config) {
    address = new InetSocketAddress(config.sourcePort);

    acceptor = new NioDatagramAcceptor();
    acceptor.setHandler(new MinaServerHandler());
    DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
    if (acceptor.getFilterChain().get(LOGGER) == null) {
        chain.addLast(LOGGER, new LoggingFilter());
    }
    if (acceptor.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        chain.addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    DatagramSessionConfig dcfg = acceptor.getSessionConfig();
    dcfg.setReuseAddress(true);
    dcfg.setReadBufferSize(config.bufferSize);
    dcfg.setIdleTime(IdleStatus.WRITER_IDLE, 10);
    dcfg.setBroadcast(true);

    KeepAliveFilter keepAliveFilter = MinaUtil.initServerKeepAlive(config, this);
    if (keepAliveFilter != null) {
        acceptor.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
 
开发者ID:EthanCo,项目名称:Halo-Turbo,代码行数:26,代码来源:MinaUdpServerSocket.java

示例11: setupVmProtocol

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
protected void setupVmProtocol(String uri) {
    boolean minaLogger = configuration.isMinaLogger();
    List<IoFilter> filters = configuration.getFilters();

    address = new VmPipeAddress(configuration.getPort());
    connector = new VmPipeConnector();

    // connector config
    if (minaLogger) {
        connector.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, connector.getFilterChain());
    if (configuration.getSslContextParameters() != null) {
        LOG.warn("Using vm protocol"
                 + ", but an SSLContextParameters instance was provided.  SSLContextParameters is only supported on the TCP protocol.");
    }
    configureCodecFactory("Mina2Producer", connector);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:Mina2Producer.java

示例12: setupVmProtocol

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
protected void setupVmProtocol(String uri, Mina2Configuration configuration) {

        boolean minaLogger = configuration.isMinaLogger();
        List<IoFilter> filters = configuration.getFilters();

        address = new VmPipeAddress(configuration.getPort());
        acceptor = new VmPipeAcceptor();

        // acceptor connectorConfig
        configureCodecFactory("Mina2Consumer", acceptor, configuration);
        if (minaLogger) {
            acceptor.getFilterChain().addLast("logger", new LoggingFilter());
        }
        appendIoFiltersToChain(filters, acceptor.getFilterChain());
        if (configuration.getSslContextParameters() != null) {
            LOG.warn("Using vm protocol"
                     + ", but an SSLContextParameters instance was provided.  SSLContextParameters is only supported on the TCP protocol.");
        }
    }
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:Mina2Consumer.java

示例13: MinaDestination

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
public MinaDestination(String host, int port, boolean withLogging) throws Exception {
    socketAddress = new InetSocketAddress(host, port);
    connector = new NioSocketConnector(Runtime.getRuntime().availableProcessors() + 1);
    connector.setConnectTimeoutMillis(10000L);
    connectorConfig = connector.getSessionConfig();
    executor = new OrderedThreadPoolExecutor(5);

    connector.getFilterChain().addLast("threadPool", new ExecutorFilter(executor));
    if (withLogging) {
        connector.getFilterChain().addLast("logger", new LoggingFilter());
    }

    SslFilter filter = new SslFilter(SSLContext.getDefault(), true);
    filter.setUseClientMode(true);
    connector.getFilterChain().addFirst("sslFilter", filter);
}
 
开发者ID:oehf,项目名称:ipf-oht-atna,代码行数:17,代码来源:MinaTLSSyslogSenderImpl.java

示例14: initialize

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
public void initialize() {
	idleTime = U.getInt("chat.server.idleTime");
	System.out.println(idleTime);

	clientAcceptor = new NioSocketAcceptor();
	clientAcceptor.setReuseAddress(true);

	DefaultIoFilterChainBuilder chain = clientAcceptor.getFilterChain();
	SocketSessionConfig config = clientAcceptor.getSessionConfig();
	config.setReuseAddress(true);
	config.setIdleTime(IdleStatus.READER_IDLE, idleTime);// 读空闲 20秒
	config.setReadBufferSize(4096);// 默认2048
	config.setKeepAlive(true);
	config.setTcpNoDelay(true);// 禁用/开启nagle算法
	// 编解码
	chain.addLast("coder", new ProtocolCodecFilter(new MessageCodecFactory()));
	// 日志
	chain.addLast("logger", new LoggingFilter());
	// 业务逻辑处理线程池
	chain.addLast("threadPool", new ExecutorFilter());
}
 
开发者ID:East196,项目名称:maker,代码行数:22,代码来源:TcpServer.java

示例15: Work

import org.apache.mina.filter.logging.LoggingFilter; //导入依赖的package包/类
public Work(){
			NioSocketConnector connector = new NioSocketConnector(); 
			connector.getFilterChain().addLast( "logger", new LoggingFilter() ); 
			connector.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new MessageCodecFactory())); //设置编码过滤器 
			connector.setConnectTimeoutMillis(30000); 
			connector.setHandler(new ClientMessageHandler());//设置事件处理器 
			ConnectFuture cf = connector.connect( 
					new InetSocketAddress("127.0.0.1", 50000));//建立连接 
			cf.awaitUninterruptibly();//等待连接创建完成 
			ByteArray ba = new ByteArray();
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("parseId", 1);
			jsonObject.put("command", 1);
			jsonObject.put("text", "涂鸦");
			ba.writeUTF(jsonObject.toJSONString());
			cf.getSession().write(ba.toArray());
//			cf.getSession().write("涂鸦");//发送消息 
//			cf.getSession().write("quit");//发送消息 
//			cf.getSession().getCloseFuture().awaitUninterruptibly();//等待连接断开 
//			connector.dispose();
		}
 
开发者ID:mklm1525,项目名称:GameServer_demo,代码行数:22,代码来源:TestClient.java


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