• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 Esmertec AG.
3  * Copyright (C) 2007 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.im.imps;
19 
20 abstract class MultiPhaseTransaction extends AsyncTransaction {
21 
22     public enum TransactionStatus {
23         TRANSACTION_COMPLETED,
24         TRANSACTION_CONTINUE,
25     }
26 
27     /* Multi-phase asynchronous transaction carries no AsyncCompletion.
28      */
MultiPhaseTransaction(ImpsTransactionManager manager)29     public MultiPhaseTransaction(ImpsTransactionManager manager) {
30         super(manager);
31     }
32 
33     @Override
notifySuccessResponse(Primitive response)34     protected void notifySuccessResponse(Primitive response) {
35         TransactionStatus status = processResponse(response);
36         if (status != TransactionStatus.TRANSACTION_CONTINUE) {
37             mTransManager.endClientTransaction(this);
38         }
39     }
40 
41     @Override
notifyErrorResponse(ImpsErrorInfo error)42     protected void notifyErrorResponse(ImpsErrorInfo error) {
43         TransactionStatus status = processResponseError(error);
44         if (status != TransactionStatus.TRANSACTION_CONTINUE) {
45             mTransManager.endClientTransaction(this);
46         }
47     }
48 
processResponseError(ImpsErrorInfo error)49     public abstract TransactionStatus processResponseError(ImpsErrorInfo error);
processResponse(Primitive response)50     public abstract TransactionStatus processResponse(Primitive response);
51 
52     @Override
onResponseError(ImpsErrorInfo error)53     final public void onResponseError(ImpsErrorInfo error) { }
54 
55     @Override
onResponseOk(Primitive response)56     final public void onResponseOk(Primitive response) { }
57 
58 }
59