Example usage for com.google.gwt.user.client.rpc.impl RpcStatsContext RpcStatsContext

List of usage examples for com.google.gwt.user.client.rpc.impl RpcStatsContext RpcStatsContext

Introduction

In this page you can find the example usage for com.google.gwt.user.client.rpc.impl RpcStatsContext RpcStatsContext.

Prototype

public RpcStatsContext() 

Source Link

Usage

From source file:fr.putnami.pwt.core.service.client.DefaultCommandController.java

License:Open Source License

private int sendRequest(List<Request> requests, AsyncCallback<List<CommandResponse>> callback) {
    if (requests == null || requests.isEmpty()) {
        return 0;
    }/*from   w w  w  . jav  a 2  s .  c  om*/
    try {
        Collection<Serializer> serializers = Sets.newHashSet();
        List<CommandRequest> commands = Lists.newArrayList();

        for (Request request : requests) {
            serializers.add(request.param.getSerializer());
            commands.add(request.command);
            if (!request.param.isQuiet()) {
                this.fireEvent(new CommandRequestEvent(request.requestId, request.command));
            }
        }

        ServiceCallback serviceCallback = new ServiceCallback(requests, callback);
        CommandServiceCompositeSerializer compositeSerializer = new CommandServiceCompositeSerializer(
                serializers);

        SerializationStreamFactory streamFactory = new CommandSerializationStreamFactory(compositeSerializer,
                this.moduleBaseURL);
        SerializationStreamWriter streamWriter = streamFactory.createStreamWriter();

        streamWriter.writeString(DefaultCommandController.REMOTE_SERVICE_INTERFACE_NAME);
        streamWriter.writeString(DefaultCommandController.METHOD_NAME);
        streamWriter.writeInt(1);
        streamWriter.writeString(List.class.getName());
        streamWriter.writeObject(commands);

        String payload = streamWriter.toString();

        RpcStatsContext statsContext = new RpcStatsContext();

        RequestCallback responseHandler = new RequestCallbackAdapter<List<CommandResponse>>(streamFactory,
                DefaultCommandController.METHOD_NAME, statsContext, serviceCallback, null,
                ResponseReader.OBJECT);

        this.rpcRequestBuilder.create(this.remoteServiceURL);
        this.rpcRequestBuilder.setCallback(responseHandler);
        this.rpcRequestBuilder.setContentType(DefaultCommandController.RPC_CONTENT_TYPE);
        this.rpcRequestBuilder.setRequestData(payload);
        this.rpcRequestBuilder.setRequestId(statsContext.getRequestId());

        RequestBuilder rb = this.rpcRequestBuilder.finish();
        CsrfController.get().securize(rb);
        rb.send();

        return requests.size();
    } catch (SerializationException e) {
        throw new CommandException(e.getMessage());
    } catch (RequestException e) {
        throw new CommandException(e.getMessage());
    }
}