Safe protection

I have wrapped my updated code in a class like below. If it's not clear from the code, I post it interacting with a soothing service with OAuth.

Is this normal for thread safety? I mean, the user clicks two places at once and starts two API calls. Is this code good? Do I need to maintain an internal queue? And if so, how should I do it?

Judging by this , I would say no. But I'm not sure.

public class RestClient implements IRestClient {
    private IRestAPI api;

    /**
     *
     * @param accessToken
     */
    public RestClient(final String accessToken)
    {
        RequestInterceptor requestInterceptor = new RequestInterceptor()
        {
            @Override
            public void intercept(RequestFacade request) {
                request.addHeader("Authorization", "Bearer " + accessToken);
            }
        };

        RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(Config.ENDPOINT)
                .setRequestInterceptor(requestInterceptor)
                .build();
        api = restAdapter.create(IRestAPI.class);
    }

    @Override
    public void getUserProfile(Callback callback) {
        api.getUserProfile(callback);
    }

    @Override
    public void getFriendList(Callback callback) {
        api.getFriendList(callback);
    }

    @Override
    public void sendMessage(User user, String message, Callback callback) {
        api.sendMessage(user, message, callback);
    }

    @Override
    public void createSomething(Some thing, Callback callback) {
        api.createSomething(thing, callback);
    }

    ...
}

      

Suggestions / comments and more. Thanks in advance.

+3


source to share





All Articles