001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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 = new StopWatch();
037    
038                    stopWatch.start();
039    
040                    if (_log.isInfoEnabled()) {
041                            _log.info(
042                                    "Sending notifications for {mailId=" +
043                                            subscriptionSender.getMailId() + "}");
044                    }
045    
046                    subscriptionSender.flushNotifications();
047    
048                    if (_log.isInfoEnabled()) {
049                            _log.info(
050                                    "Sending notifications for {mailId=" +
051                                            subscriptionSender.getMailId() + "} completed in " +
052                                                    (stopWatch.getTime() / Time.SECOND) + " seconds");
053                    }
054            }
055    
056            private static Log _log = LogFactoryUtil.getLog(
057                    SubscriptionSenderMessageListener.class);
058    
059    }