當前位置: 首頁>>代碼示例>>Java>>正文


Java ProtocolCodecFilter類代碼示例

本文整理匯總了Java中org.apache.mina.filter.codec.ProtocolCodecFilter的典型用法代碼示例。如果您正苦於以下問題:Java ProtocolCodecFilter類的具體用法?Java ProtocolCodecFilter怎麽用?Java ProtocolCodecFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ProtocolCodecFilter類屬於org.apache.mina.filter.codec包,在下文中一共展示了ProtocolCodecFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的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: connect

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
public void connect() {		
	synchronized(mutex) {
		if (connected.getFlag()) return;
		if (connecting.getFlag()) return;
		log.warning("Connecting to TC at " + getHost() + ":" + getPort() + " ...");
		connecting.setFlag(true);
	}
	
	try {
		ioConnector = new NioSocketConnector();
		
		ioConnector.setHandler(this);
		
		ioConnector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
		
		connectFuture = ioConnector.connect(address);
		
		connectFuture.addListener(connectionListener);
	} catch (Exception e1) {
		try {
			connecting.setFlag(false);
		} catch (Exception e2) {				
		}
	}
	
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:27,代碼來源:TCMinaClient.java

示例3: start

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
/**
 * start Mina serversocket
 * @throws Exception
 */
public void start() throws Exception {
	IoBuffer.setUseDirectBuffer(false);
	IoBuffer.setAllocator(new SimpleBufferAllocator());

	acceptor = new NioSocketAcceptor(pool);
	acceptor.setReuseAddress(true);
	acceptor.getSessionConfig().setAll(getSessionConfig());

	int serverPort = GateServerConfig.serverPort;
	logger.info("socket server start at port:{},正在監聽客戶端的連接...", serverPort);
	DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
	filterChain.addLast("codec", new ProtocolCodecFilter(MessageCodecFactory.getInstance()));
	acceptor.setHandler( new ServerSocketIoHandler() );//指定業務邏輯處理器
	acceptor.setDefaultLocalAddress(new InetSocketAddress(serverPort) );//設置端口號
	acceptor.bind();//啟動監聽

}
 
開發者ID:kingston-csj,項目名稱:jforgame,代碼行數:22,代碼來源:SocketServer.java

示例4: start

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的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

示例5: configureConnector

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的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

示例6: Channel

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
public Channel(final int world, final int channel) {
    this.world = world;
    this.channel = channel;
    this.mapFactory = new MapleMapFactory(MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")), world, channel);

    try {
        eventSM = new EventScriptManager(this, ServerConstants.EVENTS.split(" "));
        port = 7575 + this.channel - 1;
        port += (world * 100);
        ip = ServerConstants.HOST + ":" + port;
        IoBuffer.setUseDirectBuffer(false);
        IoBuffer.setAllocator(new SimpleBufferAllocator());
        acceptor = new NioSocketAcceptor();
        TimerManager.getInstance().register(new respawnMaps(), 10000);
        acceptor.setHandler(new MapleServerHandler(world, channel));
        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
        acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new MapleCodecFactory()));
        acceptor.bind(new InetSocketAddress(port));
        ((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);

        eventSM.init();
        System.out.println("    Channel " + getId() + ": Listening on port " + port);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:27,代碼來源:Channel.java

示例7: main

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的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

示例8: run_startup_configurations

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
public static void run_startup_configurations() {
    ip = ServerConfig.IP_ADDRESS + ":" + PORT;

    ByteBuffer.setUseDirectBuffers(false);
    ByteBuffer.setAllocator(new SimpleByteBufferAllocator());

    acceptor = new SocketAcceptor();
    final SocketAcceptorConfig cfg = new SocketAcceptorConfig();
    cfg.getSessionConfig().setTcpNoDelay(true);
    cfg.setDisconnectOnUnbind(true);
    cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
    players = new PlayerStorage(-10);

    try {
        InetSocketadd = new InetSocketAddress(PORT);
        acceptor.bind(InetSocketadd, new MapleServerHandler(), cfg);
        System.out.println("Cash Shop Server is listening on port " + PORT + ".");
    } catch (final IOException e) {
        System.out.println(" Failed!");
        System.err.println("Could not bind to port " + PORT + ".");
        throw new RuntimeException("Binding failed.", e);
    }
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:24,代碼來源:CashShopServer.java

示例9: run_startup_configurations

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
public static final void run_startup_configurations() {
    userLimit = ServerConfig.USER_LIMIT;
    serverName = ServerConfig.SERVER_NAME;
    eventMessage = ServerConfig.EVENT_MSG;
    maxCharacters = ServerConfig.MAX_CHARACTERS;

    ByteBuffer.setUseDirectBuffers(false);
    ByteBuffer.setAllocator(new SimpleByteBufferAllocator());

    acceptor = new SocketAcceptor();
    final SocketAcceptorConfig cfg = new SocketAcceptorConfig();
    cfg.getSessionConfig().setTcpNoDelay(true);
    cfg.setDisconnectOnUnbind(true);
    cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));

    try {
        InetSocketadd = new InetSocketAddress(8484);
        acceptor.bind(InetSocketadd, new MapleServerHandler(), cfg);
        System.out.println("Login Server is listening on port 8484.");
    } catch (IOException e) {
        System.out.println(" Failed!");
        System.err.println("Could not bind to port 8484: " + e);
    }
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:25,代碼來源:LoginServer.java

示例10: MinaClient

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
/**
 * 初始化
 * 
 * @param ipArray
 *            ip地址數組
 * @param portArray
 *            端口數組
 * @param nameArray
 *            名稱數組
 * @throws Exception
 */
public MinaClient(String[] ipArray, int[] portArray, String[] nameArray, Class<?> HandlerClass) throws Exception {
	for (int i = 0; i < ipArray.length; i++) {
		String ip = ipArray[i];
		int port = portArray[i];
		String name = nameArray[i];
		IoConnector ioConnector = new NioSocketConnector();

		ioConnector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaEncoder(), new MinaDecoder()));
		MinaHandler minaHandler = (MinaHandler) HandlerClass.newInstance();
		minaHandler.ioConnector = ioConnector;
		minaHandler.name = name;
		ioConnector.setHandler(minaHandler);
		ioConnector.setConnectTimeoutMillis(10000);
		InetSocketAddress inetSocketAddress = new InetSocketAddress(ip, port);
		ioConnectorMap.put(ioConnector, inetSocketAddress);
		ioConnectorStateMap.put(ioConnector, false);
	}
	start();
}
 
開發者ID:dianbaer,項目名稱:grain,代碼行數:31,代碼來源:MinaClient.java

示例11: main

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的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

示例12: main

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
public static void main(String[] args) throws Exception{
	int port=9527;
	
	final IoAcceptor acceptor=new SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1,
               							   Executors.newCachedThreadPool());
	acceptor.getFilterChain().addLast("stringserialize", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
	IoHandler handler=new IoHandlerAdapter(){

		public void messageReceived(IoSession session, Object message)
				throws Exception {
			if("quit".equalsIgnoreCase(message.toString())){
				acceptor.unbindAll();
				System.out.println("Server has been shutdown!");
				System.exit(0);
			}
			System.out.println("Message from client: "+message);
			session.write("Server response��"+message);
		}
		
	};
	acceptor.bind(new InetSocketAddress(port), handler);
	System.out.println("Server listen on port: "+port);
}
 
開發者ID:java-scott,項目名稱:java-project,代碼行數:24,代碼來源:Server.java

示例13: serverStart

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
@Override
protected void serverStart() throws RemotingException {

    acceptor = new NioSocketAcceptor(); //TCP Acceptor

    // acceptor.getFilterChain().addFirst("logging", new MinaLoggingFilter());
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecFactory(getCodec())));
    acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());

    acceptor.setHandler(new MinaHandler(this));
    IoSessionConfig cfg = acceptor.getSessionConfig();
    cfg.setReaderIdleTime(remotingServerConfig.getReaderIdleTimeSeconds());
    cfg.setWriterIdleTime(remotingServerConfig.getWriterIdleTimeSeconds());
    cfg.setBothIdleTime(remotingServerConfig.getServerChannelMaxIdleTimeSeconds());

    bindAddress = new InetSocketAddress(remotingServerConfig.getListenPort());
    try {
        acceptor.bind(bindAddress);
    } catch (IOException e) {
        throw new RemotingException("Start Mina server error", e);
    }
}
 
開發者ID:WenZuHuai,項目名稱:light-task-scheduler,代碼行數:23,代碼來源:MinaRemotingServer.java

示例14: clientStart

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的package包/類
@Override
protected void clientStart() throws RemotingException {
    try {
        connector = new NioSocketConnector(); //TCP Connector

        // connector.getFilterChain().addFirst("logging", new MinaLoggingFilter());
        connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecFactory(getCodec())));
        connector.getFilterChain().addLast("mdc", new MdcInjectionFilter());

        connector.setHandler(new MinaHandler(this));
        IoSessionConfig cfg = connector.getSessionConfig();
        cfg.setReaderIdleTime(remotingClientConfig.getReaderIdleTimeSeconds());
        cfg.setWriterIdleTime(remotingClientConfig.getWriterIdleTimeSeconds());
        cfg.setBothIdleTime(remotingClientConfig.getClientChannelMaxIdleTimeSeconds());
    } catch (Exception e) {
        throw new RemotingException("Mina Client start error", e);
    }
}
 
開發者ID:WenZuHuai,項目名稱:light-task-scheduler,代碼行數:19,代碼來源:MinaRemotingClient.java

示例15: init

import org.apache.mina.filter.codec.ProtocolCodecFilter; //導入依賴的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


注:本文中的org.apache.mina.filter.codec.ProtocolCodecFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。