001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }