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 = 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    }