本文整理汇总了Java中org.eclipse.jetty.websocket.api.Session.close方法的典型用法代码示例。如果您正苦于以下问题:Java Session.close方法的具体用法?Java Session.close怎么用?Java Session.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.websocket.api.Session
的用法示例。
在下文中一共展示了Session.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDepthStreamWatcher
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
@Test
public void testDepthStreamWatcher() throws Exception, BinanceApiException {
Session session = binanceApi.websocketDepth(symbol, new BinanceWebSocketAdapterDepth() {
@Override
public void onMessage(BinanceEventDepthUpdate message) {
log.info(message.toString());
}
});
Thread.sleep(3000);
session.close();
}
示例2: testTradesStreamWatcher
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
@Test
public void testTradesStreamWatcher() throws Exception, BinanceApiException {
Session session = binanceApi.websocketTrades(symbol, new BinanceWebSocketAdapterAggTrades() {
@Override
public void onMessage(BinanceEventAggTrade message) {
log.info(message.toString());
}
});
Thread.sleep(5000);
session.close();
}
示例3: testKlinesStreamWatcher
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
@Test
public void testKlinesStreamWatcher() throws Exception, BinanceApiException {
Session session = binanceApi.websocketKlines(symbol, BinanceInterval.ONE_MIN, new BinanceWebSocketAdapterKline() {
@Override
public void onMessage(BinanceEventKline message) {
log.info(message.toString());
}
});
Thread.sleep(3000);
session.close();
}
示例4: onWebSocketText
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
/**
* Called by Jetty when a text frame is received from the WebSocket client.
*/
@Override
public void onWebSocketText(String message) {
log.info("Received unsupported text message from peer {}", peerID);
Session session = getSession();
if (session != null && session.isOpen()) {
session.close(StatusCode.BAD_DATA, "This endpoint only accepts binary messages");
}
}
示例5: offerMessage
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
/**
* @see ClientConnection#offerMessage(ServerToClient)
*/
public boolean offerMessage(ServerToClient message) {
Session session = getSession();
if (session == null || !session.isOpen()) return false;
if (inFlightMessages.incrementAndGet() > MAX_IN_FLIGHT_MESSAGES) {
inFlightMessages.decrementAndGet();
return false;
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(stream, null);
writeToClient.write(message, encoder);
encoder.flush();
} catch (Exception e) {
log.warn("Failed to encode message to client", e);
session.close(StatusCode.SERVER_ERROR, "Internal server error");
return true;
}
session.getRemote().sendBytes(ByteBuffer.wrap(stream.toByteArray()), new WriteCallback() {
@Override
public void writeSuccess() {
inFlightMessages.decrementAndGet();
}
@Override
public void writeFailed(Throwable error) {
inFlightMessages.decrementAndGet();
log.info("Sending message to WebSocket client failed: ", error);
}
});
return true;
}
示例6: onWebSocketConnect
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
@Override
public void onWebSocketConnect(Session session) {
this.session = session;
if (context.getAttribute(WEB_SOCKET_ATTR_NAME) != null) {
session.close();
System.out.println("Another client is already connected. Connection refused");
} else {
context.setAttribute(WEB_SOCKET_ATTR_NAME, this);
System.out.println("Client connected");
}
}
示例7: closeConnection
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
/**
* Sends the given status on the given WebSocket connection and closes the
* connection.
*
* @param session The outbound WebSocket connection to close.
* @param guac_status The status to send.
*/
private void closeConnection(Session session, GuacamoleStatus guac_status) {
try {
int code = guac_status.getWebSocketCode();
String message = Integer.toString(guac_status.getGuacamoleStatusCode());
session.close(new CloseStatus(code, message));
}
catch (IOException e) {
logger.debug("Unable to close WebSocket connection.", e);
}
}
示例8: onWebSocketClose
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
@OnWebSocketClose
public void onWebSocketClose(Session session, int closeCode, String closeReason) {
log.debug("Closing websocket");
this.eventsSubscription.dispose();
session.close(closeCode, closeReason);
}
示例9: onWebSocketError
import org.eclipse.jetty.websocket.api.Session; //导入方法依赖的package包/类
@OnWebSocketError
public void onWebSocketError(Session session, Throwable ex) {
log.error(ex.getMessage());
this.eventsSubscription.dispose();
session.close();
}