Search in sources :

Example 1 with ClientContext

use of com.hazelcast.client.impl.spi.ClientContext in project hazelcast by hazelcast.

the class ClientCacheNearCacheLeakTest method createNearCacheContextBuilder.

private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder(CacheConfig<K, V> cacheConfig) {
    ClientConfig clientConfig = getClientConfig();
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = createClientCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    ICache<K, V> clientCache = cacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
    NearCacheManager nearCacheManager = ((ClientCacheProxy) clientCache).getContext().getNearCacheManager(clientCache.getServiceName());
    String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(DEFAULT_NEAR_CACHE_NAME);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
    ClientContext clientContext = ((ClientProxy) clientCache).getContext();
    RepairingTask repairingTask = clientContext.getRepairingTask(CacheService.SERVICE_NAME);
    return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new ICacheDataStructureAdapter<K, V>(clientCache)).setNearCache(nearCache).setNearCacheManager(nearCacheManager).setCacheManager(cacheManager).setRepairingTask(repairingTask);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) RepairingTask(com.hazelcast.internal.nearcache.impl.invalidation.RepairingTask) ClientContext(com.hazelcast.client.impl.spi.ClientContext) Data(com.hazelcast.internal.serialization.Data) NearCacheTestContextBuilder(com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder) ClientProxy(com.hazelcast.client.impl.spi.ClientProxy) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 2 with ClientContext

use of com.hazelcast.client.impl.spi.ClientContext in project hazelcast by hazelcast.

the class ClientCacheInvalidationMetaDataFetcherTest method getRepairingTask.

@SuppressWarnings("unchecked")
private RepairingTask getRepairingTask(String cacheName, int partition, long givenSequence, UUID givenUuid) {
    HazelcastInstance member = factory.newHazelcastInstance();
    distortRandomPartitionSequence(getPrefixedName(cacheName), partition, givenSequence, member);
    distortRandomPartitionUuid(partition, givenUuid, member);
    ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(new NearCacheConfig(cacheName));
    HazelcastClientProxy client = (HazelcastClientProxy) factory.newHazelcastClient(clientConfig);
    CachingProvider clientCachingProvider = createClientCachingProvider(client);
    Cache<Integer, Integer> clientCache = clientCachingProvider.getCacheManager().createCache(cacheName, newCacheConfig());
    ClientContext clientContext = ((ClientProxy) clientCache).getContext();
    return clientContext.getRepairingTask(SERVICE_NAME);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientContext(com.hazelcast.client.impl.spi.ClientContext) ClientProxy(com.hazelcast.client.impl.spi.ClientProxy) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Example 3 with ClientContext

use of com.hazelcast.client.impl.spi.ClientContext in project hazelcast by hazelcast.

the class HazelcastClientInstanceImpl method start.

public void start() {
    try {
        lifecycleService.start();
        startMetrics();
        invocationService.start();
        ClientContext clientContext = new ClientContext(this);
        userCodeDeploymentService.start();
        Collection<EventListener> configuredListeners = instantiateConfiguredListenerObjects();
        clusterService.start(configuredListeners);
        clientClusterViewListenerService.start();
        connectionManager.start();
        startHeartbeat();
        startIcmpPing();
        connectionManager.connectToCluster();
        diagnostics.start();
        // static loggers at beginning of file
        diagnostics.register(new BuildInfoPlugin(loggingService.getLogger(BuildInfoPlugin.class)));
        diagnostics.register(new ConfigPropertiesPlugin(loggingService.getLogger(ConfigPropertiesPlugin.class), properties));
        diagnostics.register(new SystemPropertiesPlugin(loggingService.getLogger(SystemPropertiesPlugin.class)));
        // periodic loggers
        diagnostics.register(new MetricsPlugin(loggingService.getLogger(MetricsPlugin.class), metricsRegistry, properties));
        diagnostics.register(new SystemLogPlugin(properties, connectionManager, this, loggingService.getLogger(SystemLogPlugin.class)));
        diagnostics.register(new NetworkingImbalancePlugin(properties, connectionManager.getNetworking(), loggingService.getLogger(NetworkingImbalancePlugin.class)));
        diagnostics.register(new EventQueuePlugin(loggingService.getLogger(EventQueuePlugin.class), listenerService.getEventExecutor(), properties));
        metricsRegistry.provideMetrics(listenerService);
        ClientConnectionStrategyConfig connectionStrategyConfig = config.getConnectionStrategyConfig();
        boolean asyncStart = connectionStrategyConfig.isAsyncStart();
        if (!asyncStart) {
            waitForInitialMembershipEvents();
        }
        connectionManager.tryConnectToAllClusterMembers(!asyncStart);
        listenerService.start();
        proxyManager.init(config, clientContext);
        invocationService.addBackupListener();
        loadBalancer.init(getCluster(), config);
        clientStatisticsService.start();
        clientExtension.afterStart(this);
        cpSubsystem.init(clientContext);
        addClientConfigAddedListeners(configuredListeners);
        sendStateToCluster();
    } catch (Throwable e) {
        try {
            lifecycleService.terminate();
        } catch (Throwable t) {
            ignore(t);
        }
        throw rethrow(e);
    }
}
Also used : ConfigPropertiesPlugin(com.hazelcast.internal.diagnostics.ConfigPropertiesPlugin) MetricsPlugin(com.hazelcast.internal.diagnostics.MetricsPlugin) ClientContext(com.hazelcast.client.impl.spi.ClientContext) BuildInfoPlugin(com.hazelcast.internal.diagnostics.BuildInfoPlugin) NetworkingImbalancePlugin(com.hazelcast.internal.diagnostics.NetworkingImbalancePlugin) EventQueuePlugin(com.hazelcast.internal.diagnostics.EventQueuePlugin) ClientConnectionStrategyConfig(com.hazelcast.client.config.ClientConnectionStrategyConfig) SystemPropertiesPlugin(com.hazelcast.internal.diagnostics.SystemPropertiesPlugin) EventListener(java.util.EventListener) SystemLogPlugin(com.hazelcast.internal.diagnostics.SystemLogPlugin)

Example 4 with ClientContext

use of com.hazelcast.client.impl.spi.ClientContext in project hazelcast by hazelcast.

the class NearCacheMetricsProvider method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    descriptor.withPrefix(NEARCACHE_PREFIX);
    ClientContext clientContext = proxyManager.getContext();
    if (clientContext == null) {
        return;
    }
    clientContext.getNearCacheManagers().values().stream().flatMap(nearCacheManager -> nearCacheManager.listAllNearCaches().stream()).forEach(nearCache -> {
        String nearCacheName = nearCache.getName();
        NearCacheStatsImpl nearCacheStats = (NearCacheStatsImpl) nearCache.getNearCacheStats();
        context.collect(descriptor.copy().withDiscriminator(NEARCACHE_DISCRIMINATOR_NAME, nearCacheName), nearCacheStats);
    });
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ClientContext(com.hazelcast.client.impl.spi.ClientContext) NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) ProxyManager(com.hazelcast.client.impl.spi.ProxyManager) NEARCACHE_DISCRIMINATOR_NAME(com.hazelcast.internal.metrics.MetricDescriptorConstants.NEARCACHE_DISCRIMINATOR_NAME) NEARCACHE_PREFIX(com.hazelcast.internal.metrics.MetricDescriptorConstants.NEARCACHE_PREFIX) NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl) ClientContext(com.hazelcast.client.impl.spi.ClientContext)

Example 5 with ClientContext

use of com.hazelcast.client.impl.spi.ClientContext in project hazelcast by hazelcast.

the class ClientMapNearCacheLeakTest method createNearCacheContextBuilder.

private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder() {
    ClientConfig clientConfig = getClientConfig();
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    IMap<K, V> clientMap = client.getMap(DEFAULT_NEAR_CACHE_NAME);
    NearCacheManager nearCacheManager = ((ClientMapProxy) clientMap).getContext().getNearCacheManager(clientMap.getServiceName());
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
    ClientContext clientContext = ((ClientProxy) clientMap).getContext();
    RepairingTask repairingTask = clientContext.getRepairingTask(MapService.SERVICE_NAME);
    return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new IMapDataStructureAdapter<K, V>(clientMap)).setNearCache(nearCache).setNearCacheManager(nearCacheManager).setRepairingTask(repairingTask);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) RepairingTask(com.hazelcast.internal.nearcache.impl.invalidation.RepairingTask) ClientContext(com.hazelcast.client.impl.spi.ClientContext) Data(com.hazelcast.internal.serialization.Data) IMapDataStructureAdapter(com.hazelcast.internal.adapter.IMapDataStructureAdapter) ClientProxy(com.hazelcast.client.impl.spi.ClientProxy) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy)

Aggregations

ClientContext (com.hazelcast.client.impl.spi.ClientContext)8 ClientConfig (com.hazelcast.client.config.ClientConfig)4 ClientProxy (com.hazelcast.client.impl.spi.ClientProxy)4 HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)3 ProxyManager (com.hazelcast.client.impl.spi.ProxyManager)3 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)2 NearCacheStatsImpl (com.hazelcast.internal.monitor.impl.NearCacheStatsImpl)2 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)2 RepairingTask (com.hazelcast.internal.nearcache.impl.invalidation.RepairingTask)2 Data (com.hazelcast.internal.serialization.Data)2 CachingProvider (javax.cache.spi.CachingProvider)2 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)1 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)1 ClientConnectionStrategyConfig (com.hazelcast.client.config.ClientConnectionStrategyConfig)1 ClientMetricsConfig (com.hazelcast.client.config.ClientMetricsConfig)1 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 TcpClientConnection (com.hazelcast.client.impl.connection.tcp.TcpClientConnection)1