use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMemberAttributeTest method testChangeAttributes.
@Test(timeout = 120000)
public void testChangeAttributes() throws Exception {
Config c = new Config();
JoinConfig join = c.getNetworkConfig().getJoin();
join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
join.getMulticastConfig().setEnabled(false);
HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(c);
Member m1 = h1.getCluster().getLocalMember();
m1.setIntAttribute("Test", 123);
HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(c);
assertEquals(2, h2.getCluster().getMembers().size());
Member member = null;
for (Member m : h2.getCluster().getMembers()) {
if (m == h2.getCluster().getLocalMember()) {
continue;
}
member = m;
}
assertNotNull(member);
assertEquals(m1, member);
assertNotNull(member.getIntAttribute("Test"));
assertEquals(123, (int) member.getIntAttribute("Test"));
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CountDownLatch latch = new CountDownLatch(3);
final MembershipListener listener = new LatchMembershipListener(latch);
h2.getCluster().addMembershipListener(listener);
h1.getCluster().addMembershipListener(listener);
client.getCluster().addMembershipListener(listener);
m1.setIntAttribute("Test", 321);
// Force sleep to distribute value
assertOpenEventually(latch);
assertNotNull(member.getIntAttribute("Test"));
assertEquals(321, (int) member.getIntAttribute("Test"));
boolean found = false;
Collection<Member> members = client.getCluster().getMembers();
for (Member m : members) {
if (m.equals(m1)) {
assertEquals(321, (int) m.getIntAttribute("Test"));
found = true;
}
}
assertTrue(found);
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientEngineImpl method getConnectedClientStats.
@Override
public Map<ClientType, Integer> getConnectedClientStats() {
int numberOfCppClients = 0;
int numberOfDotNetClients = 0;
int numberOfJavaClients = 0;
int numberOfNodeJSClients = 0;
int numberOfPythonClients = 0;
int numberOfOtherClients = 0;
OperationService operationService = node.nodeEngine.getOperationService();
Map<ClientType, Integer> resultMap = new HashMap<ClientType, Integer>();
Map<String, ClientType> clientsMap = new HashMap<String, ClientType>();
for (Member member : node.getClusterService().getMembers()) {
Address target = member.getAddress();
Operation clientInfoOperation = new GetConnectedClientsOperation();
Future<Map<String, ClientType>> future = operationService.invokeOnTarget(SERVICE_NAME, clientInfoOperation, target);
try {
Map<String, ClientType> endpoints = future.get();
if (endpoints == null) {
continue;
}
//Merge connected clients according to their uuid.
for (Map.Entry<String, ClientType> entry : endpoints.entrySet()) {
clientsMap.put(entry.getKey(), entry.getValue());
}
} catch (Exception e) {
logger.warning("Cannot get client information from: " + target.toString(), e);
}
}
//Now we are regrouping according to the client type
for (ClientType clientType : clientsMap.values()) {
switch(clientType) {
case JAVA:
numberOfJavaClients++;
break;
case CSHARP:
numberOfDotNetClients++;
break;
case CPP:
numberOfCppClients++;
break;
case NODEJS:
numberOfNodeJSClients++;
break;
case PYTHON:
numberOfPythonClients++;
break;
default:
numberOfOtherClients++;
}
}
resultMap.put(ClientType.CPP, numberOfCppClients);
resultMap.put(ClientType.CSHARP, numberOfDotNetClients);
resultMap.put(ClientType.JAVA, numberOfJavaClients);
resultMap.put(ClientType.NODEJS, numberOfNodeJSClients);
resultMap.put(ClientType.PYTHON, numberOfPythonClients);
resultMap.put(ClientType.OTHER, numberOfOtherClients);
return resultMap;
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class SerializationTest method testMemberLeftException_usingSimpleMember.
@Test
public void testMemberLeftException_usingSimpleMember() throws Exception {
String uuid = UuidUtil.newUnsecureUuidString();
String host = "127.0.0.1";
int port = 5000;
Member member = new SimpleMemberImpl(MemberVersion.of("3.8.0"), uuid, new InetSocketAddress(host, port));
testMemberLeftException(uuid, host, port, member);
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class SerializationTest method testMemberLeftException_withLiteMemberImpl.
@Test
public void testMemberLeftException_withLiteMemberImpl() throws Exception {
String uuid = UuidUtil.newUnsecureUuidString();
String host = "127.0.0.1";
int port = 5000;
Member member = new MemberImpl(new Address(host, port), MemberVersion.of("3.8.0"), false, uuid, null, null, true);
testMemberLeftException(uuid, host, port, member);
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class SerializationTest method testMemberLeftException_withLiteSimpleMemberImpl.
@Test
public void testMemberLeftException_withLiteSimpleMemberImpl() throws Exception {
String uuid = UuidUtil.newUnsecureUuidString();
String host = "127.0.0.1";
int port = 5000;
Member member = new SimpleMemberImpl(MemberVersion.of("3.8.0"), uuid, new InetSocketAddress(host, port), true);
testMemberLeftException(uuid, host, port, member);
}
Aggregations