本文整理汇总了Java中org.apache.mina.transport.socket.SocketSessionConfig类的典型用法代码示例。如果您正苦于以下问题:Java SocketSessionConfig类的具体用法?Java SocketSessionConfig怎么用?Java SocketSessionConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SocketSessionConfig类属于org.apache.mina.transport.socket包,在下文中一共展示了SocketSessionConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SocketServer
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
public SocketServer(int port, int threadPoolSize) {
NioSocketAcceptor acceptor = new NioSocketAcceptor();
acceptor.setHandler(new ServerHandler());
// acceptor.getFilterChain().addLast("mychian",new ProtocolCodecFilter(new TextLineCodecFactory()));
// acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(threadPoolSize)));
SocketSessionConfig ssc = acceptor.getSessionConfig();// 建立连接的配置文件
ssc.setReadBufferSize(4096);// 设置接收最大字节默认4096
ssc.setReceiveBufferSize(10240);// 设置输入缓冲区的大小
ssc.setSendBufferSize(10240);// 设置输出缓冲区的大小
ssc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
try {
// 绑定端口
acceptor.bind(new InetSocketAddress(port));
System.out.println("服务器启动正常,监听端口 " + port);
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: Channel
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的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();
}
}
示例3: main
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的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: initialize
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的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());
}
示例5: run_startup_configurations
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
public static void run_startup_configurations() {
autoPaoDian = Integer.parseInt(ServerProperties.getProperty("autoPaoDian", "1"));
port = Short.parseShort(ServerProperties.getProperty("cashshop.port", String.valueOf(DEFAULT_PORT)));
ip = ServerProperties.getProperty("world.host", ServerConstants.IP) + ":" + port;
IoBuffer.setUseDirectBuffer(false);
IoBuffer.setAllocator(new SimpleBufferAllocator());
acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
players = new PlayerStorage(MapleServerHandler.CASH_SHOP_SERVER);
try {
acceptor.setHandler(new MapleServerHandler(MapleServerHandler.CASH_SHOP_SERVER));
acceptor.bind(new InetSocketAddress(port));
((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);
FileoutputUtil.log("完成!");
FileoutputUtil.log("商城伺服器正在监听" + port + "端口\r\n");
} catch (IOException e) {
FileoutputUtil.log("失败!");
System.err.println("无法绑定" + port + "端口");
throw new RuntimeException("绑定端口失败.", e);
}
}
示例6: startListner
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
public void startListner(IoHandler iohandler,int listenPort) throws Exception{
acceptor = new NioSocketAcceptor();
acceptor.setBacklog(100);
acceptor.setReuseAddress(true);
acceptor.setHandler(iohandler);
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
IoFilter protocol = new ProtocolCodecFilter(new GameProtocolcodecFactory());
chain.addLast("codec", protocol);
threadpool = new OrderedThreadPoolExecutor(500);
threadpool.setThreadFactory(new ServerThreadFactory("OrderedThreadPool"));
chain.addLast("threadPool", new ExecutorFilter(threadpool));
int recsize = 5120;
int sendsize = 40480;
int timeout = 10;
SocketSessionConfig sc = acceptor.getSessionConfig();
sc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
sc.setReceiveBufferSize(recsize);// 设置输入缓冲区的大小
sc.setSendBufferSize(sendsize);// 设置输出缓冲区的大小
sc.setTcpNoDelay(true);// flush函数的调用 设置为非延迟发送,为true则不组装成大包发送,收到东西马上发出
sc.setSoLinger(0);
sc.setIdleTime(IdleStatus.READER_IDLE, timeout);
acceptor.bind(new InetSocketAddress(listenPort));
}
示例7: main
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new WebSocketCodecFactory()));
// close sessions when the acceptor is stopped
acceptor.setCloseOnDeactivation(true);
acceptor.setHandler(new WebSocketHandler());
SocketSessionConfig sessionConf = acceptor.getSessionConfig();
sessionConf.setReuseAddress(true);
acceptor.setReuseAddress(true);
// loop through the addresses and bind
Set<InetSocketAddress> socketAddresses = new HashSet<InetSocketAddress>();
socketAddresses.add(new InetSocketAddress("0.0.0.0", 8888));
//socketAddresses.add(new InetSocketAddress("localhost", 8888));
log.debug("Binding to {}", socketAddresses.toString());
acceptor.bind(socketAddresses);
System.out.println("WS server started listening");
listening = true;
while (true) {
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
System.out.println("WS server stopped listening");
}
}
}
示例8: sessionCreated
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
public void sessionCreated(IoSession session)
{
if (session.getConfig() instanceof SocketSessionConfig)
{
SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig();
cfg.setReceiveBufferSize(1024);
cfg.setTcpNoDelay(true);
}
session.getConfig().setIdleTime(IdleStatus.READER_IDLE, timeout);
// We're going to use SSL negotiation notification.
session.setAttribute(SslFilter.USE_NOTIFICATION);
// Initialize POP3 protocol session attributes
MinaPop3Connection conn = new MinaPop3Connection(session, userManager);
session.setAttribute(CONNECTION, conn);
session.setAttribute(USING_APOP_AUTH, usingAPOPAuthMethod);
session.setAttribute(SECURED_AUTH_REQUIRED, secureAuthRequired);
session.setAttribute(PEER_IS_CLOSING_SESSION, Boolean.FALSE);
sendGreetings(conn);
}
示例9: getSessionConfig
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
private SocketSessionConfig getSessionConfig() {
SocketSessionConfig config = new DefaultSocketSessionConfig();
config.setKeepAlive(true);
config.setReuseAddress(true);
return config;
}
示例10: createConnector
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
/**
* Create the connector
*/
private void createConnector() throws LdapException
{
// Use only one thread inside the connector
connector = new NioSocketConnector( 1 );
if ( connectionConfig != null )
{
( ( SocketSessionConfig ) connector.getSessionConfig() ).setAll( connectionConfig );
}
else
{
( ( SocketSessionConfig ) connector.getSessionConfig() ).setReuseAddress( true );
}
// Add the codec to the chain
connector.getFilterChain().addLast( "ldapCodec", ldapProtocolFilter );
// If we use SSL, we have to add the SslFilter to the chain
if ( config.isUseSsl() )
{
addSslFilter();
}
// Inject the protocolHandler
connector.setHandler( this );
}
示例11: SocketServer
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
public SocketServer(int port, MessageHandler msgHandler, int threadPoolSize) {
mServerHandler = new ServerHandler(msgHandler);
acceptor = new NioSocketAcceptor();
acceptor.setHandler(mServerHandler);// 设置接收器的处理程序
acceptor.setReuseAddress(true) ;
// acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(10)));//建立有序线程池
acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(Runtime.getRuntime().availableProcessors()+1)));//建立有序线程池
// acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(128)));//建立有序线程池
/* Executor threadPool = Executors.newFixedThreadPool(threadPoolSize);// 建立线程池
acceptor.getFilterChain().addLast("exector",
new ExecutorFilter(threadPool));*/
acceptor.getFilterChain().addLast("codec",//解码\转码
new ProtocolCodecFilter(new MessageCodecFactory(Charset.forName("UTF-8"))));
try {
// 绑定端口
acceptor.bind(new InetSocketAddress(port));
logger.info("服务器启动正常,监听端口 " + port);
} catch (IOException e) {
e.printStackTrace();
}
SocketSessionConfig ssc = acceptor.getSessionConfig();// 建立连接的配置文件
ssc.setReadBufferSize(4096);// 设置接收最大字节默认4096
// ssc.setReceiveBufferSize(1024);// 设置输入缓冲区的大小
// ssc.setSendBufferSize(1024);// 设置输出缓冲区的大小
// ssc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
ssc.setTcpNoDelay(false);
}
示例12: startGMServer
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
public static void startGMServer() {
IoBuffer.setUseDirectBuffer(false);
IoBuffer.setAllocator(new SimpleBufferAllocator());
acceptor = new NioSocketAcceptor();
acceptor.setHandler(new GMServerHandler());
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new GMCodecFactory()));
((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);
try {
acceptor.bind(new InetSocketAddress(5252));
System.out.println("\r\nGM Server online : Listening on port 5252.");
} catch (Exception e) {
System.out.println("Failed binding the GM Server to port : 5252");
}
for (World w : Server.getInstance().getWorlds()) {//For when
for (Channel c : w.getChannels()) {
for (MapleCharacter chr : c.getPlayerStorage().getAllCharacters()) {
if (chr.isGM()) {
inGame.put(chr.getName(), chr.getClient().getSession());
}
}
}
}
started = true;
}
示例13: initConnector
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
private void initConnector(InetSocketAddress isa, TransportConfig config) {
// create connector
ioConnector = new NioSocketConnector(1);
ioConnector.setConnectTimeoutMillis(config.getConnectTimeout());
SocketSessionConfig sessionConfig = ioConnector.getSessionConfig();
sessionConfig.setTcpNoDelay(true);
sessionConfig.setReceiveBufferSize(8 * 1024);
sessionConfig.setSendBufferSize(8 * 1024);
DefaultIoFilterChainBuilder chainBuilder = ioConnector.getFilterChain();
final TransportProtocolEncoder encoder = new TransportProtocolEncoder();
final TransportProtocolDecoder decoder = new TransportProtocolDecoder();
encoder.setMaxObjectSize(config.getMaxSize());
decoder.setMaxObjectSize(config.getMaxSize());
// add filter
chainBuilder.addLast("codec", new ProtocolCodecFilter(encoder, decoder));
// add keep alive filter
ActiveKeepAliveMessageFactory messageFactory = new ActiveKeepAliveMessageFactory(config.getSerializeType());
KeepAliveFilter kaFilter = new KeepAliveFilter(messageFactory, IdleStatus.BOTH_IDLE);
kaFilter.setRequestInterval(config.getHeartbeatIntervalSeconds());
kaFilter.setForwardEvent(true);
chainBuilder.addLast("keepAlive", kaFilter);
// set handler
ioConnector.setHandler(new MinaIoHandler());
ioConnector.setDefaultRemoteAddress(isa);
}
示例14: main
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
public static void main(String[] args) {
NioSocketConnector connector = new NioSocketConnector();
DefaultIoFilterChainBuilder chain = connector.getFilterChain();
SocketSessionConfig config = connector.getSessionConfig();
config.setReuseAddress(true);
config.setIdleTime(IdleStatus.READER_IDLE, 20);// 读空闲 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());
connector.setHandler(new MinaMessageHandler());
connector.setConnectTimeoutMillis(15 * 1000); // 设置连接超时 ,15秒
connector.setConnectTimeoutCheckInterval(300);
// 建立连接
ConnectFuture cf = connector.connect(new InetSocketAddress("localhost", 8000));
// 等待连接创建完成
cf.awaitUninterruptibly();
Packet packet = Packet.newBuilder().setCmdId(0).setChatMsgAck(ChatMsgAck.newBuilder().setResult(123)).build();
cf.getSession().write(packet.toByteArray());
packet = Packet.newBuilder().setCmdId(1).setChatMsgAck(ChatMsgAck.newBuilder().setResult(123)).build();
cf.getSession().write(packet.toByteArray());
// 等待连接断开
cf.getSession().getCloseFuture().awaitUninterruptibly();
// 释放连接
connector.dispose();
}
示例15: start
import org.apache.mina.transport.socket.SocketSessionConfig; //导入依赖的package包/类
@Override
public void start() throws SuspendExecution, Exception {
// Acceptor
acceptor = new PooledNioSocketAcceptor(cpool);
acceptor.setBacklog(1024);
acceptor.setSessionDataStructureFactory(new PooledIoSessionDataStructureFactory(cpool));
messageFactory =
new MinaMessageFactory(
// hostAx.getActorSystem().getCustomMessageMap(),
hostAx.getActorSystem().getCMsgMap(),
localInfo.getMinaMsgPoolSize(),
localInfo.getMinaMsgPoolInitSize(),
localInfo.getMinaMsgPoolMaxSize()
);
acceptor.getFilterChain().addLast("codec", new PooledProtocolCodecFilter(cpool, new MinaCodecFactory(messageFactory)));
// Handler
acceptor.setHandler(new MinaIoHandler(hostAx));
// Config
acceptor.setReuseAddress(true);
SocketSessionConfig sscfg = acceptor.getSessionConfig();
sscfg.setReadBufferSize(2048);
sscfg.setMinReadBufferSize(2048);
sscfg.setMaxReadBufferSize(2048);
sscfg.setIdleTime(IdleStatus.READER_IDLE, localInfo.getMinaIdleTime());
sscfg.setReceiveBufferSize(64 * 1024);
sscfg.setSendBufferSize(160 * 1024);
sscfg.setWriteTimeout(2);
sscfg.setTcpNoDelay(true);
sscfg.setSoLinger(-1);
sscfg.setKeepAlive(false);
// Bind
List<SocketAddress> socketAddresses = new ArrayList<SocketAddress>();
socketAddresses.add(new InetSocketAddress(localInfo.getHost(), localInfo.getPort()));
acceptor.bind(socketAddresses);
}