use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientConnectionTest method testAsyncConnectionCreationInAsyncMethods.
@Test
public void testAsyncConnectionCreationInAsyncMethods() throws ExecutionException, InterruptedException {
hazelcastFactory.newHazelcastInstance();
CountDownLatch countDownLatch = new CountDownLatch(1);
ClientConfig config = new ClientConfig();
WaitingCredentials credentials = new WaitingCredentials("dev", "dev-pass", countDownLatch);
config.setCredentials(credentials);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
final IExecutorService executorService = client.getExecutorService(randomString());
credentials.waitFlag.set(true);
final HazelcastInstance secondInstance = hazelcastFactory.newHazelcastInstance();
final AtomicReference<Future> atomicReference = new AtomicReference<Future>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Member secondMember = secondInstance.getCluster().getLocalMember();
Future future = executorService.submitToMember(new DummySerializableCallable(), secondMember);
atomicReference.set(future);
}
});
thread.start();
try {
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNotNull(atomicReference.get());
}
}, 30);
} finally {
thread.interrupt();
thread.join();
countDownLatch.countDown();
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientSmartListenerService method start.
@Override
public void start() {
clientConnectionManager.addConnectionListener(this);
clientConnectionManager.addConnectionHeartbeatListener(this);
final ClientClusterService clientClusterService = client.getClientClusterService();
registrationExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
Collection<Member> memberList = clientClusterService.getMemberList();
for (Member member : memberList) {
clientConnectionManager.getOrTriggerConnect(member.getAddress(), false);
}
}
}, 1, 1, TimeUnit.SECONDS);
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientTransactionManagerServiceImpl method getRandomAddress.
private Address getRandomAddress() {
Member member = loadBalancer.next();
if (member == null) {
Set<Member> members = client.getCluster().getMembers();
String msg;
if (members.isEmpty()) {
msg = "No address was return by the LoadBalancer since there are no members in the cluster";
} else {
msg = "No address was return by the LoadBalancer. " + "But the cluster contains the following members:" + members;
}
throw new IllegalStateException(msg);
}
return member.getAddress();
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMemberAttributeTest method testPresharedAttributes.
@Test(timeout = 120000)
public void testPresharedAttributes() throws Exception {
Config c = new Config();
JoinConfig join = c.getNetworkConfig().getJoin();
join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
join.getMulticastConfig().setEnabled(false);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
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"));
boolean found = false;
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
Collection<Member> members = client.getCluster().getMembers();
for (Member m : members) {
if (m.equals(m1)) {
assertEquals(123, (int) m.getIntAttribute("Test"));
found = true;
}
}
assertTrue(found);
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMemberAttributeTest method testRemoveAttributes.
@Test(timeout = 120000)
public void testRemoveAttributes() 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.removeAttribute("Test");
// Force sleep to distribute value
assertOpenEventually(latch);
assertNull(member.getIntAttribute("Test"));
boolean found = false;
Collection<Member> members = client.getCluster().getMembers();
for (Member m : members) {
if (m.equals(m1)) {
assertNull(m.getIntAttribute("Test"));
found = true;
}
}
assertTrue(found);
}
Aggregations