equal
deleted
inserted
replaced
|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.sdk.internal.tools.v8; |
|
6 |
|
7 import org.chromium.sdk.internal.protocol.CommandResponse; |
|
8 import org.chromium.sdk.internal.protocol.SuccessCommandResponse; |
|
9 |
|
10 /** |
|
11 * The callback that handles JSON response to a VM command. The command-sender is staying |
|
12 * blocked until callback finishes, which allows the callback to return a result of |
|
13 * user-specified type {@code RES}. |
|
14 * <p>User should subclass this and implement |
|
15 * {@link #handleSuccessfulResponse(SuccessCommandResponse)} method. |
|
16 * @param <RES> type of result value that is passed back to caller |
|
17 */ |
|
18 public abstract class V8BlockingCallback<RES> { |
|
19 public RES messageReceived(CommandResponse response) { |
|
20 SuccessCommandResponse successResponse = response.asSuccess(); |
|
21 if (successResponse == null) { |
|
22 throw new RuntimeException("Unsuccessful command " + |
|
23 response.asFailure().getMessage()); |
|
24 } |
|
25 return handleSuccessfulResponse(successResponse); |
|
26 } |
|
27 |
|
28 /** |
|
29 * User-implementable method that handled successful json response and pass result back to |
|
30 * command-sender. |
|
31 * @param response with "success=true" |
|
32 */ |
|
33 protected abstract RES handleSuccessfulResponse(SuccessCommandResponse response); |
|
34 } |