listenAccount
You can call this operation to subscribe to an account.
public boolean listenAccount(Identity identity, EventHandler handler, EventModelType type)
Name |
Required |
Type |
Description |
identity |
true |
Identity |
The business ID of the account. |
handler |
true |
EventHandler |
A callback is called when a response is received or when a timeout or error occurs. |
type |
true |
EventModelType |
The type of the event model. 1: PULL. 2: PUSH |
Name |
Type |
Description |
result |
bool |
The returned result. true: normal. false: error. |
// event handler
EventHandler handler = new EventHandler() {
@Override
public void handle(Message message) {
EventAccountMessage eventAccountMessage = (EventAccountMessage) message;
//code
}
};
// account: Tester001
Identity identity = new Identity("c60a9d48105950a0cca07a4c6320b98c303ad42d694a634529e8e1a0a16fcdb5");
// listen account
boolean result = sdk.getEventService().listenAccount(identity, handler,EventModelType.PUSH)
listenContract
You can call this operation to subscribe to a contract.
public boolean listenContract(Identity identity, EventHandler handler, EventModelType type)
Name |
Required |
Type |
Description |
identity |
true |
Identity |
The business ID of the account. |
handler |
true |
EventHandler |
A callback is called when a response is received or when a timeout or error occurs. |
type |
true |
EventModelType |
The type of the event model. 1: PULL. 2: PUSH |
Name |
Type |
Description |
result |
bool |
The returned result. true: normal. false: error. |
/event handler
EventHandler handler = new EventHandler() {
@Override
public void handle(Message message) {
EventContractMessage eventContractMessage = (EventContractMessage) message;
// code
}
};
Identity identity = new Identity("a7937b64b8caa58f03721bb6bacf5c78cb235febe0e70b1b84cd99541461a08e");
//listen contract
boolean result = sdk.getEventService().listenContract(identity, handler,EventModelType.PUSH)
listenTopics
You can call this operation to subscribe to topic events.
public boolean listenTopics(List<String> topics, EventHandler handler, EventModelType type)
Name |
Required |
Type |
Description |
topics |
true |
List |
The topic list to be subscribed. |
handler |
true |
EventHandler |
A callback is called when a response is received or when a timeout or error occurs. |
type |
true |
EventModelType |
The type of the event model. 1: PULL. 2: PUSH |
Name |
Type |
Description |
result |
bool |
The returned result. true: normal. false: error. |
// evnet handler
EventHandler handler = new EventHandler() {
@Override
public void handle(Message message) {
EventTopicsMessage eventTopicsMessage = (EventTopicsMessage) message;
//code
}
};
// add contract
List<String> topics = new ArrayList<>();
topics.add("call_contract");
// listen topics
boolean result = sdk.getEventService().listenTopics(topics, handler, EventModelType.PUSH)
listenBlock
You can call this operation to subscribe to block events.
public boolean listenBlock(EventHandler handler, EventModelType type)
Name |
Required |
Type |
Description |
topics |
true |
List |
The topic list to be subscribed to. |
handler |
true |
EventHandler |
A callback is called when a response is received or when a timeout or error occurs. |
type |
true |
EventModelType |
The type of the event model. 1: PULL. 2: PUSH |
Name |
Type |
Description |
result |
bool |
The returned result. true: normal. false: error. |
// event handler
EventHandler handler = new EventHandler() {
@Override
public void handle(Message message) {
// code
}
};
// listen block
boolean result = sdk.getEventService().listenBlock(handler, EventModelType.PUSH)
unListenAccount
You can call this operation to unsubscribe account events.
sdk.getEventService().unListenAccount(identity)
Name |
Required |
Type |
Description |
identity |
true |
Identity |
The identity of the account to be unsubscribed. |
unListenContract
You can call this operation to unsubscribe contract events.
public boolean unListenContract(Identity identity)
Name |
Required |
Type |
Description |
identity |
true |
Identity |
The identifier of a canceled contract subscription. |
unListenTopics
You can call this operation to unsubscribe topic events.
public boolean unListenTopics(List<String> topics)
Name |
Required |
Type |
Description |
topics |
true |
List |
The topic list to be unsubscribed. |
unListenBlock
You can call this operation to unsubscribe block events.
public boolean unListenBlock()