Example usage for java.net InetAddress getByName

List of usage examples for java.net InetAddress getByName

Introduction

In this page you can find the example usage for java.net InetAddress getByName.

Prototype

public static InetAddress getByName(String host) throws UnknownHostException 

Source Link

Document

Determines the IP address of a host, given the host's name.

Usage

From source file:com.stratio.cassandra.index.schema.ColumnMapperInet.java

/** {@inheritDoc} */
@Override//from w ww. ja v a  2  s.  co  m
public String indexValue(String name, Object value) {
    if (value == null) {
        return null;
    } else if (value instanceof InetAddress) {
        InetAddress inetAddress = (InetAddress) value;
        return inetAddress.getHostAddress();
    } else if (value instanceof String) {
        String svalue = (String) value;
        if (IPV4_PATTERN.matcher(svalue).matches() || IPV6_PATTERN.matcher(svalue).matches()
                || IPV6_COMPRESSED_PATTERN.matcher(svalue).matches()) {
            try {
                return InetAddress.getByName(svalue).getHostAddress();
            } catch (UnknownHostException e) {
                Log.error(e, e.getMessage());
            }
        }
    }
    throw new IllegalArgumentException(String.format("Value '%s' cannot be cast to InetAddress", value));
}

From source file:com.adito.tunnels.agent.RemoteTunnel.java

/**
 * Constructor./*from   ww  w.  j ava 2s.  c  o m*/
 * 
 * @param tunnel tunnel
 * @param agent agent
 * @param tunnelManager tunnel manager
 * @param launchSession launch session
 * @throws IOException
 */
public RemoteTunnel(Tunnel tunnel, AgentTunnel agent, RemoteTunnelManager tunnelManager,
        LaunchSession launchSession) throws IOException {
    this.agent = agent;
    this.tunnel = tunnel;
    this.launchSession = launchSession;
    this.tunnelManager = tunnelManager;
    listeningSocket = CustomServerSocketFactory.getDefault().createServerSocket(tunnel.getSourcePort(), 50,
            Util.isNullOrTrimmedBlank(tunnel.getSourceInterface()) ? null
                    : InetAddress.getByName(tunnel.getSourceInterface()));

}

From source file:com.dropbox.presto.kafka.KafkaSplit.java

@JsonCreator
public KafkaSplit(@JsonProperty("clientId") String clientId, @JsonProperty("topicName") String topicName,
        @JsonProperty("partitionId") int partitionId, @JsonProperty("brokerHost") String brokerHost,
        @JsonProperty("brokerPort") int brokerPort, @JsonProperty("sampleRate") int sampleRate,
        @JsonProperty("startTs") long startTs, @JsonProperty("endTs") long endTs,
        @JsonProperty("zookeeper") String zookeeper, @JsonProperty("zkSessionTimeout") int zkSessionTimeout,
        @JsonProperty("zkConnectTimeout") int zkConnectTimeout) {
    checkNotNull(clientId, "clientId is null");
    checkNotNull(topicName, "topicName is null");
    checkNotNull(partitionId, "partitionId is null");
    checkNotNull(startTs, "startTs is null");
    checkNotNull(endTs, "endTs is null");
    this.clientId = clientId;
    this.topicName = topicName;
    this.partitionId = partitionId;
    this.brokerHost = brokerHost;
    this.brokerPort = brokerPort;
    this.sampleRate = sampleRate;
    this.startTs = startTs;
    this.endTs = endTs;
    this.zookeeper = zookeeper;
    this.zkSessionTimeout = zkSessionTimeout;
    this.zkConnectTimeout = zkConnectTimeout;
    try {/*from  w  ww . j a v a  2s.  c om*/
        InetAddress address = InetAddress.getByName(brokerHost);
        this.address = HostAddress.fromParts(address.getHostAddress(), 8080);
    } catch (UnknownHostException ex) {
        throw new RuntimeException(ex.toString());
    }
}

From source file:net.sf.firemox.network.Client.java

@Override
public void run() {
    String entree;//from w ww.ja  v  a 2 s. co m
    LoaderConsole.beginTask(LanguageManager.getString("wiz_network.creatingconnection") + "...", 2);
    InetAddress adr = null;
    try {
        // Connexion au serveur
        adr = InetAddress.getByName(Configuration.getString("ip"));
        clientSocket = new Socket(adr, port);
    } catch (IOException e) {
        // echec de la connexion au serveur
        JOptionPane.showMessageDialog(MagicUIComponents.magicForm,
                LanguageManager.getString("wiz_network.cannotconnectto", adr) + ", "
                        + LanguageManager.getString("wiz_network.port") + ":" + port + ". \n"
                        + LanguageManager.getString("wiz_network.port.invalid"),
                LanguageManager.getString("wiz_network.connectionpb"), JOptionPane.WARNING_MESSAGE);
        NetworkActor.cancelling = true;
        LoaderConsole.endTask();
    }

    // stopping?
    if (cancelling) {
        cancelConnexion();
        return;
    }
    LoaderConsole.beginTask(LanguageManager.getString("wiz_network.connecting"), 5);

    try {
        // Cration des flots d'entre/sortie
        outBin = clientSocket.getOutputStream();
        inBin = clientSocket.getInputStream();

        // need password?
        entree = MToolKit.readString(inBin);
        if (STR_PASSWD.equals(entree)) {
            // a password is need by this server
            if (passwd == null) {
                // ... but we haven't any
                LoaderConsole.beginTask(LanguageManager.getString("wiz_network.password.missed"));
                MToolKit.writeString(outBin, STR_NOPASSWD);
                // close stream
                IOUtils.closeQuietly(inBin);
                IOUtils.closeQuietly(outBin);
                // free pointers
                outBin = null;
                inBin = null;
            } else {
                // send our password
                MToolKit.writeString(outBin, new String(passwd));
                entree = MToolKit.readString(inBin);
                if (STR_WRONGPASSWD.equals(entree)) {
                    // wrong password
                    LoaderConsole.beginTask(LanguageManager.getString("wiz_network.password.invalid"));
                    // close stream
                    IOUtils.closeQuietly(inBin);
                    IOUtils.closeQuietly(outBin);
                    // free pointers
                    outBin = null;
                    inBin = null;
                }
            }
        }
        if (outBin != null && !STR_OK.equals(entree)) {
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.unknowncommand") + entree);
            // close stream
            IOUtils.closeQuietly(inBin);
            IOUtils.closeQuietly(outBin);
            // free pointers
            outBin = null;
            inBin = null;
        }
        if (outBin != null) {
            // send our version
            MToolKit.writeString(outBin, IdConst.VERSION);
            entree = MToolKit.readString(inBin);
            if (STR_WRONGVERSION.equals(entree)) {
                // wrong version
                LoaderConsole.beginTask(LanguageManager.getString("wiz_network.differentversionpb"));
                // close stream
                IOUtils.closeQuietly(inBin);
                IOUtils.closeQuietly(outBin);
                // free pointers
                outBin = null;
                inBin = null;
            }
        }
        if (outBin != null && !STR_OK.equals(entree)) {
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.unknowncommand") + entree);
            // close stream
            IOUtils.closeQuietly(inBin);
            IOUtils.closeQuietly(outBin);
            // free pointers
            outBin = null;
            inBin = null;
        }

        if (outBin != null) {
            /*
             * client is connected to the server client/serveur I am ...
             */
            MToolKit.writeString(outBin, nickName);
            // Opponent is ...
            String serverName = MToolKit.readString(inBin);
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.opponentis") + serverName, 10);

            // exchange shared string settings
            ((Opponent) StackManager.PLAYERS[1]).readSettings(serverName, nickName, inBin);
            ((You) StackManager.PLAYERS[0]).sendSettings(outBin);

            // stopping?
            if (cancelling) {
                cancelConnexion();
                return;
            }

            // receive, and set the random seed
            long seed = Long.parseLong(MToolKit.readString(inBin));
            MToolKit.random.setSeed(seed);
            Log.info("Seed = " + seed);

            // read mana use option
            PayMana.useMana = Integer.parseInt(MToolKit.readString(inBin)) == 1;

            // read opponent response option
            WaitActivatedChoice.opponentResponse = Integer.parseInt(MToolKit.readString(inBin)) == 1;

            // Who starts?
            final StartingOption startingOption = StartingOption.values()[Integer
                    .valueOf(MToolKit.readString(inBin)).intValue()];
            final boolean serverStarts;
            switch (startingOption) {
            case random:
            default:
                serverStarts = MToolKit.random.nextBoolean();
                break;
            case server:
                serverStarts = true;
                break;
            case client:
                serverStarts = false;
            }

            if (serverStarts) {
                // server begins
                LoaderConsole.beginTask(LanguageManager.getString("wiz_network.opponentwillstart") + " (mode="
                        + startingOption.getLocaleValue() + ")", 15);
                StackManager.idActivePlayer = 1;
                StackManager.idCurrentPlayer = 1;
            } else {
                // client begins
                LoaderConsole.beginTask(LanguageManager.getString("wiz_network.youwillstarts") + " (mode="
                        + startingOption.getLocaleValue() + ")", 15);
                StackManager.idActivePlayer = 0;
                StackManager.idCurrentPlayer = 0;
            }

            // load rules from the MDB file
            dbStream = MdbLoader.loadMDB(MToolKit.mdbFile, StackManager.idActivePlayer);
            TableTop.getInstance().initTbs();

            // send our deck
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.sendingdeck"), 25);
            deck.send(outBin);
            StackManager.PLAYERS[0].zoneManager.giveCards(deck, dbStream);
            MToolKit.writeString(outBin, "%EOF%");
            outBin.flush();

            // stopping?
            if (cancelling) {
                cancelConnexion();
                return;
            }

            // receive her/his deck
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.receivingdeck"), 55);
            readAndValidateOpponentDeck();

            // free resources
            LoaderConsole.setTaskPercent(100);

            // stopping?
            if (cancelling) {
                cancelConnexion();
                return;
            }

            // stopping?
            if (cancelling) {
                cancelConnexion();
                return;
            }

            initBigPipe();
            MagicUIComponents.magicForm.initGame();
        }
    } catch (Throwable e) {
        NetworkActor.cancelling = true;
        LoaderConsole.endTask();
        cancelConnexion();
        Log.error(e);
        throw new RuntimeException(LanguageManager.getString("wiz_network.badconnection", adr), e);
    }
}

From source file:com.clustercontrol.systemlog.util.SyslogReceiver.java

public synchronized void start() throws SocketException, UnknownHostException {
    log.info(String.format("starting SyslogReceiver. [address = %s, port = %s, charset = %s, handler = %s]",
            listenAddress, listenPort, charset.name(), _handler.getClass().getName()));

    // ?????????handler, receiver, socket?????

    // ???Hinemos???Listen???
    if (!HinemosManagerMain._isClustered) {
        socket = new DatagramSocket(listenPort, InetAddress.getByName(listenAddress));
        socket.setReceiveBufferSize(socketBufferSize);
        socket.setSoTimeout(socketTimeout);
    }/*w  w  w.  j ava  2  s.c  o m*/

    _executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "SystemLogReceiver");
        }
    });

    _handler.start();

    if (!HinemosManagerMain._isClustered) {
        _executor.submit(new ReceiverTask(socket, _handler));
    }
}

From source file:org.alfresco.test.wqs.web.publications.PublicationActions.java

@Override
@BeforeClass(alwaysRun = true)/*  w  w w  .j a v  a  2 s .  c o m*/
public void setup() throws Exception {

    testName = this.getClass().getSimpleName();
    siteName = testName;
    hostName = (shareUrl).replaceAll(".*\\//|\\:.*", "");
    try {
        ipAddress = InetAddress.getByName(hostName).toString().replaceAll(".*/", "");
        logger.info("Ip address from Alfresco server was obtained");
    } catch (UnknownHostException | SecurityException e) {
        logger.error("Ip address from Alfresco server could not be obtained");
    }
    wqsURL = siteName + ":8080/wcmqs";
    logger.info(" wcmqs url : " + wqsURL);
    logger.info("Start Tests from: " + testName);
}

From source file:it.anyplace.sync.core.beans.DeviceAddress.java

public InetAddress getInetAddress() {
    try {/*w ww. ja v a2s .c  o m*/
        return InetAddress
                .getByName(address.replaceFirst("^[^:]+://", "").replaceFirst("(:[0-9]+)?(/.*)?$", ""));
    } catch (UnknownHostException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.ibm.crail.storage.nvmf.NvmfStorageTier.java

public void init(CrailConfiguration crailConfiguration, String[] args) throws IOException {

    if (initialized) {
        throw new IOException("NvmfStorageTier already initialized");
    }/*from ww w  .  j  a v  a  2 s  .  c om*/
    initialized = true;

    NvmfStorageConstants.updateConstants(crailConfiguration);

    if (args != null) {
        Options options = new Options();
        Option bindIp = Option.builder("a").desc("ip address to bind to").hasArg().build();
        Option port = Option.builder("p").desc("port to bind to").hasArg().type(Number.class).build();
        Option pcieAddress = Option.builder("s").desc("PCIe address of NVMe device").hasArg().build();
        options.addOption(bindIp);
        options.addOption(port);
        options.addOption(pcieAddress);
        CommandLineParser parser = new DefaultParser();
        HelpFormatter formatter = new HelpFormatter();
        CommandLine line = null;
        try {
            line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length));
            if (line.hasOption(port.getOpt())) {
                NvmfStorageConstants.PORT = ((Number) line.getParsedOptionValue(port.getOpt())).intValue();
            }
        } catch (ParseException e) {
            System.err.println(e.getMessage());
            formatter.printHelp("NVMe storage tier", options);
            System.exit(-1);
        }
        if (line.hasOption(bindIp.getOpt())) {
            NvmfStorageConstants.IP_ADDR = InetAddress.getByName(line.getOptionValue(bindIp.getOpt()));
        }
        if (line.hasOption(pcieAddress.getOpt())) {
            NvmfStorageConstants.PCIE_ADDR = line.getOptionValue(pcieAddress.getOpt());
        }
    }

    NvmfStorageConstants.verify();
}

From source file:com.aurel.track.dbase.DatabaseHandler.java

/**
 * Start the database server. If it was running, stop it first.
 *///from   w  ww.  jav  a  2s .c  om
public static void startDbServer() {
    System.setProperty("derby.drda.startNetworkServer", "true");
    stopDbServer();
    try {
        dbServer = new NetworkServerControl(InetAddress.getByName("localhost"), 15270, user, password);
        java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true);
        dbServer.start(consoleWriter);
        checkForDatabase();
    } catch (Exception e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
}

From source file:zipkin.autoconfigure.storage.mysql.brave.TraceZipkinMySQLStorageAutoConfiguration.java

/** Attach the IP of the remote datasource, knowing that DNS may invalidate this */
@Bean/*from  w ww .ja v  a  2  s .c om*/
@Qualifier("mysql")
Endpoint mysql() throws UnknownHostException {
    int ipv4 = ByteBuffer.wrap(InetAddress.getByName(mysql.getHost()).getAddress()).getInt();
    return Endpoint.builder().serviceName("mysql").ipv4(ipv4).port(mysql.getPort()).build();
}