public interface TransactionListener
Note that having a listener that properly detects any transaction failure is essential for the error handling in the client application code. The following pseudo code illustrates a listener function and the client code that capture any personalization transaction failure:
public static class SimpleEngineEventListener implements TransactionListener {
// transaction end result code is available post transaction
public int resultCode;
public void onLicenseDataReceived(byte[] data) {
}
public void onTransactionBegin(TransactionType transactionType) {
}
public void onTransactionEnd(TransactionType transactionType,
int resultCode, String resultString, String serviceFault) {
// capture transaction end result code
this.resultCode = resultCode;
}
public void onTransactionProgress(TransactionType transactionType,
int currentStep, int totalSteps) {
}
}
void MyPersonalization() {
Runtime.initialize();
Engine engine = new Engine();
try {
SimpleEngineEventListener listener = new SimpleEngineEventListener();
engine.addTransactionListener(listener);
engine.personalize(null);
engine.updatePersonality(null);
// check transaction end result code
ErrorCodeException.checkResult(listener.resultCode);
} catch (Exception x) {
x.printStackTrace();
} finally {
engine.destroy();
Runtime.shutdown();
}
}
Modifier and Type | Method and Description |
---|---|
void |
onLicenseDataReceived(byte[] data)
called when some license data has been received by the engine
|
void |
onTransactionBegin(TransactionType transactionType)
called when a transaction begins
|
void |
onTransactionEnd(TransactionType transactionType,
int resultCode,
java.lang.String resultString,
java.lang.String serviceFault)
called when a transaction ends.
|
void |
onTransactionProgress(TransactionType transactionType,
int currentStep,
int totalSteps)
called when a transaction makes progress
|
void onLicenseDataReceived(byte[] data)
data
- the license datavoid onTransactionBegin(TransactionType transactionType)
transactionType
- type of the transactionvoid onTransactionProgress(TransactionType transactionType, int currentStep, int totalSteps)
transactionType
- type of the transactioncurrentStep
- current step of the transactiontotalSteps
- total steps of the transactionvoid onTransactionEnd(TransactionType transactionType, int resultCode, java.lang.String resultString, java.lang.String serviceFault)
transactionType
- type of the transactionresultCode
- result code of the transaction, 0 is success.resultString
- message String explaining the result of the transactionserviceFault
- if a transaction has failed because of a service fault, the
serviceFault contains the XML String of the SOAP fault.