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.comet;
016    
017    /**
018     * @author Edward Han
019     * @author Brian Wing Shun Chan
020     */
021    public abstract class BaseCometHandler implements CometHandler {
022    
023            @Override
024            public abstract CometHandler clone();
025    
026            @Override
027            public void destroy() throws CometException {
028                    _cometState = CometState.STATE_CLOSED;
029    
030                    try {
031                            doDestroy();
032                    }
033                    catch (CometException ce) {
034                            throw ce;
035                    }
036                    catch (Exception e) {
037                            throw new CometException(e);
038                    }
039            }
040    
041            @Override
042            public CometSession getCometSession() {
043                    return _cometSession;
044            }
045    
046            @Override
047            public CometState getCometState() {
048                    return _cometState;
049            }
050    
051            @Override
052            public void init(CometSession cometSession) throws CometException {
053                    _cometSession = cometSession;
054                    _cometState = CometState.STATE_READY;
055    
056                    try {
057                            doInit(cometSession);
058                    }
059                    catch (CometException ce) {
060                            throw ce;
061                    }
062                    catch (Exception e) {
063                            throw new CometException(e);
064                    }
065            }
066    
067            @Override
068            public void receiveData(char[] data) throws CometException {
069                    receiveData(new String(data));
070            }
071    
072            protected void doDestroy() throws Exception {
073            }
074    
075            protected void doInit(CometSession cometSession) throws Exception {
076            }
077    
078            private CometSession _cometSession;
079            private CometState _cometState = CometState.STATE_OPEN;
080    
081    }