001    /**
002     * Copyright (c) 2000-2012 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            public void destroy() throws CometException {
027                    _cometState = CometState.STATE_CLOSED;
028    
029                    try {
030                            doDestroy();
031                    }
032                    catch (CometException ce) {
033                            throw ce;
034                    }
035                    catch (Exception e) {
036                            throw new CometException(e);
037                    }
038            }
039    
040            public CometSession getCometSession() {
041                    return _cometSession;
042            }
043    
044            public CometState getCometState() {
045                    return _cometState;
046            }
047    
048            public void init(CometSession cometSession) throws CometException {
049                    _cometSession = cometSession;
050                    _cometState = CometState.STATE_READY;
051    
052                    try {
053                            doInit(cometSession);
054                    }
055                    catch (CometException ce) {
056                            throw ce;
057                    }
058                    catch (Exception e) {
059                            throw new CometException(e);
060                    }
061            }
062    
063            public void receiveData(char[] data) throws CometException {
064                    receiveData(new String(data));
065            }
066    
067            protected void doDestroy() throws Exception {
068            }
069    
070            protected void doInit(CometSession cometSession) throws Exception {
071            }
072    
073            private CometSession _cometSession;
074            private CometState _cometState = CometState.STATE_OPEN;
075    
076    }