Uploaded image for project: 'Smack'
  1. Smack
  2. SMACK-314

Don't use static initializers to load extensions

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 3.1.0
    • Fix Version/s: None
    • Component/s: Extensions
    • Labels:
      None

      Description

      As described in the forum, use of static initializers prevents extensions from being extended. This is because even if an extension class does not appear in smack-config.xml, if it is imported or otherwise referenced from another class (say, by a subclass that wants to modify an extension's behavior) that extension is still loaded via the static initializer. In many cases the initialization involves creating and attaching a packetListener or connectionListener that is difficult if not impossible to remove once it's been created. The end result is that it is not possible to subclass or otherwise modify extensions short of copying or reimplementing the code.

      My proposal (on the forum link) modifies the extension mechanism slightly so there is an interface with an 'initialize' method that is explicitly called. This not only removes the 'automatic initialization as soon as the class loaded,' but it also allows code to override and extend an extension class using standard Java OOP practices.

      I'll work on creating a patch and test case but wanted to create the issue for now. I believe it can be implemented in a backward-compatible manner with existing extensions. If there are any other concerns with this proposal please let me know.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              tomstrummer Tom Nichols
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: