Friday, 7 August 2009

Loading the License and Log4J Configuration from an Alternative Location

This article covers how to load the license and Log4J configuration from a non-default location in StreamHub Push Server version 2.0.3 or later.

Default locations

The default location for the license is a file called license.txt in the current working directory or ".". The default location for the Log4J configuration is conf/log4j.xml relative to the current working directory.

Loading from a different location

In order to load the license and Log4J configuration from a different location, we'll need to make use of a different constructor when instantiating the server. Looking at the Javadoc, we find this constructor:

public NIOServer(InetSocketAddress address,
InetSocketAddress streamingAdapterAddress,
URL licenseUrl,
URL log4jConfigurationUrl)
This constructor allows us to specify a URL for the license and logging configuration. The Javadoc also tells us the types of URL we can specify:

  • File URLs e.g. file:///C:/licenses/license.txt
  • Remote URLs e.g.
  • JAR URLs e.g. jar:file:///C:/lib/streamhub-license.jar!/license.txt or jar:!/log4j.xml
  • Classpath URLs via com.streamhub.util.UrlLoader e.g. UrlLoader.load("classpath:/license.txt"), or UrlLoader.load("classpath:/conf/log4j.xml")
As an example, the below starts a server as normal on port 80, loading the license and logging configuration from the classpath. This assumes we have prod.license and prod-logging.xml available on the classpath, perhaps through another JAR.

URL licenseUrl = UrlLoader.load("classpath:/prod.license");
URL loggingUrl = UrlLoader.load("classpath:/prod-logging.xml");
PushServer server = new NIOServer(new InetSocketAddress(80), null, licenseUrl, loggingUrl);
Note: we pass null through as the second parameter to indicate we don't want to start a streaming adapter. Streaming adapters are used to push updates through the server from remote locations and aren't covered in this article. Also, note we make use of the com.streamhub.util.UrlLoader to generate the URLs as classpath resources aren't supported by default in Java.

The second example below loads the files from a remote location, this would usually be an internal location only visible to the server and not accessible by the outside world.

URL licenseUrl = new URL("");
URL loggingUrl = new URL("");
PushServer server = new NIOServer(new InetSocketAddress(80), null, licenseUrl, loggingUrl);
The final example loads the files locally from the filesystem:

URL licenseUrl = new URL("file:///C:/prod/license.txt");
URL loggingUrl = new URL("file:///C:/prod/log4j.xml");
PushServer server = new NIOServer(new InetSocketAddress(80), null, licenseUrl, loggingUrl);
That last example brings this tutorial to an end. We've covered the default locations of license.txt and conf/log4j.xml and how to override them by passing URL arguments to the four parameter constructor. For more detail on the various constructors available, refer to the Javadoc online. More detail on the XML that goes in the Log4J configuration file can be found in the Log4J XML Configuration Primer.

StreamHub Push Server 2.0.3 Released

A new version of the core StreamHub Push Server has just been released. This is a minor release to improve the quality, configurability and documentation. There's a new constructor for specifying alternate locations for the license and log4j configuration. (More info in this blog article). And with this release we've consolidated and published all the documentation externally. Follow the links below for the latest developments:

Wednesday, 5 August 2009

StreamHub GWT Comet Adapter 1.0.2 Released

A new version of the StreamHub GWT Comet Adapter has just been released. It now features full publish/subscribe support bringing it 100% in to line with the StreamHub API. Accompanying this new release is a comprehensive set of Javadocs available to browse online or download as a JAR. Follow the links below: