Transfer client config to xml.

175 views
Skip to first unread message

Andreas Joelsson

unread,
Jun 13, 2014, 6:27:51 AM6/13/14
to haze...@googlegroups.com
Hi I have 2 clients that I need to transfer from code configuration to xml configuration.

Here is the 2 clients setup:

Client 1:
ClientConfig config = new ClientConfig();
ClientNetworkConfig network = config.getNetworkConfig();
network
.addAddress("localhost");
config
.setNetworkConfig(network);
SerializationConfig cc = config.getSerializationConfig().addDataSerializableFactory(NodeConstants.FACTORY_ID, new NodeFactory());
cc
.addDataSerializableFactory(QueueFactory.FACTORY_ID, new QueueFactory());
cc
.addDataSerializableFactory(RequestFactory.FACTORY_ID, new RequestFactory());
config
.setSerializationConfig(cc);
HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);


Client 2:
ClientConfig config = new ClientConfig();
ClientNetworkConfig network = config.getNetworkConfig();
network
.addAddress("localhost");
config
.setNetworkConfig(network);
SerializationConfig cc = config.getSerializationConfig().addDataSerializableFactory(NodeConstants.FACTORY_ID, new NodeFactory());
cc
.addDataSerializableFactory(TriggerConstants.FACTORY_ID, new TriggerFactory());
config
.setSerializationConfig(cc);
log
.debug("Pre config");
HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);


Using this setup works, but when I try to create it as a hazelcast-client config I can't get them to communicate with the factories.

Client 1:

<hazelcast-client xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
            http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.3.xsd"

           
xmlns="http://www.hazelcast.com/schema/client-config"
           
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   
<group>
       
<name>dev</name>
       
<password>dev-pass</password>
   
</group>


   
<network>
       
<cluster-members>
           
<address>localhost</address>
       
</cluster-members>
       
<smart-routing>true</smart-routing>
       
<redo-operation>true</redo-operation>
   
</network>
   
   
<serialization>
       
<portable-version>0</portable-version>
       
<data-serializable-factories>
           
<data-serializable-factory factory-id="1">se.svs.test.common.msg.node.NodeFactory</data-serializable-factory>
           
<data-serializable-factory factory-id="3">se.svs.test.common.msg.trigger.TriggerFactory</data-serializable-factory>
           
<data-serializable-factory factory-id="378461">se.svs.test.common.map.RequestFactory</data-serializable-factory>
       
</data-serializable-factories>
   
</serialization>


</hazelcast-client>


Client 2:
<hazelcast-client xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
            http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.3.xsd"

           
xmlns="http://www.hazelcast.com/schema/client-config"
           
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   
<group>
       
<name>dev</name>
       
<password>dev-pass</password>
   
</group>


   
<network>
       
<cluster-members>
           
<address>localhost</address>
       
</cluster-members>
       
<smart-routing>true</smart-routing>
       
<redo-operation>true</redo-operation>
   
</network>
   
   
<serialization>
       
<portable-version>0</portable-version>
       
<data-serializable-factories>
           
<data-serializable-factory factory-id="1">se.svs.test.common.msg.node.NodeFactory</data-serializable-factory>
           
<data-serializable-factory factory-id="3">se.svs.test.common.msg.trigger.TriggerFactory</data-serializable-factory>
       
</data-serializable-factories>
   
</serialization>


</hazelcast-client>


The read of the configuration works and registering to them works, Then when they try to access each other I get nothing.

Probably fault configuration but according to examples this is how it should be.

Then new instantiation in code is:

HazelcastInstance instance = Hazelcast.newHazelcastInstance(null);

And I have the -Dhazezlcast.config=XXX set

java -Dhazelcast.config=./hazelcastQueueConfig.xml -jar ...


// Andreas

Enes Akar

unread,
Jun 13, 2014, 5:28:00 PM6/13/14
to haze...@googlegroups.com
The new instantiation code should be:
HazelcastInstance instance = HazelcastClient.newHazelcastClient();


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/97066485-156a-4c9f-b743-30694c62b5f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Enes Akar
Director of Engineering
Mahir İz Cad. No:35, Altunizade, İstanbul

Andreas Joelsson

unread,
Jun 16, 2014, 7:40:09 AM6/16/14
to haze...@googlegroups.com
Hi, Tried with this but now the serialization method throws exception.

0 [main] INFO se.svs.test.common.aoc.MessageService  - Registered on se.svs.test.common.msg.node.NodeFactory@f06e01a.
Exception in thread "hz.client_0_dev.cached-4" Exception in thread "hz.client_0_dev.cached-5" Exception in thread "hz.client_0_dev.cached-6" com.hazelcast.nio.serialization.HazelcastSerializationException: No DataSerializerFactory registered for namespace: 1
 at com
.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:93)
 at com
.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:36)
 at com
.hazelcast.nio.serialization.StreamSerializerAdapter.read(StreamSerializerAdapter.java:59)
 at com
.hazelcast.nio.serialization.SerializationServiceImpl.toObject(SerializationServiceImpl.java:221)
 at com
.hazelcast.client.proxy.ClientTopicProxy$1.handle(ClientTopicProxy.java:56)
 at com
.hazelcast.client.proxy.ClientTopicProxy$1.handle(ClientTopicProxy.java:54)
 at com
.hazelcast.client.connection.nio.ClientConnectionManagerImpl$ClientPacketProcessor.handleEvent(ClientConnectionManagerImpl.java:459)
 at com
.hazelcast.client.connection.nio.ClientConnectionManagerImpl$ClientPacketProcessor.run(ClientConnectionManagerImpl.java:433)
 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.PoolExecutorThreadFactory$ManagedThread.run(PoolExecutorThreadFactory.java:59)
com
.hazelcast.nio.serialization.HazelcastSerializationException: No DataSerializerFactory registered for namespace: 1

I aslo tried with sending in null like in a node. So it seems it doesn't read the configuration file now.

M. Sancar Koyunlu

unread,
Jun 16, 2014, 8:19:04 AM6/16/14
to haze...@googlegroups.com
It seems that the suggestion made by Enes is available only for nodes not client.
What you can do is

String pathToClientXmlConfig = System.getProperty("hazelcast.config");
final ClientConfig clientConfig = new XmlClientConfigBuilder(pathToClientXmlConfig).build();
final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

And can you create an issue about this so that we can track and implement it ?


Andreas Joelsson

unread,
Jun 16, 2014, 8:27:59 AM6/16/14
to haze...@googlegroups.com
Hi, 

Was just about to post the "same" solution. Issue added on https://github.com/hazelcast/hazelcast/issues/2724


String environment = System.getProperty("hazelcast.config");
try {
ClientConfig config = new XmlClientConfigBuilder(environment).build();
HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);
...
 

// Andreas

M. Sancar Koyunlu

unread,
Jun 17, 2014, 3:08:37 AM6/17/14
to haze...@googlegroups.com
Issue is resolved in git issue thread.
For future reference , I am posting the comment here :

For the client is should work as well, but you need to use -Dhazelcast.client.config=....



Reply all
Reply to author
Forward
0 new messages