Class ServiceContext

  • All Implemented Interfaces:
    Serializable, org.apache.wicket.util.io.IClusterable, IPluginContext

    public class ServiceContext
    extends Object
    implements 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:
    Serialized Form
    • Constructor Detail

    • Method Detail

      • newCluster

        public IClusterControl newCluster​(IClusterConfig template,
                                          IPluginConfig parameters)
        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 interface IPluginContext
        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

        public <T extends org.apache.wicket.util.io.IClusterable> T getService​(String name,
                                                                               Class<T> clazz)
        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 interface IPluginContext
      • 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 an IServiceTracker.
        Specified by:
        getServices in interface IPluginContext
      • 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 interface IPluginContext
      • registerService

        public void registerService​(org.apache.wicket.util.io.IClusterable service,
                                    String name)
        Registers a service with the given name. A service can be registered under multiple names.
        Specified by:
        registerService in interface IPluginContext
      • unregisterService

        public void unregisterService​(org.apache.wicket.util.io.IClusterable service,
                                      String name)
        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 interface IPluginContext
      • 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 interface IPluginContext
      • stop

        public void stop()
        Stop clusters that have been started using this service context. Unregister services and trackers that have been registered.
      • attachTo

        public void attachTo​(IPluginContext pluginContext)
        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.