本文整理汇总了Java中java.nio.channels.UnresolvedAddressException类的典型用法代码示例。如果您正苦于以下问题:Java UnresolvedAddressException类的具体用法?Java UnresolvedAddressException怎么用?Java UnresolvedAddressException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnresolvedAddressException类属于java.nio.channels包,在下文中一共展示了UnresolvedAddressException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClient
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <X extends TAsyncClient> X getClient(final Class<X> clazz) {
return (X) super.clients.computeIfAbsent(ClassNameUtils.getOuterClassName(clazz), (className) -> {
TProtocolFactory protocolFactory = (TProtocolFactory) tTransport -> {
TProtocol protocol = new TBinaryProtocol(tTransport);
return new TMultiplexedProtocol(protocol, className);
};
try {
return clazz.getConstructor(TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class)
.newInstance(protocolFactory, this.clientManager, this.transport);
} catch (Throwable e) {
if (e instanceof UnresolvedAddressException) {
this.isOpen = false;
}
return null;
}
});
}
示例2: onError
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
@Override
public void onError(Exception ex) {
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(stringWriter);
try {
writer.beginObject();
writer.name("event").value("onError");
if (ex instanceof UnresolvedAddressException) {
writer.name("errorCode").value("ERR_NAME_NOT_RESOLVED");
writer.name("errorMessage").value("Unable to resolve address. Please check the url and your network connection");
} else {
writer.name("errorCode").value("ERR_NAME_UNKNOWN");
writer.name("errorMessage").value("Unknown error was thrown");
}
writer.endObject();
} catch (IOException e) {
e.printStackTrace();
}
this.callback(PluginResult.Status.OK, stringWriter.toString());
}
示例3: sendMessageToHyVarRec
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
protected String sendMessageToHyVarRec(String message, URI uri) throws UnresolvedAddressException, ExecutionException, InterruptedException, TimeoutException {
HttpClient hyvarrecClient = new HttpClient();
try {
hyvarrecClient.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
URI hyvarrecUri = uri;
Request hyvarrecRequest = hyvarrecClient.POST(hyvarrecUri);
hyvarrecRequest.header(HttpHeader.CONTENT_TYPE, "application/json");
hyvarrecRequest.content(new StringContentProvider(message), "application/json");
ContentResponse hyvarrecResponse;
String hyvarrecAnswerString = "";
hyvarrecResponse = hyvarrecRequest.send();
hyvarrecAnswerString = hyvarrecResponse.getContentAsString();
// Only for Debug
System.err.println("HyVarRec Answer: "+hyvarrecAnswerString);
return hyvarrecAnswerString;
}
示例4: newOutgoingConnection
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
public T newOutgoingConnection(InetSocketAddress dest, ConnectionListener listener) throws IOException {
SocketChannel channel;
channel = SocketChannel.open();
if (dest.isUnresolved()) {
Log.warning("Unresolved InetSocketAddress: "+ dest);
throw new ConnectException("Unresolved InetSocketAddress"+ dest.toString());
}
LWTThreadUtil.setBlocked();
try {
channel.socket().connect(dest, defSocketConnectTimeout);
//channel.connect(dest);
} catch (UnresolvedAddressException uae) {
Log.logErrorWarning(uae);
Log.warning(dest);
throw new ConnectException(dest.toString());
} finally {
LWTThreadUtil.setNonBlocked();
}
return addConnection(channel, listener);
}
示例5: connect
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
public boolean connect (SocketAddress remote, int timeout) throws IOException
{
if (!isOpen())
throw new ClosedChannelException();
if (isConnected())
throw new AlreadyConnectedException();
if (connectionPending)
throw new ConnectionPendingException();
if (!(remote instanceof InetSocketAddress))
throw new UnsupportedAddressTypeException();
connectAddress = (InetSocketAddress) remote;
if (connectAddress.isUnresolved())
throw new UnresolvedAddressException();
connected = channel.connect(connectAddress, timeout);
connectionPending = !connected;
return connected;
}
示例6: connect
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
public boolean connect (SocketAddress remote, int timeout) throws IOException
{
if (!isOpen())
throw new ClosedChannelException();
if (isConnected())
throw new AlreadyConnectedException();
if (connectionPending)
throw new ConnectionPendingException();
if (!(remote instanceof InetSocketAddress))
throw new UnsupportedAddressTypeException();
connectAddress = (InetSocketAddress) remote;
if (connectAddress.isUnresolved())
throw new UnresolvedAddressException();
connected = channel.connect(connectAddress, timeout);
connectionPending = !connected;
return connected;
}
示例7: connect
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
public ConnectFuture connect() {
connectFuture = new ConnectFuture();
runLoop.execute(new Runnable() {
public void run() {
try {
channel = SocketChannel.open();
channel.configureBlocking(false);
channel.connect(new InetSocketAddress(origin.getHost(), origin.getPort()));
reregister();
} catch (IOException | UnresolvedAddressException e) {
connectFuture.fail(e);
closed = true;
}
}
});
return connectFuture;
}
示例8: testUnresolvedException
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
@Test
public void testUnresolvedException() throws IOException, InterruptedException
{
final DefaultEventLoop eventLoop = DefaultEventLoop.createEventLoop("test");
final CountDownLatch handled = new CountDownLatch(1);
final ClientImpl client = new ClientImpl()
{
@Override
public void handleException(Exception cce, EventLoop el)
{
assertSame(el, eventLoop);
assertTrue(cce instanceof RuntimeException);
assertTrue(cce.getCause() instanceof UnresolvedAddressException);
super.handleException(cce, el);
handled.countDown();
}
};
verifyUnresolvedException(client, eventLoop, handled);
}
示例9: testUnresolvedException
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
@Test
public void testUnresolvedException() throws IOException, InterruptedException
{
final DefaultEventLoop eventLoop = DefaultEventLoop.createEventLoop("test");
final CountDownLatch handled = new CountDownLatch(1);
final AbstractLengthPrependerClient ci = new AbstractLengthPrependerClient()
{
@Override
public void onMessage(byte[] buffer, int offset, int size)
{
fail();
}
@Override
public void handleException(Exception cce, EventLoop el)
{
assertSame(el, eventLoop);
assertTrue(cce instanceof RuntimeException);
assertTrue(cce.getCause() instanceof UnresolvedAddressException);
super.handleException(cce, el);
handled.countDown();
}
};
verifyUnresolvedException(ci, eventLoop, handled);
}
示例10: testConstructor_InvalidHost
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
@Test
public void testConstructor_InvalidHost() throws Exception {
Throwable thrown = null;
try {
client = new SyncMqttClient("tcp://foo:1883", listener, 5, config);
fail("expected exception");
} catch (MqttInvocationException e) {
thrown = e.getRootCause();
assertEquals(UnresolvedAddressException.class, thrown.getClass());
}
verify(listener, timeout(5000)).disconnected(any(SyncMqttClient.class), same(thrown), eq(false));
verify(reconnectionStrategy).clone();
verifyNoMoreInteractions(listener, reconnectionStrategy);
}
示例11: testConstructor_InvalidHost
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
@Test
public void testConstructor_InvalidHost() throws Exception {
Throwable thrown = null;
try {
client = new AsyncMqttClient("tcp://foo:1883", listener, 5, config);
fail("expected exception");
} catch (MqttInvocationException e) {
thrown = e.getRootCause();
assertEquals(UnresolvedAddressException.class, thrown.getClass());
}
verify(listener, timeout(5000)).disconnected(any(AsyncMqttClient.class), same(thrown), eq(false));
verify(reconnectionStrategy).clone();
verifyNoMoreInteractions(listener, reconnectionStrategy);
}
示例12: testConnect_Unresolved
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
/**
* Test method for 'DatagramChannelImpl.connect(SocketAddress)'
*
* @throws IOException
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies UnresolvedAddressException.",
method = "connect",
args = {java.net.SocketAddress.class}
)
public void testConnect_Unresolved() throws IOException {
assertFalse(this.channel1.isConnected());
InetSocketAddress unresolved = new InetSocketAddress(
"unresolved address", 1080);
try {
this.channel1.connect(unresolved);
fail("Should throw an UnresolvedAddressException here.");
} catch (UnresolvedAddressException e) {
// OK.
}
}
示例13: testSerializationSelf
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "!SerializationSelf",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "UnresolvedAddressException",
args = {}
)
})
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new UnresolvedAddressException());
}
示例14: testSerializationCompatibility
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility with RI.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "!SerializationGolden",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "UnresolvedAddressException",
args = {}
)
})
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this, new UnresolvedAddressException());
}
示例15: openSocketChannel
import java.nio.channels.UnresolvedAddressException; //导入依赖的package包/类
public SocketChannel openSocketChannel() throws JournalNetworkException {
if (getNodeCount() == 0) {
if (isMultiCastEnabled()) {
addNode(pollServerAddress());
} else {
throw new JournalNetworkException("No server nodes");
}
}
List<ServerNode> nodes = getServerNodes();
for (int i = 0, k = nodes.size(); i < k; i++) {
ServerNode node = nodes.get(i);
try {
return openSocketChannel0(node);
} catch (UnresolvedAddressException | IOException e) {
LOG.info().$("Node ").$(node).$(" is unavailable [").$(e.getMessage()).$(']').$();
}
}
throw new JournalNetworkException("Could not connect to any node");
}