Search in sources :

Example 71 with ConnectException

use of java.net.ConnectException in project CloudStack-archive by CloudStack-extras.

the class NioConnection method run.

@Override
public void run() {
    synchronized (_thread) {
        try {
            init();
        } catch (ConnectException e) {
            s_logger.error("Unable to connect to remote");
            return;
        } catch (IOException e) {
            s_logger.error("Unable to initialize the threads.", e);
            return;
        } catch (Exception e) {
            s_logger.error("Unable to initialize the threads due to unknown exception.", e);
            return;
        }
        _isStartup = true;
        _thread.notifyAll();
    }
    while (_isRunning) {
        try {
            _selector.select();
            // Someone is ready for I/O, get the ready keys
            Set<SelectionKey> readyKeys = _selector.selectedKeys();
            Iterator<SelectionKey> i = readyKeys.iterator();
            if (s_logger.isTraceEnabled()) {
                s_logger.trace("Keys Processing: " + readyKeys.size());
            }
            // Walk through the ready keys collection.
            while (i.hasNext()) {
                SelectionKey sk = i.next();
                i.remove();
                if (!sk.isValid()) {
                    if (s_logger.isTraceEnabled()) {
                        s_logger.trace("Selection Key is invalid: " + sk.toString());
                    }
                    Link link = (Link) sk.attachment();
                    if (link != null) {
                        link.terminated();
                    } else {
                        closeConnection(sk);
                    }
                } else if (sk.isReadable()) {
                    read(sk);
                } else if (sk.isWritable()) {
                    write(sk);
                } else if (sk.isAcceptable()) {
                    accept(sk);
                } else if (sk.isConnectable()) {
                    connect(sk);
                }
            }
            s_logger.trace("Keys Done Processing.");
            processTodos();
        } catch (Throwable e) {
            s_logger.warn("Caught an exception but continuing on.", e);
        }
    }
    synchronized (_thread) {
        _isStartup = false;
    }
}
Also used : SelectionKey(java.nio.channels.SelectionKey) IOException(java.io.IOException) CancelledKeyException(java.nio.channels.CancelledKeyException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Example 72 with ConnectException

use of java.net.ConnectException in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method connectFailureNotifiesHandlerWithConnectException.

@Test
public void connectFailureNotifiesHandlerWithConnectException() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            final CountDownLatch l = new CountDownLatch(1);
            int port = findFreePort();
            client.prepareGet(String.format("http://localhost:%d/", port)).execute(new AsyncCompletionHandlerAdapter() {

                @Override
                public void onThrowable(Throwable t) {
                    try {
                        assertTrue(t instanceof ConnectException);
                    } finally {
                        l.countDown();
                    }
                }
            });
            if (!l.await(TIMEOUT, SECONDS)) {
                fail("Timed out");
            }
        });
    });
}
Also used : AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectException(java.net.ConnectException) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Example 73 with ConnectException

use of java.net.ConnectException in project timber by JakeWharton.

the class TimberTest method exceptionOnly.

@Test
public void exceptionOnly() {
    Timber.plant(new Timber.DebugTree());
    Timber.v(new IllegalArgumentException());
    assertExceptionLogged(Log.VERBOSE, null, "java.lang.IllegalArgumentException", "TimberTest", 0);
    Timber.i(new NullPointerException());
    assertExceptionLogged(Log.INFO, null, "java.lang.NullPointerException", "TimberTest", 1);
    Timber.d(new UnsupportedOperationException());
    assertExceptionLogged(Log.DEBUG, null, "java.lang.UnsupportedOperationException", "TimberTest", 2);
    Timber.w(new UnknownHostException());
    assertExceptionLogged(Log.WARN, null, "java.net.UnknownHostException", "TimberTest", 3);
    Timber.e(new ConnectException());
    assertExceptionLogged(Log.ERROR, null, "java.net.ConnectException", "TimberTest", 4);
    Timber.wtf(new AssertionError());
    assertExceptionLogged(Log.ASSERT, null, "java.lang.AssertionError", "TimberTest", 5);
}
Also used : UnknownHostException(java.net.UnknownHostException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 74 with ConnectException

use of java.net.ConnectException in project async-http-client by AsyncHttpClient.

the class NettyConnectListener method onFailure.

public void onFailure(Channel channel, Throwable cause) {
    // beware, channel can be null
    abortChannelPreemption(channel);
    boolean canRetry = future.incrementRetryAndCheck();
    LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry);
    if (//
    canRetry && // FIXME when can we have a null cause?
    cause != null && (future.getChannelState() != ChannelState.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) {
        if (requestSender.retry(future)) {
            return;
        }
    }
    LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel);
    boolean printCause = cause.getMessage() != null;
    String printedCause = printCause ? cause.getMessage() : getBaseUrl(future.getUri());
    ConnectException e = new ConnectException(printedCause);
    e.initCause(cause);
    future.abort(e);
}
Also used : ConnectException(java.net.ConnectException)

Example 75 with ConnectException

use of java.net.ConnectException in project midpoint by Evolveum.

the class DummyConnector method delete.

/**
     * {@inheritDoc}
     */
public void delete(final ObjectClass objectClass, final Uid uid, final OperationOptions options) {
    log.info("delete::begin");
    validate(objectClass);
    validate(uid);
    String id = uid.getUidValue();
    try {
        if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                resource.deleteAccountByName(id);
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                resource.deleteAccountById(id);
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
        } else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                resource.deleteGroupByName(id);
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                resource.deleteGroupById(id);
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
        } else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                resource.deletePrivilegeByName(id);
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                resource.deletePrivilegeById(id);
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
        } else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                resource.deleteOrgByName(id);
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                resource.deleteOrgById(id);
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
        } else {
            throw new ConnectorException("Unknown object class " + objectClass);
        }
    } catch (ObjectDoesNotExistException e) {
        // The framework should deal with it ... somehow
        throw new UnknownUidException(e.getMessage(), e);
    } catch (ConnectException e) {
        log.info("delete::exception " + e);
        throw new ConnectionFailedException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        log.info("delete::exception " + e);
        throw new ConnectorIOException(e.getMessage(), e);
    } catch (SchemaViolationException e) {
        log.info("delete::exception " + e);
        throw new InvalidAttributeValueException(e.getMessage(), e);
    } catch (ConflictException e) {
        log.info("delete::exception " + e);
        throw new AlreadyExistsException(e);
    }
    log.info("delete::end");
}
Also used : ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) ConflictException(com.evolveum.icf.dummy.resource.ConflictException) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) ObjectDoesNotExistException(com.evolveum.icf.dummy.resource.ObjectDoesNotExistException) UnknownUidException(org.identityconnectors.framework.common.exceptions.UnknownUidException) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)253 IOException (java.io.IOException)110 Socket (java.net.Socket)57 Test (org.junit.Test)43 InetSocketAddress (java.net.InetSocketAddress)41 SocketTimeoutException (java.net.SocketTimeoutException)35 UnknownHostException (java.net.UnknownHostException)30 InetAddress (java.net.InetAddress)24 FileNotFoundException (java.io.FileNotFoundException)22 InterruptedIOException (java.io.InterruptedIOException)20 SocketException (java.net.SocketException)20 NoRouteToHostException (java.net.NoRouteToHostException)19 InputStreamReader (java.io.InputStreamReader)18 URL (java.net.URL)16 InputStream (java.io.InputStream)14 HttpURLConnection (java.net.HttpURLConnection)14 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)13 BufferedReader (java.io.BufferedReader)12 OutputStream (java.io.OutputStream)12 Exchange (org.apache.camel.Exchange)12