Example usage for java.net InetSocketAddress getAddress

List of usage examples for java.net InetSocketAddress getAddress

Introduction

In this page you can find the example usage for java.net InetSocketAddress getAddress.

Prototype

public final InetAddress getAddress() 

Source Link

Document

Gets the InetAddress .

Usage

From source file:de.cubeisland.engine.core.webapi.ApiServer.java

/**
 * Checks whether an InetSocketAddress is blacklisted
 *
 * @param ip the IP//from  www  . j av  a2  s  . c o  m
 * @return true if it is
 */
public boolean isBlacklisted(InetSocketAddress ip) {
    return this.isBlacklisted(ip.getAddress());
}

From source file:de.cubeisland.engine.core.webapi.ApiServer.java

public void unWhitelistAddress(InetSocketAddress address) {
    this.unWhitelistAddress(address.getAddress());
}

From source file:de.cubeisland.engine.core.webapi.ApiServer.java

public void unBlacklistAddress(InetSocketAddress address) {
    this.unBlacklistAddress(address.getAddress());
}

From source file:org.apache.nifi.cluster.protocol.impl.ClusterServiceDiscovery.java

public ClusterServiceDiscovery(final String serviceName, final InetSocketAddress multicastAddress,
        final MulticastConfiguration multicastConfiguration,
        final ProtocolContext<ProtocolMessage> protocolContext) {

    if (StringUtils.isBlank(serviceName)) {
        throw new IllegalArgumentException("Service name may not be null or empty.");
    } else if (multicastAddress == null) {
        throw new IllegalArgumentException("Multicast address may not be null.");
    } else if (multicastAddress.getAddress().isMulticastAddress() == false) {
        throw new IllegalArgumentException("Multicast group must be a Class D address.");
    } else if (protocolContext == null) {
        throw new IllegalArgumentException("Protocol Context may not be null.");
    } else if (multicastConfiguration == null) {
        throw new IllegalArgumentException("Multicast configuration may not be null.");
    }/*from ww w .  jav  a  2s .  co  m*/

    this.serviceName = serviceName;
    this.multicastConfiguration = multicastConfiguration;
    this.listener = new MulticastProtocolListener(1, multicastAddress, multicastConfiguration, protocolContext);
    listener.addHandler(new ClusterManagerServiceBroadcastHandler());
}

From source file:org.apache.hadoop.security.TestSecurityUtil.java

private void verifyValues(InetSocketAddress addr, String host, String ip, int port) {
    assertTrue(!addr.isUnresolved());/*  w w w .  j  a  v a 2 s.com*/
    // don't know what the standard resolver will return for hostname.
    // should be host for host; host or ip for ip is ambiguous
    if (!SecurityUtil.useIpForTokenService) {
        assertEquals(host, addr.getHostName());
        assertEquals(host, addr.getAddress().getHostName());
    }
    assertEquals(ip, addr.getAddress().getHostAddress());
    assertEquals(port, addr.getPort());
}

From source file:com.offbynull.portmapper.upnpigd.UpnpIgdDiscovery.java

private static Set<UpnpIgdDevice> scanForDevices(InetSocketAddress multicastSocketAddress,
        Set<InetAddress> localAddresses, String searchQuery) throws IOException, InterruptedException {

    final Set<UpnpIgdDevice> ret = Collections.synchronizedSet(new HashSet<UpnpIgdDevice>());
    final Map<Channel, InetAddress> bindMap = Collections.synchronizedMap(new HashMap<Channel, InetAddress>());

    UdpCommunicatorListener listener = new UdpCommunicatorListener() {

        @Override/*ww w  .ja va2  s  .c o  m*/
        public void incomingPacket(InetSocketAddress sourceAddress, DatagramChannel channel,
                ByteBuffer packet) {
            byte[] inPacket = ByteBufferUtils.copyContentsToArray(packet);

            String inStr;
            try {
                inStr = new String(inPacket, 0, inPacket.length, "US-ASCII");
            } catch (UnsupportedEncodingException uee) {
                return;
            }

            Matcher matcher;

            URI url;
            if ((matcher = LOCATION_PATTERN.matcher(inStr)).find()) {
                String urlStr = matcher.group(1);
                try {
                    url = new URI(urlStr);
                } catch (URISyntaxException urise) {
                    return;
                }
            } else {
                return;
            }

            String name = null;
            if ((matcher = SERVER_PATTERN.matcher(inStr)).find()) {
                name = matcher.group(1);
            }

            InetAddress localAddress = bindMap.get(channel);

            UpnpIgdDevice device = new UpnpIgdDevice(localAddress, sourceAddress.getAddress(), name, url);
            ret.add(device);
        }
    };

    UdpCommunicator comm = null;
    try {
        List<DatagramChannel> channels = new ArrayList<>();

        for (InetAddress localAddr : localAddresses) {
            DatagramChannel channel = DatagramChannel.open();
            channel.configureBlocking(false);
            channel.bind(new InetSocketAddress(localAddr, 0));
            channels.add(channel);

            bindMap.put(channel, localAddr);
        }

        comm = new UdpCommunicator(channels);
        comm.startAsync().awaitRunning();
        comm.addListener(listener);

        ByteBuffer searchQueryBuffer = ByteBuffer.wrap(searchQuery.getBytes("US-ASCII")).asReadOnlyBuffer();
        for (int i = 0; i < 3; i++) {
            for (DatagramChannel channel : channels) {
                comm.send(channel, multicastSocketAddress, searchQueryBuffer.asReadOnlyBuffer());
            }

            Thread.sleep(TimeUnit.SECONDS.toMillis(MAX_WAIT + 1));
        }

        return new HashSet<>(ret);
    } finally {
        if (comm != null) {
            try {
                comm.stopAsync().awaitTerminated(); // this stop should handle closing all the datagram channels
            } catch (IllegalStateException ise) { // NOPMD
                // do nothing
            }
        }
    }
}

From source file:org.apparatus_templi.Coordinator.java

/**
 * Start the web server on the port specified in {@link Prefs} bound to the address specified in
 * {@link Prefs}. If the specified host and port can not be bound to then will sutdown the
 * entire service.//from   w w  w .  j a v  a2s.c  o m
 * 
 * @throws UnknownHostException
 *             if the address could not be bound to.
 */
private static void startWebServer(InetSocketAddress socket) throws UnknownHostException {
    assert webServer == null : "Can not start web server with one already running";

    if (socket != null) {
        Log.d(TAG, "starting web server at " + socket.getAddress().getHostAddress() + ":" + socket.getPort());
    } else {
        Log.d(TAG, "starting web server");
    }

    try {
        if ("true".equals(prefs.getPreference(Prefs.Keys.encryptServer))) {
            webServer = new org.apparatus_templi.web.EncryptedWebServer(socket);
        } else {
            webServer = new org.apparatus_templi.web.WebServer(socket);
        }
    } catch (Exception e) {
        // there are a number of exceptions that can be thrown, all are
        // terminal errors
        Log.t(TAG, e.getMessage());
        Coordinator.exitWithReason(e.getMessage());
    }

    try {
        webServer.setResourceFolder(prefs.getPreference(Prefs.Keys.webResourceFolder));
    } catch (IllegalArgumentException e) {
        Coordinator.exitWithReason("Unable to set web server resource folder " + e.getMessage());
    }

    webServer.start();
    sysTray.setStatus(SysTray.Status.RUNNING);
}

From source file:com.alibaba.dragoon.common.protocol.transport.socket.SocketConnector.java

public Future<DragoonSession> connect(final SocketAddress address, final MessageHandler messageHandler) {
    if (address == null) {
        throw new IllegalArgumentException("address is null");
    }//from w  w  w .  j  av a  2  s  . c o m

    if (!(address instanceof InetSocketAddress)) {
        throw new IllegalArgumentException("address must be VmPipeAddress.");
    }

    final InetSocketAddress inetSocketAddress = (InetSocketAddress) address;

    FutureTask<DragoonSession> task = new FutureTask<DragoonSession>(new Callable<DragoonSession>() {

        public DragoonSession call() throws Exception {
            connectCount.incrementAndGet();
            if (LOG.isInfoEnabled()) {
                LOG.info("CONNECT TO " + inetSocketAddress);
            }

            remoteAddress = inetSocketAddress.toString();
            Socket socket = new Socket(inetSocketAddress.getAddress(), inetSocketAddress.getPort());

            connectEstablishedCount.incrementAndGet();

            if (LOG.isInfoEnabled()) {
                LOG.info("CONNECTED TO " + inetSocketAddress);
            }

            SocketSessionImpl impl = new SocketSessionImpl(socket, receivedBytes, receivedMessages, sentBytes,
                    sentMessages);

            final long sessionId = generateSessionId();

            DragoonSession session = new DragoonSession(sessionId, new DragoonSessionConfig(messageHandler),
                    impl);
            impl.init(session);

            return session;
        }

    });
    connectorExecutor.submit(task);

    return task;
}

From source file:edu.umass.cs.reconfiguration.reconfigurationutils.ConsistentReconfigurableNodeConfig.java

/**
 * This method tries to return a limited number of active replica socket
 * addresses that to the extent possible have distinct IPs. The socket
 * addresses are a randomly chosen subset of size up to limit from the set
 * of all active replicas.//w  w w  . ja va 2  s  . c om
 * 
 * @param limit
 * @return Socket addresses of active replicas. Used by reconfigurator to
 *         respond to broadcast queries.
 */
public Set<InetSocketAddress> getActiveReplicaSocketAddresses(int limit) {
    Set<InetSocketAddress> actives = new HashSet<InetSocketAddress>();
    Set<Integer> activeIPs = new HashSet<Integer>();
    ArrayList<InetSocketAddress> activeNodes = new ArrayList<InetSocketAddress>();
    ArrayList<InetSocketAddress> duplicateIPs = new ArrayList<InetSocketAddress>();

    /* Create up to limit-sized ArrayList for shuffling. First add socket
     * addresses corresponding to distinct /24 IP prefixes. */
    for (NodeIDType node : this.getActiveReplicas()) {
        InetSocketAddress sockAddr = this.getNodeSocketAddress(node);
        if (!activeIPs.contains(RTTEstimator.addrToPrefixInt(sockAddr.getAddress()))) {
            activeNodes.add(sockAddr);
            activeIPs.add(RTTEstimator.addrToPrefixInt(sockAddr.getAddress()));
        } else
            duplicateIPs.add(sockAddr);
        if (activeNodes.size() >= limit)
            break;
    }
    /* Then check if we can add back some of the socket addresses with
     * duplicate /24 prefixes up to limit. */
    if (activeNodes.size() < limit) {
        for (InetSocketAddress duplicate : duplicateIPs) {
            activeNodes.add(duplicate);
            if (activeNodes.size() >= limit)
                break;
        }
    }

    // shuffle to return actives in random order
    Collections.shuffle(activeNodes);
    for (InetSocketAddress sockAddr : activeNodes) {
        actives.add(sockAddr);
        if (actives.size() >= limit)
            break;
    }
    return actives;
}