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

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

Introduction

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

Prototype

public int getRequestId() 

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.j a  v  a 2s . co  m*/
    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());
    }
}

From source file:org.rhq.coregui.client.util.rpc.TrackingRemoteServiceProxy.java

License:Open Source License

@Override
protected <T> RequestCallback doCreateRequestCallback(ResponseReader responseReader, String methodName,
        RpcStatsContext statsContext, AsyncCallback<T> callback) {

    RequestCallback original = super.doCreateRequestCallback(responseReader, methodName, statsContext,
            callback);//from w  w  w.  ja v a2 s . c o  m
    TrackingRequestCallback trackingCallback = new TrackingRequestCallback(statsContext.getRequestId(),
            methodName, original);

    RPCTracker.getInstance().register(trackingCallback);

    return trackingCallback;
}