Java Code Examples for org.kurento.jsonrpc.Transaction#getSession()

The following examples show how to use org.kurento.jsonrpc.Transaction#getSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloseSessionTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final Transaction transaction, Request<String> request)
    throws Exception {

  Session session = transaction.getSession();

  if (session.isNew()) {
    transaction.sendResponse("new");
  } else {
    transaction.sendResponse("old");
  }

  if (counter == 2) {
    session.close();
  }
  counter++;
}
 
Example 2
Source File: BidirectionalMultiTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(Transaction transaction, Request<Integer> request) throws Exception {

  log.debug("Request id:" + request.getId());
  log.debug("Request method:" + request.getMethod());
  log.debug("Request params:" + request.getParams());

  transaction.sendResponse(request.getParams());

  final Session session = transaction.getSession();
  final Object params = request.getParams();

  new Thread() {
    @Override
    public void run() {
      asyncReverseSend(session, params);
    }
  }.start();
}
 
Example 3
Source File: BidirectionalTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(Transaction transaction, Request<Object> request) throws Exception {

  log.debug("Request id:" + request.getId());
  log.debug("Request method:" + request.getMethod());
  log.debug("Request params:" + request.getParams());

  transaction.sendResponse(request.getParams());

  final Session session = transaction.getSession();
  final Object params = request.getParams();

  new Thread() {
    @Override
    public void run() {
      asyncReverseSend(session, params);
    }
  }.start();
}
 
Example 4
Source File: RpcNotificationService.java    From openvidu with Apache License 2.0 5 votes vote down vote up
public RpcConnection newRpcConnection(Transaction t, Request<JsonObject> request) {
	String participantPrivateId = t.getSession().getSessionId();
	RpcConnection connection = new RpcConnection(t.getSession());
	RpcConnection oldConnection = rpcConnections.putIfAbsent(participantPrivateId, connection);
	if (oldConnection != null) {
		log.warn("Concurrent initialization of rpcSession {}", participantPrivateId);
		connection = oldConnection;
	}
	return connection;
}
 
Example 5
Source File: JsonRpcUserControl.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
public ParticipantSession getParticipantSession(Transaction transaction) {
  Session session = transaction.getSession();
  ParticipantSession participantSession = (ParticipantSession) session.getAttributes().get(
      ParticipantSession.SESSION_KEY);
  if (participantSession == null) {
    participantSession = new ParticipantSession();
    session.getAttributes().put(ParticipantSession.SESSION_KEY, participantSession);
  }
  return participantSession;
}
 
Example 6
Source File: JsonRpcNotificationService.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
public SessionWrapper addTransaction(Transaction t, Request<JsonObject> request) {
  String sessionId = t.getSession().getSessionId();
  SessionWrapper sw = sessions.get(sessionId);
  if (sw == null) {
    sw = new SessionWrapper(t.getSession());
    SessionWrapper oldSw = sessions.putIfAbsent(sessionId, sw);
    if (oldSw != null) {
      log.warn("Concurrent initialization of session wrapper #{}", sessionId);
      sw = oldSw;
    }
  }
  sw.addTransaction(request.getId(), t);
  return sw;
}
 
Example 7
Source File: ReconnectionTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final Transaction transaction, Request<String> request)
    throws Exception {

  Session session = transaction.getSession();

  if (session.isNew()) {
    transaction.sendResponse("new");
  } else {
    transaction.sendResponse("old");
  }
}
 
Example 8
Source File: ReconnectionFromServerTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final Transaction transaction, Request<String> request)
    throws Exception {

  log.debug("Receive request in server: " + request);

  if (session == null) {
    session = transaction.getSession();
  }

  if (session.isNew()) {
    transaction.sendResponse("new");
  } else {
    transaction.sendResponse("old");
  }

  log.debug("Response sent from server");

  executor.schedule(new Runnable() {
    @Override
    public void run() {
      try {
        log.debug("Request send from server");
        JsonElement result = session.sendRequest("hello");
        log.debug("Response received in server");
        log.debug("Result: " + result);
        s.release();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }, 500, TimeUnit.MILLISECONDS);
}