Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Wiki Markup
{scrollbar}

Tapestry Inversion of Control Container

Main article: Tapestry IoC

Contents

Table of Contents
excludeContents|Tapestry Inversion of Control Container|Related Articles
printablefalse

 

Div
stylefloat:right
titleRelated Articles
classaui-label
Content by Label
showLabelsfalse
showSpacefalse
titleRelated Articles
cqllabel = "ioc" and space = currentSpace()
Wiki Markup
{float:right|background=#eee} {contentbylabel:title=Related Articles|showLabels=false|showSpace=false|space=@self|labels=ioc} {float}

Why do I need to define an interface for my services? Why can't I just use the class itself?

...

This same concern applies to any long-lived resource (a thread, a database connection, a JMS queue connection) that a service may hold onto. Your code needs to know when the application has been undeployed and shutdown. This is actually quite easy, by adding some post-injection logic to your implementation class.

Code Block
controlstrue
languagejava
titleMyServiceImpl.java
linenumberstrue

public class MyServiceImpl implements MyService
{
  private boolean shuttingDown;

  private final Thread workerThread;

  public MyServiceImpl()
  {
    workerThread = new Thread(. . .);
  }

  . . .

  @PostInjection
  public void startupService(RegistryShutdownHub shutdownHub)
  {
    shutdownHub.addRegistryShutdownListener(new Runnable()
    {
      public void run() 
      {
        shuttingDown = true;

        workerThread.interrupt();
      }
    });
  }
}

...

Warning

It is not recommended that MyServiceImpl take RegistryShutdownHub as a constructor parameter and register itself as a listener inside the constructor. Doing so is an example of unsafe publishing, a remote an unlikely but potential thread safety issue.

...

The solution is the @EagerLoad annotation; service implementation classes marked with this annotation are loaded when the Registry is first startup, rather than lazily.

Wiki Markup
{scrollbar}