threads = Collections.synchronizedList(new ArrayList(maxSessions)); if (tps != null) tps.stop(); tps = new TPS (cfg.getBoolean ("auto-update-tps", true)); for (int i=0; i<sessions; i++) {
@Override public void stopService () { NameRegistrar.unregister(getName()); if (loadMonitorExecutor != null) loadMonitorExecutor.shutdown(); Thread[] tt = threads.toArray(new Thread[threads.size()]); if (iisp != isp) for (Object o=iisp.inp(queue); o != null; o=iisp.inp(queue)) isp.out(queue, o); // push back to replicated space for (Thread t : tt) iisp.out(queue, Boolean.FALSE, 60 * 1000); for (Thread thread : tt) { try { thread.join (60*1000); threads.remove(thread); } catch (InterruptedException e) { getLog().warn ("Session " + thread.getName() +" does not respond - attempting to interrupt"); thread.interrupt(); } } tps.stop(); for (Destroyable destroyable : destroyables) { try { destroyable.destroy(); } catch (Throwable t) { getLog().warn (t); } } } public void queue (Serializable context) {
public void test1000TPSAutoUpdate() throws Exception { TPS tps = new TPS(true); for (int i=0; i<1000; i++) tps.tick(); Thread.sleep (1050L); // java.util.Timer is not accurate assertEquals("Expected 1000 TPS", 1000, tps.intValue()); assertEquals("Still expecting 1000 TPS on a second call", 1000, tps.intValue()); Thread.sleep (1000L); assertTrue ("Average should be aprox 0.5 but it's " + tps.getAvg(), tps.getAvg() >= 0.5); assertEquals( "TPS should be zero but it's "+tps.intValue() + " (" + tps.floatValue() + ")", 0, tps.intValue() ); assertEquals ("Peak has to be 1000", 1000, tps.getPeak()); tps.stop(); } public void test1000TPSManualUpdate() throws Exception {