org.apache.mina.core.service.IoProcessor Java Examples

The following examples show how to use org.apache.mina.core.service.IoProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NioSocketAcceptor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected NioSession accept(IoProcessor<NioSession> processor, ServerSocketChannel handle) throws Exception {

    SelectionKey key = handle.keyFor(selector);

    if ((key == null) || (!key.isValid()) || (!key.isAcceptable())) {
        return null;
    }

    // accept the connection from the client
    SocketChannel ch = handle.accept();

    if (ch == null) {
        return null;
    }

    return new NioSocketSession(this, processor, ch);
}
 
Example #2
Source File: ModbusExport.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #3
Source File: DefaultIoFuture.java    From jane with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check for a deadlock, ie look into the stack trace that we don't have already an instance of the caller.
 */
private void checkDeadLock() {
	// Only read / write / connect / write future can cause dead lock.
	if (!(this instanceof CloseFuture || this instanceof WriteFuture || this instanceof ConnectFuture))
		return;

	// Get the current thread stackTrace.
	// Using Thread.currentThread().getStackTrace() is the best solution,
	// even if slightly less efficient than doing a new Exception().getStackTrace(),
	// as internally, it does exactly the same thing. The advantage of using
	// this solution is that we may benefit some improvement with some future versions of Java.
	StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

	// Simple and quick check.
	for (StackTraceElement stackElement : stackTrace) {
		if (NioProcessor.class.getName().equals(stackElement.getClassName())) {
			// new IllegalStateException("t").getStackTrace();
			throw new IllegalStateException("DEAD LOCK: " + IoFuture.class.getSimpleName()
					+ ".await() was invoked from an I/O processor thread. Please use "
					+ IoFutureListener.class.getSimpleName() + " or configure a proper thread model alternatively");
		}
	}

	// And then more precisely.
	for (StackTraceElement s : stackTrace) {
		try {
			Class<?> cls = DefaultIoFuture.class.getClassLoader().loadClass(s.getClassName());

			if (IoProcessor.class.isAssignableFrom(cls)) {
				throw new IllegalStateException("DEAD LOCK: " + IoFuture.class.getSimpleName()
						+ ".await() was invoked from an I/O processor thread. Please use "
						+ IoFutureListener.class.getSimpleName() + " or configure a proper thread model alternatively");
			}
		} catch (ClassNotFoundException e) {
		}
	}
}
 
Example #4
Source File: StaticModbusExport.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: NioDatagramSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new acceptor-side session instance.
 */
NioDatagramSession(IoService service, DatagramChannel channel, IoProcessor<NioSession> processor,
        SocketAddress remoteAddress) {
    super(processor, service, channel);
    config = new NioDatagramSessionConfig(channel);
    config.setAll(service.getSessionConfig());
    this.remoteAddress = (InetSocketAddress) remoteAddress;
    this.localAddress = (InetSocketAddress) channel.socket().getLocalSocketAddress();
}
 
Example #6
Source File: ConnectionBaseImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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 ();
}
 
Example #7
Source File: ClientBaseConnection.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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)" );
}
 
Example #8
Source File: MulticastSocketSession.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
/**
    * Creates a new acceptor-side session instance.
    */
MulticastSocketSession(IoService service,
				MulticastSocket socket, IoProcessor<MulticastSocketSession> processor,
                       SocketAddress remoteAddress) 
   {
	super(service);
	
       this.service = service;
       this.socket = socket;
       this.config = new MulticastDatagramSessionConfig(socket);
       this.handler = service.getHandler();
       this.processor = processor;
       this.remoteAddress = (InetSocketAddress) remoteAddress;
       this.localAddress = (InetSocketAddress) socket.getLocalSocketAddress();
   }
 
Example #9
Source File: DriverInformation.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public DriverInformation ( final IoProcessor<NioSession> processor )
{
    this.processor = processor;
}
 
Example #10
Source File: DriverFactoryImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public DriverFactoryImpl ( final IoProcessor<NioSession> processor )
{
    this.processor = processor;
}
 
Example #11
Source File: DriverFactoryImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public DriverFactoryImpl ( final IoProcessor<NioSession> processor )
{
    this.processor = processor;
}
 
Example #12
Source File: DriverInformationImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public DriverInformationImpl ( final IoProcessor<NioSession> processor )
{
    this.processor = processor;
}
 
Example #13
Source File: DriverInformationImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public DriverInformationImpl ( final IoProcessor<NioSession> processor )
{
    this.processor = processor;
}
 
Example #14
Source File: DriverFactoryImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public DriverFactoryImpl ( final IoProcessor<NioSession> processor )
{
    this.processor = processor;
}
 
Example #15
Source File: DriverFactoryImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public DriverFactoryImpl ( final IoProcessor<NioSession> processor )
{
    this.processor = processor;
}
 
Example #16
Source File: DriverInformationImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public DriverInformationImpl ( final IoProcessor<NioSession> processor )
{
    this.processor = processor;
}
 
Example #17
Source File: ModbusExportImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
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 );
}
 
Example #18
Source File: ModbusExport.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public ModbusExport ( final String id, final ScheduledExecutorService executor, final IoProcessor<NioSession> processor, final HiveSource hiveSource, final ManageableObjectPool<DataItem> itemObjectPool )
{
    this ( executor, processor, hiveSource, new ObjectPoolDataItemFactory ( executor, itemObjectPool, String.format ( "org.eclipse.scada.da.server.exporter.modbus.export.%s.information.", id ) ), "ModbusExporter/" + id ); //$NON-NLS-1$
}
 
Example #19
Source File: NioSession.java    From jane with GNU Lesser General Public License v3.0 4 votes vote down vote up
public IoProcessor<NioSession> getProcessor() {
	return service.getProcessor();
}
 
Example #20
Source File: MulticastSocketSession.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
/**
    * Creates a new connector-side session instance.
    */
MulticastSocketSession(IoService service,
                       MulticastSocket socket, IoProcessor<MulticastSocketSession> processor) {
       this(service, socket, processor, socket.getRemoteSocketAddress());
   }
 
Example #21
Source File: StaticModbusExport.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 );
    }
}
 
Example #22
Source File: DummySession.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final IoProcessor<AbstractIoSession> getProcessor() {
    return processor;
}
 
Example #23
Source File: NioSession.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public IoProcessor<NioSession> getProcessor() {
    return processor;
}
 
Example #24
Source File: WrapperNioSocketConnector.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public IoProcessor<NioSession> getIoProcessor() {
	return ioProcessor;
}
 
Example #25
Source File: MulticastSocketSession.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public IoProcessor<MulticastSocketSession> getProcessor() {
    return processor;
}
 
Example #26
Source File: NioSocketConnector.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected NioSession newSession(IoProcessor<NioSession> processor, SocketChannel handle) {
    return new NioSocketSession(this, processor, handle);
}
 
Example #27
Source File: NioDatagramConnector.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new instance.
 */
public NioDatagramConnector(IoProcessor<NioSession> processor) {
    super(new DefaultDatagramSessionConfig(), processor);
}
 
Example #28
Source File: NioDatagramConnector.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected NioSession newSession(IoProcessor<NioSession> processor, DatagramChannel handle) {
    NioSession session = new NioDatagramSession(this, handle, processor);
    session.getConfig().setAll(getSessionConfig());
    return session;
}
 
Example #29
Source File: NioDatagramSession.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new connector-side session instance.
 */
NioDatagramSession(IoService service, DatagramChannel channel, IoProcessor<NioSession> processor) {
    this(service, channel, processor, channel.socket().getRemoteSocketAddress());
}
 
Example #30
Source File: VmPipeSession.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IoProcessor<VmPipeSession> getProcessor() {
    return filterChain.getProcessor();
}