001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.messaging;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.messaging.BaseMessageListener;
020    import com.liferay.portal.kernel.messaging.Message;
021    import com.liferay.portal.kernel.util.Time;
022    import com.liferay.portal.util.SubscriptionSender;
023    
024    import org.apache.commons.lang.time.StopWatch;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class SubscriptionSenderMessageListener extends BaseMessageListener {
030    
031            @Override
032            protected void doReceive(Message message) throws Exception {
033                    SubscriptionSender subscriptionSender =
034                            (SubscriptionSender)message.getPayload();
035    
036                    StopWatch stopWatch = null;
037    
038                    if (_log.isInfoEnabled()) {
039                            stopWatch = new StopWatch();
040    
041                            stopWatch.start();
042    
043                            _log.info(
044                                    "Sending notifications for {mailId=" +
045                                            subscriptionSender.getMailId() + "}");
046                    }
047    
048                    subscriptionSender.flushNotifications();
049    
050                    if (_log.isInfoEnabled()) {
051                            _log.info(
052                                    "Sending notifications for {mailId=" +
053                                            subscriptionSender.getMailId() + "} completed in " +
054                                                    (stopWatch.getTime() / Time.SECOND) + " seconds");
055                    }
056            }
057    
058            private static Log _log = LogFactoryUtil.getLog(
059                    SubscriptionSenderMessageListener.class);
060    
061    }