/** * Start collecting stats for the {@link org.apache.mina.common.IoSession} of the service. * New sessions or destroyed will be automaticly added or removed. */ public void start() { synchronized (this) { if ( worker != null && worker.isAlive() ) throw new RuntimeException( "Stat collecting already started" ); // add all current sessions polledSessions = new ConcurrentLinkedQueue<>(); Map<Long, IoSession> sessions = service.getManagedSessions(); if (sessions != null) { for (IoSession ioSession : sessions.values()) { addSession(ioSession); } } // listen for new ones service.addListener( serviceListener ); // start polling worker = new Worker(); worker.start(); } }
@Override public Map<Long, org.apache.sshd.common.io.IoSession> getManagedSessions() { IoService ioService = getIoService(); Map<Long, IoSession> managedMap = ioService.getManagedSessions(); Map<Long, IoSession> mina = new TreeMap<>(managedMap); Map<Long, org.apache.sshd.common.io.IoSession> sessions = new TreeMap<>(Comparator.naturalOrder()); for (Long id : mina.keySet()) { // Avoid possible NPE if the MinaSession hasn't been created yet IoSession minaSession = mina.get(id); org.apache.sshd.common.io.IoSession session = getSession(minaSession); if (session != null) { sessions.put(id, session); } } return sessions; }
/** * Closes all managed sessions of an Initiator/Acceptor. * * @param ioService Acceptor or Initiator implementation * @param awaitTermination whether to wait for underlying ExecutorService to terminate * @param logger used for logging WARNING when IoSession could not be closed */ public static void closeManagedSessionsAndDispose(IoService ioService, boolean awaitTermination, Logger logger) { Map<Long, IoSession> managedSessions = ioService.getManagedSessions(); for (IoSession ioSession : managedSessions.values()) { if (!ioSession.isClosing()) { CloseFuture closeFuture = ioSession.closeNow(); boolean completed = false; try { completed = closeFuture.await(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } if (!completed) { logger.warn("Could not close IoSession {}", ioSession); } } } if (!ioService.isDisposing()) { ioService.dispose(awaitTermination); } }
/** * Closes all managed sessions of an Initiator/Acceptor. * * @param ioService Acceptor or Initiator implementation * @param awaitTermination whether to wait for underlying ExecutorService to terminate * @param logger used for logging WARNING when IoSession could not be closed */ public static void closeManagedSessionsAndDispose(IoService ioService, boolean awaitTermination, Logger logger) { Map<Long, IoSession> managedSessions = ioService.getManagedSessions(); for (IoSession ioSession : managedSessions.values()) { if (!ioSession.isClosing()) { CloseFuture closeFuture = ioSession.closeNow(); boolean completed = false; try { completed = closeFuture.await(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } if (!completed) { logger.warn("Could not close IoSession {}", ioSession); } } } if (!ioService.isDisposing()) { ioService.dispose(awaitTermination); } }
/** * Start collecting stats for the {@link org.apache.mina.common.IoSession} of the service. * New sessions or destroyed will be automaticly added or removed. */ public void start() { synchronized (this) { if ( worker != null && worker.isAlive() ) throw new RuntimeException( "Stat collecting already started" ); // add all current sessions polledSessions = new ConcurrentLinkedQueue<>(); Map<Long, IoSession> sessions = service.getManagedSessions(); if (sessions != null) { for (IoSession ioSession : sessions.values()) { addSession(ioSession); } } // listen for new ones service.addListener( serviceListener ); // start polling worker = new Worker(); worker.start(); } }
if (name.equals("findSessions")) { IoSessionFinder finder = new IoSessionFinder((String) params[0]); return finder.find(getSource().getManagedSessions().values()); Set<IoSession> registeredSessions = new LinkedHashSet<IoSession>(); for (IoSession s : finder.find(getSource().getManagedSessions().values())) { try { getServer().registerMBean( String command = (String) params[1]; Object expr = Ognl.parseExpression(command); Set<IoSession> matches = finder.find(getSource().getManagedSessions().values());
if (name.equals("findSessions")) { IoSessionFinder finder = new IoSessionFinder((String) params[0]); return finder.find(getSource().getManagedSessions().values()); IoSessionFinder finder = new IoSessionFinder((String) params[0]); Set<IoSession> registeredSessions = new LinkedHashSet<>(); for (IoSession s: finder.find(getSource().getManagedSessions().values())) { try { getServer().registerMBean( String command = (String) params[1]; Object expr = Ognl.parseExpression(command); Set<IoSession> matches = finder.find(getSource().getManagedSessions().values());