protected BayeuxClient startClient(Oort oort, Map<String, Object> handshakeFields) { BayeuxClient client = new BayeuxClient(oort.getURL(), new LongPollingTransport(null, oort.getHttpClient())); client.setDebugEnabled(Boolean.getBoolean("debugTests")); client.handshake(handshakeFields); client.waitFor(5000, BayeuxClient.State.CONNECTED); clients.add(client); return client; }
/** * Creates an {@link OortService} with the given name. * * @param oort the Oort where this service lives * @param name the unique name across the cluster of this service */ protected OortService(Oort oort, String name) { this.oort = oort; this.name = name; this.forwardChannelName = "/service/oort/service/" + name; this.broadcastChannelName = "/oort/service/" + name; this.resultChannelName = forwardChannelName + "/result"; this.session = oort.getBayeuxServer().newLocalSession(name); this.logger = LoggerFactory.getLogger( getClass().getName() + "." + Oort.replacePunctuation(oort.getURL(), '_') + name); }
@Test public void testThreeComets() throws Exception { Server server1 = startServer(0); int groupPort = ((NetworkConnector) server1.getConnectors()[0]).getLocalPort(); Oort oort1 = startOort(server1); startConfigurer(oort1, groupPort); Server server2 = startServer(0); Oort oort2 = startOort(server2); final OortMulticastConfigurer configurer2 = startConfigurer(oort2, groupPort); // Give some time to advertise Thread.sleep(1000); Assert.assertEquals(1, oort1.getKnownComets().size()); Assert.assertEquals(1, oort2.getKnownComets().size()); // Create another comet Server server3 = startServer(0); Oort oort3 = startOort(server3); startConfigurer(oort3, groupPort); // Give some time to advertise Thread.sleep(1000); Assert.assertEquals(2, oort1.getKnownComets().size()); Assert.assertEquals(2, oort2.getKnownComets().size()); Assert.assertEquals(2, oort3.getKnownComets().size()); stopConfigurer(configurer2); stopOort(oort2); stopServer(server2); // Give some time to advertise Thread.sleep(1000); Assert.assertEquals(1, oort1.getKnownComets().size()); Assert.assertEquals(oort3.getURL(), oort1.getKnownComets().iterator().next()); Assert.assertEquals(1, oort3.getKnownComets().size()); Assert.assertEquals(oort1.getURL(), oort3.getKnownComets().iterator().next()); }
protected void onForwardMessage(Map<String, Object> data, boolean broadcast) { logger.debug("Received {} action {}", broadcast ? "broadcast" : "forwarded", data); Map<String, Object> resultData = new HashMap<>(3); resultData.put(ID_FIELD, data.get(ID_FIELD)); resultData.put(OORT_URL_FIELD, getOort().getURL()); String oortURL = (String) data.get(OORT_URL_FIELD); try { Result<R> result = onForward(new Request(oort.getURL(), data.get(PARAMETER_FIELD), oortURL)); logger.debug("Forwarded action result {}", result); if (result.succeeded()) { resultData.put(RESULT_FIELD, true); resultData.put(DATA_FIELD, result.data); } else if (result.failed()) { resultData.put(RESULT_FIELD, false); resultData.put(DATA_FIELD, result.data); } else { if (broadcast) { // Ignore and therefore return logger.debug("Ignoring broadcast action result {}", result); return; } else { // Convert ignore into failure resultData.put(RESULT_FIELD, false); resultData.put(DATA_FIELD, result.data); } } } catch (Exception x) { if (broadcast) return; String failure = x.getMessage(); if (failure == null || failure.length() == 0) failure = x.getClass().getName(); resultData.put(RESULT_FIELD, false); resultData.put(DATA_FIELD, failure); } if (getOort().getURL().equals(oortURL)) { // Local case logger.debug("Returning forwarded action result {} to local {}", resultData, oortURL); onResultMessage(resultData); } else { // Remote case OortComet comet = getOort().getComet(oortURL); if (comet != null) { logger.debug("Returning forwarded action result {} to remote {}", resultData, oortURL); comet.getChannel(resultChannelName).publish(resultData); } else { // Probably the node disconnected concurrently logger.debug( "Could not return forwarded action result {} to remote {}", resultData, oortURL); } } }
public OortMulticastConfigurer(Oort oort) { this.logger = LoggerFactory.getLogger( getClass().getName() + "." + Oort.replacePunctuation(oort.getURL(), '_')); this.oort = oort; }