0

I have two node Hazelcast (3.4.1) cluster running. I have configured it to use native memory. (Basically trying to use high density memory store). Have written a client code to connect to those cluster to perform write operation.

I trying to configure Jcache with Hazelcast in order to use cache store. Jcache provider type: client. Also I want use declarative configuration Below is my client code & configuration XML.

public class Test {

  public static void main(String[] args) {

    try {
        System.setProperty("hazelcast.config",
                "classpath:conf/hazelcast.xml");
        System.setProperty("hazelcast.jcache.provider.type", "client");
        CachingProvider cachingProvider = Caching.getCachingProvider();

        CacheManager cacheManager = cachingProvider.getCacheManager();
        ICache<String, Object> cache = cacheManager.getCache("Classroom",String.class, Object.class).unwrap(ICache.class);
        CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class);

        System.out.println("key type: " + cacheConfig.getKeyType());
        System.out.println("value type: " + cacheConfig.getValueType());
        cache.put("1", "value1");
        System.out.println("-->" + cache.get("1"));

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

My hazelcast.xml used at client

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-     
 3.4.xsd"
xmlns="http://www.hazelcast.com/schema/config"    
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group>
    <name>dev</name>
    <password>dev-pass</password>
</group>
<management-center enabled="true">http://ipaddr:8080/mancenter
</management-center>
<network>
    <port auto-increment="true" port-count="100">5701</port>
    <outbound-ports>
        <!-- Allowed port range when connecting to other nodes. 0 or * means use 
            system provided port. -->
        <ports>0</ports>
    </outbound-ports>
    <join>
        <multicast enabled="false">
            <multicast-group>224.2.2.3</multicast-group>
            <multicast-port>54327</multicast-port>
        </multicast>
        <tcp-ip enabled="true">
            <member>my domain addr 1 </member>
            <member>my domain addr 2</member>

            <connection-timeout-seconds>20</connection-timeout-seconds>
        </tcp-ip>
        <aws enabled="false">
            <access-key>my-access-key</access-key>
            <secret-key>my-secret-key</secret-key>
            <!--optional, default is us-east-1 -->
            <region>us-west-1</region>
            <!--optional, default is ec2.amazonaws.com. If set, region shouldn't 
                be set as it will override this property -->
            <host-header>ec2.amazonaws.com</host-header>
            <!-- optional, only instances belonging to this group will be discovered, 
                default will try all running instances -->
            <security-group-name>hazelcast-sg</security-group-name>
            <tag-key>type</tag-key>
            <tag-value>hz-nodes</tag-value>
        </aws>
    </join>
    <interfaces enabled="false">
        <interface>10.*.*.*</interface>
    </interfaces>


    <ssl enabled="false" />
    <socket-interceptor enabled="false" />
    <symmetric-encryption enabled="false">
        <!-- encryption algorithm such as DES/ECB/PKCS5Padding, PBEWithMD5AndDES, 
            AES/CBC/PKCS5Padding, Blowfish, DESede -->
        <algorithm>PBEWithMD5AndDES</algorithm>
        <!-- salt value to use when generating the secret key -->
        <salt>thesalt</salt>
        <!-- pass phrase to use when generating the secret key -->
        <password>thepass</password>
        <!-- iteration count to use when generating the secret key -->
        <iteration-count>19</iteration-count>
    </symmetric-encryption>
</network>
<partition-group enabled="false" />
<executor-service name="default">
    <pool-size>16</pool-size>
    <!--Queue capacity. 0 means Integer.MAX_VALUE. -->
    <queue-capacity>0</queue-capacity>
</executor-service>
<queue name="default">
    <!-- Maximum size of the queue. When a JVM's local queue size reaches the 
        maximum, all put/offer operations will get blocked until the queue size of 
        the JVM goes down below the maximum. Any integer between 0 and Integer.MAX_VALUE. 
        0 means Integer.MAX_VALUE. Default is 0. -->
    <max-size>0</max-size>
    <!-- Number of backups. If 1 is set as the backup-count for example, then 
        all entries of the map will be copied to another JVM for fail-safety. 0 means 
        no backup. -->
    <backup-count>0</backup-count>

    <!-- Number of async backups. 0 means no backup. -->
    <async-backup-count>0</async-backup-count>

    <empty-queue-ttl>-1</empty-queue-ttl>
</queue>
<map name="default">
    <!-- Data type that will be used for storing recordMap. Possible values: 
        BINARY (default): keys and values will be stored as binary data OBJECT : 
        values will be stored in their object forms NATIVE : values will be stored 
        in non-heap region of JVM -->
    <in-memory-format>NATIVE</in-memory-format>

    <!-- Number of backups. If 1 is set as the backup-count for example, then 
        all entries of the map will be copied to another JVM for fail-safety. 0 means 
        no backup. -->
    <backup-count>0</backup-count>
    <!-- Number of async backups. 0 means no backup. -->
    <async-backup-count>0</async-backup-count>
    <!-- Maximum number of seconds for each entry to stay in the map. Entries 
        that are older than <time-to-live-seconds> and not updated for <time-to-live-seconds> 
        will get automatically evicted from the map. Any integer between 0 and Integer.MAX_VALUE. 
        0 means infinite. Default is 0. -->
    <time-to-live-seconds>0</time-to-live-seconds>
    <!-- Maximum number of seconds for each entry to stay idle in the map. 
        Entries that are idle(not touched) for more than <max-idle-seconds> will 
        get automatically evicted from the map. Entry is touched if get, put or containsKey 
        is called. Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. 
        Default is 0. -->
    <max-idle-seconds>0</max-idle-seconds>
    <!-- Valid values are: NONE (no eviction), LRU (Least Recently Used), LFU 
        (Least Frequently Used). NONE is the default. -->
    <eviction-policy>NONE</eviction-policy>
    <!-- Maximum size of the map. When max size is reached, map is evicted 
        based on the policy defined. Any integer between 0 and Integer.MAX_VALUE. 
        0 means Integer.MAX_VALUE. Default is 0. -->
    <max-size policy="PER_NODE">0</max-size>
    <!-- When max. size is reached, specified percentage of the map will be 
        evicted. Any integer between 0 and 100. If 25 is set for example, 25% of 
        the entries will get evicted. -->
    <eviction-percentage>25</eviction-percentage>
    <!-- Minimum time in milliseconds which should pass before checking if 
        a partition of this map is evictable or not. Default value is 100 millis. -->
    <min-eviction-check-millis>100</min-eviction-check-millis>
    <!-- While recovering from split-brain (network partitioning), map entries 
        in the small cluster will merge into the bigger cluster based on the policy 
        set here. When an entry merge into the cluster, there might an existing entry 
        with the same key already. Values of these entries might be different for 
        that same key. Which value should be set for the key? Conflict is resolved 
        by the policy set here. Default policy is PutIfAbsentMapMergePolicy There 
        are built-in merge policies such as com.hazelcast.map.merge.PassThroughMergePolicy; 
        entry will be overwritten if merging entry exists for the key. com.hazelcast.map.merge.PutIfAbsentMapMergePolicy 
        ; entry will be added if the merging entry doesn't exist in the cluster. 
        com.hazelcast.map.merge.HigherHitsMapMergePolicy ; entry with the higher 
        hits wins. com.hazelcast.map.merge.LatestUpdateMapMergePolicy ; entry with 
        the latest update wins. -->
    <merge-policy>com.hazelcast.map.merge.PutIfAbsentMapMergePolicy
    </merge-policy>

</map>

<multimap name="default">
    <backup-count>0</backup-count>
    <value-collection-type>SET</value-collection-type>
</multimap>

<multimap name="default">
    <backup-count>0</backup-count>
    <value-collection-type>SET</value-collection-type>
</multimap>

<list name="default">
    <backup-count>0</backup-count>
</list>

<set name="default">
    <backup-count>0</backup-count>
</set>

<jobtracker name="default">
    <max-thread-size>0</max-thread-size>
    <!-- Queue size 0 means number of partitions * 2 -->
    <queue-size>0</queue-size>
    <retry-count>0</retry-count>
    <chunk-size>1000</chunk-size>
    <communicate-stats>true</communicate-stats>
    <topology-changed-strategy>CANCEL_RUNNING_OPERATION
    </topology-changed-strategy>
</jobtracker>

<semaphore name="default">
    <initial-permits>0</initial-permits>
    <backup-count>1</backup-count>
    <async-backup-count>0</async-backup-count>
</semaphore>

<serialization>
    <portable-version>0</portable-version>
</serialization>

<services enable-defaults="true" />

<cache name="Classroom">

    <key-type class-name="java.lang.String" />
    <value-type class-name="java.lang.Object" />
    <statistics-enabled>false</statistics-enabled>
    <management-enabled>false</management-enabled>
</cache>

<properties>
    <property name="hazelcast.logging.type">jdk</property>
    <property name="hazelcast.jcache.provider.type">client</property>
</properties>

</hazelcast>

When the client code is executed. I am getting following exception.

            Mar 25, 2015 10:05:19 PM com.hazelcast.client.config.XmlClientConfigLocator
            INFO: Loading 'hazelcast-client-default.xml' from classpath.
            Mar 25, 2015 10:05:19 PM com.hazelcast.core.LifecycleService
            INFO: HazelcastClient[hz.client_0_dev][3.4.1] is STARTING
            Mar 25, 2015 10:05:20 PM com.hazelcast.core.LifecycleService
            INFO: HazelcastClient[hz.client_0_dev][3.4.1] is STARTED
            Mar 25, 2015 10:05:22 PM com.hazelcast.core.LifecycleService
            INFO: HazelcastClient[hz.client_0_dev][3.4.1] is CLIENT_CONNECTED
            Mar 25, 2015 10:05:22 PM com.hazelcast.client.spi.impl.ClusterListenerThread
            INFO: 

            Members [1] {
                Member [mylocalipaddress]:5701
            }

            javax.cache.CacheException: Error opening URI [hazelcast]
                at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:89)
                at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:118)
                at com.hazelcast.cache.HazelcastCachingProvider.getCacheManager(HazelcastCachingProvider.java:158)
                at com.apollo.cache.manager.Test.main(Test.java:61)
            Caused by: java.lang.IllegalArgumentException: No service registered with name: hz:impl:cacheService
                at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.initService(ClientEngineImpl.java:477)
                at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.processRequest(ClientEngineImpl.java:427)
                at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.run(ClientEngineImpl.java:353)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                at java.lang.Thread.run(Thread.java:744)
                at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
                at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)
                at ------ End remote and begin local stack-trace ------.(Unknown Source)
                at com.hazelcast.client.spi.impl.ClientCallFuture.resolveResponse(ClientCallFuture.java:201)
                at com.hazelcast.client.spi.impl.ClientCallFuture.get(ClientCallFuture.java:142)
                at com.hazelcast.client.spi.impl.ClientCallFuture.get(ClientCallFuture.java:118)
                at com.hazelcast.client.spi.ProxyManager.initialize(ProxyManager.java:200)
                at com.hazelcast.client.spi.ProxyManager.getOrCreateProxy(ProxyManager.java:183)
                at com.hazelcast.client.impl.HazelcastClientInstanceImpl.getDistributedObject(HazelcastClientInstanceImpl.java:391)
                at com.hazelcast.client.impl.HazelcastClientProxy.getDistributedObject(HazelcastClientProxy.java:234)
                at com.hazelcast.client.cache.impl.HazelcastClientCacheManager.<init>(HazelcastClientCacheManager.java:62)
                at com.hazelcast.client.cache.impl.HazelcastClientCachingProvider.createHazelcastCacheManager(HazelcastClientCachingProvider.java:75)
                at com.hazelcast.client.cache.impl.HazelcastClientCachingProvider.createHazelcastCacheManager(HazelcastClientCachingProvider.java:38)
                at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:86)

I have even tried based on the examples provided for jcache. It didn't work out. Not sure where I am going wrong. Also I am not sure jcache is configured. As mentioned in documentation, have all the dependent jars.

Usecase: To have Hazelcast cluster with native cache (high density memory store) enabled. Hazelcast Java client (jcache configured) runs on another node should connect to this cluster and perform read/write operation in to the cache.

halfer
  • 19,824
  • 17
  • 99
  • 186
dinesh m
  • 53
  • 1
  • 6

1 Answers1

4

Add the jcache api JAR to the classpath

noctarius
  • 5,979
  • 19
  • 20
  • I have cache api jar in my pom.xml – dinesh m Mar 26 '15 at 04:35
  • You might be talking about client side. Are you sure you also have it at runtime on the clusterside? The cache service is the cluster-side service that handles the client requests and is only registered when the JCache JAR is available at runtime on server side. – noctarius Mar 26 '15 at 05:33
  • Thanks noctarius. I will have the jcache in my server also. But I am not sure how this will help in solving the above exception. If you see the exception i trying to pass my custom config xml, which has my hazelcast cluster details, instead of picking this xml it loads the default xml. – dinesh m Mar 27 '15 at 05:30
  • 2
    The client side xml file needs to be called hazelcast-client.xml and have to use hazelcast-client-config.xsd. If you want to configure the serverside your hazelcast.xml must be used to configure the serverside. Your original exception is: "java.lang.IllegalArgumentException: No service registered with name: hz:impl:cacheService" which says that the server haven't started the JCache service. All in all you have multiple errors in your application if hazelcast.xml is used on clientside. – noctarius Mar 28 '15 at 09:24
  • 2
    @noctarius advice helped me. The same problem was tackled [here](http://stackoverflow.com/a/27703526/2505920) as well. Besides, one needs to be sure to properly include the required jar into the node's classpath. Check server.sh where CLASSPATH is set. – kasur Aug 13 '15 at 11:26