本文整理汇总了Java中org.glassfish.tyrus.client.ClientManager类的典型用法代码示例。如果您正苦于以下问题:Java ClientManager类的具体用法?Java ClientManager怎么用?Java ClientManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientManager类属于org.glassfish.tyrus.client包,在下文中一共展示了ClientManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getReconnecHandler
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
/**
* @return
* Returns an object of Reconnect Handler
* Responsible for reconnecting to the server when connection loses
* Handle any networking issues as well
*/
private ReconnectHandler getReconnecHandler() {
ClientManager.ReconnectHandler reconnectHandler = new ClientManager.ReconnectHandler() {
@Override
public boolean onDisconnect(CloseReason closeReason) {
// If we close the session no need to reconnect
if (WebSocketClient.this.isInterrupted || closeReason.getCloseCode() == CloseReason.CloseCodes.NORMAL_CLOSURE) {
return false;
}
reconnect("Disconnected.... Trying to reconnect .... " + closeReason);
return true;
}
@Override
public boolean onConnectFailure(Exception exception) {
if (!WebSocketClient.this.isInterrupted) {
reconnect("Connection Failure... Attempting to reconnect ..." + exception.toString());
return true;
}
return false;
}
};
return reconnectHandler;
}
示例2: connectToKillJob
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
/**
* Instantiates HydrographUiClientSocket and establishes connection with
* server in order to kill the job.
*
* @param jobID the job id
* @param url the url
* @return Session
* @throws Throwable the throwable
*/
public Session connectToKillJob(String jobID, String url) throws Throwable {
try {
HydrographUiClientSocket socket = new HydrographUiClientSocket();
ClientManager clientManager = ClientManager.createClient();
Session session = clientManager.connectToServer(socket,
new URI(url));
socket.sendMessage(getKillReq(jobID));
Thread.sleep(3000);
return session;
} catch (Throwable t) {
throw t;
}
}
示例3: initWebSocketSession
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
private void initWebSocketSession(String url, int wsConnectionTimeout) throws Exception {
CountDownLatch wsLatch = new CountDownLatch(1);
ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
ClientManager client = ClientManager.createClient();
client.connectToServer(new Endpoint() {
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
wsSession = session;
wsLatch.countDown();
}
}, cec, new URI(url));
if (!wsLatch.await(wsConnectionTimeout, TimeUnit.SECONDS)) {
throw new TimeoutException("Web socket connection timeout");
}
}
示例4: run
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Override
public void run(AtomicBoolean running) throws Exception {
System.out.println("Opening GPIO...");
ClientManager client = ClientManager.createClient();
try (GPIOPin led17 = DeviceManager.open(GPIOPin.class, led17config);
GPIOPin led4 = DeviceManager.open(GPIOPin.class, led4config);
GPIOPin led22 = DeviceManager.open(GPIOPin.class, led22config);
Session websocket = client.connectToServer(new LedManager(led17, led4, led22), URI.create("ws://192.168.1.10:8080/SensorPanel/ws/notifications/temperature"))) {
System.out.println("Main loop started.");
while (running.get()) {
Thread.sleep(1000);
}
led17.setValue(false);
led4.setValue(false);
led22.setValue(false);
}
}
示例5: connect
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
public synchronized void connect(String server) {
/**
* Only connect once, which is intended to stay connected forever. If
* manually disconnecting/connecting again should be a thing, some stuff
* may have to be changed.
*/
if (connecting) {
return;
}
connecting = true;
try {
LOGGER.info("[PubSub] Connecting to "+server);
ClientManager clientManager = ClientManager.createClient();
clientManager.getProperties().put(ClientProperties.RECONNECT_HANDLER, new Reconnect());
clientManager.asyncConnectToServer(this, new URI(server));
} catch (Exception ex) {
LOGGER.warning("[PubSub] Error connecting "+ex);
}
}
示例6: prepareConnection
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
/**
* Create and configure a Client Manager.
*/
private void prepareConnection() {
clientManager = ClientManager.createClient();
clientManager.getProperties().put(ClientProperties.RECONNECT_HANDLER, new Reconnect());
// Try to add Let's Encrypt cert for SSL
try {
SslEngineConfigurator sslEngineConfigurator = new SslEngineConfigurator(
SSLUtil.getSSLContextWithLE(), true, false, false);
clientManager.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
ssl = true;
} catch (Exception ex) {
LOGGER.warning("Failed adding support for Lets Encrypt: " + ex);
ssl = false;
}
}
示例7: connect
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Override
public synchronized CompletableFuture<SqpConnection> connect(String host, int port, String path, String database) {
_state = ConnectionState.Connecting;
_database = database;
ClientManager clientManager = ClientManager.createClient();
ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
String scheme = "ws";
_connectionFuture = new CompletableFuture<>();
URI uri;
try {
uri = new URI(scheme, null, host, port, path, null, null);
_logger.log(Level.INFO, "Attempting to connect to '" + uri + "'");
clientManager.connectToServer(this, cec, uri);
} catch (URISyntaxException | DeploymentException | IOException e) {
_connectionFuture.completeExceptionally(new ConnectionException("Failed to connect to server: " + e.getMessage(), e));
}
return _connectionFuture;
}
示例8: testAuthenBeforeConnect
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Test
public void testAuthenBeforeConnect() throws Exception {
SlackWebsocketConnection slack = new SlackWebsocketConnection("token", null, 8080);
SlackAuthen slackAuthen = PowerMockito.mock(SlackAuthen.class);
PowerMockito.whenNew(SlackAuthen.class).withNoArguments().thenReturn(slackAuthen);
PowerMockito.when(slackAuthen.tokenAuthen(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(slackInfo);
ClientManager clientManager = PowerMockito.mock(ClientManager.class);
PowerMockito.mockStatic(ClientManager.class);
PowerMockito.when(ClientManager.createClient()).thenReturn(clientManager);
boolean connect = slack.connect();
assertThat(connect, is(true));
assertThat(slack.getSlackInfo().isOk(), is(true));
Mockito.verify(slackAuthen).tokenAuthen(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt());
}
示例9: testCreateWebSoketClient
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Test
public void testCreateWebSoketClient() throws Exception {
SlackWebsocketConnection slack = new SlackWebsocketConnection("token", null, 8080);
SlackAuthen slackAuthen = PowerMockito.mock(SlackAuthen.class);
PowerMockito.whenNew(SlackAuthen.class).withNoArguments().thenReturn(slackAuthen);
PowerMockito.when(slackAuthen.tokenAuthen(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(slackInfo);
ClientManager clientManager = PowerMockito.mock(ClientManager.class);
PowerMockito.mockStatic(ClientManager.class);
PowerMockito.when(ClientManager.createClient()).thenReturn(clientManager);
boolean connect = slack.connect();
assertThat(connect, is(true));
PowerMockito.verifyStatic();
ClientManager.createClient();
}
示例10: testCreateWebSoketClientWithProxy
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Test
public void testCreateWebSoketClientWithProxy() throws Exception {
SlackWebsocketConnection slack = new SlackWebsocketConnection("token", "proxy", 8080);
SlackAuthen slackAuthen = PowerMockito.mock(SlackAuthen.class);
PowerMockito.whenNew(SlackAuthen.class).withNoArguments().thenReturn(slackAuthen);
PowerMockito.when(slackAuthen.tokenAuthen(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(slackInfo);
ClientManager clientManager = PowerMockito.mock(ClientManager.class);
PowerMockito.mockStatic(ClientManager.class);
PowerMockito.when(ClientManager.createClient()).thenReturn(clientManager);
Map<String, Object> properties = Mockito.mock(Map.class);
PowerMockito.when(clientManager.getProperties()).thenReturn(properties);
boolean connect = slack.connect();
assertThat(connect, is(true));
Mockito.verify(clientManager.getProperties()).put(Mockito.eq(ClientProperties.PROXY_URI), Mockito.anyString());
PowerMockito.verifyStatic();
ClientManager.createClient();
}
示例11: testCreateWebSocketAndConnectToServer
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Test
public void testCreateWebSocketAndConnectToServer() throws Exception {
SlackWebsocketConnection slack = new SlackWebsocketConnection("token", null, 8080);
SlackAuthen slackAuthen = PowerMockito.mock(SlackAuthen.class);
PowerMockito.whenNew(SlackAuthen.class).withNoArguments().thenReturn(slackAuthen);
PowerMockito.when(slackAuthen.tokenAuthen(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(slackInfo);
ClientManager clientManager = PowerMockito.mock(ClientManager.class);
PowerMockito.mockStatic(ClientManager.class);
PowerMockito.when(ClientManager.createClient()).thenReturn(clientManager);
boolean connect = slack.connect();
assertThat(connect, is(true));
Mockito.verify(clientManager).connectToServer(Mockito.any(Endpoint.class), Mockito.any(URI.class));
PowerMockito.verifyStatic();
ClientManager.createClient();
}
示例12: run
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Override
public void run() {
ClientManager client = ClientManager.createClient();
try {
URI uri = new URI(ApiAware.withUrl(apiProvider.getBaseUri()).getWebSocketUrl("mail"));
client.getProperties().put(ClientProperties.RECONNECT_HANDLER, new ReconnectHandler());
client.connectToServer(
new MailClientEndpoint(),
ClientEndpointConfig.Builder.create().build(),
uri
);
countDownLatch.await();
client.shutdown();
} catch (Exception e) {
logger.warn(String.format(
"Failed to connect to mail endpoint. Mail functionality is disabled. Error is: %s",
e.getMessage()
));
}
}
示例13: setUp
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.client = HttpClients.custom()
.setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(3, 2000))
.setDefaultRequestConfig(RequestConfig.custom()
.setSocketTimeout(10000)
.setConnectTimeout(10000)
.setConnectionRequestTimeout(10000)
.build()).build();
this.om = new ObjectMapper();
this.wsClient = ClientManager.createClient();
wsClient.getProperties().put(ClientProperties.HANDSHAKE_TIMEOUT, 10000);
if (System.getProperty(TRAVIS_ENV) != null) {
System.out.println("waiting for Travis machine");
waitUrlAvailable(String.format("http://%s:%d/api?name=foo", LOCALHOST, PORT));
// Thread.sleep(1); // Ugly sleep to debug travis
}
}
示例14: connectToServer
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
/**
* Instantiates HydrographUiClientSocket and establishes connection with
* server in order to get execution status.
*
* @param job the job
* @param jobID the job id
* @param url the url
* @return Session
*/
public Session connectToServer(final Job job, String jobID, String url) {
Session session = null;
counter++;
try {
HydrographUiClientSocket socket = new HydrographUiClientSocket();
ClientManager clientManager = ClientManager.createClient();
session = clientManager.connectToServer(socket, new URI(url));
socket.sendMessage(getStatusReq(jobID));
return session;
} catch (Throwable t) {
if (counter > 1) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
messageDialogForExecutionTracking(job, Display
.getDefault().getActiveShell());
}
});
logger.error("Error while connection to server");
}else{
session = connectToServer(job, jobID, url);
}
return session;
}
}
示例15: getWebSocketContainer
import org.glassfish.tyrus.client.ClientManager; //导入依赖的package包/类
@Override
public WebSocketContainer getWebSocketContainer()
{
ClientManager clientManager = ClientManager.createClient();
if (proxyAddress != null)
{
clientManager.getProperties().put(ClientProperties.PROXY_URI, "http://" + proxyAddress + ":" + proxyPort);
}
return clientManager;
}