A pattern I've used successfully in the past to access global
resources is to make everything extend from a base class that has
access to the resources. If I declare the resources to be static, the
first class to be loaded will automatically initialize the resource.
Here's an example (since my description doesn't seem too clear):

public class BaseFoo extends Mailet
{
  static MyResourceClass res;
  static
  {
    res = new MyResourceClass();
    // Error checking can also be done here.
  }
}

class Foo extends BaseFoo
{
  // Has access to static res here
}

class Bar extends BaseFoo
{
  // Has access to static res here too
}


On Feb 12, 2008 3:29 PM, Martijn Brinkers <[EMAIL PROTECTED]> wrote:
> But the 'problem' with mailet init is that there is no guranteed order.
> Lets suppose I need to access the global resource from within the init
> of a more than one mailet. Which mailet should initialize the global
> resource? I can, of course, initialize it in every init to make sure
> that the global resource is initialize but that's not something I like.
>
> As an experiment I added my own 'service' to assembly.xml which is
> configured upon startup (the service implements Configurable). This
> seems to be working but somewhere on the WIKI I read that this
> functionality will be 'removed' by giving mailets their own classloader.
>
> Martijn
>
>
> On Tue, 2008-02-12 at 22:09 +0000, Steve Brewin wrote:
> > Hi
> >
> > The Mailet init() method offers the oppurtunity to set things up. As
> > documented here - http://james.apache.org/server/2.3.1/custom_mailet.html -
> > it is called just once as the mailet container is started.
> >
> > -- Steve
> >
> >
> >
> > > -----Original Message-----
> > > From: Martijn Brinkers [mailto:[EMAIL PROTECTED]
> > > Sent: 12 February 2008 20:45
> > > To: James Users List
> > > Subject: Where should I put my initialization code?
> > >
> > >
> > > Hi,
> > >
> > > For my mailets/matchers I need to initialize some global objects upon
> > > start of James. One way to solve this would be to initialize
> > > on demand,
> > > ie when a getter is called for the global object. I would
> > > however prefer
> > > to initialize the objects beforehand because it makes testing somewhat
> > > easier. Is there a way to do this differently with James?
> > > Should I write
> > > a James service for this?
> > >
> > > Martijn
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to