You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by se...@apache.org on 2001/12/05 23:14:33 UTC

cvs commit: jakarta-james/src/java/org/apache/james/mailrepository MimeMessageJDBCSource.java

serge       01/12/05 14:14:33

  Modified:    src/java/org/apache/james/mailrepository
                        MimeMessageJDBCSource.java
  Log:
  Renamed getSize to getMessageSize on MailImpl level, and corrected implementation bugs accordingly.  Also added check for MimeMessageWrapper so it just gets the size without loading the object unnecessarily.
  
  Revision  Changes    Path
  1.3       +4 -6      jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageJDBCSource.java
  
  Index: MimeMessageJDBCSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageJDBCSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MimeMessageJDBCSource.java	2001/09/11 04:33:08	1.2
  +++ MimeMessageJDBCSource.java	2001/12/05 22:14:33	1.3
  @@ -51,10 +51,10 @@
           this.key = key;
           this.sr = sr;
   
  -        retrieveMessageBodySQL = 
  +        retrieveMessageBodySQL =
               repository.sqlQueries.getSqlString("retrieveMessageBodySQL", true);
           // this is optional
  -        retrieveMessageBodySizeSQL = 
  +        retrieveMessageBodySizeSQL =
               repository.sqlQueries.getSqlString("retrieveMessageBodySizeSQL");
       }
   
  @@ -64,8 +64,6 @@
        * a repository with the entire message in the database, which is how James 1.2 worked.
        */
       public synchronized InputStream getInputStream() throws IOException {
  -        //System.err.println("loading data for " + key + "/" + repository);
  -
           try {
               Connection conn = repository.getConnection();
   
  @@ -101,10 +99,10 @@
       /**
        * Runs a custom SQL statement to check the size of the message body
        */
  -    public synchronized long getSize() throws IOException {
  +    public synchronized long getMessageSize() throws IOException {
           if (retrieveMessageBodySizeSQL == null) {
               //There was no SQL statement for this repository... figure it out the hard way
  -            return super.getSize();
  +            return super.getMessageSize();
           }
   
           try {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: question

Posted by Danny Angus <da...@thought.co.uk>.
I agree with Serge that the easyiest way (at the moment) to insert message
from external sources is to use a JDBC repository.

> you could just stick the messages in the JDBC or file
> mail repositories, and within a minute they should recognize there is a
> message to process.  I know this is the case with the JDBC one (as I move
> messages around all the time on the server), and while I think the file
> repository is caching the list of messages in the spool at the moment, I
> plan to rewrite that repository soon since the Avalon stream repository
> keeps giving problems of file handles not getting closed.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: question

Posted by Serge Knystautas <se...@lokitech.com>.
Getting a reference to the object is more of an Avalon question, and I don't
know how to do that from a different JVM (assuming that's what you want).
Maybe look at how the RMI proposal works, and in turn expose some of the
mail repositories as well.

As for dropping messages into the queue to get processed, if you don't want
to deal with SMTP, you could just stick the messages in the JDBC or file
mail repositories, and within a minute they should recognize there is a
message to process.  I know this is the case with the JDBC one (as I move
messages around all the time on the server), and while I think the file
repository is caching the list of messages in the spool at the moment, I
plan to rewrite that repository soon since the Avalon stream repository
keeps giving problems of file handles not getting closed.

Serge Knystautas
Loki Technologies - Unstoppable Websites
http://www.lokitech.com/
----- Original Message -----
From: "Lucas Gonze" <lu...@gonze.com>
To: "James Developers List" <ja...@jakarta.apache.org>
Sent: Wednesday, December 05, 2001 6:31 PM
Subject: question


>
> Background: my goal is to pick up messages from external sources, not SMTP
> senders, and drop them into the normal message processing loop.  My class
will
> be a new thread looping on its data source.
>
> I believe that the best way to do this is via the spool manager:
>         spool = (SpoolRepository)
comp.getComponent(Constants.SPOOL_REPOSITORY);
> ...
>         JamesSpoolManager.process(MailImpl myNewMessage)
>
> So my question: how can an external class get a handle to either the
> SpoolRepository or the ComponentManager?  (This may be an Avalon issue?
Don't
> think so.)
>
> Thanks in advance.
>
> - Lucas



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: question

Posted by Lucas Gonze <lu...@gonze.com>.
per Oki:
> I've done it once (for some other reason); it provided nothing but
> headaches (when you are upgrading your James to the latest one, then your
> code might work or might not work). You may just forget it.

That is sound advice.  In the short term, while I'm plumbing my app through, I
just created a stub Mailet to give me access to system objects via
MailetContext.  During the cleanup phase I'll probably repackage as an Avalon
component.

- Lucas


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: question

Posted by Oki DZ <ok...@pindad.com>.
On Thu, 6 Dec 2001, Lucas Gonze wrote:
> A nice n easy solution which allows me to use whatever repository is best,
> including mbox files, but...
> 
>     public void setComponentManager(ComponentManager comp) {
>         this.comp = new SimpleComponentManager(comp);
>     }
> 
>     public void init() throws Exception {
> 
>         logger = (Logger) comp.getComponent(Interfaces.LOGGER);
>         logger.log("JamesSpoolManager init...", "Processor", logger.INFO);
>         spool = (SpoolRepository) comp.getComponent(Constants.SPOOL_REPOSITORY);
>         mailetcontext = (MailetContext)
> comp.getComponent(Interfaces.MAIL_SERVER);
> 
> ..I still need a way to get a handle to comp.

Which version of James do you currently use? I use 1.3-dev:
    public void initialize() throws Exception {

        getLogger().info("JamesSpoolManager init...");
        workerPool = blockContext.getThreadPool( "default" );
        MailStore mailstore
          = (MailStore)
compMgr.lookup("org.apache.james.services.MailStore");
        spool = mailstore.getInboundSpool();
        if (DEEP_DEBUG) getLogger().debug("Got spool: " +
spool.getRepositoryName());

You can get the component compMgr there; which was initialized (by Avalon)
in the JamesSpoolManager.compose(): 

    public void compose(ComponentManager comp) {
        compMgr = new DefaultComponentManager(comp);
    }

Once you get it, then you can get access to other blocks defined in James
(including your other own blocks, of course).
 
> A really easy way to get a handle to the James.comp object is to subclass the
> James class, have the conf file instantiate my subclass, and use my derived
> class when I need to see the handle.  In James.java the comp variable is
> private, so is there an objection to either making it protected or adding an
> accessor method getComponentManager()?

I've done it once (for some other reason); it provided nothing but
headaches (when you are upgrading your James to the latest one, then your 
code might work or might not work). You may just forget it.
 
> The JDBC solution is not bad at all, but a solution that lets me use non-JDBC
> repositories is better.  This solution lets me use any kind of repository.

Yes, the JDBC solution would make you tied to the db repository.

> (n.b.: it's ok if my code is in the same JVM as James.)

Then writing an Avalon block would be the right way. Writing ones would be
quite challenging, but it would be really worthwhile.

Oki



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: question

Posted by Lucas Gonze <lu...@gonze.com>.
> You can write an Avalon block, and then get a handle on the spool
> repository; take a look at JamesSpoolManager.initialize(). Problem is,
> this block would be one of the James blocks, so that the class wouldn't be
> quite external.
>
> Oki

A nice n easy solution which allows me to use whatever repository is best,
including mbox files, but...

    public void setComponentManager(ComponentManager comp) {
        this.comp = new SimpleComponentManager(comp);
    }

    public void init() throws Exception {

        logger = (Logger) comp.getComponent(Interfaces.LOGGER);
        logger.log("JamesSpoolManager init...", "Processor", logger.INFO);
        spool = (SpoolRepository) comp.getComponent(Constants.SPOOL_REPOSITORY);
        mailetcontext = (MailetContext)
comp.getComponent(Interfaces.MAIL_SERVER);

...I still need a way to get a handle to comp.

A really easy way to get a handle to the James.comp object is to subclass the
James class, have the conf file instantiate my subclass, and use my derived
class when I need to see the handle.  In James.java the comp variable is
private, so is there an objection to either making it protected or adding an
accessor method getComponentManager()?

The JDBC solution is not bad at all, but a solution that lets me use non-JDBC
repositories is better.  This solution lets me use any kind of repository.
(n.b.: it's ok if my code is in the same JVM as James.)

- Lucas


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: question

Posted by Oki DZ <ok...@pindad.com>.
On Wed, 5 Dec 2001, Lucas Gonze wrote:

> Background: my goal is to pick up messages from external sources, not SMTP 
> senders, and drop them into the normal message processing loop.  My class will 
> be a new thread looping on its data source. 

I think the easiest way is to look into SMTPHandler, and see what it does
before storing the messages into the spool (ie: SMTPHandler.doDATA()) By
using database repository, you could write your class so that it stores
the data (messages?) in the spool. Later, James spool manager would just
pick the messages up and send them out.

BTW, using other kind of repositories will do, but I think the db one is
the easiest to implement; you can just "select" and see whether your class
works as expected.

> So my question: how can an external class get a handle to either the
> SpoolRepository or the ComponentManager?  (This may be an Avalon issue?  Don't
> think so.)

You can write an Avalon block, and then get a handle on the spool
repository; take a look at JamesSpoolManager.initialize(). Problem is,
this block would be one of the James blocks, so that the class wouldn't be
quite external.

Oki




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


question

Posted by Lucas Gonze <lu...@gonze.com>.
Background: my goal is to pick up messages from external sources, not SMTP
senders, and drop them into the normal message processing loop.  My class will
be a new thread looping on its data source.

I believe that the best way to do this is via the spool manager:
        spool = (SpoolRepository) comp.getComponent(Constants.SPOOL_REPOSITORY);
...
        JamesSpoolManager.process(MailImpl myNewMessage)

So my question: how can an external class get a handle to either the
SpoolRepository or the ComponentManager?  (This may be an Avalon issue?  Don't
think so.)

Thanks in advance.

- Lucas


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>