當前位置: 首頁>>代碼示例>>Java>>正文


Java Session.close方法代碼示例

本文整理匯總了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();
}
 
開發者ID:webcerebrium,項目名稱:java-binance-api,代碼行數:12,代碼來源:DepthStreamTest.java

示例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();
}
 
開發者ID:webcerebrium,項目名稱:java-binance-api,代碼行數:12,代碼來源:AggTradesStreamTest.java

示例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();
}
 
開發者ID:webcerebrium,項目名稱:java-binance-api,代碼行數:12,代碼來源:KlinesStreamTest.java

示例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");
    }
}
 
開發者ID:trvedata,項目名稱:trvedb,代碼行數:12,代碼來源:EventsConnection.java

示例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;
}
 
開發者ID:trvedata,項目名稱:trvedb,代碼行數:39,代碼來源:EventsConnection.java

示例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");
	}
}
 
開發者ID:mohamnag,項目名稱:javafx_webview_debugger,代碼行數:12,代碼來源:DevToolsWebSocket.java

示例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);
    }

}
 
開發者ID:apache,項目名稱:guacamole-client,代碼行數:20,代碼來源:GuacamoleWebSocketTunnelListener.java

示例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);
}
 
開發者ID:adamkewley,項目名稱:jobson,代碼行數:7,代碼來源:ObservableSocket.java

示例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();
}
 
開發者ID:adamkewley,項目名稱:jobson,代碼行數:7,代碼來源:ObservableSocket.java


注:本文中的org.eclipse.jetty.websocket.api.Session.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。