@Override public void start ( final BundleContext context ) throws Exception { this.executor = ScheduledExportedExecutorService.newSingleThreadExportedScheduledExecutor ( "org.eclipse.scada.da.server.osgi.modbus" ); this.nioExecutor = ExportedExecutorService.newSingleThreadExportedExecutor ( "org.eclipse.scada.da.server.osgi.modbus.NioProcessor" ); this.processor = new NioProcessor ( this.nioExecutor ); this.masterFactory = new MasterFactory ( context, this.executor, this.processor ); this.slaveFactory = new SlaveFactory ( context, this.masterFactory, this.executor ); { final Dictionary<String, Object> properties = new Hashtable<> (); properties.put ( Constants.SERVICE_DESCRIPTION, "Modbus master device factory" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, "org.eclipse.scada.da.server.osgi.modbus.masterDevice" ); this.masterFactoryHandle = context.registerService ( ConfigurationFactory.class, this.masterFactory, properties ); } { final Dictionary<String, Object> properties = new Hashtable<> (); properties.put ( Constants.SERVICE_DESCRIPTION, "Modbus slave device factory" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, "org.eclipse.scada.da.server.osgi.modbus.slaveDevice" ); this.slaveFactoryHandle = context.registerService ( ConfigurationFactory.class, this.slaveFactory, properties ); } }
@Override public void stop ( final BundleContext context ) throws Exception { this.masterFactoryHandle.unregister (); this.masterFactory.dispose (); this.slaveFactoryHandle.unregister (); this.slaveFactory.dispose (); this.processor.dispose (); this.executor.shutdown (); this.nioExecutor.shutdown (); }
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()); }
new PlatypusThreadFactory("polling-", false)); ioProcessorExecutor.allowCoreThreadTimeOut(true); NioSocketConnector lconnector = new NioSocketConnector(aProcessor, new NioProcessor(ioProcessorExecutor)); lconnector.setDefaultRemoteAddress(new InetSocketAddress(host, port));