use of io.vertx.core.net.impl.ServerID in project vert.x by eclipse.
the class AsyncMultiMapTest method testMapAddGet.
@Test
public void testMapAddGet() {
ServerID serverID1 = new ServerID(1234, "foo.com");
map.add("some-sub", serverID1, onSuccess(res -> {
assertNull(res);
ServerID serverID2 = new ServerID(4321, "blah.com");
map.add("some-sub", serverID2, onSuccess(res2 -> {
assertNull(res2);
ServerID serverID3 = new ServerID(5432, "quux.com");
map.add("some-sub2", serverID3, onSuccess(res3 -> {
assertNull(res3);
map.get("some-sub", onSuccess(res4 -> {
Set<ServerID> set = new HashSet<>();
for (ServerID sid : res4) {
set.add(sid);
}
assertEquals(2, set.size());
assertTrue(set.contains(serverID1));
assertTrue(set.contains(serverID2));
map.get("some-sub2", onSuccess(res5 -> {
Set<ServerID> set2 = new HashSet<>();
for (ServerID sid : res5) {
set2.add(sid);
}
assertEquals(1, set2.size());
assertTrue(set2.contains(serverID3));
testComplete();
}));
}));
}));
}));
}));
await();
}
use of io.vertx.core.net.impl.ServerID in project vert.x by eclipse.
the class AsyncMultiMapTest method testMapRemove.
@Test
public void testMapRemove() {
ServerID serverID1 = new ServerID(1234, "foo.com");
map.add("some-sub", serverID1, onSuccess(res -> {
assertNull(res);
ServerID serverID2 = new ServerID(4321, "blah.com");
map.add("some-sub", serverID2, onSuccess(res2 -> {
assertNull(res2);
ServerID serverID3 = new ServerID(5432, "quux.com");
map.add("some-sub2", serverID3, onSuccess(res3 -> {
assertNull(res3);
map.get("some-sub", onSuccess(res4 -> {
Set<ServerID> set = new HashSet<>();
for (ServerID sid : res4) {
set.add(sid);
}
assertEquals(2, set.size());
assertTrue(set.contains(serverID1));
assertTrue(set.contains(serverID2));
map.get("some-sub2", onSuccess(res5 -> {
Set<ServerID> set2 = new HashSet<>();
for (ServerID sid : res5) {
set2.add(sid);
}
assertEquals(1, set2.size());
assertTrue(set2.contains(serverID3));
map.remove("some-sub2", serverID1, onSuccess(res6 -> {
assertFalse(res6);
map.remove("some-sub2", serverID3, onSuccess(res7 -> {
map.get("some-sub2", onSuccess(res8 -> {
Set<ServerID> set3 = new HashSet<>();
for (ServerID sid : res8) {
set3.add(sid);
}
assertEquals(0, set3.size());
testComplete();
}));
}));
}));
}));
}));
}));
}));
}));
await();
}
use of io.vertx.core.net.impl.ServerID in project vert.x by eclipse.
the class ClusteredEventBus method sendToSubs.
private <T> void sendToSubs(ChoosableIterable<ClusterNodeInfo> subs, SendContextImpl<T> sendContext) {
String address = sendContext.message.address();
if (sendContext.message.isSend()) {
// Choose one
ClusterNodeInfo ci = subs.choose();
ServerID sid = ci == null ? null : ci.serverID;
if (sid != null && !sid.equals(serverID)) {
//We don't send to this node
metrics.messageSent(address, false, false, true);
sendRemote(sid, sendContext.message);
} else {
metrics.messageSent(address, false, true, false);
deliverMessageLocally(sendContext);
}
} else {
// Publish
boolean local = false;
boolean remote = false;
for (ClusterNodeInfo ci : subs) {
if (!ci.serverID.equals(serverID)) {
//We don't send to this node
remote = true;
sendRemote(ci.serverID, sendContext.message);
} else {
local = true;
}
}
metrics.messageSent(address, true, local, remote);
if (local) {
deliverMessageLocally(sendContext);
}
}
}
use of io.vertx.core.net.impl.ServerID in project vert.x by eclipse.
the class ClusteredMessage method readFromWire.
public void readFromWire(Buffer buffer, CodecManager codecManager) {
int pos = 0;
// Overall Length already read when passed in here
byte protocolVersion = buffer.getByte(pos);
if (protocolVersion > WIRE_PROTOCOL_VERSION) {
throw new IllegalStateException("Invalid wire protocol version " + protocolVersion + " should be <= " + WIRE_PROTOCOL_VERSION);
}
pos++;
byte systemCodecCode = buffer.getByte(pos);
pos++;
if (systemCodecCode == -1) {
// User codec
int length = buffer.getInt(pos);
pos += 4;
byte[] bytes = buffer.getBytes(pos, pos + length);
String codecName = new String(bytes, CharsetUtil.UTF_8);
messageCodec = codecManager.getCodec(codecName);
if (messageCodec == null) {
throw new IllegalStateException("No message codec registered with name " + codecName);
}
pos += length;
} else {
messageCodec = codecManager.systemCodecs()[systemCodecCode];
}
byte bsend = buffer.getByte(pos);
send = bsend == 0;
pos++;
int length = buffer.getInt(pos);
pos += 4;
byte[] bytes = buffer.getBytes(pos, pos + length);
address = new String(bytes, CharsetUtil.UTF_8);
pos += length;
length = buffer.getInt(pos);
pos += 4;
if (length != 0) {
bytes = buffer.getBytes(pos, pos + length);
replyAddress = new String(bytes, CharsetUtil.UTF_8);
pos += length;
}
int senderPort = buffer.getInt(pos);
pos += 4;
length = buffer.getInt(pos);
pos += 4;
bytes = buffer.getBytes(pos, pos + length);
String senderHost = new String(bytes, CharsetUtil.UTF_8);
pos += length;
headersPos = pos;
int headersLength = buffer.getInt(pos);
pos += headersLength;
bodyPos = pos;
sender = new ServerID(senderPort, senderHost);
wireBuffer = buffer;
fromWire = true;
}
Aggregations