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.kernel.poller;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     */
022    public abstract class BasePollerProcessor implements PollerProcessor {
023    
024            @Override
025            public void receive(
026                            PollerRequest pollerRequest, PollerResponse pollerResponse)
027                    throws PollerException {
028    
029                    try {
030                            doReceive(pollerRequest, pollerResponse);
031                    }
032                    catch (Exception e) {
033                            throw new PollerException(e);
034                    }
035            }
036    
037            @Override
038            public void send(PollerRequest pollerRequest) throws PollerException {
039                    try {
040                            doSend(pollerRequest);
041                    }
042                    catch (Exception e) {
043                            throw new PollerException(e);
044                    }
045            }
046    
047            protected abstract void doReceive(
048                            PollerRequest pollerRequest, PollerResponse pollerResponse)
049                    throws Exception;
050    
051            protected abstract void doSend(PollerRequest pollerRequest)
052                    throws Exception;
053    
054            protected boolean getBoolean(PollerRequest pollerRequest, String name) {
055                    return getBoolean(pollerRequest, name, GetterUtil.DEFAULT_BOOLEAN);
056            }
057    
058            protected boolean getBoolean(
059                    PollerRequest pollerRequest, String name, boolean defaultValue) {
060    
061                    return GetterUtil.getBoolean(
062                            pollerRequest.getParameterMap().get(name), defaultValue);
063            }
064    
065            protected double getDouble(PollerRequest pollerRequest, String name) {
066                    return getDouble(pollerRequest, name, -1);
067            }
068    
069            protected double getDouble(
070                    PollerRequest pollerRequest, String name, double defaultValue) {
071    
072                    return GetterUtil.getDouble(
073                            pollerRequest.getParameterMap().get(name), defaultValue);
074            }
075    
076            protected int getInteger(PollerRequest pollerRequest, String name) {
077                    return getInteger(pollerRequest, name, -1);
078            }
079    
080            protected int getInteger(
081                    PollerRequest pollerRequest, String name, int defaultValue) {
082    
083                    return GetterUtil.getInteger(
084                            pollerRequest.getParameterMap().get(name), defaultValue);
085            }
086    
087            protected long getLong(PollerRequest pollerRequest, String name) {
088                    return getLong(pollerRequest, name, -1);
089            }
090    
091            protected long getLong(
092                    PollerRequest pollerRequest, String name, long defaultValue) {
093    
094                    return GetterUtil.getLong(
095                            pollerRequest.getParameterMap().get(name), defaultValue);
096            }
097    
098            protected String getString(PollerRequest pollerRequest, String name) {
099                    return getString(pollerRequest, name, null);
100            }
101    
102            protected String getString(
103                    PollerRequest pollerRequest, String name, String defaultValue) {
104    
105                    return GetterUtil.getString(
106                            pollerRequest.getParameterMap().get(name), defaultValue);
107            }
108    
109    }