use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class ClientConsoleApp method main.
/**
* Starts the test application. Loads the config from classpath hazelcast.xml,
* if it fails to load, will use default config.
*
* @param args none
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ClientConfig clientConfig;
try {
clientConfig = new XmlClientConfigBuilder().build();
} catch (IllegalArgumentException e) {
clientConfig = new ClientConfig();
}
final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
ClientConsoleApp clientConsoleApp = new ClientConsoleApp(client);
clientConsoleApp.start(args);
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class ClientMultiMapProxy method aggregate.
@Override
public <SuppliedValue, Result> Result aggregate(Supplier<K, V, SuppliedValue> supplier, Aggregation<K, SuppliedValue, Result> aggregation) {
HazelcastInstance hazelcastInstance = getContext().getHazelcastInstance();
JobTracker jobTracker = hazelcastInstance.getJobTracker("hz::aggregation-multimap-" + name);
return aggregate(supplier, aggregation, jobTracker);
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class ClientConnectionTest method testWithLegalAndIllegalAddressTogether.
@Test
public void testWithLegalAndIllegalAddressTogether() {
String illegalAddress = randomString();
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
ClientConfig config = new ClientConfig();
config.setProperty(ClientProperty.SHUFFLE_MEMBER_LIST.getName(), "false");
config.getNetworkConfig().addAddress(illegalAddress).addAddress("localhost");
HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
Collection<Client> connectedClients = server.getClientService().getConnectedClients();
assertEquals(connectedClients.size(), 1);
Client serverSideClientInfo = connectedClients.iterator().next();
assertEquals(serverSideClientInfo.getUuid(), client.getLocalEndpoint().getUuid());
}
use of com.hazelcast.core.HazelcastInstance 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.HazelcastInstance in project hazelcast by hazelcast.
the class ClientConnectionTest method destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce.
@Test
public void destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce() {
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
final CountingConnectionRemoveListener listener = new CountingConnectionRemoveListener();
connectionManager.addConnectionListener(listener);
final Address serverAddress = new Address(server.getCluster().getLocalMember().getSocketAddress());
final Connection connectionToServer = connectionManager.getConnection(serverAddress);
final CountDownLatch isConnected = new CountDownLatch(1);
clientImpl.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
isConnected.countDown();
}
}
});
connectionToServer.close(null, null);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(isConnected.await(5, TimeUnit.SECONDS));
}
});
connectionToServer.close(null, null);
assertEquals("connection removed should be called only once", 1, listener.count.get());
}
Aggregations