use of org.osate.aadl2.Connection in project wildfly-core by wildfly.
the class ProtocolConnectionUtils method connectSync.
/**
* Connect sync.
*
* @param configuration the protocol configuration
* @return the connection
* @throws IOException
*/
public static Connection connectSync(final ProtocolConnectionConfiguration configuration) throws IOException {
long timeoutMillis = configuration.getConnectionTimeout();
CallbackHandler handler = configuration.getCallbackHandler();
final CallbackHandler actualHandler;
ProtocolTimeoutHandler timeoutHandler = configuration.getTimeoutHandler();
// Note: If a client supplies a ProtocolTimeoutHandler it is taking on full responsibility for timeout management.
if (timeoutHandler == null) {
GeneralTimeoutHandler defaultTimeoutHandler = new GeneralTimeoutHandler();
// No point wrapping our AnonymousCallbackHandler.
actualHandler = handler != null ? new WrapperCallbackHandler(defaultTimeoutHandler, handler) : null;
timeoutHandler = defaultTimeoutHandler;
} else {
actualHandler = handler;
}
final IoFuture<Connection> future = connect(actualHandler, configuration);
IoFuture.Status status = timeoutHandler.await(future, timeoutMillis);
Connection result = checkFuture(status, future, configuration);
if (result == null) {
// Did not complete in time; tell remoting we don't want it
future.cancel();
// In case the future completed between when we waited for it and when we cancelled,
// close any connection that was established. We don't want to risk using a
// Connection after we told remoting to cancel, and if we don't use it we must close it.
Connection toClose = checkFuture(future.getStatus(), future, configuration);
StreamUtils.safeClose(toClose);
throw ProtocolLogger.ROOT_LOGGER.couldNotConnect(configuration.getUri());
}
return result;
}
use of org.osate.aadl2.Connection in project wildfly-core by wildfly.
the class ConnectSyncUnitTestCase method getConfiguration.
private static ProtocolConnectionConfiguration getConfiguration(IoFuture.Status initialStatus, boolean completeOnRecheck, boolean failOnRecheck) {
final FutureResult<Connection> futureResult = new FutureResult<>();
// It seems you need to add a cancel handler if you want a
// call to futureResult.getIoFuture().cancel() to trigger a change in the future to State.CANCELLED.
// So add one so we can test whether cancel() has been called.
futureResult.addCancelHandler(new Cancellable() {
public Cancellable cancel() {
futureResult.setCancelled();
return this;
}
});
final MockConnection connection = initialStatus == IoFuture.Status.DONE || completeOnRecheck ? new MockConnection() : null;
final TestTimeoutHandler timeoutHandler = new TestTimeoutHandler(futureResult, initialStatus, connection, failOnRecheck);
final MockEndpoint endpoint = new MockEndpoint(futureResult);
ProtocolConnectionConfiguration result = ProtocolConnectionConfiguration.create(endpoint, URI.create("http://127.0.0.1"));
result.setTimeoutHandler(timeoutHandler);
return result;
}
use of org.osate.aadl2.Connection in project wildfly-core by wildfly.
the class ManagementChannelHandler method getRemoteAddress.
/**
* Get the remote address.
*
* @return the remote address, {@code null} if not available
*/
public InetAddress getRemoteAddress() {
final Channel channel;
try {
channel = strategy.getChannel();
} catch (IOException e) {
return null;
}
final Connection connection = channel.getConnection();
final InetSocketAddress peerAddress = connection.getPeerAddress(InetSocketAddress.class);
return peerAddress == null ? null : peerAddress.getAddress();
}
use of org.osate.aadl2.Connection in project hop by apache.
the class SshDialog method test.
private void test() {
Exception exception = null;
String errMsg = null;
Connection connection = null;
SshMeta meta = new SshMeta();
getInfo(meta);
try {
connection = SshData.openConnection(variables, meta);
} catch (Exception e) {
exception = e;
errMsg = e.getMessage();
} finally {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
/* Ignore */
}
}
}
if (exception == null) {
MessageBox messageBox;
messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
messageBox.setMessage(BaseMessages.getString(PKG, "SSHDialog.Connected.OK", meta.getServerName(), meta.getUserName()) + Const.CR);
messageBox.setText(BaseMessages.getString(PKG, "SSHDialog.Connected.Title.Ok"));
messageBox.open();
} else {
new ErrorDialog(shell, "Error", BaseMessages.getString(PKG, "SSHDialog.Connected.NOK.ConnectionBad", meta.getServerName(), meta.getUserName()) + Const.CR + errMsg + Const.CR, exception);
}
}
use of org.osate.aadl2.Connection in project Sentinel by alibaba.
the class OkHttpResourceExtractorTest method testCustomizeOkHttpUrlCleaner.
@Test
public void testCustomizeOkHttpUrlCleaner() {
OkHttpResourceExtractor extractor = new OkHttpResourceExtractor() {
@Override
public String extract(Request request, Connection connection) {
String regex = "/okhttp/back/";
String url = request.url().toString();
if (url.contains(regex)) {
url = url.substring(0, url.indexOf(regex) + regex.length()) + "{id}";
}
return request.method() + ":" + url;
}
};
String url = "http://localhost:8083/okhttp/back/abc";
Request request = new Request.Builder().url(url).build();
assertEquals("GET:http://localhost:8083/okhttp/back/{id}", extractor.extract(request, null));
}
Aggregations