本文整理汇总了Java中org.apache.mina.transport.socket.nio.NioProcessor类的典型用法代码示例。如果您正苦于以下问题:Java NioProcessor类的具体用法?Java NioProcessor怎么用?Java NioProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NioProcessor类属于org.apache.mina.transport.socket.nio包,在下文中一共展示了NioProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SlaveHost
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
/**
* Create a new slave host and bind to a single TCP port
*
* @param options
* optional protocol options
* @param port
* the TCP port to bind to
*/
public SlaveHost ( final ProtocolOptions options, final int port ) throws IOException
{
this.options = makeOptions ( options );
this.connector = null;
this.processor = new SimpleIoProcessorPool<> ( NioProcessor.class );
final SocketAcceptor nioAcceptor = new NioSocketAcceptor ( this.processor );
this.acceptor = nioAcceptor;
nioAcceptor.setReuseAddress ( true );
nioAcceptor.setBacklog ( 5 );
this.disposeAcceptor = true;
setupAcceptor ( null );
this.acceptor.bind ( new InetSocketAddress ( port ) );
}
示例2: start
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
@Override
public void start ( final BundleContext context ) throws Exception
{
Activator.instance = this;
if ( !Boolean.getBoolean ( "org.eclipse.scada.core.client.ngp.disableSharedProcessor" ) )
{
this.processor = new SimpleIoProcessorPool<> ( NioProcessor.class );
}
this.factory = new DriverFactoryImpl ( this.processor );
final Dictionary<String, String> properties = new Hashtable<String, String> ();
properties.put ( org.eclipse.scada.core.client.DriverFactory.INTERFACE_NAME, "ca" );
properties.put ( org.eclipse.scada.core.client.DriverFactory.DRIVER_NAME, "ngp" );
properties.put ( Constants.SERVICE_DESCRIPTION, "Eclipse SCADA CA NGP Adapter" );
properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
this.handle = context.registerService ( org.eclipse.scada.core.client.DriverFactory.class, this.factory, properties );
}
示例3: start
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
@Override
public void start ( final BundleContext context ) throws Exception
{
Activator.instance = this;
if ( !Boolean.getBoolean ( "org.eclipse.scada.core.client.ngp.disableSharedProcessor" ) )
{
this.processor = new SimpleIoProcessorPool<> ( NioProcessor.class );
}
this.factory = new DriverFactoryImpl ( this.processor );
final Dictionary<String, String> properties = new Hashtable<String, String> ();
properties.put ( org.eclipse.scada.core.client.DriverFactory.INTERFACE_NAME, "hd" );
properties.put ( org.eclipse.scada.core.client.DriverFactory.DRIVER_NAME, "ngp" );
properties.put ( Constants.SERVICE_DESCRIPTION, "Eclipse SCADA HD NGP Adapter" );
properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
this.handle = context.registerService ( org.eclipse.scada.core.client.DriverFactory.class, this.factory, properties );
}
示例4: create
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
public static ModbusMaster create ( final BundleContext context, final ScheduledExecutorService executor, final String id, final NioProcessor processor, final Map<String, String> parameters ) throws Exception
{
final ModbusMaster device = new ModbusMaster ( context, id, executor, processor, "ModbusMaster", "modbus" );
try
{
device.configure ( parameters );
}
catch ( final Exception e )
{
// dispose what was already created
device.dispose ();
throw e;
}
return device;
}
示例5: start
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
@Override
public void start ( final BundleContext context ) throws Exception
{
Activator.instance = this;
if ( !Boolean.getBoolean ( "org.eclipse.scada.core.client.ngp.disableSharedProcessor" ) )
{
this.processor = new SimpleIoProcessorPool<> ( NioProcessor.class );
}
this.factory = new DriverFactoryImpl ( this.processor );
final Dictionary<String, String> properties = new Hashtable<String, String> ();
properties.put ( org.eclipse.scada.core.client.DriverFactory.INTERFACE_NAME, "da" );
properties.put ( org.eclipse.scada.core.client.DriverFactory.DRIVER_NAME, "ngp" );
properties.put ( Constants.SERVICE_DESCRIPTION, "Eclipse SCADA DA NGP Adapter" );
properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
this.handle = context.registerService ( org.eclipse.scada.core.client.DriverFactory.class, this.factory, properties );
}
示例6: start
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
@Override
public void start ( final BundleContext context ) throws Exception
{
Activator.instance = this;
if ( !Boolean.getBoolean ( "org.eclipse.scada.core.client.ngp.disableSharedProcessor" ) )
{
this.processor = new SimpleIoProcessorPool<> ( NioProcessor.class );
}
this.factory = new DriverFactoryImpl ( this.processor );
final Dictionary<String, String> properties = new Hashtable<String, String> ();
properties.put ( org.eclipse.scada.core.client.DriverFactory.INTERFACE_NAME, "ae" );
properties.put ( org.eclipse.scada.core.client.DriverFactory.DRIVER_NAME, "ngp" );
properties.put ( Constants.SERVICE_DESCRIPTION, "Eclipse SCADA AE NGP Adapter" );
properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
this.handle = context.registerService ( org.eclipse.scada.core.client.DriverFactory.class, this.factory, properties );
}
示例7: start
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的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;
}
}
示例8: run
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的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());
}
}
示例9: SimpleIoProcessorPool
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
/**
* Creates a new instance of SimpleIoProcessorPool with a defined number of IoProcessors in the pool
*
* @param size The number of IoProcessor in the pool
*/
public SimpleIoProcessorPool(int size) {
if (size <= 0) {
throw new IllegalArgumentException("size: " + size + " (expected: positive integer)");
}
executor = Executors.newFixedThreadPool(size,
r -> new Thread(r, NioProcessor.class.getSimpleName() + '-' + idGenerator.incrementAndGet()));
pool = new NioProcessor[size];
boolean success = false;
try {
for (int i = 0; i < pool.length; i++) {
pool[i] = new NioProcessor(executor);
}
success = true;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (!success) {
dispose();
}
}
}
示例10: getProcessor
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的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;
}
示例11: ExporterFactoryImpl
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
public ExporterFactoryImpl ()
{
super ( FrameworkUtil.getBundle ( ExporterFactoryImpl.class ).getBundleContext () );
this.executor = new ScheduledExportedExecutorService ( FrameworkUtil.getBundle ( ExporterFactoryImpl.class ).getSymbolicName (), 1 );
this.processor = new SimpleIoProcessorPool<> ( NioProcessor.class );
this.hiveSource = new ServiceListenerHiveSource ( FrameworkUtil.getBundle ( ExporterFactoryImpl.class ).getBundleContext (), this.executor );
this.hiveSource.open ();
this.itemPool = new ObjectPoolImpl<> ();
this.itemPoolHandler = ObjectPoolHelper.registerObjectPool ( FrameworkUtil.getBundle ( ExporterFactoryImpl.class ).getBundleContext (), this.itemPool, DataItem.class );
}
示例12: AbstractConnectionDevice
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
public AbstractConnectionDevice ( final BundleContext context, final String id, final NioProcessor processor, final ScheduledExecutorService executor, final String itemPrefix )
{
this.id = id;
this.processor = processor;
this.context = context;
this.itemPrefix = itemPrefix;
this.executor = executor;
this.itemFactory = new DataItemFactory ( context, executor, getItemId ( null ) );
this.stateItem = this.itemFactory.createInput ( "state", Collections.<String, Variant> emptyMap () );
this.connectionItem = this.itemFactory.createInput ( "connection", Collections.<String, Variant> emptyMap () );
}
示例13: start
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的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)));
}
示例14: initializeAndBindPlatypusAcceptor
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
private void initializeAndBindPlatypusAcceptor(InetSocketAddress s) throws IOException, Exception {
//final SslFilter sslFilter = new SslFilter(sslContext); commented out until MINA Sslfilter bugs will be fixed
ThreadPoolExecutor connectionsPollerExecutor = new ThreadPoolExecutor(1, 1,
3L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(),
new PlatypusThreadFactory("nio-polling-", false));
final IoAcceptor acceptor = new NioSocketAcceptor(connectionsPollerExecutor, new NioProcessor(executor));
//acceptor.getFilterChain().addLast("encryption", sslFilter); commented out until MINA Sslfilter bugs will be fixed
acceptor.getFilterChain().addLast("platypusCodec", new ProtocolCodecFilter(new ResponseEncoder(), new RequestDecoder()));
/*
acceptor.getFilterChain().addLast("executor", new ExecutorFilter(executor, IoEventType.EXCEPTION_CAUGHT,
IoEventType.MESSAGE_RECEIVED, IoEventType.MESSAGE_SENT, IoEventType.SESSION_CLOSED, IoEventType.SESSION_IDLE, IoEventType.CLOSE, IoEventType.WRITE));
*/
PlatypusRequestsHandler handler = new PlatypusRequestsHandler(this);
acceptor.setHandler(handler);
Integer sessionIdleTime = portsSessionIdleTimeouts != null ? portsSessionIdleTimeouts.get(s.getPort()) : null;
if (sessionIdleTime == null || sessionIdleTime == 0) {
sessionIdleTime = PlatypusRequestsHandler.SESSION_TIME_OUT;
}
Integer sessionIdleCheckInterval = portsSessionIdleCheckIntervals != null ? portsSessionIdleCheckIntervals.get(s.getPort()) : null;
if (sessionIdleCheckInterval == null || sessionIdleCheckInterval == 0) {
sessionIdleCheckInterval = PlatypusRequestsHandler.IDLE_TIME_EVENT;
}
handler.setSessionIdleCheckInterval(sessionIdleCheckInterval);
handler.setSessionIdleTime(sessionIdleTime);
acceptor.bind(s);
Logger.getLogger(ServerMain.class.getName()).log(Level.INFO, "Listening platypus protocol on {0}", s.toString());
}
示例15: dispose
import org.apache.mina.transport.socket.nio.NioProcessor; //导入依赖的package包/类
@Override
public final void dispose() {
if (disposing) {
return;
}
synchronized (pool) {
if (disposing) {
return;
}
disposing = true;
for (NioProcessor ioProcessor : pool) {
if (ioProcessor == null) {
// Special case if the pool has not been initialized properly
continue;
}
if (ioProcessor.isDisposing()) {
continue;
}
ioProcessor.dispose();
}
executor.shutdown();
Arrays.fill(pool, null);
disposed = true;
}
}