Define tcpip interfaces declaritavely

291 views
Skip to first unread message

syg6

unread,
Dec 14, 2009, 6:35:37 AM12/14/09
to Hazelcast
When I use the hazelcast.xml to define my interfaces, all is well:

<network>
<join>
<multicast enabled="false" />
<tcp-ip enabled="true">
<interface>192.168.0.1</interface>
<interface>192.168.0.2</interface>
</tcp-ip>
</join>
<interfaces enabled="false">
<interface>10.10.1.*</interface>
</interfaces>
</network>

But when I do the same thing declaritavely, no go:

Config cfg = new XmlConfigBuilder().build();
cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled
(false);
cfg.getNetworkConfig().getInterfaces().clear();
cfg.getNetworkConfig().getInterfaces().addInterface("192.168.0.1");
cfg.getNetworkConfig().getInterfaces().addInterface("192.168.0.2");
cfg.getNetworkConfig().getInterfaces().setEnabled(true);
cfg.setGroupName("test");
HazelcastInstance hi = Hazelcast.newHazelcastInstance(cfg);

The nodes don't find each other.

I was looking at this post and in the 'testDifferentGroups()' I
noticed you do it slightly differently. You define a Config for each
Hazelcast instance. Is it necessaryto create a Hazelcast instance for
each interface on each node? Assuming that each node will have the
same config, why create various Hazelcast instances, why not just
one?

This seems like a lot of overhead, especially for a Config like mine
where I am defining a whole bunch of Maps, each one with a distinct
TTL.

Is my code wrong or I do I have the concept of a Hazelcast instance
wrong?

Thanks!
Bob

syg6

unread,
Dec 14, 2009, 6:37:01 AM12/14/09
to Hazelcast
Oops, forgot the reference the link.

The post I was talking about was this one:

http://groups.google.com/group/hazelcast/browse_thread/thread/df8b3637da71a57c

Talip Ozturk

unread,
Dec 14, 2009, 7:16:26 AM12/14/09
to hazelcast
On Mon, Dec 14, 2009 at 1:35 PM, syg6 <syg...@gmail.com> wrote:
> When I use the hazelcast.xml to define my interfaces, all is well:
>
> <network>
>  <join>
>        <multicast enabled="false" />
>        <tcp-ip enabled="true">
>                <interface>192.168.0.1</interface>
>                <interface>192.168.0.2</interface>
>        </tcp-ip>
>  </join>
>  <interfaces enabled="false">
>        <interface>10.10.1.*</interface>
>  </interfaces>
> </network>

Equivalent of this config is
Config cfg = new XmlConfigBuilder().build();
cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
JoinMembers tcpconfig =
cfg.getNetworkConfig().getJoin().getJoinMembers();
tcpconfig.setEnabled(true);
List lsMembers = tcpconfig.getMembers();
lsMembers.clear();
lsMembers.add("192.168.0.1");
lsMembers.add("192.168.0.2");

We will change the JoinMembers to TcpIpConfig as of 1.8 final.

> cfg.getNetworkConfig().getInterfaces().addInterface("192.168.0.1");
here you are actually setting the following elements..
<interfaces enabled="false">
<interface>10.10.1.*</interface>

> I was looking at this post and in the 'testDifferentGroups()' I
> noticed you do it slightly differently. You define a Config for each
> Hazelcast instance. Is it necessaryto create a Hazelcast instance for
> each interface on each node? Assuming that each node will have the
> same config, why create various Hazelcast instances, why not just
> one?

Each HazelcastInstance is a totally separate cluster member.
For more see http://code.google.com/docreader/#p=hazelcast&s=hazelcast&t=ClusterTestHowTo

syg6

unread,
Dec 14, 2009, 7:56:26 AM12/14/09
to Hazelcast
Hmmm ...

I changed my xml to this:

...
<network>
<port auto-increment="true">5701</port>
<join>
<multicast enabled="false"/>
<tcp-ip enabled="true"/>
</join>
<interfaces enabled="true"/>
</network>
...

And my code to this (as per your instructions):

Config cfg = new XmlConfigBuilder().build();
cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled
(false);
JoinMembers tcpconfig = cfg.getNetworkConfig().getJoin().getJoinMembers
();
tcpconfig.setEnabled(true);
List<String> lsMembers = tcpconfig.getMembers();
lsMembers.clear();
lsMembers.add("192.168.0.1");
lsMembers.add("192.168.0.2");

No go. I also tried adding:

tcpconfig.setMembers(lsMembers);
cfg.getNetworkConfig().getJoin().setJoinMembers(tcpconfig);

I keep getting:

com.hazelcast.impl.AddressPicker pickAddress
GRAVE: Hazelcast CANNOT start on this node. No matching network
interface found.
Interface matching must be either disabled or updated in the
hazelcast.xml config file.
java.lang.RuntimeException: Hazelcast CANNOT start on this node. No
matching network interface found.
Interface matching must be either disabled or updated in the
hazelcast.xml config file.
at com.hazelcast.impl.AddressPicker.pickAddress
(AddressPicker.java:119)
at com.hazelcast.impl.Node.<init>(Node.java:191)
at com.hazelcast.impl.FactoryImpl.<init>(FactoryImpl.java:252)
at com.hazelcast.impl.FactoryImpl.newHazelcastInstanceProxy
(FactoryImpl.java:93)
at com.hazelcast.core.Hazelcast.newHazelcastInstance
(Hazelcast.java:171)
at com.vpfw.ClusterTest3.start(ClusterTest3.java:36)
at com.vpfw.ClusterTest3.main(ClusterTest3.java:19)

I'm not sure if the problem is my hazelcast.xml or my code. I'd like
to leave the xml as empty as possible and define everything
declaritavily.

Bob
> For more seehttp://code.google.com/docreader/#p=hazelcast&s=hazelcast&t=ClusterTe...

Talip Ozturk

unread,
Dec 14, 2009, 8:09:25 AM12/14/09
to hazelcast
Hazelcast reports you that
"Hazelcast CANNOT start on this node. No matching network
interface found."

This means. You defined which interface (ip) Hazelcast should bind to
and no such interface is found. Notice that you enabled interfaces:
<interfaces enabled="true"/>
but you didn't specify any interface.


If you want to configure everything programmatically then here is the
config you should use.

Config cfg = new XmlConfigBuilder().build();
// turn of the multicast
cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
JoinMembers tcpconfig = cfg.getNetworkConfig().getJoin().getJoinMembers();
// turn on the tcp/ip join
tcpconfig.setEnabled(true);
List<String> lsMembers = tcpconfig.getMembers();
lsMembers.clear();
lsMembers.add("192.168.0.1");
lsMembers.add("192.168.0.2");
// declare the interface Hazelcast should bind to
cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled
(false);
cfg.getNetworkConfig().getInterfaces().clear();
// find and bind to any interface matching 192.168.0.*
cfg.getNetworkConfig().getInterfaces().addInterface("192.168.0.*");
cfg.getNetworkConfig().getInterfaces().setEnabled(true);

I am assuming that machines in your cluster have 192.168.0.* ips..

If you are still confused, please read these first:
http://code.google.com/docreader/#p=hazelcast&s=hazelcast&t=ConfigFullTcpIp
http://code.google.com/docreader/#p=hazelcast&s=hazelcast&t=ConfigSpecifyInterfaces


-talip
> --
>
> You received this message because you are subscribed to the Google Groups "Hazelcast" group.
> To post to this group, send email to haze...@googlegroups.com.
> To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.
>
>
>

syg6

unread,
Dec 14, 2009, 10:16:22 AM12/14/09
to Hazelcast
Wicked. Thanks Talip, that worked.

I had read the documentation about specifying network interfaces and
TCP/IP cluster but it all references hazelcast.xml, there's not much
on how to do this stuff programatically.

I wasn't clear on the difference between the JoinMembers and
Interfaces. But now I get it.

Cheers,
Bob
> If you are still confused, please read these first:http://code.google.com/docreader/#p=hazelcast&s=hazelcast&t=ConfigFul...http://code.google.com/docreader/#p=hazelcast&s=hazelcast&t=ConfigSpe...
Reply all
Reply to author
Forward
0 new messages