本文整理汇总了Java中org.red5.server.api.Red5.setConnectionLocal方法的典型用法代码示例。如果您正苦于以下问题:Java Red5.setConnectionLocal方法的具体用法?Java Red5.setConnectionLocal怎么用?Java Red5.setConnectionLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.red5.server.api.Red5
的用法示例。
在下文中一共展示了Red5.setConnectionLocal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendCursorStatus
import org.red5.server.api.Red5; //导入方法依赖的package包/类
public void sendCursorStatus() {
try {
Point mouseP = MouseInfo.getPointerInfo().getLocation();
float scaleFactor = (1.0f * dim.getResizeX()) / dim.getSpinnerWidth();
// Real size: Real mouse position = Resize : X
int x = (int)((mouseP.getX() - dim.getSpinnerX()) * scaleFactor);
int y = (int)((mouseP.getY() - dim.getSpinnerY()) * scaleFactor);
if (instance.getConnection() != null) {
if (Red5.getConnectionLocal() == null) {
Red5.setConnectionLocal(instance.getConnection());
}
instance.invoke("setNewCursorPosition", new Object[] { x, y }, this);
}
} catch (NullPointerException npe) {
//noop
} catch (Exception err) {
frame.setStatus("Exception: " + err);
log.error("[sendCursorStatus]", err);
}
}
示例2: captureScreenStop
import org.red5.server.api.Red5; //导入方法依赖的package包/类
private void captureScreenStop(String action) {
try {
log.debug("INVOKE screenSharerAction" );
Map<String, Object> map = new HashMap<>();
map.put(action, true);
if (Red5.getConnectionLocal() == null) {
Red5.setConnectionLocal(instance.getConnection());
}
instance.invoke("screenSharerAction", new Object[] { map }, this);
} catch (Exception err) {
log.error("captureScreenStop Exception: ", err);
frame.setStatus("Exception: " + err);
}
}
示例3: call
import org.red5.server.api.Red5; //导入方法依赖的package包/类
public Packet call() throws Exception {
//keep a ref for executor thread
taskThread = Thread.currentThread();
// set connection to thread local
Red5.setConnectionLocal(conn);
try {
// pass message to the handler
handler.messageReceived(conn, packet);
// if we get this far, set done / completed flag
packet.setProcessed(true);
} finally {
// clear thread local
Red5.setConnectionLocal(null);
}
if (log.isDebugEnabled()) {
log.debug("Processing message for {} is processed: {} packet #{}", sessionId, packet.isProcessed(), packetNumber);
}
return packet;
}
示例4: getConnection
import org.red5.server.api.Red5; //导入方法依赖的package包/类
/**
* Returns a connection based on the current client session id.
*
* @return RTMPTConnection
*/
protected RTMPTConnection getConnection() {
String sessionId = requestInfo.get().getSessionId();
RTMPTConnection conn = (RTMPTConnection) manager.getConnectionBySessionId(sessionId);
if (conn != null) {
// check for non-connected state
if (!conn.isDisconnected()) {
// clear thread local reference
Red5.setConnectionLocal(conn);
} else {
removeConnection(sessionId);
}
} else {
log.warn("Null connection for session id: {}", sessionId);
}
return conn;
}
示例5: connectionHandler
import org.red5.server.api.Red5; //导入方法依赖的package包/类
@Test
public void connectionHandler() {
context = (Context) applicationContext.getBean("web.context");
TestConnection conn = new TestConnection(host, "/", null);
// add the connection to thread local
Red5.setConnectionLocal(conn);
// resolve root
IScope scope = context.resolveScope("/");
IClientRegistry reg = context.getClientRegistry();
IClient client = reg.newClient(null);
assertNotNull(client);
log.debug("----------------------------------\nDump scope details");
((Scope) scope).dump();
log.debug("----------------------------------\n");
conn.initialize(client);
if (!conn.connect(scope)) {
assertTrue("didnt connect", false);
} else {
assertTrue("should have a scope", conn.getScope() != null);
conn.close();
assertTrue("should not be connected", !conn.isConnected());
}
Red5.setConnectionLocal(null);
}
示例6: testDecodeBufferExTS
import org.red5.server.api.Red5; //导入方法依赖的package包/类
@Test
public void testDecodeBufferExTS() {
//log.debug("\testDecodeBufferExTS");
RTMPProtocolDecoder dec = new RTMPProtocolDecoder();
RTMPConnection conn = new RTMPMinaConnection();
Red5.setConnectionLocal(conn);
RTMP rtmp = conn.getState();
rtmp.setState(RTMP.STATE_CONNECTED);
// lastHeader: Header [streamId=1, channelId=4, dataType=18, timerBase=0, timerDelta=0, size=309, extended=false]
// get the local decode state
RTMPDecodeState state = conn.getDecoderState();
// meta and audio 4x chunks
IoBuffer in = IoBuffer.wrap(IOUtils.hexStringToByteArray("04000000000135120100000002000d40736574446174614672616d6502000a6f6e4d65746144617461080000000d00086475726174696f6e0040d518000000000000057769647468004064000000000000000668656967687400405e000000000000000d766964656f64617461726174650040686a000000000000096672616d657261746500403900000000c40000000c766964656f636f6465636964004000000000000000000d617564696f6461746172617465000000000000000000000f617564696f73616d706c65726174650040d5888000000000000f617564696f73616d706c6573697a65004030000000000000000673746572656f0100000c617564696f636f6465636964004000c40000000000000007656e636f64657202000d4c61766635362e31352e313032000866696c6573697a650000000000000000000000090400000000006908010000002afff340c400104002e62d4110009080200830107ea04cfa810710e0987f820ec130fc401897c1c0c70ff502008020eea04c1f0fe7fcb9fc10ff90d107c1f82008021feb07c1c04010041c20f89c1fff6b6edad93d99d8da6cd42a08e459095589d4b5fb9a4e679a1f4400001a00006a082afff342c41a19c91f225d89300055a47640c62cee7ccc85c08c42cadb6b56daebe65989f78c3ef3cfbd694ac0c34aa855ee0598a031f0a0686212d43631a4c59a926383c2d5201c5e9b7377"));
Packet packet = null;
do {
packet = dec.decodePacket(conn, state, in);
} while (packet == null);
assertNotNull(packet);
assertTrue(packet.getMessage() instanceof Notify);
do {
packet = dec.decodePacket(conn, state, in);
} while (packet == null);
assertNotNull(packet);
assertTrue(packet.getMessage() instanceof AudioData);
}
示例7: setConnectionAsSharingClient
import org.red5.server.api.Red5; //导入方法依赖的package包/类
public void setConnectionAsSharingClient() {
log.debug("########## setConnectionAsSharingClient");
try {
if (Red5.getConnectionLocal() == null) {
Red5.setConnectionLocal(instance.getConnection());
}
Map<String, Object> map = new HashMap<>();
int scaledWidth = dim.getResizeX();
int scaledHeight = dim.getResizeY();
map.put("screenWidth", scaledWidth);
map.put("screenHeight", scaledHeight);
map.put("startRecording", startRecording);
map.put("startStreaming", startSharing);
map.put("startPublishing", startPublishing);
map.put("publishingHost", frame.getPublishHost());
map.put("publishingApp", frame.getPublishApp());
map.put("publishingId", frame.getPublishId());
if (Red5.getConnectionLocal() == null) {
Red5.setConnectionLocal(instance.getConnection());
}
instance.invoke("setConnectionAsSharingClient", new Object[] { map }, this);
} catch (Exception err) {
frame.setStatus("Error: " + err.getLocalizedMessage());
log.error("[setConnectionAsSharingClient]", err);
}
}
示例8: pushVideo
import org.red5.server.api.Red5; //导入方法依赖的package包/类
public void pushVideo(VideoData data, int ts) {
if (startPublish) {
if (Red5.getConnectionLocal() == null) {
Red5.setConnectionLocal(client.getConnection());
}
RTMPMessage rtmpMsg = RTMPMessage.build(data, ts);
client.publishStreamData(streamId, rtmpMsg);
}
}
示例9: handler
import org.red5.server.api.Red5; //导入方法依赖的package包/类
@Test
public void handler() {
context = (Context) applicationContext.getBean("web.context");
Scope testApp = (Scope) context.resolveScope(appPath);
assertTrue("should have a handler", testApp.hasHandler());
IClientRegistry reg = context.getClientRegistry();
IClient client = reg.newClient(null);
TestConnection conn = new TestConnection(host, appPath, client.getId());
conn.initialize(client);
Red5.setConnectionLocal(conn);
assertTrue("client should not be null", client != null);
log.debug("{}", client);
String key = "key";
String value = "value";
client.setAttribute(key, value);
assertTrue("attributes not working", client.getAttribute(key) == value);
assertTrue(conn.connect(testApp));
assertTrue("app should have 1 client", testApp.getClients().size() == 1);
assertTrue("host should have 1 client", testApp.getParent().getClients().size() == 1);
conn.close();
assertTrue("app should have 0 client", testApp.getClients().size() == 0);
assertTrue("host should have 0 client", testApp.getParent().getClients().size() == 0);
//client.disconnect();
Red5.setConnectionLocal(null);
}
示例10: messageReceived
import org.red5.server.api.Red5; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
if (log.isTraceEnabled()) {
log.trace("messageReceived session: {} message: {}", session, message);
log.trace("Filter chain: {}", session.getFilterChain());
}
String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID);
if (log.isTraceEnabled()) {
log.trace("Message received on session: {} id: {}", session.getId(), sessionId);
}
RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId);
if (conn != null) {
if (message != null) {
if (message instanceof Packet) {
byte state = conn.getStateCode();
// checking the state before allowing a task to be created will hopefully prevent rejected task exceptions
if (state != RTMP.STATE_DISCONNECTING && state != RTMP.STATE_DISCONNECTED) {
Red5.setConnectionLocal(conn);
conn.handleMessageReceived((Packet) message);
Red5.setConnectionLocal(null);
} else {
log.info("Ignoring received message on {} due to state: {}", sessionId, RTMP.states[state]);
}
}
}
} else {
log.warn("Connection was not found for {}, force closing", sessionId);
forceClose(session);
}
}
示例11: execute
import org.red5.server.api.Red5; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void execute(ISchedulingService service) {
if (!pendingInMessages.isEmpty()) {
// ensure the job is not already running
if (running.compareAndSet(false, true)) {
int available = pendingInMessages.size();
log.debug("process - available: {}", available);
// set connection local
Red5.setConnectionLocal(conn);
// get the session
IoSession session = getSession();
// grab some of the incoming data
LinkedList<Object> sliceList = new LinkedList<Object>();
int sliceSize = pendingInMessages.drainTo(sliceList, Math.min(maxInMessagesPerProcess, available));
log.debug("processing: {}", sliceSize);
// handle the messages
for (Object message : sliceList) {
try {
handler.messageReceived(message, session);
} catch (Exception e) {
log.error("Could not process received message", e);
}
// exit execution of the parent connection is closing
if (isClosing()) {
break;
}
}
// unset connection local
Red5.setConnectionLocal(null);
// reset run state
running.compareAndSet(true, false);
} else {
log.trace("Process already running");
}
} else {
log.trace("No incoming messages to process");
}
}
示例12: handleOpen
import org.red5.server.api.Red5; //导入方法依赖的package包/类
/**
* Start a new RTMPT session.
*
* @param req
* Servlet request
* @param resp
* Servlet response
* @throws IOException
* I/O exception
*/
protected void handleOpen(HttpServletRequest req, HttpServletResponse resp) throws IOException {
log.debug("handleOpen");
// skip sent data
skipData(req);
// TODO: should we evaluate the pathinfo?
RTMPTConnection conn = (RTMPTConnection) manager.createConnection(RTMPTConnection.class);
log.trace("{}", conn);
if (conn != null) {
// set properties
conn.setServlet(this);
conn.setServletRequest(req);
// add the connection to the manager
manager.setConnection(conn);
// set handler
conn.setHandler(handler);
conn.setDecoder(handler.getCodecFactory().getRTMPDecoder());
conn.setEncoder(handler.getCodecFactory().getRTMPEncoder());
handler.connectionOpened(conn);
conn.dataReceived();
conn.updateReadBytes(req.getContentLength());
// set thread local reference
Red5.setConnectionLocal(conn);
if (conn.getId() != 0) {
// return session id to client
returnMessage(String.format("%s\n", conn.getSessionId()), resp);
} else {
// no more clients are available for serving
returnMessage((byte) 0, resp);
}
} else {
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
resp.setHeader("Connection", "Keep-Alive");
resp.setHeader("Cache-Control", "no-cache");
resp.flushBuffer();
}
}
示例13: removeConnection
import org.red5.server.api.Red5; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public RTMPConnection removeConnection(String sessionId) {
log.debug("Removing connection with session id: {}", sessionId);
if (log.isTraceEnabled()) {
log.trace("Connections ({}) at pre-remove: {}", connMap.size(), connMap.values());
}
// remove from map
RTMPConnection conn = connMap.remove(sessionId);
if (conn != null) {
log.trace("Connections: {}", conns.decrementAndGet());
Red5.setConnectionLocal(null);
}
return conn;
}
示例14: encode
import org.red5.server.api.Red5; //导入方法依赖的package包/类
@Override
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws ProtocolCodecException {
// get the connection from the session
String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID);
log.trace("Session id: {}", sessionId);
RTMPConnection conn = (RTMPConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId);
if (conn != null) {
Red5.setConnectionLocal(conn);
final Semaphore lock = conn.getEncoderLock();
try {
// acquire the encoder lock
lock.acquire();
// get the buffer
final IoBuffer buf = message instanceof IoBuffer ? (IoBuffer) message : getEncoder().encode(message);
if (buf != null) {
if (log.isTraceEnabled()) {
log.trace("Writing output data: {}", Hex.encodeHexString(buf.array()));
}
out.write(buf);
} else {
log.trace("Response buffer was null after encoding");
}
} catch (Exception ex) {
log.error("Exception during encode", ex);
} finally {
lock.release();
Red5.setConnectionLocal(null);
}
} else {
log.debug("Connection is no longer available for encoding, may have been closed already");
}
}
示例15: messageReceived
import org.red5.server.api.Red5; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
log.debug("messageReceived");
if (message instanceof Packet && message != null) {
String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID);
log.trace("Session id: {}", sessionId);
RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId);
Red5.setConnectionLocal(conn);
conn.handleMessageReceived((Packet) message);
Red5.setConnectionLocal(null);
} else {
log.debug("Not packet type: {}", message);
}
}