本文整理汇总了Java中org.eclipse.jetty.websocket.WebSocketClientFactory类的典型用法代码示例。如果您正苦于以下问题:Java WebSocketClientFactory类的具体用法?Java WebSocketClientFactory怎么用?Java WebSocketClientFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketClientFactory类属于org.eclipse.jetty.websocket包,在下文中一共展示了WebSocketClientFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runVC
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
public static VirtualClient runVC(final String[] args) throws Exception {
final int game = args.length > 0 ? Integer.parseInt(args[0]) : 1;
final String host = "localhost";
//final String host = "192.168.0.1";
final int port = 8282;
final WebSocketClientFactory factory = new WebSocketClientFactory();
factory.setBufferSize(4096);
factory.start();
final WebSocketClient client = factory.newWebSocketClient();
client.setMaxIdleTime(60 * 1000 * 5);
client.setMaxTextMessageSize(1024 * 64);
final VirtualClient virtualClient = new VirtualClient("virtual-client", client, host, port, "io");
virtualClient.start();
final IMessage message1 = MESSAGES.newClient(virtualClient.getName());
virtualClient.send(message1);
final IMessage message2 = MESSAGES.newGameConnection(game);
virtualClient.send(message2);
//virtualClient.stop();
//factory.stop();
return virtualClient;
}
示例2: WebSocketTransport
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
protected WebSocketTransport(String token, SignalFxEndpoint endpoint, int apiVersion,
int timeout, boolean compress, int maxBinaryMessageSize) {
this.token = token;
this.endpoint = endpoint;
this.path = "/v" + apiVersion + "/signalflow/connect";
this.timeout = timeout;
this.compress = compress;
try {
WebSocketClientFactory factory = new WebSocketClientFactory();
factory.start();
this.webSocketClient = factory.newWebSocketClient();
this.webSocketClient.setMaxBinaryMessageSize(maxBinaryMessageSize);
URIBuilder uriBuilder = new URIBuilder(String.format("%s://%s:%s%s",
endpoint.getScheme(), endpoint.getHostname(), endpoint.getPort(), path));
this.transportConnection = new TransportConnection(token);
this.webSocketClient.open(uriBuilder.build(), this.transportConnection, timeout,
TimeUnit.SECONDS);
} catch (Exception ex) {
throw new SignalFlowException("failed to construct websocket transport", ex);
}
}
示例3: ConnectionTask
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
/**
* Constructor
*
* @param factory
* @param map
*/
public ConnectionTask(WebSocketClientFactory factory, SparseArray<Connection> map) {
_factory = factory;
_map = map;
if (!_factory.isRunning()) {
try {
_factory.start();
} catch (Exception e) {
}
}
}
示例4: simpleTest
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
@Test
public void simpleTest() throws Exception
{
final int port = 6666;
String connectionURI = "ws://localhost:" + port + WebSocketServerInputOperator.DEFAULT_EXTENSION;
final String message = "hello world";
WebSocketServerInputOperator wssio = new TestWSSIO();
wssio.setPort(port);
wssio.setup(null);
WebSocketClientFactory clientFactory = new WebSocketClientFactory();
clientFactory.start();
WebSocketClient client = new WebSocketClient(clientFactory);
Future<WebSocket.Connection> connectionFuture = client.open(new URI(connectionURI), new TestWebSocket());
WebSocket.Connection connection = connectionFuture.get(5, TimeUnit.SECONDS);
connection.sendMessage(message);
long startTime = System.currentTimeMillis();
while (startTime + 10000 > System.currentTimeMillis()) {
if (TestWSSIO.messages.size() >= 1) {
break;
}
Thread.sleep(100);
}
Assert.assertEquals("The number of messages recieved is incorrect.", 1, TestWSSIO.messages.size());
Assert.assertEquals("Incorrect message received", message, TestWSSIO.messages.get(0));
connection.close();
wssio.teardown();
}
示例5: initialize
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
_factory = new WebSocketClientFactory();
_conn = new SparseArray<Connection>();
_create = new ConnectionTask(_factory, _conn);
_send = new SendingTask(_conn);
_close = new DisconnectionTask(_conn);
try {
start();
} catch (Exception e) {
}
}
示例6: testCloseChannel
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
@Test
public void testCloseChannel() throws Exception {
//given
final Config config = Application.getInstance(Config.class);
final WebSocketService webSocketService = Application.getInstance(WebSocketService.class);
webSocketService.removeChannels("/websocket");
final WebSocketClientFactory factory = new WebSocketClientFactory();
factory.start();
final String url = "ws://" + config.getConnectorHttpHost() + ":" + config.getConnectorHttpPort() + "/websocket";
//when
final WebSocketClient client = new WebSocketClient(factory);
client.open(new URI(url), new WebSocket.OnTextMessage() {
@Override
public void onOpen(Connection connection) {
// intentionally left blank
}
@Override
public void onClose(int closeCode, String message) {
// intentionally left blank
}
@Override
public void onMessage(String data) {
// intentionally left blank
}
}).get(5, TimeUnit.SECONDS);
webSocketService.close("/websocket");
//then
assertThat(webSocketService.getChannels("/websocket"), not(nullValue()));
assertThat(webSocketService.getChannels("/websocket").size(), equalTo(0));
}
示例7: createWebSocketClient
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
/**
* A factory method for {@link WebSocketClient} class
*
* @return
*/
protected WebSocketClient createWebSocketClient() {
factory = new WebSocketClientFactory();
factory.getSslContextFactory().setTrustAll(false);
try {
factory.start();
} catch (Exception e) {
throw new IllegalStateException(e);
}
final WebSocketClient client = factory.newWebSocketClient();
// you can manipulate the client by overriding this method.
return client;
}
示例8: initialize
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
@Override
public void initialize(CordovaInterface cordova, final CordovaWebView webView) {
super.initialize(cordova, webView);
_factory = new WebSocketClientFactory();
_conn = new SparseArray<Connection>();
_executor = Executors.newSingleThreadExecutor();
_runner = new TaskRunner();
_runner.setTask(CREATE_TASK, new ConnectionTask(_factory, _conn));
_runner.setTask(SEND_TASK, new SendingTask(_conn));
_runner.setTask(CLOSE_TASK, new DisconnectionTask(_conn));
_runner.setTask(RESET_TASK, new ResetTask(_conn));
_runner.setTask(DESTROY_TASK, new DestroyTask(_factory, _conn));
_executor.execute(_runner);
Log.setLogLevel(getLogLevel(this.preferences));
}
示例9: JsonRpcWsClient
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
public JsonRpcWsClient(URI serviceUri, String protocol) {
this(serviceUri, protocol, null, new ObjectMapper());
WebSocketClientFactory clientFactory = new WebSocketClientFactory();
try {
clientFactory.start();
} catch (Exception e) {
LOG.error("Error creating WS client factory", e);
}
mClient = clientFactory.newWebSocketClient();
}
示例10: before
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
@Before
public void before() throws Exception {
// start the test server
LOG.info("Starting server");
mServer = new TestServer();
mServer.start();
// get URI of the server
mServerUri = new URI("ws://localhost:" + mServer.getLocalPort() + "/ws");
// create JSON-RPC client
LOG.info("Creating RPC client");
mClient = new JsonRpcClient();
mClient.setRequestTimeout(2000);
// create WSC factory
LOG.info("Creating WS client factory");
mWscFactory = new WebSocketClientFactory();
mWscFactory.start();
// create and bind the ws client
LOG.info("Creating WS client");
mWsClient = new JsonRpcWsClient(mServerUri, "jsonrpc/json", mWscFactory.newWebSocketClient());
// bind the ws client to the transport
LOG.info("Binding WS client to RPC client");
mWsClient.bindClient(mClient);
// create RPC proxy
LOG.info("Creating RPC proxy");
mProxy = mWsClient.makeProxy(ISimpleServer.class);
// let the ws client connect
LOG.info("Connecting WS client");
mWsClient.connect(10, TimeUnit.SECONDS);
}
示例11: getJettyFactory
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
public WebSocketClientFactory getJettyFactory() {
return fact;
}
示例12: setJettyFactory
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
public void setJettyFactory(WebSocketClientFactory fact) {
this.fact = fact;
}
示例13: DestroyTask
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
/**
* Constructor
*
* @param factory
* @param map
*/
public DestroyTask(WebSocketClientFactory factory, SparseArray<Connection> map) {
_factory = factory;
_map = map;
}
示例14: connectWebsocket
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
public void connectWebsocket(String url, int sampleEveryN, boolean showMessages) {
try {
int timeout = 9000; // 9 seconds
System.out.println("NOTE: For GeoEvent Stream Service append /subscribe to the Web Socket URL");
System.out.println("Starting: If you see rapid connection lost messages. Ctrl-C and check you're URL");
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setTrustAll(true);
sslContextFactory.start();
final WebSocketClientFactory factory = new WebSocketClientFactory();
factory.start();
WebSocketClient client = factory.newWebSocketClient();
URI uri = new URI(url);
//WebSocketMessage msg = new WebSocketMessage();
//WebSocket.Connection websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages)).get(5, TimeUnit.SECONDS);
WebSocket.Connection websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages),timeout, TimeUnit.SECONDS);
//System.out.println(System.currentTimeMillis());
websocketConnection.setMaxTextMessageSize(MAX_MESSAGE_SIZE);
//System.out.println(timeout);
websocketConnection.setMaxIdleTime(timeout);
//websocketConnection.setMaxIdleTime(-1);
while (true) {
if (websocketConnection.isOpen()) {
// Wait a second
Thread.sleep(1000);
} else {
// Reopen
websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages)).get(5, TimeUnit.SECONDS);
websocketConnection.setMaxTextMessageSize(MAX_MESSAGE_SIZE);
websocketConnection.setMaxIdleTime(timeout);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: ConnectionTask
import org.eclipse.jetty.websocket.WebSocketClientFactory; //导入依赖的package包/类
/**
* Constructor
*
* @param factory
* @param map
*/
public ConnectionTask(WebSocketClientFactory factory, SparseArray<Connection> map) {
_factory = factory;
_map = map;
}