Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scheduled-executor] ScheduledTaskHandler.of(urn) fails when IPv6 address is used #10898

Closed
mdogan opened this issue Jul 10, 2017 · 0 comments
Closed

Comments

@mdogan
Copy link
Contributor

@mdogan mdogan commented Jul 10, 2017

ScheduledTaskHandlerImpl.of(urn) assumes address is IPv4.

    public static void main(String[] args) throws Exception {
        setIPv6Address();

        HazelcastInstance instance = Hazelcast.newHazelcastInstance();
        IScheduledExecutorService scheduler = instance.getScheduledExecutorService("scheduler");
        IScheduledFuture<?> future = scheduler.scheduleOnMember(new Runnable() {
            @Override
            public void run() {
            }
        }, instance.getCluster().getLocalMember(), 1, TimeUnit.HOURS);

        String urn = future.getHandler().toUrn();
        future = scheduler.getScheduledFuture(ScheduledTaskHandler.of(urn));
    }

    private static void setIPv6Address() throws SocketException {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = networkInterfaces.nextElement();
            Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
            while (inetAddresses.hasMoreElements()) {
                InetAddress address = inetAddresses.nextElement();
                if (!address.isLoopbackAddress() && address instanceof Inet6Address) {
                    System.setProperty("hazelcast.local.localAddress", address.getHostAddress());
                    return;
                }
            }
        }
    }

Or simply;

    public static void main(String[] args) throws Exception {
        Address address = new Address("fe80:9a5a:ebff:fe8e::f228", 5701);
        ScheduledTaskHandler handler = ScheduledTaskHandlerImpl.of(address, "scheduler", "task");
        ScheduledTaskHandlerImpl.of(handler.toUrn());
    }

fails with

Exception in thread "main" java.lang.NumberFormatException: For input string: "9a5a"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.parseInt(Integer.java:615)
	at com.hazelcast.scheduledexecutor.impl.ScheduledTaskHandlerImpl.of(ScheduledTaskHandlerImpl.java:191)
@mmedenjak mmedenjak added this to the 3.9 milestone Jul 10, 2017
@mmedenjak mmedenjak changed the title ScheduledTaskHandler.of(urn) fails when IPv6 address is used [scheduled-executor] ScheduledTaskHandler.of(urn) fails when IPv6 address is used Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.