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

The following examples show how to use org.apache.mina.core.service.AbstractIoService. 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: MulticastSocketProcessor.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
boolean removeNow(MulticastSocketSession session) {
//FIXME
      //clearWriteRequestQueue(session);

      try {
          destroy(session);
          return true;
      } catch (Exception e) {
          IoFilterChain filterChain = session.getFilterChain();
          filterChain.fireExceptionCaught(e);
      } finally {
      	//FIXME
          //clearWriteRequestQueue(session);
          ((AbstractIoService) session.getService()).getListeners().fireSessionDestroyed(session);
      }
      return false;
  }
 
Example #2
Source File: AbstractIoSession.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * TODO Add method documentation
 */
public final void increaseWrittenBytes(int increment, long currentTime) {
    if (increment <= 0) {
        return;
    }

    writtenBytes += increment;
    lastWriteTime = currentTime;
    idleCountForBoth.set(0);
    idleCountForWrite.set(0);

    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().increaseWrittenBytes(increment, currentTime);
    }

    increaseScheduledWriteBytes(-increment);
}
 
Example #3
Source File: AbstractIoSession.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * TODO Add method documentation
 */
public final void increaseWrittenMessages(WriteRequest request, long currentTime) {
    Object message = request.getMessage();
    if (message instanceof IoBuffer) {
        IoBuffer b = (IoBuffer) message;
        if (b.hasRemaining()) {
            return;
        }
    }

    writtenMessages++;
    lastWriteTime = currentTime;
    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().increaseWrittenMessages(currentTime);
    }

    decreaseScheduledWriteMessages();
}
 
Example #4
Source File: NioProcessor.java    From jane with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void createSessions() {
	NioSession session;
	while ((session = creatingSessions.poll()) != null) {
		try {
			session.setSelectionKey(session.getChannel().configureBlocking(false).register(selector, SelectionKey.OP_READ, session));
			AbstractIoService service = session.getService();
			service.getFilterChainBuilder().buildFilterChain(session.getFilterChain());
			service.fireSessionCreated(session);
		} catch (Exception e) {
			ExceptionMonitor.getInstance().exceptionCaught(e);
			try {
				session.destroy();
			} catch (Exception e1) {
				ExceptionMonitor.getInstance().exceptionCaught(e1);
			} finally {
				session.setScheduledForRemove();
			}
		}
	}
}
 
Example #5
Source File: NioSession.java    From jane with GNU Lesser General Public License v3.0 6 votes vote down vote up
NioSession(AbstractIoService service, SocketChannel channel, ConnectFuture future) {
	this.service = service;
	this.channel = channel;
	config = new SessionConfigImpl(service);
	IoSessionDataStructureFactory factory = service.getSessionDataStructureFactory();
	attributes = factory.getAttributeMap(this);
	writeRequestQueue = factory.getWriteRequestQueue(this);
	if (future != null) {
		// DefaultIoFilterChain will notify the future. (We support ConnectFuture only for now).
		setAttribute(DefaultIoFilterChain.SESSION_CREATED_FUTURE, future);
		// In case that ConnectFuture.cancel() is invoked before setSession() is invoked,
		// add a listener that closes the connection immediately on cancellation.
		future.addListener((ConnectFuture cf) -> {
			if (cf.isCanceled())
				closeNow();
		});
	}
}
 
Example #6
Source File: MulticastSocketProcessor.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private boolean addNow(MulticastSocketSession session) {

        boolean registered = false;
        boolean notified = false;
        try {
            registered = true;

            // Build the filter chain of this session.
            session.getService().getFilterChainBuilder().buildFilterChain(
                    session.getFilterChain());

            // DefaultIoFilterChain.CONNECT_FUTURE is cleared inside here
            // in AbstractIoFilterChain.fireSessionOpened().
            ((AbstractIoService) session.getService()).getListeners().fireSessionCreated(session);
            notified = true;
            bufSize = session.getConfig().getReadBufferSize();
        } catch (Exception e) {
            if (notified)
            {
                // Clear the DefaultIoFilterChain.CONNECT_FUTURE attribute
                // and call ConnectFuture.setException().
                remove(session);
                IoFilterChain filterChain = session.getFilterChain();
                filterChain.fireExceptionCaught(e);
                wakeup();
            } else {
                ExceptionMonitor.getInstance().exceptionCaught(e);
                try {
                    destroy(session);
                } catch (Exception e1) {
                    ExceptionMonitor.getInstance().exceptionCaught(e1);
                } finally {
                    registered = false;
                }
            }
        }
        return registered;
    }
 
Example #7
Source File: AbstractIoSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO Add method documentation
 */
public final void increaseReadBytes(long increment, long currentTime) {
    if (increment <= 0) {
        return;
    }

    readBytes += increment;
    lastReadTime = currentTime;
    idleCountForBoth.set(0);
    idleCountForRead.set(0);

    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().increaseReadBytes(increment, currentTime);
    }
}
 
Example #8
Source File: AbstractIoSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO Add method documentation
 */
public final void increaseReadMessages(long currentTime) {
    readMessages++;
    lastReadTime = currentTime;
    idleCountForBoth.set(0);
    idleCountForRead.set(0);

    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().increaseReadMessages(currentTime);
    }
}
 
Example #9
Source File: AbstractIoSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO Add method documentation
 */
public final void increaseScheduledWriteBytes(int increment) {
    scheduledWriteBytes.addAndGet(increment);
    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().increaseScheduledWriteBytes(increment);
    }
}
 
Example #10
Source File: AbstractIoSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO Add method documentation
 */
public final void increaseScheduledWriteMessages() {
    scheduledWriteMessages.incrementAndGet();
    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().increaseScheduledWriteMessages();
    }
}
 
Example #11
Source File: AbstractIoSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO Add method documentation
 */
private void decreaseScheduledWriteMessages() {
    scheduledWriteMessages.decrementAndGet();
    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().decreaseScheduledWriteMessages();
    }
}
 
Example #12
Source File: AbstractPollingIoProcessor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Process a new session :
 * - initialize it
 * - create its chain
 * - fire the CREATED listeners if any
 *
 * @param session The session to create
 * @return true if the session has been registered
 */
private boolean addNow(S session) {
    boolean registered = false;

    try {
        init(session);
        registered = true;

        // Build the filter chain of this session.
        IoFilterChainBuilder chainBuilder = session.getService().getFilterChainBuilder();
        chainBuilder.buildFilterChain(session.getFilterChain());

        // DefaultIoFilterChain.CONNECT_FUTURE is cleared inside here
        // in AbstractIoFilterChain.fireSessionOpened().
        // Propagate the SESSION_CREATED event up to the chain
        IoServiceListenerSupport listeners = ((AbstractIoService) session.getService()).getListeners();
        listeners.fireSessionCreated(session);
    } catch (Throwable e) {
        ExceptionMonitor.getInstance().exceptionCaught(e);

        try {
            destroy(session);
        } catch (Exception e1) {
            ExceptionMonitor.getInstance().exceptionCaught(e1);
        } finally {
            registered = false;
        }
    }

    return registered;
}
 
Example #13
Source File: AbstractPollingIoProcessor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private boolean removeNow(S session) {
    clearWriteRequestQueue(session);

    try {
        destroy(session);
        return true;
    } catch (Exception e) {
        IoFilterChain filterChain = session.getFilterChain();
        filterChain.fireExceptionCaught(e);
    } finally {
        clearWriteRequestQueue(session);
        ((AbstractIoService) session.getService()).getListeners().fireSessionDestroyed(session);
    }
    return false;
}
 
Example #14
Source File: NioSession.java    From jane with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public AbstractIoService getService() {
	return service;
}