Monitoring shared states
To monitor changes to a shared state, register an event listener by using registerListener API. You need to pass a com.adobe.eventType.hub event type and a com.adobe.eventSource.sharedState event source. This listener is now be called when the shared state changes for any extension. To check an extension’s or an internal module’s shared state, check the stateowner key in the event data.
In the example below, you can find the listener that is being registered in the extension’s init method and the listener implementation where the shared state check is happening. The extension is checking for changes to the com.adobe.module.configuration shared state.
Android
iOS

Java

MyExtension.java

1
MyExtension(final ExtensionApi extensionApi) {
2
super(extensionApi);
3
ExtensionErrorCallback<ExtensionError> errorCallback = new ExtensionErrorCallback<ExtensionError>() {
4
@Override
5
public void error(final ExtensionError extensionError) {
6
Log.e("MyExtension", String.format("An error occurred while registering MySharedStateListener %d %s", extensionError.getErrorCode(), extensionError.getErrorName()));
7
}
8
};
9
10
getApi().registerEventListener("com.adobe.eventType.hub", "com.adobe.eventSource.sharedState", MySharedStateListener.class, errorCallback);
11
}
Copied!

MySharedStateListener.java

1
@Override
2
public void hear(final Event event) {
3
Map<String, Object> eventData = event.getEventData();
4
if (eventData == null) {
5
return;
6
}
7
8
String stateOwner = (String) eventData.get("stateowner");
9
if ("com.adobe.module.configuration".equals(stateOwner)) {
10
// do something with the updated configuration information
11
}
12
}
Copied!

Objective-C

MyExtension.m

1
- (instancetype) init {
2
NSError* error = nil;
3
if ([self.api registerListener: [MyExtensionListener class] eventType:@"com.adobe.eventType.hub" eventSource:@"com.adobe.eventSource.sharedState" error:&error]) {
4
NSLog(@"MyExtensionListener was registered");
5
} else if (error) {
6
NSLog(@"An error occured while registering MyExtensionListener: %ld", [error code]);
7
}
8
}
Copied!

MyExtensionListener.m

1
- (void) hear:(ACPExtensionEvent *)event {
2
NSDictionary* eventDataDict = event.eventData;
3
NSString* stateowner = [eventDataDict objectForKey:@"stateowner"];
4
if (stateowner && [stateowner isEqualToString:@"com.adobe.module.configuration"]) {
5
// do something with the updated configuration information
6
}
7
}
Copied!
Last modified 5mo ago
Export as PDF
Copy link