[jboss-cvs] JBossAS SVN: r110417 - in projects/jboss-jca/trunk: adapters and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 20 14:41:24 EST 2011
Author: jesper.pedersen
Date: 2011-01-20 14:41:23 -0500 (Thu, 20 Jan 2011)
New Revision: 110417
Added:
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/MailResourceAdapter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/IMAPMailFolder.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/IMAPsMailFolder.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailActivation.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailActivationSpec.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailFolder.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailListener.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/NewMsgsWorker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/POP3MailFolder.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/POP3sMailFolder.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/package.html
projects/jboss-jca/trunk/adapters/src/main/resources/mail/
projects/jboss-jca/trunk/adapters/src/main/resources/mail/META-INF/
projects/jboss-jca/trunk/adapters/src/main/resources/mail/META-INF/ra.xml
Modified:
projects/jboss-jca/trunk/adapters/build.xml
projects/jboss-jca/trunk/build.xml
projects/jboss-jca/trunk/ivy.xml
projects/jboss-jca/trunk/lib/
Log:
[JBJCA-493] Mail resource adapter
Modified: projects/jboss-jca/trunk/adapters/build.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/build.xml 2011-01-20 16:41:17 UTC (rev 110416)
+++ projects/jboss-jca/trunk/adapters/build.xml 2011-01-20 19:41:23 UTC (rev 110417)
@@ -82,7 +82,8 @@
index="true"
indexMetaInf="true"
update="true"
- level="9">
+ level="9"
+ includes="**/jdbc/**">
<manifest>
<attribute name="Implementation-Title" value="IronJacamar JDBC Resource Adapter"/>
<attribute name="Implementation-Version" value="${major}.${minor}.${patch}.${type}"/>
@@ -101,6 +102,25 @@
<fileset dir="src/main/resources/jdbc/xa"/>
</jar>
+ <jar destfile="${build.adapters.dir}/${name}-mail.jar"
+ basedir="${build.adapters.dir}/impl"
+ index="true"
+ indexMetaInf="true"
+ update="true"
+ level="9"
+ includes="**/mail/**">
+ <manifest>
+ <attribute name="Implementation-Title" value="IronJacamar Mail Resource Adapter"/>
+ <attribute name="Implementation-Version" value="${major}.${minor}.${patch}.${type}"/>
+ <attribute name="Implementation-Vendor" value="The IronJacamar project (http://www.jboss.org/ironjacamar)"/>
+ <attribute name="Implementation-Vendor-Id" value="org.jboss"/>
+ </manifest>
+ </jar>
+
+ <jar destfile="${target.dir}/mail.rar">
+ <filelist dir="${build.adapters.dir}" files="${name}-mail.jar"/>
+ <fileset dir="src/main/resources/mail"/>
+ </jar>
</target>
<!-- =================================
@@ -253,10 +273,9 @@
<fileset dir="src/main/resources"/>
</copy>
- <copy todir="${build.adapters.dir}">
- <fileset dir="src/test/resources"/>
- </copy>
-
+ <copy todir="${build.adapters.dir}">
+ <fileset dir="src/test/resources"/>
+ </copy>
<copy todir="${build.adapters.dir}/">
<fileset dir="${target.dir}">
@@ -301,10 +320,25 @@
</manifest>
</jar>
+ <jar destfile="${target.dir}/mail-sources.jar"
+ basedir="src/main/java"
+ index="true"
+ indexMetaInf="true"
+ update="true"
+ level="9"
+ includes="**/adapters/mail/**">
+ <manifest>
+ <attribute name="Implementation-Title" value="IronJacamar Adapters Mail - Sources"/>
+ <attribute name="Implementation-Version" value="${major}.${minor}.${patch}.${type}"/>
+ <attribute name="Implementation-Vendor" value="The IronJacamar project (http://www.jboss.org/ironjacamar)"/>
+ <attribute name="Implementation-Vendor-Id" value="org.jboss"/>
+ </manifest>
+ </jar>
+
<mkdir dir="${build.adapters.dir}/docs"/>
- <mkdir dir="${build.adapters.dir}/docs"/>
- <javadoc destdir="${build.adapters.dir}/docs"
+ <mkdir dir="${build.adapters.dir}/docs/jdbc"/>
+ <javadoc destdir="${build.adapters.dir}/docs/jdbc"
doclet="org.jboss.apiviz.APIviz"
docletpathref="sjc.lib.path.id"
author="true"
@@ -323,12 +357,12 @@
<link offline="true" href="http://java.sun.com/j2se/5/docs/api/" packagelistLoc="${java.home}/../docs/api"/>
</javadoc>
- <copy todir="${build.adapters.dir}/docs" overwrite="true">
+ <copy todir="${build.adapters.dir}/docs/jdbc" overwrite="true">
<fileset dir="${tools.dir}/api"/>
</copy>
<jar destfile="${target.dir}/jdbc-local-javadoc.jar"
- basedir="${build.adapters.dir}/docs"
+ basedir="${build.adapters.dir}/docs/jdbc"
index="true"
indexMetaInf="true"
update="true"
@@ -342,7 +376,7 @@
</jar>
<jar destfile="${target.dir}/jdbc-xa-javadoc.jar"
- basedir="${build.adapters.dir}/docs"
+ basedir="${build.adapters.dir}/docs/jdbc"
index="true"
indexMetaInf="true"
update="true"
@@ -355,6 +389,44 @@
</manifest>
</jar>
+ <mkdir dir="${build.adapters.dir}/docs/mail"/>
+ <javadoc destdir="${build.adapters.dir}/docs/mail"
+ doclet="org.jboss.apiviz.APIviz"
+ docletpathref="sjc.lib.path.id"
+ author="true"
+ version="true"
+ windowtitle="IronJacamar Mail Adapter - API"
+ doctitle="IronJacamar Mail Adapter - API"
+ use="true"
+ additionalparam="-author -version"
+ classpath="${build.adapters.dir}"
+ classpathref="sjc.lib.path.id"
+ bottom="Copyright © 2008 Red Hat Middleware LLC (http://www.jboss.com/)">
+
+ <packageset dir="src/main/java" defaultexcludes="yes">
+ <include name="**/adapters/mail/**"/>
+ </packageset>
+
+ <link offline="true" href="http://java.sun.com/j2se/5/docs/api/" packagelistLoc="${java.home}/../docs/api"/>
+ </javadoc>
+ <copy todir="${build.adapters.dir}/docs/mail" overwrite="true">
+ <fileset dir="${tools.dir}/api"/>
+ </copy>
+
+ <jar destfile="${target.dir}/mail-javadoc.jar"
+ basedir="${build.adapters.dir}/docs/mail"
+ index="true"
+ indexMetaInf="true"
+ update="true"
+ level="9">
+ <manifest>
+ <attribute name="Implementation-Title" value="IronJacamar Adapters Mail - JavaDoc"/>
+ <attribute name="Implementation-Version" value="${major}.${minor}.${patch}.${type}"/>
+ <attribute name="Implementation-Vendor" value="The IronJacamar project (http://www.jboss.org/ironjacamar)"/>
+ <attribute name="Implementation-Vendor-Id" value="org.jboss"/>
+ </manifest>
+ </jar>
+
</target>
</project>
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/MailResourceAdapter.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/MailResourceAdapter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/MailResourceAdapter.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail;
+
+import org.jboss.jca.adapters.mail.inflow.MailActivation;
+import org.jboss.jca.adapters.mail.inflow.MailActivationSpec;
+import org.jboss.jca.adapters.mail.inflow.NewMsgsWorker;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.resource.NotSupportedException;
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkManager;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.logging.Logger;
+
+/**
+ * The mail resource adapter
+ *
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class MailResourceAdapter implements ResourceAdapter
+{
+ /** The logger */
+ private static Logger log = Logger.getLogger(MailResourceAdapter.class);
+
+ /** The bootstrap context */
+ private BootstrapContext ctx;
+
+ /** The activations by activation spec */
+ private ConcurrentHashMap<MailActivationSpec, MailActivation> activations;
+
+ /** The new message worker */
+ private NewMsgsWorker newMsgsWorker;
+
+ /** Queue size */
+ private Integer queueSize;
+
+ /**
+ * Constructor
+ */
+ public MailResourceAdapter()
+ {
+ this.ctx = null;
+ this.activations = new ConcurrentHashMap<MailActivationSpec, MailActivation>();
+ this.newMsgsWorker = null;
+ this.queueSize = Integer.valueOf(1024);
+ }
+
+ /**
+ * Get the queue size
+ * @return The value
+ */
+ public Integer getQueueSize()
+ {
+ return queueSize;
+ }
+
+ /**
+ * Set the queue size
+ * @param v The value
+ */
+ public void setQueueSize(Integer v)
+ {
+ if (v != null && v.intValue() > 0)
+ queueSize = v;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start(BootstrapContext ctx) throws ResourceAdapterInternalException
+ {
+ log.debugf("start");
+
+ this.ctx = ctx;
+
+ WorkManager mgr = ctx.getWorkManager();
+ newMsgsWorker = new NewMsgsWorker(mgr, queueSize);
+
+ try
+ {
+ mgr.scheduleWork(newMsgsWorker);
+ }
+ catch (WorkException e)
+ {
+ throw new ResourceAdapterInternalException(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop()
+ {
+ log.debugf("stop");
+
+ newMsgsWorker.release();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec)
+ throws ResourceException
+ {
+ log.debugf("endpointActivation: endpointFactory=%s,spec=%s", endpointFactory, spec);
+
+ if (spec == null)
+ throw new NotSupportedException("Null MailActivationSpec instance");
+
+ if (!(spec instanceof MailActivationSpec))
+ throw new NotSupportedException("Not a MailActivationSpec instance" + spec.getClass().getName());
+
+ MailActivationSpec mailSpec = (MailActivationSpec)spec;
+ MailActivation activation = new MailActivation(endpointFactory, mailSpec);
+
+ try
+ {
+ newMsgsWorker.watch(activation);
+ activations.put(mailSpec, activation);
+ }
+ catch (InterruptedException e)
+ {
+ throw new ResourceException("Failed to schedule new msg check", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec spec)
+ {
+ log.debugf("endpointDeactivation: endpointFactory=%s,spec=%s", endpointFactory, spec);
+
+ if (spec != null && spec instanceof MailActivationSpec)
+ {
+ MailActivation activation = activations.remove(spec);
+
+ if (activation != null)
+ activation.release();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException
+ {
+ return new XAResource[0];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode()
+ {
+ return super.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean equals(Object other)
+ {
+ return super.equals(other);
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/IMAPMailFolder.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/IMAPMailFolder.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/IMAPMailFolder.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import javax.mail.Flags.Flag;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.NoSuchProviderException;
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.search.SearchTerm;
+
+/**
+ * An IMAP mail folder
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class IMAPMailFolder extends MailFolder
+{
+ /**
+ * Constructor
+ * @param spec The mail activation spec
+ */
+ public IMAPMailFolder(MailActivationSpec spec)
+ {
+ super(spec);
+ }
+
+ /**
+ * Get the messages from a folder
+ * @param folder The folder
+ * @return The messages
+ * @exception MessagingException Thrown if there is an error
+ */
+ protected Message[] getMessages(Folder folder) throws MessagingException
+ {
+ Message[] result = folder.search(new SearchTerm() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean match(Message msg)
+ {
+ try
+ {
+ return !msg.isSet(Flag.SEEN);
+ }
+ catch (MessagingException e)
+ {
+ return false;
+ }
+ }
+ });
+
+ if (result != null && result.length > 0)
+ return result;
+
+ return new Message[0];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Store openStore(Session session) throws NoSuchProviderException
+ {
+ return session.getStore("imap");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void markMessageSeen(Message message) throws MessagingException
+ {
+ message.setFlag(Flag.SEEN, true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void closeStore(boolean success, Store store, Folder folder) throws MessagingException
+ {
+ try
+ {
+ if (folder != null && folder.isOpen())
+ {
+ folder.close(success);
+ }
+ }
+ finally
+ {
+ if (store != null && store.isConnected())
+ {
+ store.close();
+ }
+ }
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/IMAPsMailFolder.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/IMAPsMailFolder.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/IMAPsMailFolder.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import javax.mail.NoSuchProviderException;
+import javax.mail.Session;
+import javax.mail.Store;
+
+/**
+ * An IMAPs mail folder
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class IMAPsMailFolder extends IMAPMailFolder
+{
+ /**
+ * Constructor
+ * @param spec The activation spec
+ */
+ public IMAPsMailFolder(MailActivationSpec spec)
+ {
+ super(spec);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Store openStore(Session session) throws NoSuchProviderException
+ {
+ return session.getStore("imaps");
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailActivation.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailActivation.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailActivation.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import java.lang.reflect.Method;
+
+import javax.mail.Message;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.work.Work;
+
+import org.jboss.logging.Logger;
+
+/**
+ * The MailActivation encapsulates a MailResourceAdapter#endpointActivation
+ *
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class MailActivation implements Comparable, Work
+{
+ /** The logger */
+ private static final Logger log = Logger.getLogger(MailActivation.class);
+
+ /** The MailListener.onMessage method */
+ public static final Method ON_MESSAGE;
+
+ /** A flag indicated if the unit of work has been released */
+ private boolean released;
+
+ /** The time at which the next new msgs check should be performed */
+ private long nextNewMsgCheckTime;
+
+ /** The activation spec for the mail folder */
+ protected MailActivationSpec spec;
+
+ /** The message endpoint factory */
+ protected MessageEndpointFactory endpointFactory;
+
+ static
+ {
+ try
+ {
+ Class[] sig = {Message.class};
+ ON_MESSAGE = MailListener.class.getMethod("onMessage", sig);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Constructor
+ * @param endpointFactory The message endpoint factory
+ * @param spec The mail activation spec
+ */
+ public MailActivation(MessageEndpointFactory endpointFactory, MailActivationSpec spec)
+ {
+ this.endpointFactory = endpointFactory;
+ this.spec = spec;
+ }
+
+ /**
+ * Get the next message check time
+ * @return The value
+ */
+ public long getNextNewMsgCheckTime()
+ {
+ return nextNewMsgCheckTime;
+ }
+
+ /**
+ * Update the next message check time
+ * @param now The current time
+ */
+ public void updateNextNewMsgCheckTime(long now)
+ {
+ nextNewMsgCheckTime = now + spec.getPollingInterval();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo(Object obj)
+ {
+ MailActivation ma = (MailActivation)obj;
+
+ return (int)(nextNewMsgCheckTime - ma.getNextNewMsgCheckTime());
+ }
+
+ /**
+ * Is the activation released ?
+ * @return True if released; otherwise false
+ */
+ public boolean isReleased()
+ {
+ return released;
+ }
+
+ /**
+ * Release the activation
+ */
+ public void release()
+ {
+ released = true;
+
+ log.tracef("released");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ released = false;
+
+ log.tracef("Begin new msgs check");
+
+ try
+ {
+ MailFolder mailFolder = MailFolder.getInstance(spec);
+ mailFolder.open();
+
+ while (mailFolder.hasNext())
+ {
+ Message msg = (Message) mailFolder.next();
+ deliverMsg(msg);
+ }
+
+ mailFolder.close();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to execute folder check, spec=" + spec);
+ }
+
+ log.tracef("End new msgs check");
+ }
+
+ /**
+ * Deliver the message
+ * @param msg The message
+ */
+ private void deliverMsg(Message msg)
+ {
+ MessageEndpoint endpoint = null;
+ try
+ {
+ endpoint = endpointFactory.createEndpoint(null);
+ if (endpoint != null && endpoint instanceof MailListener)
+ {
+ log.tracef("deliverMsg: msg subject=", msg.getSubject());
+
+ MailListener listener = (MailListener)endpoint;
+ listener.onMessage(msg);
+ }
+ }
+ catch (Throwable e)
+ {
+ log.debug("onMessage delivery failure", e);
+ }
+ finally
+ {
+ if (endpoint != null)
+ {
+ endpoint.release();
+ }
+ }
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailActivationSpec.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailActivationSpec.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailActivationSpec.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,362 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import java.io.Serializable;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.InvalidPropertyException;
+import javax.resource.spi.ResourceAdapter;
+
+/**
+ * The encapsulation of the mail folder endpoint specification
+ *
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class MailActivationSpec implements ActivationSpec, Serializable
+{
+ /** @since 1.0 */
+ private static final long serialVersionUID = -3034364895936568423L;
+
+ /** The resource adapter */
+ private transient ResourceAdapter ra;
+
+ /** The mail server hostname/address */
+ private String mailServer = "mailhost";
+
+ /** The mail store protocol */
+ private String storeProtocol = "imap";
+
+ /** The mail folder name */
+ private String mailFolder;
+
+ /** The message selector */
+ private String messageSelector;
+
+ /** The mail store user */
+ private String userName;
+
+ /** The mail store password */
+ private String password;
+
+ /** The new messages check delay in MS */
+ private Long pollingInterval = Long.valueOf(60000L);
+
+ /** The maximum number of messages */
+ private Integer maxMessages = Integer.valueOf(1);
+
+ /** Enable JavaMail debugging*/
+ private Boolean debug;
+
+ /** Flush - for pop3 flush the mailbox after checking */
+ private Boolean flush = Boolean.TRUE;
+
+ /** Starttls - ssl */
+ private Boolean starttls;
+
+ /** The port */
+ private Integer port;
+
+ /**
+ * Constructor
+ */
+ public MailActivationSpec()
+ {
+ }
+
+ /**
+ * Get the mail server
+ * @return The value
+ */
+ public String getMailServer()
+ {
+ return mailServer;
+ }
+
+ /**
+ * Set the mail server
+ * @param mailServer The value
+ */
+ public void setMailServer(String mailServer)
+ {
+ this.mailServer = mailServer;
+ }
+
+ /**
+ * Get the store protocol
+ * @return The value
+ */
+ public String getStoreProtocol()
+ {
+ return storeProtocol;
+ }
+
+ /**
+ * Set the store protocol
+ * @param storeProtocol The value
+ */
+ public void setStoreProtocol(String storeProtocol)
+ {
+ this.storeProtocol = storeProtocol;
+ }
+
+ /**
+ * Get the mail folder
+ * @return The value
+ */
+ public String getMailFolder()
+ {
+ return mailFolder;
+ }
+
+ /**
+ * Set the mail folder
+ * @param mailFolder The value
+ */
+ public void setMailFolder(String mailFolder)
+ {
+ this.mailFolder = mailFolder;
+ }
+
+ /**
+ * Get the message selector
+ * @return The value
+ */
+ public String getMessageSelector()
+ {
+ return messageSelector;
+ }
+
+ /**
+ * Set the message selector
+ * @param messageSelector The value
+ */
+ public void setMessageSelector(String messageSelector)
+ {
+ this.messageSelector = messageSelector;
+ }
+
+ /**
+ * Get the user name
+ * @return The value
+ */
+ public String getUserName()
+ {
+ return userName;
+ }
+
+ /**
+ * Set the user name
+ * @param userName The value
+ */
+ public void setUserName(String userName)
+ {
+ this.userName = userName;
+ }
+
+ /**
+ * Get the password
+ * @return The value
+ */
+ public String getPassword()
+ {
+ return password;
+ }
+
+ /**
+ * Set the password
+ * @param password The value
+ */
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ /**
+ * Get the polling interval
+ * @return The value
+ */
+ public Long getPollingInterval()
+ {
+ return pollingInterval;
+ }
+
+ /**
+ * Set the polling interval
+ * @param pollingInterval The value
+ */
+ public void setPollingInterval(Long pollingInterval)
+ {
+ this.pollingInterval = pollingInterval;
+ }
+
+ /**
+ * Get the max messages
+ * @return The value
+ */
+ public Integer getMaxMessages()
+ {
+ return maxMessages;
+ }
+
+ /**
+ * Set the max messages
+ * @param maxMessages The value
+ */
+ public void setMaxMessages(Integer maxMessages)
+ {
+ this.maxMessages = maxMessages;
+ }
+
+ /**
+ * Get the max messages
+ * @return The value
+ */
+ public Boolean isDebug()
+ {
+ return debug;
+ }
+
+ /**
+ * Set the debug
+ * @param debug The value
+ */
+ public void setDebug(Boolean debug)
+ {
+ this.debug = debug;
+ }
+
+ /**
+ * Get the port
+ * @return The value
+ */
+ public Integer getPort()
+ {
+ return port;
+ }
+
+ /**
+ * Set the port
+ * @param port The value
+ */
+ public void setPort(Integer port)
+ {
+ this.port = port;
+ }
+
+ /**
+ * Get the starttls
+ * @return The value
+ */
+ public Boolean isStarttls()
+ {
+ return starttls;
+ }
+
+ /**
+ * Set the starttls
+ * @param starttls The value
+ */
+ public void setStarttls(Boolean starttls)
+ {
+ this.starttls = starttls;
+ }
+
+ /**
+ * Get the flush
+ * @return The value
+ */
+ public Boolean isFlush()
+ {
+ return flush;
+ }
+
+ /**
+ * Set the flush
+ * @param flush The value
+ */
+ public void setFlush(Boolean flush)
+ {
+ this.flush = flush;
+ }
+
+ /**
+ * Get the resource adapter
+ * @return The value
+ */
+ public ResourceAdapter getResourceAdapter()
+ {
+ return ra;
+ }
+
+ /**
+ * Set the resource adapter
+ * @param ra The value
+ * @exception ResourceException Thrown if an error occurs
+ */
+ public void setResourceAdapter(ResourceAdapter ra) throws ResourceException
+ {
+ this.ra = ra;
+ }
+
+ /**
+ * Validate
+ * @exception InvalidPropertyException Thrown if an error occurs
+ */
+ public void validate() throws InvalidPropertyException
+ {
+ }
+
+ /**
+ * String representation
+ * @return The value
+ */
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer("MailActivationSpec(");
+ tmp.append("mailServer=");
+ tmp.append(mailServer);
+ tmp.append(", storeProtocol=");
+ tmp.append(storeProtocol);
+ tmp.append(", mailFolder=");
+ tmp.append(mailFolder);
+ tmp.append(", pollingInterval=");
+ tmp.append(pollingInterval);
+ tmp.append(", messageSelector=");
+ tmp.append(messageSelector);
+ tmp.append(", userName=");
+ tmp.append(userName);
+ tmp.append(", maxMessages=");
+ tmp.append(maxMessages);
+ tmp.append(", debug=");
+ tmp.append(debug);
+ tmp.append(", starttls=");
+ tmp.append(starttls);
+ tmp.append(", port=");
+ tmp.append(port);
+ tmp.append(")");
+ return tmp.toString();
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailFolder.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailFolder.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailFolder.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,230 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.NoSuchProviderException;
+import javax.mail.Session;
+import javax.mail.Store;
+
+/**
+ * An encapsulation of a mail store folder used by the MailActivation.run to
+ * poll and retrieve new messages.
+ *
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public abstract class MailFolder implements Iterator
+{
+ private Session session;
+ private Store store;
+ private Folder folder;
+ private String mailServer;
+ private String folderName;
+ private String userName;
+ private String password;
+ private Integer port;
+ private Boolean debug;
+ private Boolean starttls;
+ private Properties sessionProps;
+
+ private Message[] msgs = {};
+ private int messagePosition;
+
+ /**
+ * Constructor
+ * @param spec The mail activation spec
+ */
+ public MailFolder(MailActivationSpec spec)
+ {
+ mailServer = spec.getMailServer();
+ folderName = spec.getMailFolder();
+ userName = spec.getUserName();
+ password = spec.getPassword();
+ debug = spec.isDebug();
+ starttls = spec.isStarttls();
+ port = spec.getPort();
+
+ sessionProps = new Properties();
+ sessionProps.setProperty("mail.transport.protocol", "smtp");
+ sessionProps.setProperty("mail.smtp.host", mailServer);
+ sessionProps.setProperty("mail.debug", debug + "");
+
+ // JavaMail doesn't implement POP3 STARTTLS
+ sessionProps.setProperty("mail.imap.starttls.enable", starttls + "");
+ }
+
+ /**
+ * Open a mail session
+ * @exception Exception Thrown if a session can't be established
+ */
+ public void open() throws Exception
+ {
+ // Get a session object
+ session = Session.getInstance(sessionProps);
+ session.setDebug(debug);
+ // Get a store object
+ store = openStore(session);
+ if (port == 0)
+ {
+ store.connect(mailServer, userName, password);
+ }
+ else
+ {
+ store.connect(mailServer, port, userName, password);
+ }
+ folder = store.getFolder(folderName);
+
+ if (folder == null || (!this.folder.exists()))
+ {
+ MessagingException e = new MessagingException("Failed to find folder: " + folderName);
+ throw e;
+ }
+
+ folder.open(Folder.READ_WRITE);
+ msgs = getMessages(folder);
+ }
+
+ /**
+ * Closes the mail session
+ * @exception MessagingException Thrown if an error occurs duing close
+ */
+ public void close() throws MessagingException
+ {
+ close(true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasNext()
+ {
+ return messagePosition < msgs.length;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object next()
+ {
+ try
+ {
+ Message m = msgs[messagePosition++];
+ markMessageSeen(m);
+ return m;
+ }
+ catch (MessagingException e)
+ {
+ close(false);
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Closes a mail session
+ * @param checkSuccessful Check if it was a successful close
+ */
+ protected void close(boolean checkSuccessful)
+ {
+ try
+ {
+ closeStore(checkSuccessful, store, folder);
+ }
+ catch (MessagingException e)
+ {
+ throw new RuntimeException("Error closing mail store", e);
+ }
+ }
+
+ /**
+ * Get an instance of a mail folder
+ * @param mailActivationSpec The mail activation spec
+ * @return The mail folder; <code>null</code> if not IMAP / POP based
+ */
+ public static MailFolder getInstance(MailActivationSpec mailActivationSpec)
+ {
+ if ("pop3".equals(mailActivationSpec.getStoreProtocol()))
+ {
+ return new POP3MailFolder(mailActivationSpec);
+ }
+ else if ("imap".equals(mailActivationSpec.getStoreProtocol()))
+ {
+ return new IMAPMailFolder(mailActivationSpec);
+ }
+ else if ("pop3s".equals(mailActivationSpec.getStoreProtocol()))
+ {
+ return new POP3sMailFolder(mailActivationSpec);
+ }
+ else if ("imaps".equals(mailActivationSpec.getStoreProtocol()))
+ {
+ return new IMAPsMailFolder(mailActivationSpec);
+ }
+
+ return null;
+ }
+
+ /**
+ * Open a store
+ * @param session The mail session
+ * @return The store
+ * @exception NoSuchProviderException Thrown if there is no provider
+ */
+ protected abstract Store openStore(Session session) throws NoSuchProviderException;
+
+ /**
+ * Close a store
+ * @param success Check for successful close
+ * @param store The store
+ * @param folder The folder
+ * @exception MessagingException Thrown if there is an error
+ */
+ protected abstract void closeStore(boolean success, Store store, Folder folder) throws MessagingException;
+
+ /**
+ * Get the messages from a folder
+ * @param folder The folder
+ * @return The messages
+ * @exception MessagingException Thrown if there is an error
+ */
+ protected abstract Message[] getMessages(Folder folder) throws MessagingException;
+
+ /**
+ * Mark a message as seen
+ * @param message The messages
+ * @exception MessagingException Thrown if there is an error
+ */
+ protected abstract void markMessageSeen(Message message) throws MessagingException;
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailListener.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailListener.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/MailListener.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import javax.mail.Message;
+
+/**
+ * The message inflow interface an MDB must implement to receive messages
+ * from the JavaMail adaptor.
+ *
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public interface MailListener
+{
+ /**
+ * Calls with a message
+ * @param msg The message
+ */
+ public void onMessage(Message msg);
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/NewMsgsWorker.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/NewMsgsWorker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/NewMsgsWorker.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import java.util.concurrent.PriorityBlockingQueue;
+
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkEvent;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkListener;
+import javax.resource.spi.work.WorkManager;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Handles new messages
+ *
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class NewMsgsWorker implements Work, WorkListener
+{
+ private static Logger log = Logger.getLogger(NewMsgsWorker.class);
+
+ private boolean released;
+
+ private WorkManager mgr;
+
+ private PriorityBlockingQueue<MailActivation> pollQueue;
+
+ /**
+ * Constructor
+ * @param mgr The work manager
+ * @param queueSize The queue size
+ */
+ public NewMsgsWorker(WorkManager mgr, Integer queueSize)
+ {
+ this.mgr = mgr;
+ this.pollQueue = new PriorityBlockingQueue<MailActivation>(queueSize.intValue());
+ }
+
+ /**
+ * Watch an activation
+ * @param activation The activation
+ * @exception InterruptedException Thrown if the queue is interrupted
+ */
+ public void watch(MailActivation activation) throws InterruptedException
+ {
+ activation.updateNextNewMsgCheckTime(System.currentTimeMillis());
+
+ pollQueue.put(activation);
+ }
+
+ /**
+ * Release
+ */
+ public void release()
+ {
+ released = true;
+
+ log.tracef("released");
+ }
+
+ /**
+ * Run
+ */
+ public void run()
+ {
+ log.tracef("Begin run");
+
+ while (!released)
+ {
+ try
+ {
+ MailActivation ma = (MailActivation) pollQueue.take();
+
+ // Wait until its time to check for new msgs
+ long now = System.currentTimeMillis();
+ long nextTime = ma.getNextNewMsgCheckTime();
+ long sleepMS = nextTime - now;
+
+ if (sleepMS > 0)
+ Thread.sleep(sleepMS);
+
+ if (released)
+ break;
+
+ // This has to go after the sleep otherwise we can get into an inconsistent state
+ if (ma.isReleased())
+ continue;
+
+ // Now schedule excecution of the new msg check
+ mgr.scheduleWork(ma, WorkManager.INDEFINITE, null, this);
+ }
+ catch (InterruptedException e)
+ {
+ log.warn("Interrupted waiting for new msg check", e);
+ }
+ catch (WorkException e)
+ {
+ log.warn("Failed to schedule new msg check", e);
+ }
+ }
+
+ log.tracef("End run");
+ }
+
+ /**
+ * Work accepted
+ * @param e The event
+ */
+ public void workAccepted(WorkEvent e)
+ {
+ log.tracef("workAccepted: e=%s", e);
+ }
+
+ /**
+ * Work rejected
+ * @param e The event
+ */
+ public void workRejected(WorkEvent e)
+ {
+ log.tracef("workRejected: e=%s", e);
+ }
+
+ /**
+ * Work started
+ * @param e The event
+ */
+ public void workStarted(WorkEvent e)
+ {
+ log.tracef("workStarted: e=%s", e);
+ }
+
+ /**
+ * Work completed
+ * @param e The event
+ */
+ public void workCompleted(WorkEvent e)
+ {
+ log.tracef("workCompleted: e=%s", e);
+
+ MailActivation activation = (MailActivation) e.getWork();
+ try
+ {
+ watch(activation);
+ }
+ catch (InterruptedException ex)
+ {
+ log.warn("Failed to reschedule new msg check", ex);
+ }
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/POP3MailFolder.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/POP3MailFolder.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/POP3MailFolder.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import javax.mail.Flags.Flag;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.NoSuchProviderException;
+import javax.mail.Session;
+import javax.mail.Store;
+
+/**
+ * Represents a POP3 mail folder
+ *
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class POP3MailFolder extends MailFolder
+{
+ private boolean flush;
+
+ /**
+ * Constructor
+ * @param spec The mail activation
+ */
+ public POP3MailFolder(MailActivationSpec spec)
+ {
+ super(spec);
+ this.flush = spec.isFlush();
+ }
+
+ /**
+ * Get the messages from a folder
+ * @param folder The folder
+ * @return The messages
+ * @exception MessagingException Thrown if there is an error
+ */
+ protected Message[] getMessages(Folder folder) throws MessagingException
+ {
+ return folder.getMessages();
+ }
+
+ /**
+ * Open a store
+ * @param session The mail session
+ * @return The store
+ * @exception NoSuchProviderException Thrown if there is no provider
+ */
+ protected Store openStore(Session session) throws NoSuchProviderException
+ {
+ return session.getStore("pop3");
+ }
+
+ /**
+ * Mark a message as seen
+ * @param message The messages
+ * @exception MessagingException Thrown if there is an error
+ */
+ protected void markMessageSeen(Message message) throws MessagingException
+ {
+ message.setFlag(Flag.DELETED, true);
+ }
+
+ /**
+ * Close a store
+ * @param success Check for successful close
+ * @param store The store
+ * @param folder The folder
+ * @exception MessagingException Thrown if there is an error
+ */
+ protected void closeStore(boolean success, Store store, Folder folder) throws MessagingException
+ {
+ try
+ {
+ if (folder != null && folder.isOpen())
+ {
+ folder.close(success && flush);
+ }
+ }
+ finally
+ {
+ if (store != null && store.isConnected())
+ {
+ store.close();
+ }
+ }
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/POP3sMailFolder.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/POP3sMailFolder.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/POP3sMailFolder.java 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.mail.inflow;
+
+import javax.mail.NoSuchProviderException;
+import javax.mail.Session;
+import javax.mail.Store;
+
+/**
+ * Represents a POP3s mail folder
+ *
+ * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class POP3sMailFolder extends POP3MailFolder
+{
+ /**
+ * Constructor
+ * @param spec The mail activation
+ */
+ public POP3sMailFolder(MailActivationSpec spec)
+ {
+ super(spec);
+ }
+
+ /**
+ * Open a store
+ * @param session The mail session
+ * @return The store
+ * @exception NoSuchProviderException Thrown if there is no provider
+ */
+ protected Store openStore(Session session) throws NoSuchProviderException
+ {
+ return session.getStore("pop3s");
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/inflow/package.html 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,3 @@
+<body>
+This package contains the inflow part of the mail resource adapter.
+</body>
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/mail/package.html 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,3 @@
+<body>
+This package contains the mail resource adapter.
+</body>
Added: projects/jboss-jca/trunk/adapters/src/main/resources/mail/META-INF/ra.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/resources/mail/META-INF/ra.xml (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/resources/mail/META-INF/ra.xml 2011-01-20 19:41:23 UTC (rev 110417)
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- $Id: ra.xml 71556 2008-04-01 13:39:35Z adrian at jboss.org $ -->
+
+<connector xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
+ version="1.5">
+
+ <description>JBoss JavaMail Resource Adapter</description>
+ <display-name>JavaMail Adapter</display-name>
+
+ <vendor-name>Red Hat Middleware LLC</vendor-name>
+ <eis-type>JavaMail Adapter</eis-type>
+ <resourceadapter-version>7.0</resourceadapter-version>
+
+ <license>
+ <description>
+ JBoss, Home of Professional Open Source.
+ Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ as indicated by the @author tags. See the copyright.txt file in the
+ distribution for a full listing of individual contributors.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ </description>
+ <license-required>true</license-required>
+ </license>
+
+ <resourceadapter>
+ <resourceadapter-class>org.jboss.jca.adapters.mail.MailResourceAdapter</resourceadapter-class>
+ <config-property>
+ <config-property-name>QueueSize</config-property-name>
+ <config-property-type>java.lang.Integer</config-property-type>
+ <config-property-value>1024</config-property-value>
+ </config-property>
+
+ <inbound-resourceadapter>
+ <messageadapter>
+ <messagelistener>
+ <messagelistener-type>org.jboss.jca.adapters.mail.inflow.MailListener</messagelistener-type>
+ <activationspec>
+ <activationspec-class>org.jboss.jca.adapters.mail.inflow.MailActivationSpec</activationspec-class>
+ <required-config-property>
+ <config-property-name>mailServer</config-property-name>
+ </required-config-property>
+ <required-config-property>
+ <config-property-name>mailFolder</config-property-name>
+ </required-config-property>
+ <required-config-property>
+ <config-property-name>storeProtocol</config-property-name>
+ </required-config-property>
+ </activationspec>
+ </messagelistener>
+ </messageadapter>
+ </inbound-resourceadapter>
+
+ </resourceadapter>
+
+</connector>
Modified: projects/jboss-jca/trunk/build.xml
===================================================================
--- projects/jboss-jca/trunk/build.xml 2011-01-20 16:41:17 UTC (rev 110416)
+++ projects/jboss-jca/trunk/build.xml 2011-01-20 19:41:23 UTC (rev 110417)
@@ -120,6 +120,7 @@
<property name="version.jetty.glassfish" value="2.1.v20100127"/>
<property name="version.jasper" value="glassfish_2.1.0.v201004190952"/>
<property name="version.junit" value="4.8.2"/>
+ <property name="version.mail-api" value="1.4.4"/>
<property name="version.maven" value="2.2.1"/>
<property name="version.slf4j" value="1.5.8"/>
<property name="version.transaction.api" value="1.0.1.GA"/>
@@ -144,6 +145,9 @@
<fileset dir="${lib.dir}/sjc">
<include name="**/*.jar"/>
</fileset>
+ <fileset dir="${lib.dir}/mail">
+ <include name="**/*.jar"/>
+ </fileset>
<fileset dir="${lib.dir}/tools">
<include name="**/*.jar"/>
</fileset>
@@ -165,6 +169,9 @@
<fileset dir="${lib.dir}/arquillian">
<include name="**/*.jar"/>
</fileset>
+ <fileset dir="${lib.dir}/mail">
+ <include name="**/*.jar"/>
+ </fileset>
<fileset dir="${lib.dir}/test">
<include name="**/*.jar"/>
</fileset>
@@ -193,6 +200,9 @@
<fileset dir="${lib.dir}/sjc">
<include name="**/*.jar"/>
</fileset>
+ <fileset dir="${lib.dir}/mail">
+ <include name="**/*.jar"/>
+ </fileset>
<fileset dir="${lib.dir}/test">
<include name="**/*.jar"/>
</fileset>
@@ -242,7 +252,7 @@
================================= -->
<target name="resolve" depends="init">
<ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]"
- conf="common,sjc,embedded,arquillian,jetty,test,tools"
+ conf="common,sjc,embedded,arquillian,jetty,mail,test,tools"
sync="true"/>
</target>
@@ -467,6 +477,9 @@
<fileset dir="${lib.dir}/sjc">
<include name="*.jar"/>
</fileset>
+ <fileset dir="${lib.dir}/mail">
+ <include name="*.jar"/>
+ </fileset>
<fileset dir="${lib.dir}/test">
<include name="*.jar"/>
</fileset>
@@ -517,6 +530,9 @@
<fileset dir="${lib.dir}/sjc">
<include name="*.jar"/>
</fileset>
+ <fileset dir="${lib.dir}/mail">
+ <include name="*.jar"/>
+ </fileset>
<fileset dir="${lib.dir}/test">
<include name="*.jar"/>
</fileset>
@@ -611,6 +627,7 @@
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
<fileset dir="${lib.dir}/jetty" includes="*.jar" />
<fileset dir="${lib.dir}/sjc" includes="*.jar" />
+ <fileset dir="${lib.dir}/mail" includes="*.jar" />
<fileset dir="${lib.dir}/test" includes="*.jar" />
<fileset dir="${lib.dir}/tools" includes="*.jar" />
</classpath>
@@ -649,6 +666,7 @@
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
<fileset dir="${lib.dir}/jetty" includes="*.jar" />
<fileset dir="${lib.dir}/sjc" includes="*.jar" />
+ <fileset dir="${lib.dir}/mail" includes="*.jar" />
<fileset dir="${lib.dir}/test" includes="*.jar" />
<fileset dir="${lib.dir}/tools" includes="*.jar" />
</classpath>
@@ -687,6 +705,7 @@
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
<fileset dir="${lib.dir}/jetty" includes="*.jar" />
<fileset dir="${lib.dir}/sjc" includes="*.jar" />
+ <fileset dir="${lib.dir}/mail" includes="*.jar" />
<fileset dir="${lib.dir}/test" includes="*.jar" />
<fileset dir="${lib.dir}/tools" includes="*.jar" />
</classpath>
@@ -725,6 +744,7 @@
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
<fileset dir="${lib.dir}/jetty" includes="*.jar" />
<fileset dir="${lib.dir}/sjc" includes="*.jar" />
+ <fileset dir="${lib.dir}/mail" includes="*.jar" />
<fileset dir="${lib.dir}/test" includes="*.jar" />
<fileset dir="${lib.dir}/tools" includes="*.jar" />
</classpath>
@@ -763,6 +783,7 @@
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
<fileset dir="${lib.dir}/jetty" includes="*.jar" />
<fileset dir="${lib.dir}/sjc" includes="*.jar" />
+ <fileset dir="${lib.dir}/mail" includes="*.jar" />
<fileset dir="${lib.dir}/test" includes="*.jar" />
<fileset dir="${lib.dir}/tools" includes="*.jar" />
</classpath>
@@ -801,6 +822,7 @@
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
<fileset dir="${lib.dir}/jetty" includes="*.jar" />
<fileset dir="${lib.dir}/sjc" includes="*.jar" />
+ <fileset dir="${lib.dir}/mail" includes="*.jar" />
<fileset dir="${lib.dir}/test" includes="*.jar" />
<fileset dir="${lib.dir}/tools" includes="*.jar" />
</classpath>
@@ -840,6 +862,7 @@
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
<fileset dir="${lib.dir}/jetty" includes="*.jar" />
<fileset dir="${lib.dir}/sjc" includes="*.jar" />
+ <fileset dir="${lib.dir}/mail" includes="*.jar" />
<fileset dir="${lib.dir}/test" includes="*.jar" />
<fileset dir="${lib.dir}/tools" includes="*.jar" />
</classpath>
@@ -1018,7 +1041,7 @@
<fail message="IronJacamar doesn't support JDK 7+ artifacts" if="HAVE_JDK_1.7"/>
<ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]"
- conf="${name}-codegenerator,${name}-common-api,${name}-common-impl,${name}-common-impl-papaki,${name}-common-spi,${name}-core-api,${name}-core-impl,${name}-core-spi,${name}-deployers-common,${name}-deployers-fungal,${name}-embedded,${name}-embedded-arquillian,${name}-spec-api,${name}-validator,${name}-validator-ant,${name}-validator-cli,jdbc-local,jdbc-xa"
+ conf="${name}-codegenerator,${name}-common-api,${name}-common-impl,${name}-common-impl-papaki,${name}-common-spi,${name}-core-api,${name}-core-impl,${name}-core-spi,${name}-deployers-common,${name}-deployers-fungal,${name}-embedded,${name}-embedded-arquillian,${name}-spec-api,${name}-validator,${name}-validator-ant,${name}-validator-cli,jdbc-local,jdbc-xa,mail"
sync="true"/>
<delete file="${target.dir}/release.sh"/>
@@ -1394,6 +1417,22 @@
<snapshot-deploy-file file="snapshot.sh" artifact="jdbc-xa" extension="rar"/>
<snapshot-install-file file="install-snapshot.sh" artifact="jdbc-xa" extension="rar"/>
+ <!-- mail -->
+ <delete file="${target.dir}/mail.xml"/>
+ <ivy:makepom artifactName="mail"
+ conf="mail"
+ ivyfile="${basedir}/ivy.xml"
+ pomfile="${target.dir}/mail.xml"
+ headerFile="${tools.dir}/mvn/HEADER"
+ templatefile="${tools.dir}/mvn/pom.template"
+ printIvyInfo="false">
+ <mapping conf="mail" scope="runtime"/>
+ </ivy:makepom>
+
+ <deploy-file file="release.sh" artifact="mail" extension="rar"/>
+ <snapshot-deploy-file file="snapshot.sh" artifact="mail" extension="rar"/>
+ <snapshot-install-file file="install-snapshot.sh" artifact="mail" extension="rar"/>
+
<chmod file="${target.dir}/release.sh" perm="755"/>
<chmod file="${target.dir}/snapshot.sh" perm="755"/>
<chmod file="${target.dir}/install-snapshot.sh" perm="755"/>
Modified: projects/jboss-jca/trunk/ivy.xml
===================================================================
--- projects/jboss-jca/trunk/ivy.xml 2011-01-20 16:41:17 UTC (rev 110416)
+++ projects/jboss-jca/trunk/ivy.xml 2011-01-20 19:41:23 UTC (rev 110417)
@@ -33,12 +33,13 @@
</description>
</info>
- <configurations defaultconfmapping="common->default;sjc->default;embedded->default;arquillian->default;jetty->default;test->default;tools->default;ironjacamar-codegenerator->default;ironjacamar-common-api->default;ironjacamar-common-impl->default;ironjacamar-common-impl-papaki->default;ironjacamar-common-spi->default;ironjacamar-core-api->default;ironjacamar-core-impl->default;ironjacamar-core-spi->default;ironjacamar-depchain->default;ironjacamar-deployers-common->default;ironjacamar-deployers-fungal->default;ironjacamar-embedded->default;ironjacamar-embedded-arquillian->default;ironjacamar-spec-api->default;ironjacamar-validator->default;ironjacamar-validator-ant->default;ironjacamar-validator-cli->default;ironjacamar-validator-maven->default;jdbc-local->default;jdbc-xa->default">
+ <configurations defaultconfmapping="common->default;sjc->default;embedded->default;arquillian->default;jetty->default;test->default;mail->default;;tools->default;ironjacamar-codegenerator->default;ironjacamar-common-api->default;ironjacamar-common-impl->default;ironjacamar-common-impl-papaki->default;ironjacamar-common-spi->default;ironjacamar-core-api->default;ironjacamar-core-impl->default;ironjacamar-core-spi->default;ironjacamar-depchain->default;ironjacamar-deployers-common->default;ironjacamar-deployers-fungal->default;ironjacamar-embedded->default;ironjacamar-embedded-arquillian->default;ironjacamar-spec-api->default;ironjacamar-validator->default;ironjacamar-validator-ant->default;ironjacamar-validator-cli->default;ironjacamar-validator-maven->default;jdbc-local->default;jdbc-xa->default">
<conf name="common" transitive="false"/>
<conf name="sjc" transitive="false"/>
<conf name="embedded" transitive="false"/>
<conf name="arquillian" transitive="false"/>
<conf name="jetty" transitive="false"/>
+ <conf name="mail" transitive="false"/>
<conf name="test" transitive="false"/>
<conf name="tools" transitive="false"/>
@@ -62,6 +63,7 @@
<conf name="ironjacamar-validator-maven" transitive="false"/>
<conf name="jdbc-local" transitive="false"/>
<conf name="jdbc-xa" transitive="false"/>
+ <conf name="mail" transitive="false"/>
</configurations>
<publications>
@@ -85,6 +87,7 @@
<artifact name="ironjacamar-validator-maven" type="jar"/>
<artifact name="jdbc-local" type="rar"/>
<artifact name="jdbc-xa" type="rar"/>
+ <artifact name="mail" type="rar"/>
</publications>
<dependencies>
@@ -98,6 +101,7 @@
<dependency org="com.github.fungal" name="fungal-cli" rev="${version.fungal}" conf="sjc,ironjacamar-depchain"/>
<dependency org="com.h2database" name="h2" rev="${version.h2}" conf="test"/>
<dependency org="dom4j" name="dom4j" rev="${version.dom4j}" conf="jetty,tools"/>
+ <dependency org="javax.mail" name="mail" rev="${version.mail-api}" conf="mail"/>
<dependency org="javax.validation" name="validation-api" rev="${version.validation-api}" conf="common,ironjacamar-core-impl,ironjacamar-depchain,ironjacamar-deployers-fungal"/>
<dependency org="jdepend" name="jdepend" rev="${version.jdepend}" conf="tools"/>
<dependency org="junit" name="junit" rev="${version.junit}" conf="test"/>
Property changes on: projects/jboss-jca/trunk/lib
___________________________________________________________________
Name: svn:ignore
- *.jar
standalone
test
qe
sjc
common
embedded
jetty
arquillian
tools
ironjacamar-core-api
ironjacamar-deployers-common
ironjacamar-deployers-fungal
ironjacamar-codegenerator
ironjacamar-spec-api
ironjacamar-validator-ant
ironjacamar-validator
ironjacamar-common-impl
ironjacamar-common-impl-papaki
ironjacamar-core-impl
ironjacamar-embedded-arquillian
ironjacamar-embedded
+ *.jar
standalone
test
qe
sjc
common
embedded
jetty
arquillian
mail
tools
ironjacamar-core-api
ironjacamar-deployers-common
ironjacamar-deployers-fungal
ironjacamar-codegenerator
ironjacamar-spec-api
ironjacamar-validator-ant
ironjacamar-validator
ironjacamar-common-impl
ironjacamar-common-impl-papaki
ironjacamar-core-impl
ironjacamar-embedded-arquillian
ironjacamar-embedded
More information about the jboss-cvs-commits
mailing list