本文整理汇总了Java中org.apache.mina.transport.socket.nio.NioSession类的典型用法代码示例。如果您正苦于以下问题:Java NioSession类的具体用法?Java NioSession怎么用?Java NioSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NioSession类属于org.apache.mina.transport.socket.nio包,在下文中一共展示了NioSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: ModbusExport
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
/**
* Create a new modbus exporter
*
* @param executor
* the executor used for
* @param processor
* the IO processor
* @param hiveSource
* the source of the hive to export
* @param itemFactory
* an optional item factory for publishing statistics
* @param logName
* an optional name for logging
*/
public ModbusExport ( final ScheduledExecutorService executor, final IoProcessor<NioSession> processor, final HiveSource hiveSource, final ObjectPoolDataItemFactory itemFactory, final String logName )
{
this.executor = executor;
this.hiveSource = hiveSource;
this.processor = processor;
this.logName = logName != null ? logName : toString ();
if ( itemFactory != null )
{
this.exporter = new ObjectExporter ( itemFactory, true, true );
this.exporter.attachTarget ( this.info );
}
else
{
this.exporter = null;
}
}
开发者ID:eclipse,项目名称:neoscada,代码行数:32,代码来源:ModbusExport.java
示例2: start
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
protected void start() throws Exception{
buildExecutors();
IoProcessor<NioSession> processor = new SimpleIoProcessorPool<NioSession>(NioProcessor.class, ioExecutor, coreSize);
acceptor = new NioSocketAcceptor(acceptorExecutor, processor);
// acceptor.setBacklog(cfg.getBacklog());
buildFilterChain();
acceptor.setHandler(handler);
try {
List<SocketAddress> address = new ArrayList<SocketAddress>();
//可添加多个
address.add(new InetSocketAddress((String)rule.get("ip"), (Integer)rule.get("port")));
acceptor.bind(address);
} catch (IOException e) {
stop();
throw e;
}
}
开发者ID:dreajay,项目名称:jcode,代码行数:20,代码来源:TcpAcceptor.java
示例3: run
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public void run() throws Exception {
if (start) {
SimpleIoProcessorPool<NioSession> simpleIoProcessorPool = new SimpleIoProcessorPool(
NioProcessor.class, LoginServer.ExecutorService);
acceptor = new NioSocketAcceptor(LoginServer.ExecutorService,
simpleIoProcessorPool);
acceptor.getSessionConfig().setTcpNoDelay(true);
acceptor.getFilterChain().addLast("ThreadPool",
new ExecutorFilter(LoginServer.ExecutorService));
acceptor.getFilterChain().addLast("executor",
new ExecutorFilter(LoginServer.ExecutorService));
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 15);
acceptor.setHandler(new LoginGatewayHandler(this));
acceptor.bind(new InetSocketAddress(getPort()));
log.info("网关端口监听于 " + getPort());
}
}
开发者ID:316181444,项目名称:Hxms,代码行数:18,代码来源:LoginGateway.java
示例4: getProcessor
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
/**
* Find the processor associated to a session.
* If it hasn't be stored into the session's attributes, pick a new processor and stores it.
*/
private NioProcessor getProcessor(NioSession session) {
NioProcessor processor = session.getNioProcessor();
if (processor == null) {
if (disposing) {
throw new IllegalStateException(getClass().getSimpleName() + " is disposed");
}
processor = pool[(int) ((session.getId() & Long.MAX_VALUE) % pool.length)];
if (processor == null) {
throw new IllegalStateException("null processor in pool");
}
session.setNioProcessor(processor);
}
return processor;
}
开发者ID:dwing4g,项目名称:jane,代码行数:23,代码来源:SimpleIoProcessorPool.java
示例5: processHandles
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
/**
* This method will process new sessions for the Worker class.
* All keys that have had their status updates as per the Selector.selectedKeys() method will be processed here.
* Only keys that are ready to accept connections are handled here.
* <p/>
* Session objects are created by making new instances of SocketSessionImpl
* and passing the session object to the SocketIoProcessor class.
*/
private void processHandles(Set<SelectionKey> keys) throws IOException {
for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext();) {
SelectionKey key = it.next();
@SuppressWarnings("resource")
ServerSocketChannel channel = (key.isValid() && key.isAcceptable() ? (ServerSocketChannel) key.channel() : null);
it.remove();
// Associates a new created connection to a processor, and get back a session
NioSession session = accept(processor, channel);
if (session == null) {
continue;
}
initSession(session, null);
// add the session to the SocketIoProcessor
session.getProcessor().add(session);
}
}
开发者ID:dwing4g,项目名称:jane,代码行数:28,代码来源:AbstractPollingIoAcceptor.java
示例6: StaticModbusExport
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
private StaticModbusExport ( final ScheduledExecutorService executor, final IoProcessor<NioSession> processor, final HiveSource hiveSource, final ObjectPoolDataItemFactory itemFactory, final boolean disposeProcessor )
{
super ( executor, processor, hiveSource, itemFactory );
this.executor = executor;
this.processor = processor;
this.disposeProcessor = disposeProcessor;
}
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:StaticModbusExport.java
示例7: ConnectionBaseImpl
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public ConnectionBaseImpl ( final ProtocolConfigurationFactory protocolConfigurationFactory, final ConnectionInformation connectionInformation, final IoProcessor<NioSession> processor ) throws Exception
{
super ( new ProtocolIoHandlerFactory ( protocolConfigurationFactory ), new FilterChainBuilder ( true ), connectionInformation, processor );
this.responseManager = new ResponseManager ( this.statistics, this.messageSender, this.executor );
this.callbackHandlerManager = new CallbackHandlerManager ( this.statistics );
this.callbackManager = new OpenCallbacksManager ( this, this.statistics, this.executor );
this.callbackFactory = new DefaultCallbackFactory ();
}
开发者ID:eclipse,项目名称:neoscada,代码行数:9,代码来源:ConnectionBaseImpl.java
示例8: ClientBaseConnection
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
protected ClientBaseConnection ( final IoHandlerFactory handlerFactory, final IoLoggerFilterChainBuilder chainBuilder, final ConnectionInformation connectionInformation, final IoProcessor<NioSession> processor ) throws Exception
{
super ( connectionInformation );
this.stateNotifier = new StateNotifier ( this.executor, this );
this.handler = handlerFactory.create ( this );
if ( processor != null )
{
this.connector = new NioSocketConnector ( processor );
}
else
{
this.connector = new NioSocketConnector ();
}
this.chainBuilder = chainBuilder;
this.chainBuilder.setLoggerName ( ClientBaseConnection.class.getName () + ".protocol" );
this.connector.setFilterChainBuilder ( this.chainBuilder );
this.connector.setHandler ( this.handler );
this.statistics.setLabel ( STATS_CACHE_ADDRESS, "Flag if the IP address gets cached" );
this.statistics.setCurrentValue ( STATS_CACHE_ADDRESS, this.cacheAddress ? 1.0 : 0.0 );
this.statistics.setLabel ( STATS_CURRENT_STATE, "Numeric connection state" );
this.statistics.setLabel ( STATS_CONNECT_CALLS, "Calls to connect" );
this.statistics.setLabel ( STATS_DISCONNECT_CALLS, "Calls to disconnect" );
this.statistics.setLabel ( STATS_MESSAGES_SENT, "Messages sent" );
this.statistics.setLabel ( STATS_MESSAGES_RECEIVED, "Messages received" );
this.statistics.setLabel ( STATS_CREATION_TIMESTAMP, "Timestamp of creation (in seconds)" );
this.statistics.setCurrentValue ( STATS_CREATION_TIMESTAMP, Math.floor ( System.currentTimeMillis () / 1000 ) );
this.statistics.setLabel ( STATS_LAST_CONNECT_TIMESTAMP, "Timestamp of last CONNECT (in seconds)" );
this.statistics.setLabel ( STATS_LAST_BOUND_TIMESTAMP, "Timestamp of last BOUND (in seconds)" );
}
开发者ID:eclipse,项目名称:neoscada,代码行数:40,代码来源:ClientBaseConnection.java
示例9: start
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public void start() throws Exception {
buildExecutors();
IoProcessor<NioSession> processor = new SimpleIoProcessorPool<NioSession>(
NioProcessor.class, ioExecutor, coreSize);
connector = new NioSocketConnector(connectorExecutor, processor);
connector.setConnectTimeoutMillis((Integer) rule.get("timeout")); // 设置连接超时。见AbstractPollingIoConnector.processTimedOutSessions()与ConnectionRequest类
// connector.getSessionConfig().setUseReadOperation(true); //
// 亦可使用该方式实现同步发送并接收数据,这样无须设置Handler,通过session.read()获取
handler = new ShortConnectorHandler();
connector.setHandler(handler);
DefaultIoFilterChainBuilder filterChain = connector.getFilterChain();
filterChain.addLast("codec", new ProtocolCodecFilter(
ProtocolCodecFactoryFactory.getInstance(rule)));
}
开发者ID:dreajay,项目名称:jcode,代码行数:15,代码来源:TcpConnector.java
示例10: Delegator
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public Delegator(IoProcessor<NioSession> ioProcessor, CertificateManager certificateManager) {
this.ioProcessor = ioProcessor;
this.certificateManager = certificateManager;
acceptor = new NioSocketAcceptor(ioProcessor);
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new DelegatorRemoteCodecFactory()));
acceptor.setReuseAddress(true);
acceptor.setHandler(this);
}
开发者ID:Akdeniz,项目名称:mitmsocks4j,代码行数:9,代码来源:Delegator.java
示例11: initSession
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
protected final void initSession(NioSession session, IoFuture future) {
// Every property but attributeMap should be set now. Now initialize the attributeMap.
// The reason why we initialize the attributeMap at last is to make sure all session properties
// such as remoteAddress are provided to IoSessionDataStructureFactory.
session.setAttributeMap(session.getService().getSessionDataStructureFactory().getAttributeMap(session));
session.setWriteRequestQueue(session.getService().getSessionDataStructureFactory().getWriteRequestQueue(session));
if (future instanceof ConnectFuture) {
// DefaultIoFilterChain will notify the future. (We support ConnectFuture only for now).
session.setAttribute(DefaultIoFilterChain.SESSION_CREATED_FUTURE, future);
}
finishSessionInitialization0(session, future);
}
开发者ID:dwing4g,项目名称:jane,代码行数:15,代码来源:AbstractIoService.java
示例12: processConnections
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
/**
* Process the incoming connections, creating a new session for each valid connection.
*/
private int processConnections(Set<SelectionKey> keys) {
int nHandles = 0;
// Loop on each connection request
for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext();) {
@SuppressWarnings("resource")
SocketChannel channel = (SocketChannel) it.next().channel();
it.remove();
ConnectionRequest connectionRequest = getConnectionRequest(channel);
if (connectionRequest == null) {
continue;
}
boolean success = false;
try {
if (finishConnect(channel)) {
NioSession session = newSession(processor, channel);
initSession(session, connectionRequest);
// Forward the remaining process to the IoProcessor.
session.getProcessor().add(session);
nHandles++;
}
success = true;
} catch (Exception e) {
connectionRequest.setException(e);
} finally {
if (!success) {
// The connection failed, we have to cancel it.
cancelQueue.offer(connectionRequest);
}
}
}
return nHandles;
}
开发者ID:dwing4g,项目名称:jane,代码行数:39,代码来源:AbstractPollingIoConnector.java
示例13: build
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
/**
* Build a new modbus export instance based on the current builder state
* <br/>
* <em>Note:</em> The call is responsible for disposing the created
* instance using {@link ModbusExport#dispose()}.
*
* @return a newly created modbus instance
*/
public ModbusExport build ()
{
final ScheduledExecutorService executor;
if ( this.threadFactory == null )
{
executor = ScheduledExportedExecutorService.newSingleThreadExportedScheduledExecutor ( "StaticModubusExporter/" + COUNTER.incrementAndGet () );
}
else
{
executor = new ScheduledExportedExecutorService ( "StaticModubusExporter/" + COUNTER.incrementAndGet (), 1, this.threadFactory );
}
boolean disposeProcessor;
final IoProcessor<NioSession> processor;
if ( this.processor == null )
{
processor = new SimpleIoProcessorPool<> ( NioProcessor.class );
disposeProcessor = true;
}
else
{
processor = this.processor;
disposeProcessor = false;
}
final StaticModbusExport result = new StaticModbusExport ( executor, processor, this.hiveSource, null, disposeProcessor );
try
{
result.setProperties ( this.hiveProperies );
result.setReadTimeout ( this.readTimeout );
result.setSlaveId ( this.slaveId );
result.setPort ( this.port );
// we must call this after "setProperties", since this method creates the block
result.setBlockConfiguration ( this.definitions );
return result;
}
catch ( final Throwable e )
{
result.dispose ();
throw new RuntimeException ( "Failed to start exporter", e );
}
}
开发者ID:eclipse,项目名称:neoscada,代码行数:55,代码来源:StaticModbusExport.java
示例14: ModbusExportImpl
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public ModbusExportImpl ( final String id, final ScheduledExecutorService executor, final IoProcessor<NioSession> processor, final HiveSource hiveSource, final ManageableObjectPool<DataItem> itemObjectPool )
{
super ( id, executor, processor, hiveSource, itemObjectPool );
}
开发者ID:eclipse,项目名称:neoscada,代码行数:5,代码来源:ModbusExportImpl.java
示例15: DriverInformationImpl
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public DriverInformationImpl ( final IoProcessor<NioSession> processor )
{
this.processor = processor;
}
开发者ID:eclipse,项目名称:neoscada,代码行数:5,代码来源:DriverInformationImpl.java
示例16: DriverFactoryImpl
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public DriverFactoryImpl ( final IoProcessor<NioSession> processor )
{
this.processor = processor;
}
开发者ID:eclipse,项目名称:neoscada,代码行数:5,代码来源:DriverFactoryImpl.java
示例17: DriverInformation
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public DriverInformation ( final IoProcessor<NioSession> processor )
{
this.processor = processor;
}
开发者ID:eclipse,项目名称:neoscada,代码行数:5,代码来源:DriverInformation.java
示例18: SharedExecutorMinaConnector
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public SharedExecutorMinaConnector(Executor executor, IoProcessor<NioSession> ioProcessor, FactoryManager manager, IoHandler handler) {
super(manager, handler);
this.executor = executor;
this.ioProcessor = ioProcessor;
}
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:6,代码来源:SharedExecutorMinaConnector.java
示例19: SharedExecutorMinaAcceptor
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public SharedExecutorMinaAcceptor(Executor executor, IoProcessor<NioSession> ioProcessor, FactoryManager manager, IoHandler handler) {
super(manager, handler);
this.executor = executor;
this.ioProcessor = ioProcessor;
}
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:6,代码来源:SharedExecutorMinaAcceptor.java
示例20: SharedExecutorMinaServiceServiceFactory
import org.apache.mina.transport.socket.nio.NioSession; //导入依赖的package包/类
public SharedExecutorMinaServiceServiceFactory(Executor executor) {
super();
this.executor = executor;
this.ioProcessor = new SimpleIoProcessorPool<NioSession>(NioProcessor.class, executor);
}
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:7,代码来源:SharedExecutorMinaServiceServiceFactory.java
注:本文中的org.apache.mina.transport.socket.nio.NioSession类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论