本文整理匯總了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");
}