Skip to main content
Version: 6.0-SNAPSHOT
Enterprise Edition
This feature requires Hazelcast Enterprise, a licensed edition of the Hazelcast Platform.

Non-associated Namespaces

You can configure a default namespace with resources that can be used by any data structure that does not have an associated User Code Namespaces defined, or, for example, a partition loss listener. A default namespace is also useful when you are using an API that is not namespace-aware.

You can use static or dynamic configuration to define your default namespace.

Static Configuration​

You can define your default namespace either programmatically or in the hazelcast configuration file.

The default namespace is used for data structure related operations where a specific namespace cannot be explicitly defined. The operation itself must still support User Code Namespaces to be able to use the default namespace, so adding resources to the default namespace is not the equivalent of adding them to the Hazelcast classpath.

For further information on static configuration, see the Static Configuration section.

Programmatically​

To configure a default namespace programmatically, add the following lines to your code:

java
UserCodeNamespaceConfig userCodeNamespaceConfig = new UserCodeNamespaceConfig();
userCodeNamespaceConfig.setName("default");
userCodeNamespaceConfig.addClass(loadClass("org.example.RequiredClass"));
config.getNamespacesConfig().addNamespaceConfig(userCodeNamespaceConfig);

Configuration File​

To configure a default namespace using static configuration in the hazelcast configuration file, complete the following steps:

  1. If not already open, open the hazelcast configuration file in your preferred editor and scroll to the User Code Namespaces section

  2. Define the name of the namespace as default, as follows:

    xml
    <user-code-namespaces enabled="true">
    ...
    <namespace name="default">
    </namespace>
    </user-code-namespaces>
  3. Define the resources

    To define a resource, you must provide, the resource type, and the location (URL) in which the resource can be found.You can also provide an identifier; this is recommended if needed for debugging purposes.

    The resource type can be JAR (jar), JARS IN ZIP (jars-in-zip), or CLASS (class); the following extract provides examples for both of these resource types:

    xml
    <user-code-namespaces enabled="true">
    ...
    <namespace name="default">
    <jar id="jarID">
    <url>file:///yoursrc/class/ucnDefaults/MyJarFile.jar</url>
    </jar>
    <jars-in-zip id="MyJARsInZIPFileID">
    <url>file:///yoursrc/class/ucnDefaults/MyJarZIP.zip</url>
    </jars-in-zip>
    <class id="classId">
    <url>file:///yoursrc/class/ucnDefaults/MyClass.class</url>
    </class>
    </namespace>
    </user-code-namespaces>
  4. Save the file

Dynamic Configuration​

To configure a default namespace using dynamic configuration, add the following to your member.java file:

java
UserCodeNamespaceConfig userCodeNamespaceConfig = new UserCodeNamespaceConfig("default");
UserCodeNamespaceConfig userCodeNamespaceConfig = new UserCodeNamespaceConfig("default");
// Add your resources to the namespace
config.getNamespacesConfig().addNamespaceConfig(userCodeNamespaceConfig);

For further information on dynamic configuration, see the Dynamic Configuration API topic.