Java Code Examples for java.net.Inet4Address.getByName()

The following are Jave code examples for showing how to use getByName() of the java.net.Inet4Address class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: nighthawk   File: JaRedisInterceptor.java   Source Code and License Vote up 6 votes
private void beginTrace(Jedis jedis, Method method) {
    if (isTraceEnabled()) {
        try {
            InetAddress address = Inet4Address.getByName(jedis.getClient().getHost());
            int port = jedis.getClient().getPort();
            String serviceName = "redis-DB-" + jedis.getClient().getDB();
            Beginning beginning = new Beginning();
            beginning.setSpanName(serviceName);
            beginning.setAddress(address);
            beginning.setPort(port);
            beginning.addAnnotation("execute.command", method.getName());
            beginTrace(beginning);
        } catch (Exception e) {
            setClientSent();
        }
    }
}
 
Example 2
Project: nighthawk   File: StatementTracer.java   Source Code and License Vote up 6 votes
public void beginTrace(String sql, String url) {
    if (isTraceEnabled()) {
        try {
            String afterJDBC = url.substring(5); // jdbc:
            String scheme = afterJDBC.substring(0, afterJDBC.indexOf(":"));
            URLParser parser = parsers.get(scheme);
            if (parser == null) {
                throw new IllegalStateException("unknown db scheme: " + scheme);
            }
            DatabaseURL databaseUrl = parser.parse(url);
            String serviceName = scheme + "-" + databaseUrl.getDataBase();
            InetAddress address = Inet4Address.getByName(databaseUrl.getHost());
            Beginning beginning = new Beginning();
            beginning.setSpanName(serviceName);
            beginning.setAddress(address);
            beginning.setPort(databaseUrl.getPort());
            beginning.addAnnotation("execute.sql", sql);
            beginTrace(beginning);
        } catch (Exception e) {
            setClientSent();
        }
    }
}
 
Example 3
Project: jaer   File: SpiNNaker_InterfaceFactory.java   Source Code and License Vote up 6 votes
private void pingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pingButtonActionPerformed
       String host = hostTF.getText();
     try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        InetAddress adr = Inet4Address.getByName(host);
        try{
            adr.isReachable(3000);
            JOptionPane.showMessageDialog(this, host+" is reachable, but it may not be the SpiNNaker!");
        }catch(IOException notReachable){
            JOptionPane.showMessageDialog(this, host+" is not reachable: "+notReachable.toString(), "Not reachable", JOptionPane.WARNING_MESSAGE);
        }
    } catch (UnknownHostException ex) {
              JOptionPane.showMessageDialog(this, host+" is unknown host: "+ex.toString(), "Host not found", JOptionPane.WARNING_MESSAGE);
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }

}
 
Example 4
Project: jaer   File: eDVS128_InterfaceFactory.java   Source Code and License Vote up 6 votes
private void pingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pingButtonActionPerformed
    String host = hostTF.getText();
    try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        InetAddress adr = Inet4Address.getByName(host);
        try {
            adr.isReachable(3000);
            JOptionPane.showMessageDialog(this, host + " is reachable. However it may not be the eDVS!");
        } catch (IOException notReachable) {
            JOptionPane.showMessageDialog(this, host + " is not reachable: " + notReachable.toString(), "Not reachable", JOptionPane.WARNING_MESSAGE);
        }
    } catch (UnknownHostException ex) {
        JOptionPane.showMessageDialog(this, host + " is unknown host: " + ex.toString(), "Host not found", JOptionPane.WARNING_MESSAGE);
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }

}
 
Example 5
Project: FinalSpeed   File: CapEnv.java   Source Code and License Vote up 6 votes
public void createTcpTun_Client(String dstAddress,short dstPort) throws Exception{
	Inet4Address serverAddress=(Inet4Address) Inet4Address.getByName(dstAddress);
	TCPTun conn=new TCPTun(this,serverAddress,dstPort,local_mac,gateway_mac);
	tcpManager.addConnection_Client(conn);
	boolean success=false;
	for(int i=0;i<6;i++){
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if(conn.preDataReady){
			success=true;
			break;
		}
	}
	if(success){
		tcpManager.setDefaultTcpTun(conn);
	}else {
		tcpManager.removeTun(conn);
		tcpManager.setDefaultTcpTun(null);
		throw new Exception("创建隧道失败!");
	}
}