Package org.hippoecm.frontend.service
Class ServiceContext
java.lang.Object
org.hippoecm.frontend.service.ServiceContext
- All Implemented Interfaces:
Serializable
,org.apache.wicket.util.io.IClusterable
,IPluginContext
Wrapper class for IPluginContext that keeps a record of what services and trackers are registered and what clusters
are started. These can later be cleaned up by invoking stop().
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
attachTo
(IPluginContext pluginContext) reattach a service context to a plugin context.<T extends org.apache.wicket.util.io.IClusterable>
IServiceReference<T>getReference
(T service) Retrieve a reference that can be stored in a page that is different from the one that contains the plugin.<T extends org.apache.wicket.util.io.IClusterable>
TgetService
(String name, Class<T> clazz) Retrieve a service.<T extends org.apache.wicket.util.io.IClusterable>
List<T>getServices
(String name, Class<T> clazz) Retrieve the full list of services that registered under the service name and that are instances of the class.newCluster
(IClusterConfig template, IPluginConfig parameters) Create a new cluster of plugins.void
registerService
(org.apache.wicket.util.io.IClusterable service, String name) Registers a service with the given name.void
registerTracker
(IServiceTracker<? extends org.apache.wicket.util.io.IClusterable> listener, String name) Registers a service tracker with the given name.void
stop()
Stop clusters that have been started using this service context.void
unregisterService
(org.apache.wicket.util.io.IClusterable service, String name) Unregisters a service from the given name.void
unregisterTracker
(IServiceTracker<? extends org.apache.wicket.util.io.IClusterable> listener, String name) Unregisters a service tracker with the given name.
-
Constructor Details
-
ServiceContext
-
-
Method Details
-
newCluster
Create a new cluster of plugins. The template specifies what services are provided, what services are used and what additional properties can be set for the cluster. The parameters specify the values that are required to create a cluster from the template.Note that clusters that are started during the construction phase will not be able to reference services that have been created in the same phase.
- Specified by:
newCluster
in interfaceIPluginContext
- Parameters:
template
- A cluster template, i.e. a configuration hierarchy whose variables have not yet been expanded. The template contains values such as "${myparam}" that will be expanded.parameters
- The values for the variables in the template.
-
getService
Retrieve a service. The first service that registered under the service name and that is an instance of the class, is returned. Always use an interface for the class name.- Specified by:
getService
in interfaceIPluginContext
-
getServices
public <T extends org.apache.wicket.util.io.IClusterable> List<T> getServices(String name, Class<T> clazz) Retrieve the full list of services that registered under the service name and that are instances of the class. The list is immutable and will not be updated by the system. To receive notifications when services (un)register, use anIServiceTracker
.- Specified by:
getServices
in interfaceIPluginContext
-
getReference
public <T extends org.apache.wicket.util.io.IClusterable> IServiceReference<T> getReference(T service) Retrieve a reference that can be stored in a page that is different from the one that contains the plugin. It is necessary to use these when communicating across pages, e.g. as in the case of a non-ajax modal window.Since the service reference contains a unique id for the service, it can also be used to construct unique service names.
- Specified by:
getReference
in interfaceIPluginContext
-
registerService
Registers a service with the given name. A service can be registered under multiple names.- Specified by:
registerService
in interfaceIPluginContext
-
unregisterService
Unregisters a service from the given name. If the service has been registered under other names as well, it will still be available under those.- Specified by:
unregisterService
in interfaceIPluginContext
-
registerTracker
public void registerTracker(IServiceTracker<? extends org.apache.wicket.util.io.IClusterable> listener, String name) Registers a service tracker with the given name.- Specified by:
registerTracker
in interfaceIPluginContext
-
unregisterTracker
public void unregisterTracker(IServiceTracker<? extends org.apache.wicket.util.io.IClusterable> listener, String name) Unregisters a service tracker with the given name.- Specified by:
unregisterTracker
in interfaceIPluginContext
-
stop
public void stop()Stop clusters that have been started using this service context. Unregister services and trackers that have been registered. -
attachTo
reattach a service context to a plugin context. This operation is only valid if the service context was stopped before.- Parameters:
pluginContext
- the plugin context to attach to.
-