当前位置: 首页>>代码示例>>Java>>正文


Java CloseCode类代码示例

本文整理汇总了Java中javax.websocket.CloseReason.CloseCode的典型用法代码示例。如果您正苦于以下问题:Java CloseCode类的具体用法?Java CloseCode怎么用?Java CloseCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CloseCode类属于javax.websocket.CloseReason包,在下文中一共展示了CloseCode类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendCloseMessage

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
        // PROTOCOL_ERROR is probably better than GOING_AWAY here
        msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
        msg.putShort((short) closeCode.getCode());
    }

    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
        appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
        wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
        handleCloseException(ioe, closeCode);
    } catch (WritePendingException wpe) {
        handleCloseException(wpe, closeCode);
    } finally {
        webSocketContainer.unregisterSession(localEndpoint, this);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:28,代码来源:WsSession.java

示例2: handleCloseException

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
private void handleCloseException(Exception e, CloseCode closeCode) {
    // Failed to send close message. Close the socket and let the caller
    // deal with the Exception
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("wsSession.sendCloseFail", id), e);
    }
    wsRemoteEndpoint.close();
    // Failure to send a close message is not unexpected in the case of
    // an abnormal closure (usually triggered by a failure to read/write
    // from/to the client. In this case do not trigger the endpoint's
    // error handling
    if (closeCode != CloseCodes.CLOSED_ABNORMALLY) {
        localEndpoint.onError(this, e);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:WsSession.java

示例3: sendCloseFrame

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
public void sendCloseFrame(CloseCode closeCode) throws IOException {
    int code = closeCode.getCode();
    byte[] codeBytes = new byte[2];
    codeBytes[0] = (byte) (code >> 8);
    codeBytes[1] = (byte) code;
    write(createFrame(true, 8, codeBytes));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:TesterWsCloseClient.java

示例4: awaitOnClose

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
public static void awaitOnClose(CloseCode... codes) {
    Set<CloseCode> set = new HashSet<CloseCode>();
    for (CloseCode code : codes) {
        set.add(code);
    }
    awaitOnClose(set);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:TestClose.java

示例5: sendCloseMessage

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
private void sendCloseMessage(CloseReason closeReason) {
	// 125 is maximum size for the payload of a control message
	ByteBuffer msg = ByteBuffer.allocate(125);
	CloseCode closeCode = closeReason.getCloseCode();
	// CLOSED_ABNORMALLY should not be put on the wire
	if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
		// PROTOCOL_ERROR is probably better than GOING_AWAY here
		msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
	} else {
		msg.putShort((short) closeCode.getCode());
	}

	String reason = closeReason.getReasonPhrase();
	if (reason != null && reason.length() > 0) {
		appendCloseReasonWithTruncation(msg, reason);
	}
	msg.flip();
	try {
		wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
	} catch (IOException ioe) {
		handleCloseException(ioe, closeCode);
	} catch (WritePendingException wpe) {
		handleCloseException(wpe, closeCode);
	} finally {
		webSocketContainer.unregisterSession(localEndpoint, this);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:28,代码来源:WsSession.java

示例6: handleCloseException

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
private void handleCloseException(Exception e, CloseCode closeCode) {
	// Failed to send close message. Close the socket and let the caller
	// deal with the Exception
	if (log.isDebugEnabled()) {
		log.debug(sm.getString("wsSession.sendCloseFail", id), e);
	}
	wsRemoteEndpoint.close();
	// Failure to send a close message is not unexpected in the case of
	// an abnormal closure (usually triggered by a failure to read/write
	// from/to the client. In this case do not trigger the endpoint's
	// error handling
	if (closeCode != CloseCodes.CLOSED_ABNORMALLY) {
		localEndpoint.onError(this, e);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:16,代码来源:WsSession.java

示例7: stopThread

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
public void stopThread() {

			LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
			if (ActivityCompat.checkSelfPermission(EventNotificationService.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(EventNotificationService.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
				// TODO: Consider calling
				//    ActivityCompat#requestPermissions
				// here to request the missing permissions, and then overriding
				//   public void onRequestPermissionsResult(int requestCode, String[] permissions,
				//                                          int[] grantResults)
				// to handle the case where the user grants the permission. See the documentation
				// for ActivityCompat#requestPermissions for more details.
				Intent errorActivityIntent = new Intent(EventNotificationService.this, ErrorReportActivity.class);
				errorActivityIntent.putExtra(Constants.ERROR_MESSAGE, "Unable to start the event " +
						"notification service because the user has not provided permission to " +
						"use the GPS.");
				EventNotificationService.this.startActivity(errorActivityIntent);
				Log.i(TAG,"Unable to start the event notification service because the user has not " +
						"provided permission to use the GPS.");
				return;
			}
			locationManager.removeUpdates(this);

			stopThread = true;

			try {

				session.close(new CloseReason(new CloseCode() {
                    @Override
                    public int getCode() {
                        return 1000;
                    }
                }, "The user stopped the reasoning."));
				Log.i(TAG, "Session is not null and is going to close from stopThread().");
				session = null;
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
 
开发者ID:CityPulse,项目名称:Brasov-Bus-Route-Planner,代码行数:40,代码来源:EventNotificationService.java

示例8: closeConnection

import javax.websocket.CloseReason.CloseCode; //导入依赖的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 {
        CloseCode code = CloseReason.CloseCodes.getCloseCode(guac_status.getWebSocketCode());
        String message = Integer.toString(guac_status.getGuacamoleStatusCode());
        session.close(new CloseReason(code, message));
    }
    catch (IOException e) {
        logger.debug("Unable to close WebSocket connection.", e);
    }

}
 
开发者ID:apache,项目名称:guacamole-client,代码行数:20,代码来源:GuacamoleWebSocketTunnelEndpoint.java

示例9: sendCloseMessage

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
        // PROTOCOL_ERROR is probably better than GOING_AWAY here
        msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
        msg.putShort((short) closeCode.getCode());
    }

    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
        appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
        wsRemoteEndpoint.startMessageBlock(
                Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
        // Failed to send close message. Close the socket and let the caller
        // deal with the Exception
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("wsSession.sendCloseFail"), ioe);
        }
        wsRemoteEndpoint.close();
        // Failure to send a close message is not unexpected in the case of
        // an abnormal closure (usually triggered by a failure to read/write
        // from/to the client. In this case do not trigger the endpoint's
        // error handling
        if (closeCode != CloseCodes.CLOSED_ABNORMALLY) {
            localEndpoint.onError(this, ioe);
        }
    } finally {
        webSocketContainer.unregisterSession(localEndpoint, this);
    }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:39,代码来源:WsSession.java

示例10: getCloseCode

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
static CloseCode getCloseCode(int code) {
    if (code > 2999 && code < 5000) {
        return CloseCodes.getCloseCode(code);
    }
    switch (code) {
        case 1000:
            return CloseCodes.NORMAL_CLOSURE;
        case 1001:
            return CloseCodes.GOING_AWAY;
        case 1002:
            return CloseCodes.PROTOCOL_ERROR;
        case 1003:
            return CloseCodes.CANNOT_ACCEPT;
        case 1004:
            // Should not be used in a close frame
            // return CloseCodes.RESERVED;
            return CloseCodes.PROTOCOL_ERROR;
        case 1005:
            // Should not be used in a close frame
            // return CloseCodes.NO_STATUS_CODE;
            return CloseCodes.PROTOCOL_ERROR;
        case 1006:
            // Should not be used in a close frame
            // return CloseCodes.CLOSED_ABNORMALLY;
            return CloseCodes.PROTOCOL_ERROR;
        case 1007:
            return CloseCodes.NOT_CONSISTENT;
        case 1008:
            return CloseCodes.VIOLATED_POLICY;
        case 1009:
            return CloseCodes.TOO_BIG;
        case 1010:
            return CloseCodes.NO_EXTENSION;
        case 1011:
            return CloseCodes.UNEXPECTED_CONDITION;
        case 1012:
            // Not in RFC6455
            // return CloseCodes.SERVICE_RESTART;
            return CloseCodes.PROTOCOL_ERROR;
        case 1013:
            // Not in RFC6455
            // return CloseCodes.TRY_AGAIN_LATER;
            return CloseCodes.PROTOCOL_ERROR;
        case 1015:
            // Should not be used in a close frame
            // return CloseCodes.TLS_HANDSHAKE_FAILURE;
            return CloseCodes.PROTOCOL_ERROR;
        default:
            return CloseCodes.PROTOCOL_ERROR;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:52,代码来源:Util.java

示例11: getCloseCode

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
static CloseCode getCloseCode(int code) {
	if (code > 2999 && code < 5000) {
		return CloseCodes.getCloseCode(code);
	}
	switch (code) {
	case 1000:
		return CloseCodes.NORMAL_CLOSURE;
	case 1001:
		return CloseCodes.GOING_AWAY;
	case 1002:
		return CloseCodes.PROTOCOL_ERROR;
	case 1003:
		return CloseCodes.CANNOT_ACCEPT;
	case 1004:
		// Should not be used in a close frame
		// return CloseCodes.RESERVED;
		return CloseCodes.PROTOCOL_ERROR;
	case 1005:
		// Should not be used in a close frame
		// return CloseCodes.NO_STATUS_CODE;
		return CloseCodes.PROTOCOL_ERROR;
	case 1006:
		// Should not be used in a close frame
		// return CloseCodes.CLOSED_ABNORMALLY;
		return CloseCodes.PROTOCOL_ERROR;
	case 1007:
		return CloseCodes.NOT_CONSISTENT;
	case 1008:
		return CloseCodes.VIOLATED_POLICY;
	case 1009:
		return CloseCodes.TOO_BIG;
	case 1010:
		return CloseCodes.NO_EXTENSION;
	case 1011:
		return CloseCodes.UNEXPECTED_CONDITION;
	case 1012:
		// Not in RFC6455
		// return CloseCodes.SERVICE_RESTART;
		return CloseCodes.PROTOCOL_ERROR;
	case 1013:
		// Not in RFC6455
		// return CloseCodes.TRY_AGAIN_LATER;
		return CloseCodes.PROTOCOL_ERROR;
	case 1015:
		// Should not be used in a close frame
		// return CloseCodes.TLS_HANDSHAKE_FAILURE;
		return CloseCodes.PROTOCOL_ERROR;
	default:
		return CloseCodes.PROTOCOL_ERROR;
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:52,代码来源:Util.java

示例12: getCloseCode

import javax.websocket.CloseReason.CloseCode; //导入依赖的package包/类
static CloseCode getCloseCode(int code) {
    if (code > 2999 && code < 5000) {
        return CloseCodes.NORMAL_CLOSURE;
    }
    switch (code) {
        case 1000:
            return CloseCodes.NORMAL_CLOSURE;
        case 1001:
            return CloseCodes.GOING_AWAY;
        case 1002:
            return CloseCodes.PROTOCOL_ERROR;
        case 1003:
            return CloseCodes.CANNOT_ACCEPT;
        case 1004:
            // Should not be used in a close frame
            // return CloseCodes.RESERVED;
            return CloseCodes.PROTOCOL_ERROR;
        case 1005:
            // Should not be used in a close frame
            // return CloseCodes.NO_STATUS_CODE;
            return CloseCodes.PROTOCOL_ERROR;
        case 1006:
            // Should not be used in a close frame
            // return CloseCodes.CLOSED_ABNORMALLY;
            return CloseCodes.PROTOCOL_ERROR;
        case 1007:
            return CloseCodes.NOT_CONSISTENT;
        case 1008:
            return CloseCodes.VIOLATED_POLICY;
        case 1009:
            return CloseCodes.TOO_BIG;
        case 1010:
            return CloseCodes.NO_EXTENSION;
        case 1011:
            return CloseCodes.UNEXPECTED_CONDITION;
        case 1012:
            // Not in RFC6455
            // return CloseCodes.SERVICE_RESTART;
            return CloseCodes.PROTOCOL_ERROR;
        case 1013:
            // Not in RFC6455
            // return CloseCodes.TRY_AGAIN_LATER;
            return CloseCodes.PROTOCOL_ERROR;
        case 1015:
            // Should not be used in a close frame
            // return CloseCodes.TLS_HANDSHAKE_FAILURE;
            return CloseCodes.PROTOCOL_ERROR;
        default:
            return CloseCodes.PROTOCOL_ERROR;
    }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:52,代码来源:Util.java


注:本文中的javax.websocket.CloseReason.CloseCode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。