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