@Override public void messageReceived(IoSession session, Object message) throws Exception { MRTMPPacket mrtmpPacket = (MRTMPPacket) message; int clientId = mrtmpPacket.getHeader().getClientId(); RTMPConnection conn = rtmpConnManager.getConnection(clientId); if (conn == null) { log.debug("Client " + clientId + " is already closed."); return; } RTMP rtmpState = conn.getState(); switch (mrtmpPacket.getHeader().getType()) { case MRTMPPacket.CLOSE: conn.setStateCode(RTMP.STATE_EDGE_DISCONNECTING); conn.close(); break; case MRTMPPacket.RTMP: RTMPHeader rtmpHeader = (RTMPHeader) mrtmpPacket.getHeader(); RTMPBody rtmpBody = (RTMPBody) mrtmpPacket.getBody(); boolean toDisconnect = false; // conn.getWriteLock().lock(); try { if (rtmpState.getState() == RTMP.STATE_ORIGIN_CONNECT_FORWARDED && rtmpHeader.getRtmpType() == TYPE_INVOKE) { // we got the connect invocation result from Origin // parse the result Invoke invoke = (Invoke) rtmpBody.getRtmpPacket().getMessage(); if ("connect".equals(invoke.getCall().getServiceMethodName())) { if (invoke.getCall().getStatus() == Call.STATUS_SUCCESS_RESULT) { rtmpState.setState(RTMP.STATE_CONNECTED); } else { // TODO set EdgeRTMP state to closing ? toDisconnect = true; } } } } finally { // conn.getWriteLock().unlock(); } log.debug("Forward packet to client: {}", rtmpBody.getRtmpPacket().getMessage()); // send the packet back to client conn.write(rtmpBody.getRtmpPacket()); if (toDisconnect) { conn.close(); } // conn.getWriteLock().lock(); try { if (rtmpState.getState() == RTMP.STATE_CONNECTED) { conn.startRoundTripMeasurement(); } } finally { // conn.getWriteLock().unlock(); } break; default: break; } }
public byte getStateCode() { getReadLock().lock(); try { return state.getState(); } finally { getReadLock().unlock(); } }
public byte getStateCode() { return state.getState(); }