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;
}
}
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");
}
});
});
}
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);
}
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);
}
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");
}
Aggregations