List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:eu.smeny.jpapercut.smtp.MailServer.java
public static String retrieveHostname() { String hostname;//from ww w .j av a 2s . co m try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { // Tries environment variables hostname = System.getenv("COMPUTERNAME"); if (StringUtils.isEmpty(hostname)) { hostname = System.getenv("HOSTNAME"); } if (StringUtils.isEmpty(hostname)) { hostname = "localhost"; } } return hostname; }
From source file:com.amazonaws.services.kinesis.flume.KinesisSource.java
@Override public void configure(Context context) { String endpoint = context.getString("endpoint", ConfigurationConstants.DEFAULT_KINESIS_ENDPOINT); String streamName = Preconditions.checkNotNull(context.getString("streamName"), "streamName is required"); String applicationName = Preconditions.checkNotNull(context.getString("applicationName"), "applicationName is required"); String initialPosition = context.getString("initialPosition", "TRIM_HORIZON"); String workerId = null;//from ww w . j av a 2s . c o m if (initialPosition.equals("LATEST")) { DEFAULT_INITIAL_POSITION = InitialPositionInStream.LATEST; } String accessKeyId = context.getString("accessKeyId"); String secretAccessKey = context.getString("secretAccessKey"); AWSCredentialsProvider credentialsProvider; if (accessKeyId != null && secretAccessKey != null) { credentialsProvider = new MyAwsCredentials(accessKeyId, secretAccessKey); } else { credentialsProvider = new DefaultAWSCredentialsProviderChain(); } try { workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID(); } catch (UnknownHostException e) { e.printStackTrace(); } LOG.info("Using workerId: " + workerId); kinesisClientLibConfiguration = new KinesisClientLibConfiguration(applicationName, streamName, credentialsProvider, workerId).withKinesisEndpoint(endpoint) .withInitialPositionInStream(DEFAULT_INITIAL_POSITION); }
From source file:UUIDGenerator.java
private static synchronized void initializeForType1() { if (RANDOM != null) return;/*from w ww. j a v a 2 s . c om*/ // note that secure random is very slow the first time // it is used; consider switching to a standard random RANDOM = new SecureRandom(); _seq = (short) RANDOM.nextInt(MAX_14BIT); byte[] ip = null; try { ip = InetAddress.getLocalHost().getAddress(); } catch (IOException ioe) { throw new RuntimeException(ioe); } IP = new byte[6]; RANDOM.nextBytes(IP); System.arraycopy(ip, 0, IP, 2, ip.length); }
From source file:com.cloudera.branchreduce.impl.thrift.LordMain.java
@Override public int run(String[] args) throws Exception { LOG.info("Initializing lord..."); initialize(args);// w w w .ja va 2s .c o m LOG.info("Lord initialized."); String hostname = InetAddress.getLocalHost().getHostName(); ServerSocket socket = new ServerSocket(0); ApplicationMasterParameters appMasterParams = new LuaApplicationMasterParameters(getConf(), ImmutableMap.<String, Object>of("MASTER_HOSTNAME", hostname, "MASTER_PORT", socket.getLocalPort())); appMasterParams.setTrackingUrl(String.format("%s:%d", hostname, socket.getLocalPort())); ApplicationMasterService appMasterService = new ApplicationMasterServiceImpl(appMasterParams, getConf()); LOG.info("Starting application master service"); appMasterService.startAndWait(); TaskMaster taskMaster = new TaskMaster(numVassals, initialTasks, globalState); LordHandler lordHandler = new LordHandler(taskMaster); TServerSocket serverTransport = new TServerSocket(socket); Lord.Processor lordProc = new Lord.Processor(lordHandler); final TServer thriftServer = new TThreadPoolServer( new TThreadPoolServer.Args(serverTransport).processor(lordProc)); LOG.info("Starting lord thrift server"); Thread thriftServerThread = new Thread("Lord Thrift Server") { @Override public void run() { thriftServer.serve(); }; }; thriftServerThread.start(); do { Thread.sleep(1000); } while (appMasterService.hasRunningContainers()); // Send final notifications lordHandler.signalJobFinished(); while (!lordHandler.finishedNotificationSent()) { Thread.sleep(1000); } thriftServerThread.join(1000); LOG.info("Stopping application master service"); appMasterService.stopAndWait(); return 0; }
From source file:org.log.kafka.consumer.MessageConsumer.java
public MessageConsumer(DataProcessor insertRowForLogDB) { this.rowDataProcessor = insertRowForLogDB; getKafkaConsumer();/*from www.j av a 2 s. com*/ try { SERVER_NAME = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { SERVER_NAME = "UnKnownHost"; } }
From source file:org.aludratest.service.gui.web.selenium.httpproxy.AuthenticatingHttpProxy.java
/** Constructor with the central configuration settings. */ public AuthenticatingHttpProxy(int localPort, String targetHost, int targetPort) { try {/*www . j a va 2 s .co m*/ this.localHost = InetAddress.getLocalHost().getHostAddress(); this.localPort = localPort; this.realHost = new HttpHost(targetHost, targetPort); this.customHeaders = new HashMap<String, String>(); this.running = false; this.serverThread = null; } catch (UnknownHostException e) { throw new AutomationException("Error initializing " + getClass(), e); } }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.cda.HttpQueryBackend.java
public static Credentials getCredentials(final String user, final String password) { if (StringUtils.isEmpty(user)) { return null; }/* w w w. java 2 s . co m*/ final int domainIdx = user.indexOf(DOMAIN_SEPARATOR); if (domainIdx == -1) { return new UsernamePasswordCredentials(user, password); } try { final String domain = user.substring(0, domainIdx); final String username = user.substring(domainIdx + 1); final String host = InetAddress.getLocalHost().getHostName(); return new NTCredentials(username, password, host, domain); } catch (UnknownHostException uhe) { return new UsernamePasswordCredentials(user, password); } }
From source file:au.com.jwatmuff.eventmanager.Main.java
private static boolean updateRmiHostName() { try {//from w ww .j av a2 s . co m String existingHostName = System.getProperty("java.rmi.server.hostname"); String newHostName = InetAddress.getLocalHost().getHostAddress(); if (!ObjectUtils.equals(existingHostName, newHostName)) { log.info("Updating RMI hostname to: " + newHostName); System.setProperty("java.rmi.server.hostname", newHostName); return true; } } catch (Exception e) { } return false; }
From source file:com.zxy.commons.apidocs.conf.ApplicationSwaggerConfig.java
@Bean public Docket appApi() { Docket docket = new Docket(DocumentationType.SWAGGER_2); // if(groupName!=null && groupName.length() > 0) { // docket.groupName(groupName); // }// w w w . j av a2 s. co m String host = env.getProperty("apidocs.host", ""); String port = env.getProperty("apidocs.port", ""); String basePath = env.getProperty("apidocs.basepath", ""); if (StringUtils.isEmpty(host)) { try { host = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { host = "localhost"; } } if (!StringUtils.isEmpty(port)) { docket.host(host + ":" + port); } else { docket.host(host); } if (!StringUtils.isEmpty(basePath)) { docket.pathProvider(new AbstractPathProvider() { @Override protected String getDocumentationPath() { return "/"; } @Override protected String applicationPath() { return basePath; } }); } ApiSelectorBuilder builder = docket.apiInfo(apiInfo()) // .enable(enabled) .forCodeGeneration(true).select(); Predicate<String> paths = appPaths(); if (paths != null) { builder.paths(paths); } return builder.build(); }
From source file:com.tc.server.UpdateCheckAction.java
private int getClientId() { try {/* w ww. java 2 s . com*/ return InetAddress.getLocalHost().hashCode(); } catch (Throwable t) { return 0; } }