1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * The contents of this file are subject to the terms of the Common Development and
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * Distribution License (the License). You may not use this file except in compliance with the
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * specific language governing permission and limitations under the License.
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * When distributing Covered Software, include this CDDL Header Notice in each file and include
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * Header, with the fields enclosed by brackets [] replaced by your own identifying
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * information: "Portions copyright [year] [name of copyright owner]".
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott * Copyright 2015-2016 ForgeRock AS.
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshottimport com.sun.identity.sm.ServiceConfigManager;
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshottimport com.sun.identity.sm.ServiceSchemaManager;
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * ServiceListeners provides a simplified API for creating appropriate {@link ServiceListener} instances
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * to respond to changes in either Configuration or Schema.
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * This class is intended to reduce the boiler plate code required to enable a service to respond
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * to configuration changes.
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * For an example of usage, the following indicates an example of listening for changes to the
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * global configuration changes in iPlanetAMNamingService.
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * ServiceListeners builder = ...
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * Action action = ... // Implementation to respond when config/service changes.
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * builder.config("iPlanetAMNamingService").global(action).listen();
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * Note: The listener triggering order should be considered non-deterministic. <b>Do not depend
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * on the order</b> of listener triggering.
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott private final PrivilegedAction<SSOToken> action;
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public ServiceListeners(PrivilegedAction<SSOToken> action) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public ListenerBuilder config(String serviceName) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott return new ListenerBuilder(new ServiceConfigManager(serviceName, AccessController.doPrivileged(action)));
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public ListenerBuilder schema(String serviceName) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott return new ListenerBuilder(new ServiceSchemaManager(serviceName, AccessController.doPrivileged(action)));
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott * Builder responsible for providing fluent-like functions for building up
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott * Action instances which will respond to changes in Service configuration.
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott private final Map<ConfigType, Collection<Action>> actions;
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott private ServiceSchemaManager schemaManager = null;
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott private ServiceConfigManager configManager = null;
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott for (ConfigType type : ConfigType.values()) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public ListenerBuilder(ServiceConfigManager configManager) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public ListenerBuilder(ServiceSchemaManager schemaManager) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public ListenerBuilder global(Action action) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public ListenerBuilder organisation(Action action) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public ListenerBuilder schema(Action action) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott ServiceListener listener = new ServiceListener() {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public void schemaChanged(String serviceName, String version) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott for (Action a : actions.get(ConfigType.SCHEMA)) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public void globalConfigChanged(String serviceName, String version, String groupName, String serviceComponent, int type) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott for (Action a : actions.get(ConfigType.GLOBAL)) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott public void organizationConfigChanged(String serviceName, String version, String orgName, String groupName, String serviceComponent, int type) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott for (Action a : actions.get(ConfigType.ORGANISATION)) {
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * A generic listener which will respond to a configuration or schema change event.