use of java.nio.channels.UnresolvedAddressException in project j2objc by google.
the class AsynchronousSocketChannelTest method test_connect_unresolvedAddress.
public void test_connect_unresolvedAddress() throws Exception {
AsynchronousSocketChannel asc = AsynchronousSocketChannel.open();
try {
asc.connect(new InetSocketAddress("unresolvedname", 31415));
fail();
} catch (UnresolvedAddressException expected) {
}
assertNull(asc.getRemoteAddress());
assertTrue(asc.isOpen());
asc.close();
}
use of java.nio.channels.UnresolvedAddressException in project j2objc by google.
the class AsynchronousServerSocketChannelTest method test_bind_unresolvedAddress.
public void test_bind_unresolvedAddress() throws Throwable {
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
try {
assc.bind(new InetSocketAddress("unresolvedname", 31415));
fail();
} catch (UnresolvedAddressException expected) {
}
assertNull(assc.getLocalAddress());
assertTrue(assc.isOpen());
assc.close();
}
use of java.nio.channels.UnresolvedAddressException in project jstorm by alibaba.
the class KafkaConsumer method fetchMessages.
public ByteBufferMessageSet fetchMessages(int partition, long offset) throws IOException {
String topic = config.topic;
FetchRequest req = new FetchRequestBuilder().clientId(config.clientId).addFetch(topic, partition, offset, config.fetchMaxBytes).maxWait(config.fetchWaitMaxMs).build();
FetchResponse fetchResponse = null;
SimpleConsumer simpleConsumer = null;
try {
simpleConsumer = findLeaderConsumer(partition);
if (simpleConsumer == null) {
// LOG.error(message);
return null;
}
fetchResponse = simpleConsumer.fetch(req);
} catch (Exception e) {
if (e instanceof ConnectException || e instanceof SocketTimeoutException || e instanceof IOException || e instanceof UnresolvedAddressException) {
LOG.warn("Network error when fetching messages:", e);
if (simpleConsumer != null) {
String host = simpleConsumer.host();
int port = simpleConsumer.port();
simpleConsumer = null;
throw new KafkaException("Network error when fetching messages: " + host + ":" + port + " , " + e.getMessage(), e);
}
} else {
throw new RuntimeException(e);
}
}
if (fetchResponse.hasError()) {
short code = fetchResponse.errorCode(topic, partition);
if (code == ErrorMapping.OffsetOutOfRangeCode() && config.resetOffsetIfOutOfRange) {
long startOffset = getOffset(topic, partition, config.startOffsetTime);
offset = startOffset;
}
if (leaderBroker != null) {
LOG.error("fetch data from kafka topic[" + config.topic + "] host[" + leaderBroker.host() + ":" + leaderBroker.port() + "] partition[" + partition + "] error:" + code);
} else {
}
return null;
} else {
ByteBufferMessageSet msgs = fetchResponse.messageSet(topic, partition);
return msgs;
}
}
use of java.nio.channels.UnresolvedAddressException in project storm by apache.
the class KafkaUtils method fetchMessages.
public static ByteBufferMessageSet fetchMessages(KafkaConfig config, SimpleConsumer consumer, Partition partition, long offset) throws TopicOffsetOutOfRangeException, FailedFetchException, RuntimeException {
ByteBufferMessageSet msgs = null;
String topic = partition.topic;
int partitionId = partition.partition;
FetchRequestBuilder builder = new FetchRequestBuilder();
FetchRequest fetchRequest = builder.addFetch(topic, partitionId, offset, config.fetchSizeBytes).clientId(config.clientId).maxWait(config.fetchMaxWait).minBytes(config.minFetchByte).build();
FetchResponse fetchResponse;
try {
fetchResponse = consumer.fetch(fetchRequest);
} catch (Exception e) {
if (e instanceof ConnectException || e instanceof SocketTimeoutException || e instanceof IOException || e instanceof UnresolvedAddressException) {
LOG.warn("Network error when fetching messages:", e);
throw new FailedFetchException(e);
} else {
throw new RuntimeException(e);
}
}
if (fetchResponse.hasError()) {
KafkaError error = KafkaError.getError(fetchResponse.errorCode(topic, partitionId));
if (error.equals(KafkaError.OFFSET_OUT_OF_RANGE) && config.useStartOffsetTimeIfOffsetOutOfRange) {
String msg = partition + " Got fetch request with offset out of range: [" + offset + "]";
LOG.warn(msg);
throw new TopicOffsetOutOfRangeException(msg);
} else {
String message = "Error fetching data from [" + partition + "] for topic [" + topic + "]: [" + error + "]";
LOG.error(message);
throw new FailedFetchException(message);
}
} else {
msgs = fetchResponse.messageSet(topic, partitionId);
}
LOG.debug("Messages fetched. [config = {}], [consumer = {}], [partition = {}], [offset = {}], [msgs = {}]", config, consumer, partition, offset, msgs);
return msgs;
}
use of java.nio.channels.UnresolvedAddressException in project robovm by robovm.
the class SocketChannelTest method testCFII_Unresolved.
public void testCFII_Unresolved() throws IOException {
statusNotConnected_NotPending();
InetSocketAddress unresolved = new InetSocketAddress("unresolved address", 1080);
try {
this.channel1.connect(unresolved);
fail("Should throw an UnresolvedAddressException here.");
} catch (UnresolvedAddressException e) {
// OK.
}
}
Aggregations