当前位置: 首页>>代码示例>>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;未经允许,请勿转载。