public EngineWireHandler( @NotNull final WireType byteToWire, @NotNull final AssetTree assetTree, @NotNull final Throttler throttler) { super(byteToWire); this.sessionProvider = assetTree.root().getView(SessionProvider.class); this.eventLoop = assetTree.root().findOrCreateView(EventLoop.class); assert eventLoop != null; try { this.eventLoop.start(); } catch (RejectedExecutionException e) { LOG.debug("", e); } this.hostIdentifier = assetTree.root().findOrCreateView(HostIdentifier.class); this.assetTree = assetTree; this.mapWireHandler = new MapWireHandler<>(); this.metaDataConsumer = wireInConsumer(); this.keySetHandler = new CollectionWireHandler(); this.entrySetHandler = new CollectionWireHandler(); this.valuesHandler = new CollectionWireHandler(); this.subscriptionHandler = new ObjectKVSubscriptionHandler(throttler); this.topologySubscriptionHandler = new TopologySubscriptionHandler(throttler); this.topicPublisherHandler = new TopicPublisherHandler(); this.publisherHandler = new PublisherHandler(); this.referenceHandler = new ReferenceHandler(); this.replicationHandler = new ReplicationHandler(); this.systemHandler = new SystemHandler(); }
private Map<String, UserStat> getMonitoringMap() { Map<String, UserStat> userMonitoringMap = null; Asset userAsset = assetTree.root().getAsset("proc/users"); if (userAsset != null && userAsset.getView(MapView.class) != null) { userMonitoringMap = userAsset.getView(MapView.class); } return userMonitoringMap; }
@After public void after() throws IOException { assetTree.close(); if (serverEndpoint != null) serverEndpoint.close(); serverAssetTree.close(); if (map instanceof Closeable) ((Closeable) map).close(); TCPRegistry.reset(); System.setProperty("Throttler.maxEventsPreSecond", "0"); }
@Before public void before() throws IOException { System.setProperty("Throttler.maxEventsPreSecond", "1"); serverAssetTree = new VanillaAssetTree().forTesting(); methodName(name.getMethodName()); final String hostPort = "ThrottledKeySubscriptionEventTest." + name.getMethodName() + ".host.port"; TCPRegistry.createServerSocketChannelFor(hostPort); serverEndpoint = new ServerEndpoint(hostPort, serverAssetTree, WIRE_TYPE); assetTree = new VanillaAssetTree().forRemoteAccess(hostPort, WIRE_TYPE); map = assetTree.acquireMap(NAME, String.class, String.class); }
/** * because we have set System.setProperty("Throttler.maxEventsPreSecond", "1"); in the static * above, we will only get one event per second, this test also checks that the messages still * arrive in order. * * @throws IOException * @throws InterruptedException */ @Test public void testReceivingThrottledEventsInOrder() throws IOException, InterruptedException { final BlockingQueue<String> eventsQueue = new LinkedBlockingDeque<>(); YamlLogging.showServerWrites = true; YamlLogging.showServerReads = true; yamlLoggger( () -> { try { Subscriber<String> add = eventsQueue::add; assetTree.registerSubscriber(NAME, String.class, add); for (int i = 0; i < 10; i++) { map.put("Hello" + i, "World" + i); } final long start = System.currentTimeMillis(); for (int i = 0; i < 10; i++) { String actual = eventsQueue.poll(5, SECONDS); Assert.assertNotNull(actual); Assert.assertEquals("Hello" + i, actual); } // because we are only sending 1 message per second this should take around 10 // seconds, certainly longer than 5 seconds Assert.assertTrue(System.currentTimeMillis() > start + TimeUnit.SECONDS.toMillis(5)); } catch (Exception e) { throw Jvm.rethrow(e); } }); }