Example usage for java.net UnknownHostException getMessage

List of usage examples for java.net UnknownHostException getMessage

Introduction

In this page you can find the example usage for java.net UnknownHostException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.flink.runtime.jobmanager.JobManager.java

public JobManager(ExecutionMode executionMode) throws Exception {

    final String ipcAddressString = GlobalConfiguration.getString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY,
            null);//  w w  w.ja  v  a  2s .c om

    InetAddress ipcAddress = null;
    if (ipcAddressString != null) {
        try {
            ipcAddress = InetAddress.getByName(ipcAddressString);
        } catch (UnknownHostException e) {
            throw new Exception("Cannot convert " + ipcAddressString + " to an IP address: " + e.getMessage(),
                    e);
        }
    }

    final int ipcPort = GlobalConfiguration.getInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY,
            ConfigConstants.DEFAULT_JOB_MANAGER_IPC_PORT);

    // Read the suggested client polling interval
    this.recommendedClientPollingInterval = GlobalConfiguration.getInteger(
            ConfigConstants.JOBCLIENT_POLLING_INTERVAL_KEY, ConfigConstants.DEFAULT_JOBCLIENT_POLLING_INTERVAL);

    // read the default number of times that failed tasks should be re-executed
    this.defaultExecutionRetries = GlobalConfiguration.getInteger(ConfigConstants.DEFAULT_EXECUTION_RETRIES_KEY,
            ConfigConstants.DEFAULT_EXECUTION_RETRIES);

    // delay between retries should be one heartbeat timeout
    this.delayBetweenRetries = 2
            * GlobalConfiguration.getLong(ConfigConstants.JOB_MANAGER_DEAD_TASKMANAGER_TIMEOUT_KEY,
                    ConfigConstants.DEFAULT_JOB_MANAGER_DEAD_TASKMANAGER_TIMEOUT);

    // Load the job progress collector
    this.eventCollector = new EventCollector(this.recommendedClientPollingInterval);

    this.libraryCacheManager = new BlobLibraryCacheManager(new BlobServer(),
            GlobalConfiguration.getConfiguration());

    // Register simple job archive
    int archived_items = GlobalConfiguration.getInteger(ConfigConstants.JOB_MANAGER_WEB_ARCHIVE_COUNT,
            ConfigConstants.DEFAULT_JOB_MANAGER_WEB_ARCHIVE_COUNT);
    if (archived_items > 0) {
        this.archive = new MemoryArchivist(archived_items);
        this.eventCollector.registerArchivist(archive);
    } else {
        this.archive = null;
    }

    this.currentJobs = new ConcurrentHashMap<JobID, ExecutionGraph>();

    // Create the accumulator manager, with same archiving limit as web
    // interface. We need to store the accumulators for at least one job.
    // Otherwise they might be deleted before the client requested the
    // accumulator results.
    this.accumulatorManager = new AccumulatorManager(Math.min(1, archived_items));

    // Determine own RPC address
    final InetSocketAddress rpcServerAddress = new InetSocketAddress(ipcAddress, ipcPort);

    // Start job manager's IPC server
    try {
        final int handlerCount = GlobalConfiguration.getInteger(ConfigConstants.JOB_MANAGER_IPC_HANDLERS_KEY,
                ConfigConstants.DEFAULT_JOB_MANAGER_IPC_HANDLERS);
        this.jobManagerServer = RPC.getServer(this, rpcServerAddress.getHostName(), rpcServerAddress.getPort(),
                handlerCount);
        this.jobManagerServer.start();
    } catch (IOException e) {
        throw new Exception("Cannot start RPC server: " + e.getMessage(), e);
    }

    LOG.info("Starting job manager in " + executionMode + " mode");

    // Try to load the instance manager for the given execution mode
    if (executionMode == ExecutionMode.LOCAL) {
        final int numTaskManagers = GlobalConfiguration
                .getInteger(ConfigConstants.LOCAL_INSTANCE_MANAGER_NUMBER_TASK_MANAGER, 1);
        this.instanceManager = new LocalInstanceManager(numTaskManagers);
    } else if (executionMode == ExecutionMode.CLUSTER) {
        this.instanceManager = new InstanceManager();
    } else {
        throw new IllegalArgumentException("ExecutionMode");
    }

    // create the scheduler and make it listen at the availability of new instances
    this.scheduler = new Scheduler(this.executorService);
    this.instanceManager.addInstanceListener(this.scheduler);
}

From source file:pl.project13.maven.git.GitCommitIdMojo.java

void loadBuildHostData(@NotNull Properties properties) {
    String buildHost = null;//from ww w  . j av a 2  s.c  om
    try {
        buildHost = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        log.info("Unable to get build host, skipping property {}. Error message: {}", BUILD_HOST,
                e.getMessage());
    }
    put(properties, BUILD_HOST, buildHost);
}

From source file:com.mobicage.rpc.http.HttpCommunicator.java

private void doCommunication(final HttpProtocol protocol, final boolean force, final int loopCount,
        final WakeLockReleaseRunnable wakeLockReleaseRunnable, final CommunicationResultHandler resultHandler) {
    T.BIZZ();//from w  w  w.j  a v a2 s .  c  o m

    debugLog("doCommunication - force = " + force + " - loopCount = " + loopCount);
    boolean filterOnWifiOnly = mWifiOnlyEnabled
            && !mMainService.getNetworkConnectivityManager().isWifiConnected();
    broadcastHtppStartOutgoingCalls(filterOnWifiOnly);
    final String callsJSONString = getJSONRepresentationForOutgoingCalls(filterOnWifiOnly);
    final boolean hasNoOutgoingCallsInBacklog = callsJSONString.equals("[]");

    if (!force && protocol.getAckIDsToSend().size() == 0 && protocol.getResponseIDsToSend().size() == 0
            && hasNoOutgoingCallsInBacklog) {
        resultHandler.handle(STATUS_COMMUNICATION_FINISHED_NO_WORK_DONE);
        return;
    }

    synchronized (mStateMachineLock) {
        if (mIsCommunicating && loopCount == 1) {
            debugLog("Skipping duplicate first loop of doCommunication()");
            mKickReceived = true;
            wakeLockReleaseRunnable.run();
            return;
        } else {
            debugLog("Setting mIsCommunicating from " + mIsCommunicating + " to true for loop " + loopCount);
            mIsCommunicating = true;
        }
    }

    final StringBuilder sb = new StringBuilder("{\"av\":1, \"c\":");
    sb.append(getJSONRepresentationForOutgoingCalls(filterOnWifiOnly));
    sb.append(", \"r\":");
    sb.append(getJSONRepresentationForOutgoingResponses(protocol));
    sb.append(", \"a\":");
    sb.append(getJSONRepresentationForOutgoingAcks(protocol));
    sb.append("}");

    protocol.getAckIDsToSend().clear();
    protocol.getResponseIDsToSend().clear();

    mNetworkHandler.post(new Runnable() {
        @Override
        public void run() {
            String tmpResponse = null;
            long before = 0;
            long after = 0;
            try {
                before = System.currentTimeMillis();
                tmpResponse = doSynchronousRequest(protocol.getHttpClient(), sb.toString());
                after = System.currentTimeMillis();
                debugLog("HTTP request (loop=" + loopCount + ") finished in " + (after - before) + " millis");
            } catch (UnknownHostException e) {
                debugLog(e.getMessage());
            } catch (HttpHostConnectException e) {
                debugLog(e.getMessage());
            } catch (ServerRespondedWrongHTTPCodeException e) {
                debugLog(e.getMessage(), e);
            } catch (SSLException e) {
                debugLog(e);
            } catch (SocketTimeoutException e) {
                debugLog(e);
            } catch (IOException e) {
                debugLog(e);
            } catch (Exception e) {
                bugLog(e);
            }
            final String response = tmpResponse;
            final long fbefore = before;
            final long fafter = after;
            mMainService.postOnBIZZHandler(new SafeRunnable() {
                @Override
                protected void safeRun() throws Exception {
                    T.BIZZ();
                    if (response == null) {
                        redoCommunicationForError(protocol, force, loopCount, wakeLockReleaseRunnable,
                                resultHandler);
                        return;
                    }
                    HttpProtocol.ProtocolDetails pd = protocol.processIncomingMessagesString(response);
                    if (pd.serverTime != 0) {
                        final long serverTimestamp = pd.serverTime * 1000;
                        if (fafter - fbefore < 5000) {
                            final long localCorrelationTimestamp = fafter - (fafter - fbefore) / 2;
                            final long adjustedTimeDiff = serverTimestamp - localCorrelationTimestamp;
                            mMainService.setAdjustedTimeDiff(adjustedTimeDiff);
                        }
                    }
                    if (pd.more) {
                        resultHandler.handle(STATUS_COMMUNICATION_SERVER_HAS_MORE);
                        return;
                    }
                    if (hasNoOutgoingCallsInBacklog && protocol.getAckIDsToSend().size() == 0
                            && protocol.getResponseIDsToSend().size() == 0) {
                        resultHandler.handle(STATUS_COMMUNICATION_FINISHED_WORK_DONE);
                        return;
                    }
                    resultHandler.handle(STATUS_COMMUNICATION_CONTINUE);
                }
            });
        }
    });
}

From source file:net.jetrix.config.ServerConfig.java

public void setHost(String hostname) {
    // a value of "[ALL]" stands for any IP
    if (!"[ALL]".equals(hostname)) {
        try {/*from   ww  w . j a  va2s  .  c o m*/
            host = InetAddress.getByName(hostname);
        } catch (UnknownHostException e) {
            log.log(Level.WARNING, e.getMessage(), e);
        }
    } else {
        host = null;
    }
}

From source file:org.opendaylight.controller.forwardingrulesmanager.internal.ForwardingRulesManagerIT.java

@Test
public void testFlowEntries() {
    Flow flow = new Flow();

    Match match = new Match();
    try {//  w w  w .jav a 2 s. c o  m
        match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
    } catch (UnknownHostException e) {
    }
    flow.setMatch(match);
    Action action = new Drop();

    List<Action> actions = new ArrayList<Action>();
    actions.add(action);
    flow.setActions(actions);
    Node node;
    try {
        // Must use a node published by the stub protocol plugin else
        // connection manager will not report it as a local node
        node = new Node("STUB", 51966);
        FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
        Status stat = manager.installFlowEntry(fe);

        Assert.assertTrue(stat.getCode() == StatusCode.SUCCESS);
    } catch (ConstructionException e) {
        // Got a failure while allocating the node
        fail("Failed while allocating the node " + e.getMessage());
    }
}

From source file:ai.susi.server.ClientConnection.java

private void init() throws IOException {

    this.httpResponse = null;
    try {/*from   w  ww  . j  ava2s.  c om*/
        this.httpResponse = httpClient.execute(this.request);
    } catch (UnknownHostException e) {
        this.request.releaseConnection();
        throw new IOException("client connection failed: unknown host " + this.request.getURI().getHost());
    } catch (SocketTimeoutException e) {
        this.request.releaseConnection();
        throw new IOException("client connection timeout for request: " + this.request.getURI());
    } catch (SSLHandshakeException e) {
        this.request.releaseConnection();
        throw new IOException("client connection handshake error for domain " + this.request.getURI().getHost()
                + ": " + e.getMessage());
    }
    HttpEntity httpEntity = this.httpResponse.getEntity();
    if (httpEntity != null) {
        if (this.httpResponse.getStatusLine().getStatusCode() == 200) {
            try {
                this.inputStream = new BufferedInputStream(httpEntity.getContent());
            } catch (IOException e) {
                this.request.releaseConnection();
                throw e;
            }
            this.header = new HashMap<String, List<String>>();
            for (Header header : httpResponse.getAllHeaders()) {
                List<String> vals = this.header.get(header.getName());
                if (vals == null) {
                    vals = new ArrayList<String>();
                    this.header.put(header.getName(), vals);
                }
                vals.add(header.getValue());
            }
        } else {
            this.request.releaseConnection();
            throw new IOException("client connection to " + this.request.getURI() + " fail: " + status + ": "
                    + httpResponse.getStatusLine().getReasonPhrase());
        }
    } else {
        this.request.releaseConnection();
        throw new IOException("client connection to " + this.request.getURI() + " fail: no connection");
    }
}

From source file:org.loklak.http.ClientConnection.java

private void init() throws IOException {

    this.httpResponse = null;
    try {//w w  w  . j  ava 2s  . co  m
        this.httpResponse = httpClient.execute(this.request);
    } catch (UnknownHostException e) {
        this.request.releaseConnection();
        throw new IOException("client connection failed: unknown host " + this.request.getURI().getHost());
    } catch (SocketTimeoutException e) {
        this.request.releaseConnection();
        throw new IOException("client connection timeout for request: " + this.request.getURI());
    } catch (SSLHandshakeException e) {
        this.request.releaseConnection();
        throw new IOException("client connection handshake error for domain " + this.request.getURI().getHost()
                + ": " + e.getMessage());
    } catch (Throwable e) {
        this.request.releaseConnection();
        throw new IOException("server fail: " + e.getMessage());
    }
    HttpEntity httpEntity = this.httpResponse.getEntity();
    if (httpEntity != null) {
        if (this.httpResponse.getStatusLine().getStatusCode() == 200) {
            try {
                this.inputStream = new BufferedInputStream(httpEntity.getContent());
            } catch (IOException e) {
                this.request.releaseConnection();
                throw e;
            }
            this.header = new HashMap<String, List<String>>();
            for (Header header : httpResponse.getAllHeaders()) {
                List<String> vals = this.header.get(header.getName());
                if (vals == null) {
                    vals = new ArrayList<String>();
                    this.header.put(header.getName(), vals);
                }
                vals.add(header.getValue());
            }
        } else {
            this.request.releaseConnection();
            throw new IOException("client connection to " + this.request.getURI() + " fail: " + status + ": "
                    + httpResponse.getStatusLine().getReasonPhrase());
        }
    } else {
        this.request.releaseConnection();
        throw new IOException("client connection to " + this.request.getURI() + " fail: no connection");
    }
}

From source file:org.parosproxy.paros.core.proxy.ProxyServer.java

/**
 *
 * @return   true = the server is started successfully.
 *///from   ww  w. j ava 2 s .c o m
public synchronized int startServer(String ip, int port, boolean isDynamicPort) {

    if (isProxyRunning) {
        stopServer();
    }

    isProxyRunning = false;

    // ZAP: Set the name of the thread.
    thread = new Thread(this, "ZAP-ProxyServer");
    thread.setDaemon(true);
    // the priority below should be higher than normal to allow fast accept on the server socket
    thread.setPriority(Thread.NORM_PRIORITY + 1);

    proxySocket = null;
    for (int i = 0; i < 20 && proxySocket == null; i++) {
        try {
            proxySocket = createServerSocket(ip, port);
            proxySocket.setSoTimeout(PORT_TIME_OUT);
            isProxyRunning = true;

        } catch (UnknownHostException e) {
            // ZAP: Warn the user if the host is unknown
            if (View.isInitialised()) {
                View.getSingleton()
                        .showWarningDialog(Constant.messages.getString("proxy.error.host.unknow") + " " + ip);

            } else {
                System.out.println(Constant.messages.getString("proxy.error.host.unknow") + " " + ip);
            }

            return -1;
        } catch (BindException e) {
            if ("Cannot assign requested address".equals(e.getMessage())) {
                showErrorMessage(Constant.messages.getString("proxy.error.address") + " " + ip);
                return -1;
            } else if ("Permission denied".equals(e.getMessage())
                    || "Address already in use".equals(e.getMessage())) {
                if (!isDynamicPort) {
                    showErrorMessage(Constant.messages.getString("proxy.error.port") + " " + ip + ":" + port);
                    return -1;
                } else if (port < 65535) {
                    port++;
                }
            } else {
                handleUnknownException(e);
                return -1;
            }
        } catch (IOException e) {
            handleUnknownException(e);
            return -1;
        }

    }

    if (proxySocket == null) {
        return -1;
    }

    thread.start();

    return proxySocket.getLocalPort();

}

From source file:com.frand.easyandroid.http.FFHttpRequest.java

private void makeRequestWithRetries() throws ConnectException {
    boolean retry = true;
    IOException cause = null;//from w  w  w  .  ja  v  a 2s. com
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            makeRequest();
            return;
        } catch (UnknownHostException e) {
            if (responseHandler != null) {
                responseHandler.sendFailureMsg(e, reqTag, reqUrl);
            }
            return;
        } catch (SocketException e) {
            if (responseHandler != null) {
                responseHandler.sendFailureMsg(e, reqTag, reqUrl);
            }
            return;
        } catch (SocketTimeoutException e) {
            if (responseHandler != null) {
                responseHandler.sendFailureMsg(e, reqTag, reqUrl);
            }
            return;
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }
    ConnectException ex = new ConnectException();
    ex.initCause(cause);
    throw ex;
}

From source file:net.yacy.grid.http.ClientConnection.java

private void init() throws IOException {

    this.httpResponse = null;
    try {/*from  ww w  . j  av a 2  s .  co m*/
        this.httpResponse = httpClient.execute(this.request);
    } catch (UnknownHostException e) {
        this.request.releaseConnection();
        throw new IOException("client connection failed: unknown host " + this.request.getURI().getHost());
    } catch (SocketTimeoutException e) {
        this.request.releaseConnection();
        throw new IOException("client connection timeout for request: " + this.request.getURI());
    } catch (SSLHandshakeException e) {
        this.request.releaseConnection();
        throw new IOException("client connection handshake error for domain " + this.request.getURI().getHost()
                + ": " + e.getMessage());
    }
    HttpEntity httpEntity = this.httpResponse.getEntity();
    this.contentType = ContentType.get(httpEntity);
    if (httpEntity != null) {
        if (this.httpResponse.getStatusLine().getStatusCode() == 200) {
            try {
                this.inputStream = new BufferedInputStream(httpEntity.getContent());
            } catch (IOException e) {
                this.request.releaseConnection();
                throw e;
            }
            this.header = new HashMap<String, List<String>>();
            for (Header header : httpResponse.getAllHeaders()) {
                List<String> vals = this.header.get(header.getName());
                if (vals == null) {
                    vals = new ArrayList<String>();
                    this.header.put(header.getName(), vals);
                }
                vals.add(header.getValue());
            }
        } else {
            this.request.releaseConnection();
            throw new IOException("client connection to " + this.request.getURI() + " fail: " + status + ": "
                    + httpResponse.getStatusLine().getReasonPhrase());
        }
    } else {
        this.request.releaseConnection();
        throw new IOException("client connection to " + this.request.getURI() + " fail: no connection");
    }
}