Search in sources :

Example 36 with Gson

use of com.google.gson.Gson in project bigbluebutton by bigbluebutton.

the class WhiteboardClientMessageSender method processIsWhiteboardEnabledReply.

private void processIsWhiteboardEnabledReply(IsWhiteboardEnabledReplyMessage msg) {
    Map<String, Object> args = new HashMap<String, Object>();
    args.put("enabled", msg.enabled);
    Map<String, Object> message = new HashMap<String, Object>();
    Gson gson = new Gson();
    message.put("msg", gson.toJson(args));
    DirectClientMessage m = new DirectClientMessage(msg.meetingId, msg.requesterId, "WhiteboardIsWhiteboardEnabledReply", message);
    service.sendMessage(m);
    // broadcast message
    BroadcastClientMessage b = new BroadcastClientMessage(msg.meetingId, "WhiteboardIsWhiteboardEnabledReply", message);
    service.sendMessage(b);
}
Also used : BroadcastClientMessage(org.bigbluebutton.red5.client.messaging.BroadcastClientMessage) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) DirectClientMessage(org.bigbluebutton.red5.client.messaging.DirectClientMessage)

Example 37 with Gson

use of com.google.gson.Gson in project bigbluebutton by bigbluebutton.

the class WhiteboardClientMessageSender method processSendWhiteboardAnnotationReplyMessage.

private void processSendWhiteboardAnnotationReplyMessage(SendWhiteboardAnnotationReplyMessage msg) {
    Map<String, Object> args = new HashMap<String, Object>();
    args.put("whiteboardId", msg.whiteboardId);
    Map<String, Object> shape = new HashMap<String, Object>();
    shape.put("id", msg.shape.get("id"));
    shape.put("type", msg.shape.get("type"));
    shape.put("status", msg.shape.get("status"));
    shape.put("shape", msg.shape.get("shapes"));
    args.put("shape", shape);
    Map<String, Object> message = new HashMap<String, Object>();
    Gson gson = new Gson();
    message.put("msg", gson.toJson(args));
    //broadcast message
    BroadcastClientMessage b = new BroadcastClientMessage(msg.meetingId, "WhiteboardNewAnnotationCommand", message);
    service.sendMessage(b);
}
Also used : BroadcastClientMessage(org.bigbluebutton.red5.client.messaging.BroadcastClientMessage) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject)

Example 38 with Gson

use of com.google.gson.Gson in project bigbluebutton by bigbluebutton.

the class WhiteboardClientMessageSender method processClearWhiteboardReply.

private void processClearWhiteboardReply(ClearWhiteboardReplyMessage msg) {
    Map<String, Object> args = new HashMap<String, Object>();
    args.put("whiteboardId", msg.whiteboardId);
    Map<String, Object> message = new HashMap<String, Object>();
    Gson gson = new Gson();
    message.put("msg", gson.toJson(args));
    BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingId, "WhiteboardClearCommand", message);
    service.sendMessage(m);
}
Also used : BroadcastClientMessage(org.bigbluebutton.red5.client.messaging.BroadcastClientMessage) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject)

Example 39 with Gson

use of com.google.gson.Gson in project bigbluebutton by bigbluebutton.

the class ConnectionInvokerService method sendDirectMessage.

private void sendDirectMessage(final DirectClientMessage msg) {
    if (log.isTraceEnabled()) {
        Gson gson = new Gson();
        String json = gson.toJson(msg.getMessage());
        log.trace("Handle direct message: " + msg.getMessageName() + " msg=" + json);
    }
    final String userId = msg.getUserID();
    Runnable sender = new Runnable() {

        public void run() {
            IScope meetingScope = getScope(msg.getMeetingID());
            if (meetingScope != null) {
                IConnection conn = getConnection(meetingScope, userId);
                if (conn != null) {
                    if (conn.isConnected()) {
                        List<Object> params = new ArrayList<Object>();
                        params.add(msg.getMessageName());
                        params.add(msg.getMessage());
                        if (log.isTraceEnabled()) {
                            Gson gson = new Gson();
                            String json = gson.toJson(msg.getMessage());
                            log.debug("Send direct message: " + msg.getMessageName() + " msg=" + json);
                        }
                        ServiceUtils.invokeOnConnection(conn, "onMessageFromServer", params.toArray());
                    }
                } else {
                    log.info("Cannot send message=[" + msg.getMessageName() + "] to [" + userId + "] as no such session on meeting=[" + msg.getMeetingID() + "]");
                }
            }
        }
    };
    /**
     * We need to add a way to cancel sending when the thread is blocked.
     * Red5 uses a semaphore to guard the rtmp connection and we've seen
     * instances where our thread is blocked preventing us from sending messages
     * to other connections. (ralam nov 19, 2015)
     */
    long endNanos = System.nanoTime() + SEND_TIMEOUT;
    Future<?> f = runExec.submit(sender);
    try {
        // Only wait for the remaining time budget         
        long timeLeft = endNanos - System.nanoTime();
        f.get(timeLeft, TimeUnit.NANOSECONDS);
    } catch (ExecutionException e) {
        log.warn("ExecutionException while sending direct message on connection[" + userId + "]");
        log.warn("ExcecutionException cause: " + e.getMessage());
    } catch (InterruptedException e) {
        log.warn("Interrupted exception while sending direct message on connection[" + userId + "]");
        Thread.currentThread().interrupt();
    } catch (TimeoutException e) {
        log.warn("Timeout exception while sending direct message on connection[" + userId + "]");
        f.cancel(true);
    }
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IConnection(org.red5.server.api.IConnection) IScope(org.red5.server.api.scope.IScope) ISharedObject(org.red5.server.api.so.ISharedObject) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 40 with Gson

use of com.google.gson.Gson in project LoganSquare by bluelinelabs.

the class MainActivity method performSerializeTests.

private void performSerializeTests() {
    mBarChart.clear();
    mBarChart.setSections(new String[] { "Serialize 60 items", "Serialize 20 items", "Serialize 7 items", "Serialize 2 items" });
    Gson gson = new Gson();
    ObjectMapper objectMapper = new ObjectMapper();
    Moshi moshi = new Moshi.Builder().build();
    List<Serializer> serializers = new ArrayList<>();
    for (Response response : mResponsesToSerialize) {
        for (int iteration = 0; iteration < ITERATIONS; iteration++) {
            serializers.add(new GsonSerializer(mSerializeListener, response, gson));
            serializers.add(new JacksonDatabindSerializer(mSerializeListener, response, objectMapper));
            serializers.add(new LoganSquareSerializer(mSerializeListener, response));
            serializers.add(new MoshiSerializer(mSerializeListener, response, moshi));
        }
    }
    for (Serializer serializer : serializers) {
        serializer.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
    }
}
Also used : JacksonDatabindSerializer(com.bluelinelabs.logansquare.demo.serializetasks.JacksonDatabindSerializer) Moshi(com.squareup.moshi.Moshi) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) GsonSerializer(com.bluelinelabs.logansquare.demo.serializetasks.GsonSerializer) MoshiSerializer(com.bluelinelabs.logansquare.demo.serializetasks.MoshiSerializer) Response(com.bluelinelabs.logansquare.demo.model.Response) LoganSquareSerializer(com.bluelinelabs.logansquare.demo.serializetasks.LoganSquareSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Serializer(com.bluelinelabs.logansquare.demo.serializetasks.Serializer) MoshiSerializer(com.bluelinelabs.logansquare.demo.serializetasks.MoshiSerializer) LoganSquareSerializer(com.bluelinelabs.logansquare.demo.serializetasks.LoganSquareSerializer) GsonSerializer(com.bluelinelabs.logansquare.demo.serializetasks.GsonSerializer) JacksonDatabindSerializer(com.bluelinelabs.logansquare.demo.serializetasks.JacksonDatabindSerializer)

Aggregations

Gson (com.google.gson.Gson)1309 Test (org.junit.Test)280 HashMap (java.util.HashMap)227 GsonBuilder (com.google.gson.GsonBuilder)174 JsonObject (com.google.gson.JsonObject)157 IOException (java.io.IOException)147 CommandWrapper (ClientServerApi.CommandWrapper)123 ArrayList (java.util.ArrayList)121 CommandExecuter (CommandHandler.CommandExecuter)119 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)118 JsonSyntaxException (com.google.gson.JsonSyntaxException)103 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)96 JsonElement (com.google.gson.JsonElement)78 Type (java.lang.reflect.Type)77 Map (java.util.Map)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)53 SmartCode (BasicCommonClasses.SmartCode)50 InputStreamReader (java.io.InputStreamReader)49 List (java.util.List)49 TypeToken (com.google.gson.reflect.TypeToken)44