Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Integrating Exhibitor

Randgalt edited this page Mar 1, 2012 · 10 revisions

Exhibitor can be integrated into an existing application or you can build an extended application around it. Use the exhibitor-core artifact for this.

JAX-RS Implementation

You need to choose a JAX-RS implementation. The industry standard is Jersey. TBD

Container

Exhibitor must be part of a Java Web Application Container. Some common containers are:

  • Tomcat
  • Jetty
  • JBoss

SPI

You will need to write implementations (or use supplied defaults) for several interfaces:

Class Default Implementation(s) Description
BackupSource FileBasedBackupSource Used to backup/restore ZooKeeper data
GlobalSharedConfig FileBasedGlobalSharedConfig
JDBCBasedGlobalSharedConfig
Stores shared configuration between all instances being managed by Exhibitor
ProcessOperations StandardProcessOperations Methods to start/stop/etc. the local ZooKeeper instance

Exhibitor

You must inject/allocate a singleton instance of the Exhibitor class and call its start() method. The Exhibitor constructor takes instances of the SPI objects as arguments. It also takes an instance of InstanceConfig which supplies various configuration values needed to run the local Exhibitor instance. Use the InstanceConfigBuilder to set the various values in InstanceConfig. The only required value is the hostname of the local instance.

UIContext and UIResource

The JAX-RS portion of Exhibitor requires that a singleton instance of UIContext be injected. UIContext implements ContextResolver so it should be simple to add to the JAX-RS implementation you are using. Jersey can be configured to search the CLASSPATH for JAX-RS classes. Otherwise, you can specify them with a Jersey Application object:

final UIContext   context = new UIContext(exhibitor);
DefaultResourceConfig application = new DefaultResourceConfig()
{
    @Override
    public Set<Class<?>> getClasses()
    {
        Set<Class<?>>       classes = new HashSet<Class<?>>();
        classes.add(UIResource.class);
        return classes;
    }

    @Override
    public Set<Object> getSingletons()
    {
        Set<Object>     singletons = new HashSet<Object>();
        singletons.add(context);
        return singletons;
    }
};
ServletContainer container = new ServletContainer(application);
...